Skip to content
Draft
60 changes: 59 additions & 1 deletion src/relentless/simulate/hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,10 @@ class RunLangevinDynamics(_Integrator):

"""

def __init__(self, steps, timestep, T, friction, seed, analyzers):
def __init__(self, steps, timestep, T, friction, seed, analyzers, barostat=None):
super().__init__(steps, timestep, analyzers)
self.T = T
self.barostat = barostat
self.friction = friction
self.seed = seed

Expand Down Expand Up @@ -709,6 +710,63 @@ def _call_v2(self, sim):
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 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")
Lz1, xz1, yz1 = None, None, None

Lx2, Ly2, xy2 = self.barostat[1].as_array("HOOMD")
Lz2, xz2, yz2 = None, None, None

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:
Expand Down
6 changes: 5 additions & 1 deletion src/relentless/simulate/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ class RunLangevinDynamics(_Integrator):

"""

def __init__(self, steps, timestep, T, friction, seed, analyzers=None):
def __init__(
self, steps, timestep, T, friction, seed, barostat=None, analyzers=None
):
super().__init__(steps, timestep, analyzers)
self.T = T
self.barostat = barostat
self.friction = friction
self.seed = seed

Expand All @@ -130,6 +133,7 @@ def _make_delegate(self, sim):
steps=self.steps,
timestep=self.timestep,
T=self.T,
barostat=self.barostat,
friction=self.friction,
seed=self.seed,
analyzers=self.analyzers,
Expand Down