Skip to content
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

Ensure MSONAtoms is indeed MSONable when Atoms.info is loaded with goodies #3670

Merged
merged 10 commits into from
Mar 4, 2024

Conversation

Andrew-S-Rosen
Copy link
Member

@Andrew-S-Rosen Andrew-S-Rosen commented Mar 4, 2024

Summary

Closes #3668.

The Atoms.info dictionary can be populated with all kinds of goodies that are challenging to deal with from a (de)serialization perspective. Oftentimes, this is from users hacking things into Atoms.info. For instance, in #3668, I put a Structure object in the Atoms.info dictionary, which then broke things during serialization. In order to ensure MSONAtoms plays nice with the (de)serialization routines in monty, it is better to split off the Atoms.info metadata into its own entry in the .as_dict() dictionary that we can sanitize ourselves. That's what I've done in this PR.

The following toy example now works in a round-trip fashion:

from pymatgen.core import Structure
from monty.serialization import dumpfn, loadfn

structure = Structure(
    lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],
    species=["Mg", "O"],
    coords=[[0, 0, 0], [0.5, 0.5, 0.5]],
)
mson_atoms = structure.to_ase_atoms()
mson_atoms.info = {"test": "hi", "s": structure}
dumpfn(mson_atoms, "test.json")
loadfn("test.json")

@Andrew-S-Rosen Andrew-S-Rosen changed the title Ensure MSONAtoms is indeed MSONable [WIP] Ensure MSONAtoms is indeed MSONable Mar 4, 2024
@Andrew-S-Rosen Andrew-S-Rosen changed the title [WIP] Ensure MSONAtoms is indeed MSONable [WIP] Ensure MSONAtoms is indeed MSONable when Atoms.info is loaded with goodies Mar 4, 2024
Andrew-S-Rosen and others added 5 commits March 4, 2024 10:39
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
@Andrew-S-Rosen Andrew-S-Rosen changed the title [WIP] Ensure MSONAtoms is indeed MSONable when Atoms.info is loaded with goodies Ensure MSONAtoms is indeed MSONable when Atoms.info is loaded with goodies Mar 4, 2024
Andrew-S-Rosen and others added 3 commits March 4, 2024 11:56
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
@Andrew-S-Rosen
Copy link
Member Author

All ready to go!

@shyuep shyuep merged commit b96d9e1 into materialsproject:master Mar 4, 2024
22 checks passed
@shyuep
Copy link
Member

shyuep commented Mar 4, 2024

Thanks!

@janosh janosh added enhancement A new feature or improvement to an existing one ux User experience ase Atomic simulation environment serialization Data/object serialization labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ase Atomic simulation environment enhancement A new feature or improvement to an existing one serialization Data/object serialization ux User experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSONAtoms may not serialize appropriately if the .info flag is populated
3 participants