Skip to content

ASE MD NPT bug fixes + housekeeping #1255

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

Merged
merged 9 commits into from
Jul 29, 2025
Merged

ASE MD NPT bug fixes + housekeeping #1255

merged 9 commits into from
Jul 29, 2025

Conversation

esoteric-ephemera
Copy link
Collaborator

@esoteric-ephemera esoteric-ephemera commented Jul 23, 2025

@JaGeo
Copy link
Member

JaGeo commented Jul 23, 2025

@esoteric-ephemera the openff tests were already failing before, btw

@esoteric-ephemera
Copy link
Collaborator Author

@JaGeo pretty sure that it was #1233, do you know if we can disable dependabot for certain lines of code? That pymatgen dependence is very strict for openff or the tests break completely

@esoteric-ephemera esoteric-ephemera changed the title ASE MD NPT bug fixes ASE MD NPT bug fixes + housekeeping Jul 29, 2025
@esoteric-ephemera esoteric-ephemera added fix Bug fix PR house-keeping Formatting and code quality tweaks labels Jul 29, 2025
@esoteric-ephemera esoteric-ephemera enabled auto-merge (squash) July 29, 2025 07:45
@esoteric-ephemera
Copy link
Collaborator Author

@JaGeo part of the openff issue was related to this bug in pymatgen (the mass of Hydrogen was in fact the mass of Tritium)

Solution for more general robustness is to pass the atomic masses as an optional kwarg, as in the tests

@esoteric-ephemera esoteric-ephemera merged commit f080b54 into main Jul 29, 2025
21 checks passed
@esoteric-ephemera esoteric-ephemera deleted the ase_md_npt branch July 29, 2025 09:07
@JaGeo
Copy link
Member

JaGeo commented Jul 29, 2025

Thanks @esoteric-ephemera !!

@fraricci
Copy link
Contributor

fraricci commented Aug 5, 2025

Hi @esoteric-ephemera.

I did test this pull request and found out that it is not working as expected.

Here are my fixes:
ase/md.py

            # These use different kwargs for pressure
            if (
                isinstance(self.dynamics, DynamicsPresets)
                and DynamicsPresets(self.dynamics) == DynamicsPresets.npt_berendsen
            ) or (
--->           isinstance(self.dynamics, str)
--->           #and issubclass(self.dynamics, MolecularDynamics)
                and self.dynamics == "berendsen"
            ):
                stress_kwarg = "pressure_au"
            else:
                stress_kwarg = "externalstress"

also:

        def _callback(dyn: MolecularDynamics = md_runner) -> None:
            if self.ensemble == MDEnsemble.nve:
                return
            dyn.set_temperature(temperature_K=self.t_schedule[dyn.nsteps])
--->      if self.ensemble in (MDEnsemble.nvt,MDEnsemble.npt):
                return
            dyn.set_stress(self.p_schedule[dyn.nsteps] * 1e3 * units.bar)

Thanks!

isinstance(self.dynamics, DynamicsPresets)
and DynamicsPresets(self.dynamics) == DynamicsPresets.npt_berendsen
) or (
isinstance(self.dynamics, type)
Copy link
Contributor

@fraricci fraricci Aug 5, 2025

Choose a reason for hiding this comment

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

it never enters this if. This fixes it:

isinstance(self.dynamics, str)
#and issubclass(self.dynamics, MolecularDynamics)

Copy link
Member

Choose a reason for hiding this comment

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

@fraricci do you want to make a PR and add a small test if possible? Happy to merge. I trust that you checked it carefully.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah OK I see - yeah there is extra logic needed for this because the user can either specify self.dynamics as a str or as a MolecularDynamics class. The changes I made should work for the latter case, but not the former like you said

I can roll this into the NEB PR I have open since that's ready to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PR house-keeping Formatting and code quality tweaks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: issue with running NPT MD BUG: OpenFF tests failing MatPesStaticFlowMaker should not have PBE+U step enabled by default
3 participants