Skip to content

Commit

Permalink
Add option to select oxidation states set for the smact_validity func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
AntObi committed Jul 8, 2024
1 parent c9dccb1 commit b45603f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion smact/screening.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,19 @@ def smact_validity(
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.
Args:
composition (Union[pymatgen.core.Composition, str]): Composition/formula to check
use_pauling_test (bool): Whether to use the Pauling electronegativity test
include_alloys (bool): If True, compositions of metal elements will be considered valid
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.
Returns:
bool: True if the composition is valid, False otherwise
Expand All @@ -462,7 +468,31 @@ def smact_validity(
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 = [

Check warning on line 479 in smact/screening.py

View check run for this annotation

Codecov / codecov/patch

smact/screening.py#L474-L479

Added lines #L474 - L479 were not covered by tests
oxi_custom(e.symbol, oxidation_states_set) for e in smact_elems
]
elif oxidation_states_set == "wiki":
warnings.warn(

Check warning on line 483 in smact/screening.py

View check run for this annotation

Codecov / codecov/patch

smact/screening.py#L482-L483

Added lines #L482 - L483 were not covered by tests
"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]

Check warning on line 487 in smact/screening.py

View check run for this annotation

Codecov / codecov/patch

smact/screening.py#L487

Added line #L487 was not covered by tests

else:
raise (

Check warning on line 490 in smact/screening.py

View check run for this annotation

Codecov / codecov/patch

smact/screening.py#L490

Added line #L490 was not covered by tests
Exception(
f'{oxidation_states_set} is not valid. Enter either "default", "icsd", "pymatgen","wiki" or a filepath to a textfile of oxidation states.'
)
)

threshold = np.max(count)
compositions = []
for ox_states in itertools.product(*ox_combos):
Expand Down

0 comments on commit b45603f

Please sign in to comment.