Skip to content

Add box resizing to MD integrators #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/relentless/simulate/dilute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
57 changes: 56 additions & 1 deletion src/relentless/simulate/hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/relentless/simulate/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 12 additions & 1 deletion src/relentless/simulate/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -133,6 +143,7 @@ def _make_delegate(self, sim):
friction=self.friction,
seed=self.seed,
analyzers=self.analyzers,
barostat=self.barostat,
)


Expand Down
Loading