Skip to content

Commit

Permalink
Merge pull request #23 from OpenFreeEnergy/remove_engine_settings
Browse files Browse the repository at this point in the history
Remove OpenMMEngineSettings and create GromacsEngineSettings
  • Loading branch information
hannahbaumann authored Sep 27, 2024
2 parents 89fadea + dfaae75 commit f3b85ee
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
27 changes: 19 additions & 8 deletions openfe_gromacs/protocols/gromacs_md/md_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
EMOutputSettings,
EMSimulationSettings,
FFSettingsOpenMM,
GromacsEngineSettings,
GromacsMDProtocolSettings,
IntegratorSettings,
NPTOutputSettings,
NPTSimulationSettings,
NVTOutputSettings,
NVTSimulationSettings,
OpenFFPartialChargeSettings,
OpenMMEngineSettings,
OpenMMSolvationSettings,
)

Expand Down Expand Up @@ -114,7 +114,6 @@ def _dict2mdp(settings_dict: dict, shared_basepath):
"edr_file",
"log_file",
"cpt_file",
"ntomp",
]
for setting in non_mdps:
settings_dict.pop(setting)
Expand Down Expand Up @@ -483,7 +482,6 @@ def _default_settings(cls):
),
partial_charge_settings=OpenFFPartialChargeSettings(),
solvation_settings=OpenMMSolvationSettings(),
engine_settings=OpenMMEngineSettings(),
integrator_settings=IntegratorSettings(),
simulation_settings_em=EMSimulationSettings(
integrator="steep",
Expand All @@ -499,6 +497,7 @@ def _default_settings(cls):
pcoupl="C-rescale",
gen_vel="no", # If continuation from NVT simulation
),
engine_settings=GromacsEngineSettings(),
output_settings_em=EMOutputSettings(
mdp_file="em.mdp",
tpr_file="em.tpr",
Expand Down Expand Up @@ -990,7 +989,7 @@ def _run_gromacs(
cpt: str,
log: str,
edr: str,
ntomp: int,
engine_settings: GromacsEngineSettings,
shared_basebath: pathlib.Path,
):
"""
Expand All @@ -1009,6 +1008,7 @@ def _run_gromacs(
:param cpt: str
:param log: str
:param edr: str
:param engine_settings: GromacsEngineSettings
:param shared_basebath: Pathlike, optional
Where to run the calculation, defaults to current working directory
"""
Expand Down Expand Up @@ -1053,7 +1053,17 @@ def _run_gromacs(
"-ntmpi",
"1",
"-ntomp",
str(ntomp),
str(engine_settings.ntomp),
"-pme",
str(engine_settings.pme),
"-pmefft",
str(engine_settings.pmefft),
"-bonded",
str(engine_settings.bonded),
"-nb",
str(engine_settings.nb),
"-update",
str(engine_settings.update),
],
stdin=subprocess.PIPE,
cwd=shared_basebath,
Expand Down Expand Up @@ -1105,6 +1115,7 @@ def _execute(
sim_settings_npt: NPTSimulationSettings = (
protocol_settings.simulation_settings_npt
)
engine_settings: GromacsEngineSettings = protocol_settings.engine_settings
output_settings_em: EMOutputSettings = protocol_settings.output_settings_em
output_settings_nvt: NVTOutputSettings = protocol_settings.output_settings_nvt
output_settings_npt: NPTOutputSettings = protocol_settings.output_settings_npt
Expand All @@ -1131,7 +1142,7 @@ def _execute(
output_settings_em.cpt_file,
output_settings_em.log_file,
output_settings_em.edr_file,
sim_settings_em.ntomp,
engine_settings,
ctx.shared,
)

Expand Down Expand Up @@ -1159,7 +1170,7 @@ def _execute(
output_settings_nvt.cpt_file,
output_settings_nvt.log_file,
output_settings_nvt.edr_file,
sim_settings_nvt.ntomp,
engine_settings,
ctx.shared,
)

Expand Down Expand Up @@ -1190,7 +1201,7 @@ def _execute(
output_settings_npt.cpt_file,
output_settings_npt.log_file,
output_settings_npt.edr_file,
sim_settings_npt.ntomp,
engine_settings,
ctx.shared,
)

Expand Down
58 changes: 44 additions & 14 deletions openfe_gromacs/protocols/gromacs_md/md_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
"""
from typing import Literal, Optional

import pint
from gufe.settings import OpenMMSystemGeneratorFFSettings, SettingsBaseModel
from openfe.protocols.openmm_utils.omm_settings import (
IntegratorSettings,
OpenFFPartialChargeSettings,
OpenMMEngineSettings,
OpenMMSolvationSettings,
Settings,
)
Expand Down Expand Up @@ -206,12 +204,6 @@ class Config:
Number of iterations to correct for rotational lengthening in LINCS.
Default 1.
"""
ntomp: int = 1
"""
Number of threads to be used for OpenMP multithreading.
GROMACS must be compiled with OpenMP support if a value greater than 1 is
set here.
"""

@validator(
"nsteps",
Expand Down Expand Up @@ -673,6 +665,46 @@ def has_no_constraints(cls, v):
return v


class GromacsEngineSettings(SettingsBaseModel):
"""
MD engine settings for running simulations in Gromacs.
"""

ntomp: int = 1
"""
Number of threads to be used for OpenMP multithreading.
GROMACS must be compiled with OpenMP support if a value greater than 1 is
set here.
"""
pme: Literal["auto", "cpu", "gpu"] = "auto"
"""
Perform PME calculations on: auto, cpu, gpu. Default: "auto"
"""
pmefft: Literal["auto", "cpu", "gpu"] = "auto"
"""
Perform PME FFT calculations on: auto, cpu, gpu. Default: "auto"
"""
bonded: Literal["auto", "cpu", "gpu"] = "auto"
"""
Perform bonded calculations on: auto, cpu, gpu. Default: "auto"
"""
nb: Literal["auto", "cpu", "gpu"] = "auto"
"""
Calculate non-bonded interactions on: auto, cpu, gpu. Default: "auto"
"""
update: Literal["auto", "cpu", "gpu"] = "auto"
"""
Perform update and constraints on: auto, cpu, gpu. Default: "auto"
"""

@validator("ntomp")
def must_be_positive(cls, v):
if v <= 0:
errmsg = f"ntomp must be positive values, " f"got {v}."
raise ValueError(errmsg)
return v


class GromacsMDProtocolSettings(Settings):
class Config:
arbitrary_types_allowed = True
Expand All @@ -693,22 +725,20 @@ def must_be_positive(cls, v):
gro: str
top: str

# Things for creating the OpenMM systems
# Settings for creating the OpenMM systems
forcefield_settings: FFSettingsOpenMM
partial_charge_settings: OpenFFPartialChargeSettings
solvation_settings: OpenMMSolvationSettings

# MD Engine things
engine_settings: OpenMMEngineSettings

# Sampling State defining things
integrator_settings: IntegratorSettings

# Simulation run settings
simulation_settings_em: EMSimulationSettings
simulation_settings_nvt: NVTSimulationSettings
simulation_settings_npt: NPTSimulationSettings

# Gromacs run/engine settings
engine_settings: GromacsEngineSettings

# Simulations output settings
output_settings_em: EMOutputSettings
output_settings_nvt: NVTOutputSettings
Expand Down
Binary file modified openfe_gromacs/tests/data/MDProtocol_json_results.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions openfe_gromacs/tests/protocols/test_md_tokenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def protocol_result(md_json):

class TestGromacsMDProtocol(GufeTokenizableTestsMixin):
cls = gromacs_md.GromacsMDProtocol
key = "GromacsMDProtocol-76fa290de019030035f2010e9155f57f"
key = "GromacsMDProtocol-dac6fd8b3fa26dcff42763515a67f557"
repr = f"<{key}>"

@pytest.fixture()
Expand All @@ -64,7 +64,7 @@ def test_key_stable(self):

class TestGromacsMDProtocolResult(GufeTokenizableTestsMixin):
cls = gromacs_md.GromacsMDProtocolResult
key = "GromacsMDProtocolResult-4739ae9a56f36a1e7c95c503601769f4"
key = "GromacsMDProtocolResult-d11eb101c28e59af5150ec45e1961e4d"
repr = f"<{key}>"

@pytest.fixture()
Expand Down

0 comments on commit f3b85ee

Please sign in to comment.