-
Notifications
You must be signed in to change notification settings - Fork 875
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
ASE <---> pymatgen trajectory conversion #4253
Conversation
…he ASE traj interface
…nctinoality requested
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. see comments.
src/pymatgen/core/trajectory.py
Outdated
@@ -734,3 +732,160 @@ def _get_site_props(self, frames: ValidIndex) -> SitePropsType | None: | |||
return [self.site_properties[idx] for idx in frames] | |||
raise ValueError("Unexpected frames type.") | |||
raise ValueError("Unexpected site_properties type.") | |||
|
|||
def to_ase_trajectory(self, **kwargs) -> AseTrajectory: |
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 suggest we just call it to_ase. Given this class is already called Trajectory, I don't think it is a stretch to imagine to_ase meaning the ASE format for trajectory.
src/pymatgen/core/trajectory.py
Outdated
raise ImportError("ASE is required to write .traj files. pip install ase") | ||
|
||
@classmethod | ||
def ase_to_pmg_trajectory( |
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 should be just called from_ase.
src/pymatgen/core/trajectory.py
Outdated
) | ||
|
||
@staticmethod | ||
def pmg_to_ase_trajectory( |
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 think we need a separate method from to_ase?
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 @shyuep - the intent was to have two methods that don't depend on the Trajectory
class being instantiated to use as general converters. Similar design as AseAtomsAdaptor
(get_atoms
and get_structure
are both staticmethods)
I'm OK changing this if you'd rather just have the to_ase
method
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 think we need a method that is independent of Trajectory.
Looks good. Thanks. Merged. |
Adds feature to convert between ASE and pymatgen trajectories via
from_ase
andto_ase
methods onTrajectory
. Allows for carrying energies, forces, stresses, etc. between ASE and pymatgen trajectories, rather than just structural info as previously implemented.Merging would close #4252. From the discussion there: this PR ensures that any calculator attr's that are set by
AseAtomsAdaptor
are not lost in the trajectory conversion processs.To-do:
- Tests