def get_oxi_state_decorated_structure(self, structure): """ Get an oxidation state decorated structure. This currently works only for ordered structures only. Args: structure: Structure to analyze Returns: A modified structure that is oxidation state decorated. Raises: A ValueError is the valences cannot be determined. """ valences = self.get_valences(structure) editor = StructureEditor(structure) editor.add_oxidation_state_by_site(valences) return editor.modified_structure
def test_add_oxidation_states(self): si = Element("Si") fe = Element("Fe") coords = list() coords.append([0, 0, 0]) coords.append([0.75, 0.5, 0.75]) lattice = Lattice.cubic(10) s = Structure(lattice, [si, fe], coords) oxidation_states = {"Fe": 2, "Si": -4} mod = StructureEditor(s) mod.add_oxidation_state_by_element(oxidation_states) mod_s = mod.modified_structure for site in mod_s: for k in site.species_and_occu.keys(): self.assertEqual(k.oxi_state, oxidation_states[k.symbol], "Wrong oxidation state assigned!") oxidation_states = {"Fe": 2} self.assertRaises(ValueError, mod.add_oxidation_state_by_element, oxidation_states) mod.add_oxidation_state_by_site([2, -4]) mod_s = mod.modified_structure self.assertEqual(mod_s[0].specie.oxi_state, 2) self.assertRaises(ValueError, mod.add_oxidation_state_by_site, [1])