Skip to content

Commit

Permalink
Decorated _run_mlp_md_openmm so that it run in a temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
JMorado committed Mar 25, 2024
1 parent 5e532b7 commit a570288
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mlptrain/sampling/md_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import mlptrain as mlt
from mlptrain.log import logger
from mlptrain.utils import work_in_tmp_dir
from mlptrain.sampling.md import (
_convert_ase_traj,
_get_traj_name,
Expand All @@ -32,7 +33,7 @@
_HAS_OPENMM_ML = False

# Conversion factor from kJ/mol to eV
_KJ_PER_MOL_TO_EV = ase.units.eV / (ase.units.kJ / ase.units.mol)
_KJ_PER_MOL_TO_EV = (ase.units.kJ / ase.units.mol) / ase.units.eV


def run_mlp_md_openmm(
Expand Down Expand Up @@ -135,9 +136,7 @@ def run_mlp_md_openmm(
copied_substrings_list = list(copied_substrings)
kept_substrings_list = list(kept_substrings)

copied_substrings_list.extend(
['.state.xml', '.xml', '.json', '.pth', '.model']
)
copied_substrings_list.extend(['.xml', '.json', '.pth', '.model'])

if restart:
logger.info('Restarting MLP OpenMM MD')
Expand Down Expand Up @@ -169,7 +168,14 @@ def run_mlp_md_openmm(
else:
logger.info('Running MLP MD with OpenMM')

traj_openmm = _run_mlp_md_openmm(
decorator = work_in_tmp_dir(
copied_substrings=copied_substrings_list,
kept_substrings=kept_substrings_list,
)

_run_mlp_md_decorated = decorator(_run_mlp_md_openmm)

traj = _run_mlp_md_decorated(
configuration=configuration,
mlp=mlp,
temp=temp,
Expand All @@ -183,8 +189,7 @@ def run_mlp_md_openmm(
platform=platform,
**kwargs,
)

return traj_openmm
return traj


def _run_mlp_md_openmm(
Expand Down Expand Up @@ -523,6 +528,7 @@ def _add_frame_to_ase_traj():
state.getPotentialEnergy().value_in_unit(unit.kilojoules_per_mole)
* _KJ_PER_MOL_TO_EV
)

# TODO: Implement biased_energy when bias is implemented
biased_energy = potential_energy

Expand Down

0 comments on commit a570288

Please sign in to comment.