-
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
Adds support for an MSONAtoms
class that's an MSONable
form of an ASE Atoms
object
#3619
Conversation
PMGAtoms
classPMGAtoms
class that is MSONable
PMGAtoms
class that is MSONable
PMGAtoms
class that is an Atoms
object that is MSONable
PMGAtoms
class that is an Atoms
object that is MSONable
PMGAtoms
class that is simply an MSONable
form of an ASE Atoms
object
PMGAtoms
class that is simply an MSONable
form of an ASE Atoms
objectPMGAtoms
class that's an MSONable
form of an ASE Atoms
object
Signed-off-by: Andrew S. Rosen <[email protected]>
Signed-off-by: Andrew S. Rosen <[email protected]>
PMGAtoms
class that's an MSONable
form of an ASE Atoms
objectMSONableAtoms
class that's an MSONable
form of an ASE Atoms
object
MSONAbleAtoms is a mouthful.How about just call it AtomsM? |
My personal opinion is that descriptive is better than concise. It's not immediately clear what an That said, I agree it's somewhat long. I'm open to other alternatives. |
I would also vote for MSONAbleAtoms or something descriptive. |
Then MSONAtoms? |
Works for me. I'll make the change when I'm at my laptop. |
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.
Looks good to me.
I do have a question, perhaps @Andrew-S-Rosen knows, is lossless conversion to/from Structure
and Atoms
possible? Or are some attributes potentially lost?
@mkhorton Good question. I have spent a fair bit of time on this module to ensure that it is lossless, and there are back-and-forth tests for this as well. If you spot an edge case, please let me know and I will patch it! |
MSONableAtoms
class that's an MSONable
form of an ASE Atoms
objectMSONAtoms
class that's an MSONable
form of an ASE Atoms
object
Signed-off-by: Andrew S. Rosen <[email protected]>
Signed-off-by: Andrew S. Rosen <[email protected]>
@mkhorton there's no remaining known loss of information during unknown remaining edge cases are possible but likely rare |
Thanks @Andrew-S-Rosen . This is great! |
I just pushed a change that ensures MSONAtoms is returned by from_dict. This is supposed to be the case. Otherwise it loses functionality with deserializaation. |
@@ -38,18 +40,41 @@ | |||
__date__ = "Mar 8, 2012" | |||
|
|||
|
|||
class MSONAtoms(Atoms, MSONable): |
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.
Something here breaks imports in cases where the user doesn't have ASE installed. This seems to be breaking the latest mp_api
as a result:
from mp_api.client.mprester import MPRester
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/mp_api/client/__init__.py", line 8, in <module>
from .mprester import MPRester
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/mp_api/client/mprester.py", line 10, in <module>
from emmet.core.electronic_structure import BSPathType
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/emmet/core/electronic_structure.py", line 11, in <module>
from pymatgen.analysis.magnetism.analyzer import (
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/pymatgen/analysis/magnetism/__init__.py", line 5, in <module>
from pymatgen.analysis.magnetism.analyzer import (
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/pymatgen/analysis/magnetism/analyzer.py", line 24, in <module>
from pymatgen.transformations.advanced_transformations import MagOrderingTransformation, MagOrderParameterConstraint
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/pymatgen/transformations/advanced_transformations.py", line 33, in <module>
from pymatgen.io.ase import AseAtomsAdaptor
File "/home/mevans/repos/re2fractive/re2fractive/experiments/2_featurizing_refractive_index_data/.venv-mp-api/lib/python3.11/site-packages/pymatgen/io/ase.py", line 44, in <module>
class MSONAtoms(Atoms, MSONable):
^^^^^
NameError: name 'Atoms' is not defined
Will raise an issue
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.
see #3644
Summary
Here, I introduce the
MSONAtoms
class, which is simply anMSONable
version of the ASEAtoms
object, introducing an.as_dict()
andfrom_dict()
method that uses ASE's JSON encode/decoder to do the serialization. By default, the object returned fromASEAtomsAdaptor.get_atoms()
is now anMSONableAtoms
object. The originalAtoms
class can be returned via themsonable=False
keyword argument, although this should rarely be needed in practice since the functionality ofMSONAtoms
is otherwise identical toAtoms
. This is a follow-up to materialsvirtuallab/monty#619.Checklist
ruff
.mypy
.duecredit
@due.dcite
decorators to reference relevant papers by DOI (example)