ConstantPressure

class hoomd.md.methods.ConstantPressure(filter, S, tauS, couple, thermostat=None, box_dof=[True, True, True, False, False, False], rescale_all=False, gamma=0.0)

Bases: Thermostatted

Constant pressure dynamics.

Parameters:
  • filter (hoomd.filter.filter_like) – Subset of particles on which to apply this method.

  • thermostat (hoomd.md.methods.thermostats.Thermostat) – Thermostat to control temperature. Setting this to None samples a constant enthalpy (NPH) integration.

  • S (tuple[variant.variant_like, ...] or variant.variant_like) –

    Stress component set points for the barostat.

    In Voigt notation: \([S_{xx}, S_{yy}, S_{zz}, S_{yz}, S_{xz}, S_{xy}]\) \([\mathrm{pressure}]\). In case of isotropic pressure P use S = p to imply (\([p, p, p, 0, 0, 0]\)).

  • tauS (float) – Coupling constant for the barostat \([\mathrm{time}]\).

  • couple (str) – Couplings of diagonal elements of the stress tensor. One of “none”, “xy”, “xz”,”yz”, or “xyz”.

  • box_dof (list [ bool ]) – Box degrees of freedom with six boolean elements in the order x, y, z, xy, xz, yz. Defaults to [True,True,True,False,False,False]). When True, rescale corresponding lengths or tilt factors and components of particle coordinates and velocities.

  • rescale_all (bool) – When True, rescale all particles, not only those selected by the filter. Defaults to False.

  • gamma (float) – Friction constant for the box degrees of freedom. Defaults to 0 \([\mathrm{time}^{-1}]\).

ConstantPressure integrates translational and rotational degrees of freedom of the system held at constant pressure with a barostat. The barostat introduces additional degrees of freedom in the Hamiltonian that couple with box parameters. Use a thermostat to model an isothermal-isobaric (NPT) ensemble. Use no thermostat (thermostat = None) to model a isoenthalpic-isobaric (NPH) ensemble.

The barostat tensor is \(\nu_{\mathrm{ij}}\). Access these quantities using barostat_dof.

By default, ConstantPressure performs integration in a cubic box under hydrostatic pressure by simultaneously rescaling the lengths Lx, Ly and Lz of the simulation box by the same factors. Set the couplings and/or box degrees of freedom to change this default.

Couplings define which diagonal elements of the pressure tensor \(P_{\alpha,\beta}\) should be averaged over, so that the corresponding box lengths are rescaled by the same amount.

Valid couplings are:

  • 'none' (all box lengths are updated independently)

  • 'xy' (Lx and Ly are coupled)

  • 'xz' (Lx and Lz are coupled)

  • 'yz' (Ly and Lz are coupled)

  • 'xyz' (Lx, Ly, and Lz are coupled)

The degrees of freedom of the box set which lengths and tilt factors of the box should be updated, and how particle coordinates and velocities should be rescaled. The box_dof tuple controls the way the box is rescaled and updated. The first three elements box_dof[:3] controls whether the x, y, and z box lengths are rescaled and updated, respectively. The last three entries box_dof[3:] control the rescaling or the tilt factors xy, xz, and yz. All options also appropriately rescale particle coordinates and velocities.

By default, the x, y, and z degrees of freedom are updated. [True,True,True,False,False,False]

Note

When any of the diagonal x, y, z degrees of freedom is not being integrated, pressure tensor components along that direction are not considered for the remaining degrees of freedom.

ConstantPressure numerically integrates the equations of motion using the symplectic Martyna-Tobias-Klein integrator with a Langevin piston. The equation of motion of box dimensions is given by:

\[ \begin{align}\begin{aligned}\frac{d^2 L}{dt^2} &= V W^{-1} (S - S_{ext}) - \gamma \frac{dL}{dt} + R(t)\\\langle R \rangle &= 0\\\langle |R|^2 \rangle &= 2 \gamma kT \delta t W^{-1}\end{aligned}\end{align} \]

Where \(\gamma\) is the friction on the barostat piston, which damps unphysical volume oscillations at the cost of non-deterministic integration, and \(R\) is a random force, chosen appropriately for the coupled degrees of freedom.

Note

The barostat coupling constant tauS should be set within a reasonable range to avoid abrupt fluctuations in the box volume and to avoid long time to equilibration. The recommended value for most systems is \(\tau_S = 1000 \delta t\).

