From 6ad91f5d64cefcdf9032c3e93e06a5b62bfc48d3 Mon Sep 17 00:00:00 2001 From: Marcus Wieder <31651017+wiederm@users.noreply.github.com> Date: Tue, 7 Nov 2023 07:27:20 -0500 Subject: [PATCH] bugfix (#21) * bugfix * adding list * moving paramters out of protocolls * remove parameters from protocol module --------- Co-authored-by: wiederm --- guardowl/parameters.py | 79 ++++++++++++++++++++++++ guardowl/protocols.py | 78 +++-------------------- guardowl/tests/stability_test_hipen.yaml | 2 +- scripts/test_config.yaml | 35 ++++++++--- 4 files changed, 112 insertions(+), 82 deletions(-) create mode 100644 guardowl/parameters.py diff --git a/guardowl/parameters.py b/guardowl/parameters.py new file mode 100644 index 0000000..e7f6ab9 --- /dev/null +++ b/guardowl/parameters.py @@ -0,0 +1,79 @@ +from dataclasses import dataclass, field +from openmm import Platform, System, unit +from openmm.app import StateDataReporter +from openmmtools.testsystems import TestSystem +from typing import List, Union, Optional + + +@dataclass +class BaseParameters: + system: System + platform: Platform + testsystem: TestSystem + output_folder: str + log_file_name: str + + +@dataclass +class MinimizationTestParameters(BaseParameters): + convergence_criteria: unit.Quantity = field(default_factory=1.0 * unit.kilojoule_per_mole / unit.nanometer) + + +@dataclass +class StabilityTestParameters(BaseParameters): + """Parameters for a stability test. + + Parameters are stored as attributes. + + Attributes + ---------- + protocol_length : int + Length of the protocol in time units. + temperature : unit.Quantity + Temperature of the simulation. + ensemble : str + Ensemble type ('NVT', 'NPT', etc.). + simulated_annealing : bool + Whether simulated annealing is to be used. + system : System + The OpenMM System object. + platform : Platform + The OpenMM Platform object. + testsystem : TestSystem + The test system for the simulation. + output_folder : str + Path to the output folder. + log_file_name : str + Name of the log file. + state_data_reporter : StateDataReporter + The OpenMM StateDataReporter object. + """ + + protocol_length: int + temperature: Union[int, List[int]] + env: str + simulated_annealing: bool + state_data_reporter: StateDataReporter + device_index: int = 0 + ensemble: Optional[str] = None + + +@dataclass +class DOFTestParameters(BaseParameters): + """Parameters for a degree of freedom (DOF) test. + + In addition to attributes in StabilityTestParameters, extra attributes for DOF tests are included. + + Attributes + ---------- + bond : List + List of atom pairs to be considered as bonds. + angle : List + List of atom triplets to be considered as angles. + torsion : List + List of atom quartets to be considered as torsions. + """ + + bond: List = field(default_factory=lambda: []) + angle: List = field(default_factory=lambda: []) + torsion: List = field(default_factory=lambda: []) diff --git a/guardowl/protocols.py b/guardowl/protocols.py index e80f102..c0d5cac 100644 --- a/guardowl/protocols.py +++ b/guardowl/protocols.py @@ -14,6 +14,11 @@ from openmmtools.testsystems import TestSystem from .simulation import SimulationFactory +from .parameters import ( + StabilityTestParameters, + DOFTestParameters, + MinimizationTestParameters, +) def initialize_ml_system(nnp: str, topology: Topology, implementation: str) -> System: @@ -89,75 +94,6 @@ def report(self, simulation: Simulation, state: State) -> None: self._out.flush() -@dataclass -class BaseParameters: - system: System - platform: Platform - testsystem: TestSystem - output_folder: str - log_file_name: str - - -@dataclass -class StabilityTestParameters(BaseParameters): - """Parameters for a stability test. - - Parameters are stored as attributes. - - Attributes - ---------- - protocol_length : int - Length of the protocol in time units. - temperature : unit.Quantity - Temperature of the simulation. - ensemble : str - Ensemble type ('NVT', 'NPT', etc.). - simulated_annealing : bool - Whether simulated annealing is to be used. - system : System - The OpenMM System object. - platform : Platform - The OpenMM Platform object. - testsystem : TestSystem - The test system for the simulation. - output_folder : str - Path to the output folder. - log_file_name : str - Name of the log file. - state_data_reporter : StateDataReporter - The OpenMM StateDataReporter object. - """ - - protocol_length: int - temperature: Union[int, List[int]] - env: str - simulated_annealing: bool - state_data_reporter: StateDataReporter - device_index: int = 0 - ensemble: Optional[str] = None - - -@dataclass -class DOFTestParameters(BaseParameters): - """Parameters for a degree of freedom (DOF) test. - - In addition to attributes in StabilityTestParameters, extra attributes for DOF tests are included. - - Attributes - ---------- - bond : List - List of atom pairs to be considered as bonds. - angle : List - List of atom triplets to be considered as angles. - torsion : List - List of atom quartets to be considered as torsions. - """ - - bond: List = field(default_factory=lambda: []) - angle: List = field(default_factory=lambda: []) - torsion: List = field(default_factory=lambda: []) - - class DOFTest(ABC): """Abstract base class for DOF tests. @@ -609,7 +545,7 @@ def perform_stability_test(self, parms: StabilityTestParameters) -> None: ) for temperature in parms.temperature: parms.log_file_name = f"{log_file_name_}_{temperature}" - log.info('Running simulation at temperature: {temperature} K') + log.info("Running simulation at temperature: {temperature} K") self._run_simulation( parms, temperature * unit.kelvin, @@ -637,7 +573,7 @@ def run_hipen_protocol( """ from guardowl.testsystems import HipenTestsystemFactory, hipen_systems - def _run_protocol(idx: int): + def _run_protocol(hipen_idx: int): name = list(hipen_systems.keys())[hipen_idx] print( diff --git a/guardowl/tests/stability_test_hipen.yaml b/guardowl/tests/stability_test_hipen.yaml index 9efbf8a..e6eebcb 100644 --- a/guardowl/tests/stability_test_hipen.yaml +++ b/guardowl/tests/stability_test_hipen.yaml @@ -1,7 +1,7 @@ # config.yaml tests: - protocol: "hipen_protocol" - hipen_idx: 0 + hipen_idx: [0,1] nnp: "ani2x" implementation: "torchani" temperature: 300 diff --git a/scripts/test_config.yaml b/scripts/test_config.yaml index 5db010a..af234f4 100644 --- a/scripts/test_config.yaml +++ b/scripts/test_config.yaml @@ -1,7 +1,16 @@ # config.yaml tests: - protocol: "perform_alanine_dipeptide_protocol" - env: "solvent" + env: "solution" + ensemble: "npt" + nnp: "ani2x" + implementation: "torchani" + annealing: false + nr_of_simulation_steps: 50_000 + temperature: 300 + + - protocol: "perform_alanine_dipeptide_protocol" + env: "vacuum" ensemble: "npt" nnp: "ani2x" implementation: "torchani" @@ -10,7 +19,8 @@ tests: temperature: 300 - protocol: "hipen_protocol" - hipen_idx: [0,1,2,3,4,5,6,7,8,9] + hipen_idx: + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] nnp: "ani2x" implementation: "torchani" temperature: 300 @@ -21,28 +31,33 @@ tests: nnp: "ani2x" implementation: "nnpops" temperature: [300, 400, 500] - nr_of_simulation_steps: 100_000 + nr_of_simulation_steps: 1_000_000 - protocol: "waterbox_protocol" - edge_length: 15 + edge_length: 30 ensemble: "NVT" nnp: "ani2x" implementation: "nnpops" annealing: false - nr_of_simulation_steps: 50_000 + nr_of_simulation_steps: 500_000 temperature: 300 - protocol: "waterbox_protocol" - edge_length: 15 + edge_length: 30 ensemble: "npt" nnp: "ani2x" implementation: "nnpops" annealing: false - nr_of_simulation_steps: 50_000 + nr_of_simulation_steps: 500_000 temperature: 300 - - protocol: "perform_DOF_scan" + - protocol: "perform_pure_liquid_protocol" + molecule_name: ["ethane", "butane"] + nr_of_molecule: [100, 200] + ensemble: "npt" nnp: "ani2x" implementation: "torchani" - DOF_definition: { "bond": [0, 2] } - molecule_name: "ethanol" + annealing: false + nr_of_simulation_steps: 500_000 + nr_of_equilibration_steps: 5_000 + temperature: 300