diff --git a/hoomd/md/methods/rattle.py b/hoomd/md/methods/rattle.py index 09ccd3b7e0..93d5a2359c 100644 --- a/hoomd/md/methods/rattle.py +++ b/hoomd/md/methods/rattle.py @@ -1,7 +1,18 @@ # Copyright (c) 2009-2023 The Regents of the University of Michigan. # Part of HOOMD-blue, released under the BSD 3-Clause License. -"""MD integration methods with manifold constraints.""" +"""MD integration methods with manifold constraints. + +.. invisible-code-block: python + + simulation = hoomd.util.make_example_simulation() + simulation.operations.integrator = hoomd.md.Integrator(dt=0.001) + logger = hoomd.logging.Logger() + + # Rename pytest's tmp_path fixture for clarity in the documentation. + path = tmp_path + +""" from hoomd.md import _md import hoomd @@ -220,6 +231,12 @@ class Langevin(MethodRATTLE): The units of tolerance match that of the selected manifold's implicit function. Defaults to 1e-6 + default_gamma (float): Default drag coefficient for all particle types + :math:`[\mathrm{mass} \cdot \mathrm{time}^{-1}]`. + + default_gamma_r ([`float`, `float`, `float`]): Default rotational drag + coefficient tensor for all particles :math:`[\mathrm{time}^{-1}]`. + .. rubric:: Translational degrees of freedom `Langevin` uses the same integrator as `hoomd.md.methods.Langevin`, which @@ -231,12 +248,18 @@ class Langevin(MethodRATTLE): Use `Brownian` if your system is not underdamped. - Example:: + .. rubric:: Example - sphere = hoomd.md.manifold.Sphere(r=10) + .. code-block:: python + + sphere = hoomd.md.manifold.Sphere(r=5) langevin_rattle = hoomd.md.methods.rattle.Langevin( - filter=hoomd.filter.All(), kT=0.2, manifold_constraint=sphere, - seed=1) + filter=hoomd.filter.All(), + kT=1.5, + manifold_constraint=sphere, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0)) + simulation.operations.integrator.methods = [langevin_rattle] Attributes: filter (hoomd.filter.filter_like): Subset of particles to apply this @@ -263,12 +286,16 @@ class Langevin(MethodRATTLE): :math:`[\mathrm{time}^{-1}]`. """ - def __init__(self, - filter, - kT, - manifold_constraint, - tally_reservoir_energy=False, - tolerance=0.000001): + def __init__( + self, + filter, + kT, + manifold_constraint, + tally_reservoir_energy=False, + tolerance=0.000001, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0), + ): # store metadata param_dict = ParameterDict( @@ -283,11 +310,13 @@ def __init__(self, gamma = TypeParameter('gamma', type_kind='particle_types', param_dict=TypeParameterDict(1., len_keys=1)) + gamma.default = default_gamma gamma_r = TypeParameter('gamma_r', type_kind='particle_types', param_dict=TypeParameterDict((1., 1., 1.), len_keys=1)) + gamma_r.default = default_gamma_r self._extend_typeparam([gamma, gamma_r]) @@ -332,6 +361,12 @@ class Brownian(MethodRATTLE): The units of tolerance match that of the selected manifold's implicit function. Defaults to 1e-6 + default_gamma (float): Default drag coefficient for all particle types + :math:`[\mathrm{mass} \cdot \mathrm{time}^{-1}]`. + + default_gamma_r ([`float`, `float`, `float`]): Default rotational drag + coefficient tensor for all particles :math:`[\mathrm{time}^{-1}]`. + `Brownian` uses the same integrator as `hoomd.md.methods.Brownian`, which follows the overdamped Langevin equations of motion with the additional force term :math:`- \lambda \vec{F}_\mathrm{M}`. The force @@ -340,14 +375,18 @@ class Brownian(MethodRATTLE): algorithm. For more details about Brownian dynamics see `hoomd.md.methods.Brownian`. - Examples of using ``manifold_constraint``:: + .. rubric:: Example - sphere = hoomd.md.manifold.Sphere(r=10) + .. code-block:: python + + sphere = hoomd.md.manifold.Sphere(r=5) brownian_rattle = hoomd.md.methods.rattle.Brownian( - filter=hoomd.filter.All(), kT=0.2, manifold_constraint=sphere, - seed=1) - integrator = hoomd.md.Integrator(dt=0.001, methods=[brownian_rattle], - forces=[lj]) + filter=hoomd.filter.All(), + kT=1.5, + manifold_constraint=sphere, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0)) + simulation.operations.integrator.methods = [brownian_rattle] Attributes: filter (hoomd.filter.filter_like): Subset of particles to apply this @@ -374,7 +413,13 @@ class Brownian(MethodRATTLE): :math:`[\mathrm{time}^{-1}]`. """ - def __init__(self, filter, kT, manifold_constraint, tolerance=1e-6): + def __init__(self, + filter, + kT, + manifold_constraint, + tolerance=1e-6, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0)): # store metadata param_dict = ParameterDict( @@ -389,11 +434,14 @@ def __init__(self, filter, kT, manifold_constraint, tolerance=1e-6): gamma = TypeParameter('gamma', type_kind='particle_types', param_dict=TypeParameterDict(1., len_keys=1)) + gamma.default = default_gamma gamma_r = TypeParameter('gamma_r', type_kind='particle_types', param_dict=TypeParameterDict((1., 1., 1.), len_keys=1)) + gamma_r.default = default_gamma_r + self._extend_typeparam([gamma, gamma_r]) super().__init__(manifold_constraint, tolerance) @@ -433,6 +481,12 @@ class OverdampedViscous(MethodRATTLE): units of tolerance match that of the selected manifold's implicit function. Defaults to 1e-6 + default_gamma (float): Default drag coefficient for all particle types + :math:`[\mathrm{mass} \cdot \mathrm{time}^{-1}]`. + + default_gamma_r ([`float`, `float`, `float`]): Default rotational drag + coefficient tensor for all particles :math:`[\mathrm{time}^{-1}]`. + `OverdampedViscous` uses the same integrator as `hoomd.md.methods.OverdampedViscous`, with the additional force term :math:`- \lambda \vec{F}_\mathrm{M}`. The force :math:`\vec{F}_\mathrm{M}` @@ -441,14 +495,17 @@ class OverdampedViscous(MethodRATTLE): details about overdamped viscous dynamics see `hoomd.md.methods.OverdampedViscous`. - Examples of using ``manifold_constraint``:: + .. rubric:: Example - sphere = hoomd.md.manifold.Sphere(r=10) - odv_rattle = hoomd.md.methods.rattle.OverdampedViscous( - filter=hoomd.filter.All(), manifold_constraint=sphere, seed=1) - integrator = hoomd.md.Integrator( - dt=0.001, methods=[odv_rattle], forces=[lj]) + .. code-block:: python + sphere = hoomd.md.manifold.Sphere(r=5) + odv_rattle = hoomd.md.methods.rattle.OverdampedViscous( + filter=hoomd.filter.All(), + manifold_constraint=sphere, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0)) + simulation.operations.integrator.methods = [odv_rattle] Attributes: filter (hoomd.filter.filter_like): Subset of particles to apply this @@ -472,7 +529,12 @@ class OverdampedViscous(MethodRATTLE): :math:`[\mathrm{time}^{-1}]`. """ - def __init__(self, filter, manifold_constraint, tolerance=1e-6): + def __init__(self, + filter, + manifold_constraint, + tolerance=1e-6, + default_gamma=1.0, + default_gamma_r=(1.0, 1.0, 1.0)): # store metadata param_dict = ParameterDict(filter=ParticleFilter,) param_dict.update(dict(filter=filter)) @@ -483,11 +545,14 @@ def __init__(self, filter, manifold_constraint, tolerance=1e-6): gamma = TypeParameter('gamma', type_kind='particle_types', param_dict=TypeParameterDict(1., len_keys=1)) + gamma.default = default_gamma gamma_r = TypeParameter('gamma_r', type_kind='particle_types', param_dict=TypeParameterDict((1., 1., 1.), len_keys=1)) + gamma_r.default = default_gamma_r + self._extend_typeparam([gamma, gamma_r]) super().__init__(manifold_constraint, tolerance) diff --git a/hoomd/md/pytest/test_methods.py b/hoomd/md/pytest/test_methods.py index 662fc99182..19be36d0dd 100644 --- a/hoomd/md/pytest/test_methods.py +++ b/hoomd/md/pytest/test_methods.py @@ -328,6 +328,17 @@ def test_constant_pressure_attributes_attached_2d( 'kT': 1.5 }), (hoomd.md.methods.OverdampedViscous, {}), + (hoomd.md.methods.rattle.Brownian, { + 'kT': 1.5, + 'manifold_constraint': hoomd.md.manifold.Sphere(r=10) + }), + (hoomd.md.methods.rattle.Langevin, { + 'kT': 1.5, + 'manifold_constraint': hoomd.md.manifold.Sphere(r=10) + }), + (hoomd.md.methods.rattle.OverdampedViscous, { + 'manifold_constraint': hoomd.md.manifold.Sphere(r=10) + }), ]) def test_default_gamma(self, cls, init_args): c = cls(filter=hoomd.filter.All(), **init_args)