Skip to content

Commit f897eaa

Browse files
gpetrettojanosh
andauthored
Add properties to Structure and Molecule (#3264)
* Add 'properties' to Structure and Molecule * add properties in copy methods * fix structure copy * setting structure properties in more places * test struct with props to/from JSON str * assert '"test_property": 42' in json_str * fix Structure properties when reading from string * make Molecule.from_str case insensitive * Molecule.to() support both .yaml and .yml extension * Molecule.from_file() support both .yaml and .yml extension * add .yml test case in TestIMolecule.test_to_from_file_string() * fix NameError: name 'pybel' is not defined in BabelMolAdaptor.from_str() * update properties doc str: mention props be serialized when writing the structure to JSON or YAML but is lost when converting to other formats. * fix mypy * fix test_valid_magmom_struct regex --------- Co-authored-by: Janosh Riebesell <[email protected]>
1 parent c56a25a commit f897eaa

File tree

9 files changed

+147
-40
lines changed

9 files changed

+147
-40
lines changed

pymatgen/analysis/gb/grain.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
oriented_unit_cell: Structure,
6868
validate_proximity: bool = False,
6969
coords_are_cartesian: bool = False,
70+
properties: dict | None = None,
7071
) -> None:
7172
"""
7273
Makes a GB structure, a structure object with additional information
@@ -109,6 +110,8 @@ def __init__(
109110
that are less than 0.01 Ang apart. Defaults to False.
110111
coords_are_cartesian (bool): Set to True if you are providing
111112
coordinates in Cartesian coordinates. Defaults to False.
113+
properties (dict): dictionary containing properties associated
114+
with the whole GrainBoundary.
112115
"""
113116
self.oriented_unit_cell = oriented_unit_cell
114117
self.rotation_axis = rotation_axis
@@ -125,6 +128,7 @@ def __init__(
125128
validate_proximity=validate_proximity,
126129
coords_are_cartesian=coords_are_cartesian,
127130
site_properties=site_properties,
131+
properties=properties,
128132
)
129133

130134
def copy(self):

pymatgen/analysis/magnetism/analyzer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,16 @@ def matches_ordering(self, other: Structure) -> bool:
553553
b_positive = CollinearMagneticStructureAnalyzer(other, overwrite_magmom_mode="normalize", make_primitive=False)
554554

555555
b_negative = b_positive.structure.copy()
556-
b_negative.add_site_property("magmom", np.multiply(-1, b_negative.site_properties["magmom"]))
556+
b_negative.add_site_property("magmom", -np.array(b_negative.site_properties["magmom"]))
557557

558-
b_negative = CollinearMagneticStructureAnalyzer(
558+
analyzer = CollinearMagneticStructureAnalyzer(
559559
b_negative, overwrite_magmom_mode="normalize", make_primitive=False
560560
)
561561

562562
b_positive = b_positive.get_structure_with_spin()
563-
b_negative = b_negative.get_structure_with_spin()
563+
analyzer = analyzer.get_structure_with_spin()
564564

565-
return a.matches(b_positive) or a.matches(b_negative)
565+
return a.matches(b_positive) or a.matches(analyzer)
566566

567567
def __str__(self):
568568
"""

0 commit comments

Comments
 (0)