Skip to content

Commit

Permalink
bugfix (#21)
Browse files Browse the repository at this point in the history
* bugfix

* adding list

* moving paramters out of protocolls

* remove parameters from protocol module

---------

Co-authored-by: wiederm <[email protected]>
  • Loading branch information
wiederm and wiederm authored Nov 7, 2023
1 parent c02f78e commit 6ad91f5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 82 deletions.
79 changes: 79 additions & 0 deletions guardowl/parameters.py
Original file line number Diff line number Diff line change
@@ -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: [])
78 changes: 7 additions & 71 deletions guardowl/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion guardowl/tests/stability_test_hipen.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# config.yaml
tests:
- protocol: "hipen_protocol"
hipen_idx: 0
hipen_idx: [0,1]
nnp: "ani2x"
implementation: "torchani"
temperature: 300
Expand Down
35 changes: 25 additions & 10 deletions scripts/test_config.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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

0 comments on commit 6ad91f5

Please sign in to comment.