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

ASE <---> pymatgen trajectory conversion #4253

Merged
merged 14 commits into from
Jan 15, 2025

Conversation

esoteric-ephemera
Copy link
Contributor

@esoteric-ephemera esoteric-ephemera commented Jan 14, 2025

Adds feature to convert between ASE and pymatgen trajectories via from_ase and to_ase methods on Trajectory. 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

@esoteric-ephemera esoteric-ephemera changed the title [WIP] ASE <---> pymatgen trajectory conversion ASE <---> pymatgen trajectory conversion Jan 14, 2025
@esoteric-ephemera
Copy link
Contributor Author

@shyuep and @mkhorton should be ready for review whenever you get a chance

Copy link
Member

@shyuep shyuep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. see comments.

@@ -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:
Copy link
Member

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.

raise ImportError("ASE is required to write .traj files. pip install ase")

@classmethod
def ase_to_pmg_trajectory(
Copy link
Member

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.

)

@staticmethod
def pmg_to_ase_trajectory(
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

@shyuep shyuep merged commit e1993b2 into materialsproject:master Jan 15, 2025
43 checks passed
@shyuep
Copy link
Member

shyuep commented Jan 15, 2025

Looks good. Thanks. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method Trajectory.to_ase_trajectory()
2 participants