Note

If \(\gamma\) is used, its value should be chosen so that the system is near critical damping. A good initial guess is \(\gamma \approx 2 \tau_S^{-1}\). A value too high will result in long relaxation times.

Note

Set gamma = 0 to obtain the same MTK equations of motion used in HOOMD-blue releases prior to 4.0.0.

Examples:

NPH integrator with cubic symmetry:

nph = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="xyz",
)
simulation.operations.integrator.methods = [nph]

NPT integrator with cubic symmetry:

npt = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="xyz",
    thermostat=hoomd.md.methods.thermostats.Bussi(kT=1.5),
)
simulation.operations.integrator.methods = [npt]

NPT integrator with tetragonal symmetry:

npt = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="xy",
    thermostat=hoomd.md.methods.thermostats.Bussi(kT=1.5),
)
simulation.operations.integrator.methods = [npt]

NPT integrator with orthorhombic symmetry:

npt = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="none",
    thermostat=hoomd.md.methods.thermostats.Bussi(kT=1.5),
)
simulation.operations.integrator.methods = [npt]

NPT integrator with triclinic symmetry:

npt = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="none",
    box_dof=[True, True, True, True, True, True],
    thermostat=hoomd.md.methods.thermostats.Bussi(kT=1.5),
)
simulation.operations.integrator.methods = [npt]

Members inherited from AutotunedObject:

property kernel_parameters

Kernel parameters. Read more...

property is_tuning_complete

Check if kernel parameter tuning is complete. Read more...

tune_kernel_parameters()

Start tuning kernel parameters. Read more...


Members inherited from Thermostatted:

thermostat

Temperature control for the integrator. Read more...


Members defined in ConstantPressure:

filter

Subset of particles on which to apply this method.

Type:

hoomd.filter.filter_like

S

Stress components set point for the barostat. In Voigt notation, \([S_{xx}, S_{yy}, S_{zz}, S_{yz}, S_{xz}, S_{xy}]\) \([\mathrm{pressure}]\).

Examples:

npt.S = 4.0
npt.S = hoomd.variant.Ramp(A=1.0, B=2.0, t_start=0, t_ramp=1_000_000)
Type:

tuple[hoomd.variant.Variant,…]

tauS

Coupling constant for the barostat \([\mathrm{time}]\).

Example:

npt.tauS = 2.0
Type:

float

couple

Couplings of diagonal elements of the stress tensor, can be ‘none’, ‘xy’, ‘xz’, ‘yz’, or ‘xyz’.

Example:

npt.couple = "none"
Type:

str

box_dof

Box degrees of freedom with six boolean elements in the order [x, y, z, xy, xz, yz].

Example:

npt.box_dof = [False, False, True, False, False, False]
Type:

list[bool]

rescale_all

When True, rescale all particles, not only those selected by the filter.

Example:

npt.rescale_all = True
Type:

bool

gamma

Friction constant for the box degrees of freedom \([\mathrm{time^{-1}}]\).

Type:

float

barostat_dof

Additional degrees of freedom for the barostat (\(\nu_{xx}\), \(\nu_{xy}\), \(\nu_{xz}\), \(\nu_{yy}\), \(\nu_{yz}\), \(\nu_{zz}\))

Save and restore the barostat degrees of freedom when continuing simulations:

Examples:

Save before exiting:

numpy.save(file=path / "barostat_dof.npy", arr=npt.barostat_dof)

Load when continuing:

npt = hoomd.md.methods.ConstantPressure(
    filter=hoomd.filter.All(),
    tauS=1.0,
    S=2.0,
    couple="xyz",
    thermostat=hoomd.md.methods.thermostats.Bussi(kT=1.5),
)
simulation.operations.integrator.methods = [npt]

npt.barostat_dof = numpy.load(file=path / "barostat_dof.npy")
Type:

tuple[float, float, float, float, float, float]

property barostat_energy

Energy the barostat contributes to the Hamiltonian \([\mathrm{energy}]\).

Example:

logger.add(obj=npt, quantities=['barostat_energy'])

(Loggable: category=”scalar”)

thermalize_barostat_dof()

Set the thermostat and barostat momenta to random values.

thermalize_barostat_dof sets random values for the the barostat momentum \(\nu_{\mathrm{ij}}\).

Important

You must call Simulation.run before thermalize_barostat_dof.

simulation.run(0)
npt.thermalize_barostat_dof()