-
Notifications
You must be signed in to change notification settings - Fork 885
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
Fix from_ase_atoms
for Molecule
#4321
base: master
Are you sure you want to change the base?
Fix from_ase_atoms
for Molecule
#4321
Conversation
ae13e58
to
bd29d18
Compare
bd29d18
to
3ee8056
Compare
@@ -995,19 +995,6 @@ def to_ase_atoms(self, **kwargs) -> Atoms: | |||
|
|||
return AseAtomsAdaptor.get_atoms(self, **kwargs) | |||
|
|||
def from_ase_atoms(self, **kwargs) -> Structure: |
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.
Need careful check on this: AFAIK there is no other concrete class other than IMolecule/IStructure
of the abstract base classSiteCollection
that would reply on inheriting from_ase_atoms
?
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 don't believe there are. Even if there were, then presumably we would currently be missing out on such instances anyway since the pre-existing methods were on Structure
and Molecule
, right?
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.
Is there a problem here in that it will produce an IStructure
rather than a Structure
?
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.
the pre-existing methods were on Structure and Molecule, right?
If I understand the question correctly, current defination of from_ase_atoms
is given by the abstract base case SiteCollection
(from which IStructure/IMolecule
inherit):
pymatgen/src/pymatgen/core/structure.py
Lines 998 to 1009 in 55d0934
def from_ase_atoms(self, **kwargs) -> Structure: | |
"""Convert ase.Atoms to pymatgen Structure. | |
Args: | |
kwargs: Passed to AseAtomsAdaptor.get_structure. | |
Returns: | |
Structure | |
""" | |
from pymatgen.io.ase import AseAtomsAdaptor | |
return AseAtomsAdaptor.get_structure(self, **kwargs) |
Is there a problem here in that it will produce an IStructure rather than a Structure?
Thanks for catching this, this method should give the mutable Structure/Molecule
by default, I would fix the type annotation:
pymatgen/src/pymatgen/io/ase.py
Line 233 in 55d0934
def get_structure(atoms: Atoms, cls: type[Structure] = Structure, **cls_kwargs) -> Structure: |
pymatgen/src/pymatgen/io/ase.py
Lines 307 to 319 in 55d0934
# Return a Molecule object if that was specifically requested; | |
# otherwise return a Structure object as expected | |
if cls == Molecule: | |
structure = cls(symbols, positions, properties=properties, **cls_kwargs) | |
else: | |
structure = cls( | |
Lattice(lattice, pbc=atoms.pbc), | |
symbols, | |
positions, | |
coords_are_cartesian=True, | |
properties=properties, | |
**cls_kwargs, | |
) |
Perhaps we should give the corresponding class instead (i.e. IStructure.from_ase_atoms
should give IStructure
instead of Structure
, the same for IMolecule
), which would be less confusing?
2234761
to
b079afa
Compare
Summary
from_ase_atoms
forMolecule
, to closeMolecule.from_ase_atoms()
does not pass kwargs appropriately #4320