diff --git a/pymatgen/analysis/elasticity/elastic.py b/pymatgen/analysis/elasticity/elastic.py index d61423018d8..489b19683dc 100644 --- a/pymatgen/analysis/elasticity/elastic.py +++ b/pymatgen/analysis/elasticity/elastic.py @@ -599,7 +599,6 @@ def get_tgt(self, temperature: float | None = None, structure: Structure = None, """ if temperature and not structure: raise ValueError("If using temperature input, you must also include structure") - assert structure # for mypy quad = quad or DEFAULT_QUAD points = quad["points"] @@ -611,7 +610,7 @@ def get_tgt(self, temperature: float | None = None, structure: Structure = None, us = [u / np.linalg.norm(u) for u in np.transpose(us)] for u in us: # TODO: this should be benchmarked - if temperature: + if temperature and structure: c = self.get_heat_capacity(temperature, structure, p, u) num += c * self.get_ggt(p, u) * w denom += c * w diff --git a/pymatgen/core/structure.py b/pymatgen/core/structure.py index 3efa3902025..d75965c692b 100644 --- a/pymatgen/core/structure.py +++ b/pymatgen/core/structure.py @@ -357,6 +357,11 @@ def formula(self) -> str: """Returns the formula as a string.""" return self.composition.formula + @property + def alphabetical_formula(self) -> str: + """Returns the formula as a string.""" + return self.composition.alphabetical_formula + @property def elements(self) -> list[Element | Species | DummySpecies]: """Returns the elements in the structure as a list of Element objects.""" diff --git a/pymatgen/core/units.py b/pymatgen/core/units.py index 94dc97fab8f..6cb3492e71c 100644 --- a/pymatgen/core/units.py +++ b/pymatgen/core/units.py @@ -207,10 +207,10 @@ def __pow__(self, i): def __iter__(self): return iter(self._unit) - def __getitem__(self, i): + def __getitem__(self, i) -> int: return self._unit[i] - def __len__(self): + def __len__(self) -> int: return len(self._unit) def __repr__(self): @@ -254,16 +254,16 @@ def get_conversion_factor(self, new_unit): Args: new_unit: The new unit. """ - uo_base, ofactor = self.as_base_units - un_base, nfactor = Unit(new_unit).as_base_units - units_new = sorted(un_base.items(), key=lambda d: _UNAME2UTYPE[d[0]]) - units_old = sorted(uo_base.items(), key=lambda d: _UNAME2UTYPE[d[0]]) - factor = ofactor / nfactor - for uo, un in zip(units_old, units_new): - if uo[1] != un[1]: - raise UnitError(f"Units {uo} and {un} are not compatible!") - c = ALL_UNITS[_UNAME2UTYPE[uo[0]]] - factor *= (c[uo[0]] / c[un[0]]) ** uo[1] + old_base, old_factor = self.as_base_units + new_base, new_factor = Unit(new_unit).as_base_units + units_new = sorted(new_base.items(), key=lambda d: _UNAME2UTYPE[d[0]]) + units_old = sorted(old_base.items(), key=lambda d: _UNAME2UTYPE[d[0]]) + factor = old_factor / new_factor + for old, new in zip(units_old, units_new): + if old[1] != new[1]: + raise UnitError(f"Units {old} and {new} are not compatible!") + c = ALL_UNITS[_UNAME2UTYPE[old[0]]] + factor *= (c[old[0]] / c[new[0]]) ** old[1] return factor diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index e8f1491d5ac..5b9ffbab798 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -84,6 +84,7 @@ def setUp(self): [[3.8401979337, 0, 0], [1.9200989668, 3.3257101909, 0], [0, -2.2171384943, 3.1355090603]], pbc=(True, True, False), ) + self.V2O3 = IStructure.from_file(f"{TEST_FILES_DIR}/V2O3.cif") @skipIf(not (mcsqs_cmd and enum_cmd), "enumlib or mcsqs executable not present") def test_get_orderings(self): @@ -145,6 +146,13 @@ def test_formula(self): assert self.struct.formula == "Si2" assert self.labeled_structure.formula == "Si2" assert self.propertied_structure.formula == "Si2" + assert self.V2O3.formula == "V4 O6" + + def test_alphabetical_formula(self): + assert self.struct.alphabetical_formula == "Si2" + assert self.labeled_structure.alphabetical_formula == "Si2" + assert self.propertied_structure.alphabetical_formula == "Si2" + assert self.V2O3.alphabetical_formula == "O6 V4" def test_elements(self): assert self.struct.elements == [Element("Si")] diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index 6ef2efe2507..304e0d9063c 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -120,7 +120,7 @@ def test_sets_changed(self): "MVLGWSet.yaml": "104ae93c3b3be19a13b0ee46ebdd0f40ceb96597", "MVLRelax52Set.yaml": "4cfc6b1bd0548e45da3bde4a9c65b3249da13ecd", "PBE54Base.yaml": "ec317781a7f344beb54c17a228db790c0eb49282", - "PBE64Base.yaml": "a0d6cd02c6ff8e24b0005e30c56a33b155c2280b", + "PBE64Base.yaml": "480c41c2448cb25706181de268090618e282b264", "VASPIncarBase.yaml": "19762515f8deefb970f2968fca48a0d67f7964d4", "vdW_parameters.yaml": "04bb09bb563d159565bcceac6a11e8bdf0152b79", }