-
Notifications
You must be signed in to change notification settings - Fork 21
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 oxidation states option to SMACT validity function #282
Changes from all commits
b45603f
daa9ff0
7a7de52
226f41c
a805bcf
88019d9
cbf7515
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -430,13 +430,21 @@ | |
composition: Union[pymatgen.core.Composition, str], | ||
use_pauling_test: bool = True, | ||
include_alloys: bool = True, | ||
oxidation_states_set: Union[str, bytes, os.PathLike] = "default", | ||
) -> bool: | ||
"""Check if a composition is valid according to the SMACT rules. | ||
|
||
Composition is considered valid if it passes the charge neutrality test and the Pauling electronegativity test. | ||
|
||
Args: | ||
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check | ||
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check. This can be a pymatgen Composition object or a string. | ||
use_pauling_test (bool): Whether to use the Pauling electronegativity test | ||
include_alloys (bool): If True, compositions of metal elements will be considered valid | ||
include_alloys (bool): If True, compositions which only contain metal elements will be considered valid without further checks. | ||
oxidation_states_set (Union[str, bytes, os.PathLike]): A string to choose which set of | ||
oxidation states should be chosen for charge-balancing. Options are 'default', 'icsd', | ||
'pymatgen' and 'wiki' for the default, icsd, pymatgen structure predictor and Wikipedia | ||
(https://en.wikipedia.org/wiki/Template:List_of_oxidation_states_of_the_elements) oxidation states respectively. | ||
A filepath to an oxidation states text file can also be supplied. | ||
Comment on lines
+433
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests for the new The Do you want me to generate the unit testing code or open a GitHub issue to track this task? |
||
|
||
Returns: | ||
bool: True if the composition is valid, False otherwise | ||
|
@@ -462,7 +470,31 @@ | |
space = element_dictionary(elem_symbols) | ||
smact_elems = [e[1] for e in space.items()] | ||
electronegs = [e.pauling_eneg for e in smact_elems] | ||
ox_combos = [e.oxidation_states for e in smact_elems] | ||
|
||
if oxidation_states_set == "default" or oxidation_states_set is None: | ||
ox_combos = [e.oxidation_states for e in smact_elems] | ||
elif oxidation_states_set == "icsd": | ||
ox_combos = [e.oxidation_states_icsd for e in smact_elems] | ||
elif oxidation_states_set == "pymatgen": | ||
ox_combos = [e.oxidation_states_sp for e in smact_elems] | ||
elif os.path.exists(oxidation_states_set): | ||
ox_combos = [ | ||
oxi_custom(e.symbol, oxidation_states_set) for e in smact_elems | ||
] | ||
elif oxidation_states_set == "wiki": | ||
warnings.warn( | ||
"This set of oxidation states is sourced from Wikipedia. The results from using this set could be questionable and should not be used unless you know what you are doing and have inspected the oxidation states.", | ||
stacklevel=2, | ||
) | ||
ox_combos = [e.oxidation_states_wiki for e in smact_elems] | ||
|
||
else: | ||
raise ( | ||
Exception( | ||
f'{oxidation_states_set} is not valid. Enter either "default", "icsd", "pymatgen","wiki" or a filepath to a textfile of oxidation states.' | ||
) | ||
) | ||
Comment on lines
+474
to
+496
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor to reduce redundancy. The code for handling different oxi_set = {
"default": [e.oxidation_states for e in smact_elems],
"icsd": [e.oxidation_states_icsd for e in smact_elems],
"pymatgen": [e.oxidation_states_sp for e in smact_elems],
"wiki": [e.oxidation_states_wiki for e in smact_elems],
}
if oxidation_states_set in oxi_set:
ox_combos = oxi_set[oxidation_states_set]
if oxidation_states_set == "wiki":
warnings.warn(
"This set of oxidation states is sourced from Wikipedia. The results from using this set could be questionable and should not be used unless you know what you are doing and have inspected the oxidation states.",
stacklevel=2,
)
elif os.path.exists(oxidation_states_set):
ox_combos = [
oxi_custom(e.symbol, oxidation_states_set) for e in smact_elems
]
else:
raise Exception(
f'{oxidation_states_set} is not valid. Enter either "default", "icsd", "pymatgen","wiki" or a filepath to a textfile of oxidation states.'
) ToolsGitHub Check: codecov/patch
|
||
|
||
threshold = np.max(count) | ||
compositions = [] | ||
for ox_states in itertools.product(*ox_combos): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for new parameter.
The
smact_validity
function includes a new parameteroxidation_states_set
. Ensure that this parameter is thoroughly tested, as it is not currently covered in the test suite.Do you want me to generate the unit testing code or open a GitHub issue to track this task?