Skip to content

Commit

Permalink
rename oxidation_override -> oxi_states_override
Browse files Browse the repository at this point in the history
  • Loading branch information
computron committed Jul 21, 2017
1 parent bba54ca commit 6e1d7c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def to_data_dict(self):
"elements": self.as_dict().keys(),
"nelements": len(self.as_dict().keys())}

def oxi_state_guesses(self, oxidation_override=None, target_charge=0,
def oxi_state_guesses(self, oxi_states_override=None, target_charge=0,
all_oxidation_states=False):
"""
Checks if the composition is charge-balanced and returns back all
Expand All @@ -586,7 +586,7 @@ def oxi_state_guesses(self, oxidation_override=None, target_charge=0,
but X2Y2 is.
Args:
oxidation_override (dict): dict of str->list to override an
oxi_states_override (dict): dict of str->list to override an
element's common oxidation states, e.g. {"V": [2,3,4,5]}
target_charge (int): the desired total charge on the structure.
Default is 0 signifying charge balance.
Expand All @@ -602,7 +602,7 @@ def oxi_state_guesses(self, oxidation_override=None, target_charge=0,
composition is not charge balanced, an empty list is returned.
"""

oxidation_override = oxidation_override or {}
oxi_states_override = oxi_states_override or {}

# assert: Composition only has integer amounts
if not all(amt == int(amt) for amt in self.values()):
Expand All @@ -614,8 +614,8 @@ def oxi_state_guesses(self, oxidation_override=None, target_charge=0,
el_amt = self.get_el_amt_dict()
el_sums = defaultdict(set) # dict of element to possible oxid sums
for el in el_amt:
if oxidation_override.get(el):
oxids = oxidation_override[el]
if oxi_states_override.get(el):
oxids = oxi_states_override[el]
elif all_oxidation_states:
oxids = Element(el).oxidation_states
else:
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/core/tests/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,28 +397,28 @@ def test_oxi_state_guesses(self):
all_oxidation_states=True)), 4)

self.assertEqual(Composition("V2O3").oxi_state_guesses(
oxidation_override={"V": [2, 3, 4, 5]}), [{"V": 3, "O": -2}])
oxi_states_override={"V": [2, 3, 4, 5]}), [{"V": 3, "O": -2}])

# can't balance b/c missing V4+
self.assertEqual(Composition("VO2").oxi_state_guesses(
oxidation_override={"V": [2, 3, 5]}), [])
oxi_states_override={"V": [2, 3, 5]}), [])

# missing V4+, but can balance due to additional sites
self.assertEqual(Composition("V2O4").oxi_state_guesses(
oxidation_override={"V": [2, 3, 5]}), [{"V": 4, "O": -2}])
oxi_states_override={"V": [2, 3, 5]}), [{"V": 4, "O": -2}])

# multiple solutions - Mn/Fe = 2+/4+ or 3+/3+ or 4+/2+
self.assertEqual(len(Composition("MnFeO3").oxi_state_guesses(
oxidation_override={"Mn": [2, 3, 4], "Fe": [2, 3, 4]})), 3)
oxi_states_override={"Mn": [2, 3, 4], "Fe": [2, 3, 4]})), 3)

# multiple solutions prefers 3/3 over 2/4 or 4/2
self.assertEqual(Composition("MnFeO3").oxi_state_guesses(
oxidation_override={"Mn": [2, 3, 4], "Fe": [2, 3, 4]})[0],
oxi_states_override={"Mn": [2, 3, 4], "Fe": [2, 3, 4]})[0],
{"Mn": 3, "Fe": 3, "O": -2})

# target charge of 1
self.assertEqual(Composition("V2O6").oxi_state_guesses(
oxidation_override={"V": [2, 3, 4, 5]}, target_charge=-2),
oxi_states_override={"V": [2, 3, 4, 5]}, target_charge=-2),
[{"V": 5, "O": -2}])


Expand Down

0 comments on commit 6e1d7c7

Please sign in to comment.