Skip to content

Commit

Permalink
Add properties to Structure and Molecule (#3264)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
gpetretto and janosh authored Aug 24, 2023
1 parent c56a25a commit f897eaa
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 40 deletions.
4 changes: 4 additions & 0 deletions pymatgen/analysis/gb/grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
oriented_unit_cell: Structure,
validate_proximity: bool = False,
coords_are_cartesian: bool = False,
properties: dict | None = None,
) -> None:
"""
Makes a GB structure, a structure object with additional information
Expand Down Expand Up @@ -109,6 +110,8 @@ def __init__(
that are less than 0.01 Ang apart. Defaults to False.
coords_are_cartesian (bool): Set to True if you are providing
coordinates in Cartesian coordinates. Defaults to False.
properties (dict): dictionary containing properties associated
with the whole GrainBoundary.
"""
self.oriented_unit_cell = oriented_unit_cell
self.rotation_axis = rotation_axis
Expand All @@ -125,6 +128,7 @@ def __init__(
validate_proximity=validate_proximity,
coords_are_cartesian=coords_are_cartesian,
site_properties=site_properties,
properties=properties,
)

def copy(self):
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/magnetism/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,16 @@ def matches_ordering(self, other: Structure) -> bool:
b_positive = CollinearMagneticStructureAnalyzer(other, overwrite_magmom_mode="normalize", make_primitive=False)

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

b_negative = CollinearMagneticStructureAnalyzer(
analyzer = CollinearMagneticStructureAnalyzer(
b_negative, overwrite_magmom_mode="normalize", make_primitive=False
)

b_positive = b_positive.get_structure_with_spin()
b_negative = b_negative.get_structure_with_spin()
analyzer = analyzer.get_structure_with_spin()

return a.matches(b_positive) or a.matches(b_negative)
return a.matches(b_positive) or a.matches(analyzer)

def __str__(self):
"""
Expand Down
Loading

0 comments on commit f897eaa

Please sign in to comment.