diff --git a/src/relentless/simulate/dilute.py b/src/relentless/simulate/dilute.py index be80cf20..2de84d66 100644 --- a/src/relentless/simulate/dilute.py +++ b/src/relentless/simulate/dilute.py @@ -111,9 +111,10 @@ def _modify_ensemble(self, sim): class RunLangevinDynamics(_Integrator): - def __init__(self, steps, timestep, T, friction, seed, analyzers): + def __init__(self, steps, timestep, T, friction, seed, analyzers, barostat): super().__init__(steps, timestep, analyzers) self.T = T + self.barostat = barostat _modify_ensemble = RunBrownianDynamics._modify_ensemble diff --git a/src/relentless/simulate/hoomd.py b/src/relentless/simulate/hoomd.py index e7f6299d..2ba63ba0 100644 --- a/src/relentless/simulate/hoomd.py +++ b/src/relentless/simulate/hoomd.py @@ -649,9 +649,10 @@ class RunLangevinDynamics(_Integrator): """ - def __init__(self, steps, timestep, T, friction, seed, analyzers): + def __init__(self, steps, timestep, T, friction, seed, analyzers, barostat): super().__init__(steps, timestep, analyzers) self.T = T + self.barostat = barostat self.friction = friction self.seed = seed @@ -701,7 +702,61 @@ def _call_v2(self, sim): # run + analysis for analyzer in self.analyzers: analyzer.pre_run(sim, self) + if self.barostat is not None: + if isinstance(self.barostat, extent.Extent): + period = None + if sim.dimension == 2: + Lx, Ly, xy = self.barostat.as_array("HOOMD") + Lz, xz, yz = None, None, None + else: + Lx, Ly, Lz, xy, xz, yz = self.barostat.as_array("HOOMD") + elif len(self.barostat) == 2 and all( + isinstance(n, extent.Extent) for n in self.barostat + ): + period = 1 + if sim.dimension == 2: + Lx1, Ly1, xy1 = self.barostat[0].as_array("HOOMD") + Lx2, Ly2, xy2 = self.barostat[1].as_array("HOOMD") + Lz, xz, yz = None, None, None + Lx = hoomd.variant.linear_interp( + [(0, Lx1), (self.steps - 1, Lx2)] + ) + Ly = hoomd.variant.linear_interp( + [(0, Ly1), (self.steps - 1, Ly2)] + ) + xy = hoomd.variant.linear_interp( + [(0, xy1), (self.steps - 1, xy2)] + ) + else: + Lx1, Ly1, Lz1, xy1, xz1, yz1 = self.barostat[0].as_array( + "HOOMD" + ) + Lx2, Ly2, Lz2, xy2, xz2, yz2 = self.barostat[1].as_array( + "HOOMD" + ) + Lx = hoomd.variant.linear_interp( + [(0, Lx1), (self.steps - 1, Lx2)] + ) + Ly = hoomd.variant.linear_interp( + [(0, Ly1), (self.steps - 1, Ly2)] + ) + Lz = hoomd.variant.linear_interp( + [(0, Lz1), (self.steps - 1, Lz2)] + ) + xy = hoomd.variant.linear_interp( + [(0, xy1), (self.steps - 1, xy2)] + ) + xz = hoomd.variant.linear_interp( + [(0, xz1), (self.steps - 1, xz2)] + ) + yz = hoomd.variant.linear_interp( + [(0, yz1), (self.steps - 1, yz2)] + ) + + hoomd.update.box_resize( + Lx=Lx, Ly=Ly, Lz=Lz, xy=xy, xz=xz, yz=yz, period=period + ) hoomd.run(self.steps) for analyzer in self.analyzers: diff --git a/src/relentless/simulate/lammps.py b/src/relentless/simulate/lammps.py index b6311d97..ac966840 100644 --- a/src/relentless/simulate/lammps.py +++ b/src/relentless/simulate/lammps.py @@ -694,9 +694,10 @@ class RunLangevinDynamics(_Integrator): """ - def __init__(self, steps, timestep, T, friction, seed, analyzers): + def __init__(self, steps, timestep, T, friction, seed, analyzers, barostat): super().__init__(steps, timestep, analyzers) self.T = T + self.barostat = barostat self.friction = friction self.seed = seed diff --git a/src/relentless/simulate/md.py b/src/relentless/simulate/md.py index df660474..3ff1b2b3 100644 --- a/src/relentless/simulate/md.py +++ b/src/relentless/simulate/md.py @@ -118,9 +118,19 @@ class RunLangevinDynamics(_Integrator): """ - def __init__(self, steps, timestep, T, friction, seed, analyzers=None): + def __init__( + self, + steps, + timestep, + T, + friction, + seed, + analyzers=None, + barostat=None, + ): super().__init__(steps, timestep, analyzers) self.T = T + self.barostat = barostat self.friction = friction self.seed = seed @@ -133,6 +143,7 @@ def _make_delegate(self, sim): friction=self.friction, seed=self.seed, analyzers=self.analyzers, + barostat=self.barostat, )