-
Notifications
You must be signed in to change notification settings - Fork 871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking: Update AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
#3270
Conversation
Structure.properties
and Molecule.properties
do not get lost with ASE Atoms
interconversionAseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
I see you @shyuep! 👀😅 I plan to finish this PR later today. |
@janosh: When you're back on GitHub, would you mind helping me out with the |
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
@@ -292,10 +297,14 @@ def test_back_forth(self): | |||
# Molecule --> Atoms --> Molecule --> Atoms | |||
molecule = Molecule.from_file(TEST_FILES_DIR / "acetylene.xyz") | |||
molecule.set_charge_and_spin(-2, spin_multiplicity=3) | |||
molecule.info = {"test": "hi"} | |||
molecule.properties = {"test": "hi"} | |||
atoms = aio.AseAtomsAdaptor.get_atoms(molecule) | |||
molecule_back = aio.AseAtomsAdaptor.get_molecule(atoms) | |||
atoms_back = aio.AseAtomsAdaptor.get_atoms(molecule_back) | |||
for k, v in atoms.todict().items(): | |||
assert str(atoms_back.todict()[k]) == str(v) | |||
assert molecule_back == molecule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't check that the properties
were restored since Molecule.__eq__
doesn't currently look at properties
. I think that'll be unexpected behavior for must users so we should change IMolecule.__eq__
and IStructure.__eq__
even though it's strictly speaking a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that that's worthwhile to change!
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
AseAtomsAdaptor
to handle Structure.properties
/Molecule.properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thanks @arosen93! 👍
@@ -216,12 +217,19 @@ def get_structure(atoms: Atoms, cls: type[Structure] = Structure, **cls_kwargs) | |||
else: | |||
sel_dyn = None | |||
|
|||
# Atoms.info <---> Structure.properties (excluding properties["calc"]) | |||
properties = jsanitize(getattr(atoms, "info", {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janosh: Just wanted to point out one subtlety to you. Currently, we have the mapping: Atoms.info <--> Structure.properties
, since they serve the same purpose between ASE and Pymtatgen, respectively. However, I jsanitize
-d the atoms.info
before assigning it to .properties
to ensure the Structure
/Molecule
object can be (de)serialized since this is often an implicit assumption of Structure
/Molecule
objects but is not necessarily one for ASE Atoms
objects. In practice, this means that there could be some scenarios where a user interconverts between ASE Atoms
and Pymatgen Structure
/Molecule
with some loss of information; namely, if the atoms.info
is modified by jsanitize()
then it can't be restored in its original form. There might be a better solution than this, but I implemented it because oftentimes ASE will dump un-serializable class objects (namely, a Spacegroup
class) into atoms.info
, such as when reading in a CIF with symmetry flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for highlighting! Seems like a good way to go about this for now. I'll keep this in mind if we run into any issues.
Ensure
Structure.properties
andMolecule.properties
do not get lost with ASEAtoms
interconversion.Recent PR that added
properties
: #3264Breaking because
IMolecule.__eq__
andIStructure.__eq__
were changed to checkself.properties == other.properties
. See #3270 (comment).