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.propertiesAseAtomsAdaptor to handle Structure.properties/Molecule.properties
AseAtomsAdaptor to handle Structure.properties/Molecule.propertiesAseAtomsAdaptor to handle Structure.properties/Molecule.properties
| 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.
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.
I agree that that's worthwhile to change!
…_eq__ and IMolecule.__eq__ see https://github.com/materialsproject/pymatgen/pull/3270/files#r1311253937 for reasoning
AseAtomsAdaptor to handle Structure.properties/Molecule.propertiesAseAtomsAdaptor to handle Structure.properties/Molecule.properties
janosh
left a comment
There was a problem hiding this comment.
Nice work! Thanks @arosen93! 👍
| sel_dyn = None | ||
|
|
||
| # Atoms.info <---> Structure.properties (excluding properties["calc"]) | ||
| properties = jsanitize(getattr(atoms, "info", {})) |
There was a problem hiding this comment.
@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.
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.propertiesandMolecule.propertiesdo not get lost with ASEAtomsinterconversion.Recent PR that added
properties: #3264Breaking because
IMolecule.__eq__andIStructure.__eq__were changed to checkself.properties == other.properties. See #3270 (comment).