7
7
8
8
import numpy as np
9
9
from openmm import Integrator , LangevinMiddleIntegrator , MonteCarloBarostat
10
+ from openmm .app import StateDataReporter
10
11
from openmm .unit import atmosphere , kelvin , kilojoules_per_mole , nanometer , picoseconds
11
12
12
13
from atomate2 .openmm .jobs .base import BaseOpenMMMaker
13
14
from atomate2 .openmm .utils import create_list_summing_to
14
15
15
16
if TYPE_CHECKING :
17
+ from pathlib import Path
18
+
16
19
from emmet .core .openmm import OpenMMTaskDocument
17
20
from openmm .app import Simulation
18
21
@@ -41,7 +44,7 @@ class EnergyMinimizationMaker(BaseOpenMMMaker):
41
44
tolerance : float = 10
42
45
max_iterations : int = 0
43
46
44
- def run_openmm (self , sim : Simulation ) -> None :
47
+ def run_openmm (self , sim : Simulation , dir_name : Path ) -> None :
45
48
"""Run the energy minimization with OpenMM.
46
49
47
50
This method performs energy minimization on the molecular system using
@@ -62,6 +65,28 @@ def run_openmm(self, sim: Simulation) -> None:
62
65
maxIterations = self .max_iterations ,
63
66
)
64
67
68
+ if self .state_interval > 0 :
69
+ state = sim .context .getState (
70
+ getPositions = True ,
71
+ getVelocities = True ,
72
+ getForces = True ,
73
+ getEnergy = True ,
74
+ enforcePeriodicBox = self .wrap_traj ,
75
+ )
76
+
77
+ state_reporter = StateDataReporter (
78
+ file = f"{ dir_name / self .state_file_name } .csv" ,
79
+ reportInterval = 0 ,
80
+ step = True ,
81
+ potentialEnergy = True ,
82
+ kineticEnergy = True ,
83
+ totalEnergy = True ,
84
+ temperature = True ,
85
+ volume = True ,
86
+ density = True ,
87
+ )
88
+ state_reporter .report (sim , state )
89
+
65
90
66
91
@dataclass
67
92
class NPTMaker (BaseOpenMMMaker ):
@@ -87,7 +112,7 @@ class NPTMaker(BaseOpenMMMaker):
87
112
pressure : float = 1
88
113
pressure_update_frequency : int = 10
89
114
90
- def run_openmm (self , sim : Simulation ) -> None :
115
+ def run_openmm (self , sim : Simulation , dir_name : Path ) -> None :
91
116
"""Evolve the simulation for self.n_steps in the NPT ensemble.
92
117
93
118
This adds a Monte Carlo barostat to the system to put it into NPT, runs the
@@ -138,7 +163,7 @@ class NVTMaker(BaseOpenMMMaker):
138
163
name : str = "nvt simulation"
139
164
n_steps : int = 1_000_000
140
165
141
- def run_openmm (self , sim : Simulation ) -> None :
166
+ def run_openmm (self , sim : Simulation , dir_name : Path ) -> None :
142
167
"""Evolve the simulation with OpenMM for self.n_steps.
143
168
144
169
Parameters
@@ -177,7 +202,7 @@ class TempChangeMaker(BaseOpenMMMaker):
177
202
temp_steps : int | None = None
178
203
starting_temperature : float | None = None
179
204
180
- def run_openmm (self , sim : Simulation ) -> None :
205
+ def run_openmm (self , sim : Simulation , dir_name : Path ) -> None :
181
206
"""Evolve the simulation while gradually changing the temperature.
182
207
183
208
self.temperature is the final temperature. self.temp_steps
0 commit comments