Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Composition.replace() #2282

Closed
janosh opened this issue Oct 28, 2021 · 3 comments
Closed

Add Composition.replace() #2282

janosh opened this issue Oct 28, 2021 · 3 comments

Comments

@janosh
Copy link
Member

janosh commented Oct 28, 2021

Is your feature request related to a problem? Please describe.

Composition does not support elemental substitutions.

Describe the solution you'd like

New method Composition("Fe2O3").replace({"Fe": "Mg"}) similar to Structure.replace_species().

Describe alternatives you've considered

None.

Additional context

Useful when working with data-mined substitution matrices.

@shyuep
Copy link
Member

shyuep commented Oct 28, 2021

Composition is meant to be immutable. Which is why it inherits Mapping and Hashable and not dict or MutableMapping. Composition objects are probably the one of the most used keys in dictionaries and sets. So in place modifications are not allowed. FYI, the above can be easily done using Composition({(k if k.symbol != "Fe" else "Mn"): v for k, v in comp.items()}).

@shyuep shyuep closed this as completed Oct 28, 2021
@shyuep
Copy link
Member

shyuep commented Oct 28, 2021

Just a note that I have no objection if you want to create a method to do substitutions that return a new composition object. But in-place modifications are not supported.

@janosh
Copy link
Member Author

janosh commented Oct 28, 2021

Probably should have stated explicitly that I didn't want this op to be in-place.

@janosh janosh mentioned this issue Oct 29, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants