Skip to content
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

Enable flake8 for MPCD #1741

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ repos:
exclude: |
(?x)(
^hoomd/extern/|
^hoomd/mpcd/|
^hoomd/metal/
)
- repo: https://github.com/pre-commit/mirrors-clang-format
Expand Down
2 changes: 1 addition & 1 deletion hoomd/mpcd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

""" Multiparticle collision dynamics.
"""Multiparticle collision dynamics.

Simulating complex fluids and soft matter using conventional molecular dynamics
methods (`hoomd.md`) can be computationally demanding due to large disparities
Expand Down
19 changes: 12 additions & 7 deletions hoomd/mpcd/collide.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ class CollisionMethod(Operation):

Args:
period (int): Number of integration steps between collisions.
embedded_particles (hoomd.filter.filter_like): HOOMD particles to include in collision.
embedded_particles (hoomd.filter.filter_like): HOOMD particles to
include in collision.

Attributes:
embedded_particles (hoomd.filter.filter_like): HOOMD particles to include
in collision (*read only*).
embedded_particles (hoomd.filter.filter_like): HOOMD particles to
include in collision (*read only*).

These particles are included in per-cell quantities and have their
velocities updated along with the MPCD particles.
Expand All @@ -118,10 +119,12 @@ class CollisionMethod(Operation):
will not be correctly transferred to the body. Support for this
is planned in future.

period (int): Number of integration steps between collisions (*read only*).
period (int): Number of integration steps between collisions
(*read only*).

A collision is executed each time the :attr:`~hoomd.Simulation.timestep`
is a multiple of `period`. It must be a multiple of `period` for the
A collision is executed each time the
:attr:`~hoomd.Simulation.timestep` is a multiple of `period`. It
must be a multiple of `period` for the
:class:`~hoomd.mpcd.stream.StreamingMethod` if one is attached to
the :class:`~hoomd.mpcd.Integrator`.

Expand Down Expand Up @@ -166,7 +169,9 @@ class AndersenThermostat(CollisionMethod):

.. code-block:: python

andersen_thermostat = hoomd.mpcd.collide.AndersenThermostat(period=1, kT=1.0)
andersen_thermostat = hoomd.mpcd.collide.AndersenThermostat(
period=1,
kT=1.0)
simulation.operations.integrator.collision_method = andersen_thermostat

Collision including embedded particles.
Expand Down
8 changes: 5 additions & 3 deletions hoomd/mpcd/fill.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

r""" MPCD virtual-particle fillers.
r"""MPCD virtual-particle fillers.

Virtual particles are MPCD solvent particles that are added to ensure MPCD
collision cells that are sliced by solid boundaries do not become "underfilled".
Expand Down Expand Up @@ -119,7 +119,8 @@ class GeometryFiller(VirtualParticleFiller):
simulation.operations.integrator.virtual_particle_fillers = [filler]

Attributes:
geometry (hoomd.mpcd.geometry.Geometry): Surface to fill around (*read only*).
geometry (hoomd.mpcd.geometry.Geometry): Surface to fill around
(*read only*).

"""

Expand Down Expand Up @@ -147,7 +148,8 @@ def _attach_hook(self):
if isinstance(sim.device, hoomd.device.GPU):
class_info[1] += "GPU"
class_ = getattr(*class_info, None)
assert class_ is not None, "Virtual particle filler for geometry not found"
assert class_ is not None, ("Virtual particle filler for geometry"
" not found")

self._cpp_obj = class_(
sim.state._cpp_sys_def,
Expand Down
27 changes: 15 additions & 12 deletions hoomd/mpcd/force.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

r""" MPCD solvent forces.
r"""MPCD solvent forces.

MPCD can apply a body force to each MPCD particle as a function of position.
The external force should be compatible with the chosen
Expand Down Expand Up @@ -46,10 +46,10 @@ class BlockForce(SolventForce):
blocks.
half_width (float): Half the width of each block.

The `force` magnitude *F* is applied in the *x* direction on the solvent particles
in blocks defined along the *y* direction by the `half_separation` *H* and
the `half_width` *w*. The force in *x* is :math:`+F` in the upper block,
:math:`-F` in the lower block, and zero otherwise.
The `force` magnitude *F* is applied in the *x* direction on the solvent
particles in blocks defined along the *y* direction by the `half_separation`
*H* and the `half_width` *w*. The force in *x* is :math:`+F` in the upper
block, :math:`-F` in the lower block, and zero otherwise.

.. math::
:nowrap:
Expand All @@ -62,9 +62,9 @@ class BlockForce(SolventForce):
\end{cases}
\end{equation}

The `BlockForce` can be used to implement the double-parabola method for measuring
viscosity by setting :math:`H = L_y/4` and :math:`w = L_y/4`, where :math:`L_y` is
the size of the simulation box in *y*.
The `BlockForce` can be used to implement the double-parabola method for
measuring viscosity by setting :math:`H = L_y/4` and :math:`w = L_y/4`,
where :math:`L_y` is the size of the simulation box in *y*.

Warning:
You should define the blocks to lie fully within the simulation box and
Expand All @@ -77,7 +77,10 @@ class BlockForce(SolventForce):
.. code-block:: python

Ly = simulation.state.box.Ly
force = hoomd.mpcd.force.BlockForce(force=1.0, half_separation=Ly/4, half_width=Ly/4)
force = hoomd.mpcd.force.BlockForce(
force=1.0,
half_separation=Ly/4,
half_width=Ly/4)
stream = hoomd.mpcd.stream.Bulk(period=1, solvent_force=force)
simulation.operations.integrator.streaming_method = stream

Expand Down Expand Up @@ -135,9 +138,9 @@ class ConstantForce(SolventForce):

The same constant force is applied to all solvent particles, independently
of time and position. This force is useful for simulating pressure-driven
flow in conjunction with a confined geometry having no-slip boundary conditions.
It is also useful for measuring diffusion coefficients with nonequilibrium
methods.
flow in conjunction with a confined geometry having no-slip boundary
conditions. It is also useful for measuring diffusion coefficients with
nonequilibrium methods.

.. rubric:: Example:

Expand Down
6 changes: 4 additions & 2 deletions hoomd/mpcd/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
A geometry defines solid boundaries that cannot be penetrated. These
geometries are used for various operations in the MPCD algorithm including:

* Bounce-back streaming for MPCD particles (:class:`hoomd.mpcd.stream.BounceBack`)
* Bounce-back integration for MD particles (:class:`hoomd.mpcd.methods.BounceBack`)
* Bounce-back streaming for MPCD particles
(:class:`hoomd.mpcd.stream.BounceBack`)
* Bounce-back integration for MD particles
(:class:`hoomd.mpcd.methods.BounceBack`)
* Virtual particle filling (:class:`hoomd.mpcd.fill.GeometryFiller`)

Each geometry may put constraints on the size of the simulation and where
Expand Down
17 changes: 10 additions & 7 deletions hoomd/mpcd/integrate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

"""Implement MPCD Integrator."""

import hoomd
from hoomd.data.parameterdicts import ParameterDict
from hoomd.data import syncedlist
Expand Down Expand Up @@ -48,7 +50,8 @@ class Integrator(_MDIntegrator):
collision_method (hoomd.mpcd.collide.CollisionMethod): Collision method
for the MPCD solvent and any embedded particles.

virtual_particle_fillers (Sequence[hoomd.mpcd.fill.VirtualParticleFiller]): Solvent
virtual_particle_fillers
(Sequence[hoomd.mpcd.fill.VirtualParticleFiller]): Solvent
virtual-particle filler(s).

solvent_sorter (hoomd.mpcd.tune.ParticleSorter): Tuner for sorting the
Expand Down Expand Up @@ -86,7 +89,9 @@ class Integrator(_MDIntegrator):
.. code-block:: python

stream = hoomd.mpcd.stream.Bulk(period=1)
collide = hoomd.mpcd.collide.StochasticRotationDynamics(period=1, angle=130)
collide = hoomd.mpcd.collide.StochasticRotationDynamics(
period=1,
angle=130)
integrator = hoomd.mpcd.Integrator(
dt=0.1,
streaming_method=stream,
Expand Down Expand Up @@ -213,10 +218,8 @@ def cell_list(self):

@property
def virtual_particle_fillers(self):
"""Sequence[hoomd.mpcd.fill.VirtualParticleFiller]: Solvent
virtual-particle fillers.

"""
"""Sequence[hoomd.mpcd.fill.VirtualParticleFiller]: Solvent \
virtual-particle fillers."""
return self._virtual_particle_fillers

@virtual_particle_fillers.setter
Expand Down Expand Up @@ -261,7 +264,7 @@ def _setattr_param(self, attr, value):
if value is not None and value._attached:
raise ValueError("Cannot attach to multiple integrators.")

# if already attached, change out which is attached, then set parameter
# if already attached, change out and set parameter
if self._attached:
if cur_value is not None:
cur_value._detach()
Expand Down
60 changes: 30 additions & 30 deletions hoomd/mpcd/methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

r""" MPCD integration methods
r"""MPCD integration methods.

Extra integration methods for solutes (MD particles) embedded in an MPCD
solvent. These methods are not restricted to MPCD simulations: they can be used
Expand Down Expand Up @@ -31,54 +31,54 @@ class BounceBack(Method):
apply this method.
geometry (hoomd.mpcd.geometry.Geometry): Surface to bounce back from.

A bounce-back method for integrating solutes (MD particles) embedded in
an MPCD solvent. The integration scheme is velocity Verlet with bounce-back
A bounce-back method for integrating solutes (MD particles) embedded in an
MPCD solvent. The integration scheme is velocity Verlet with bounce-back
performed at the solid boundaries defined by a geometry, as in
`hoomd.mpcd.stream.BounceBack`. This gives a simple approximation of the
interactions required to keep a solute bounded in a geometry, and more complex
interactions can be specified, for example, by writing custom external fields.

Similar caveats apply to these methods as for `hoomd.mpcd.stream.BounceBack`.
In particular:

1. The simulation box is periodic, but the `geometry` may impose non-periodic
boundary conditions. You must ensure that the box is sufficiently large to
enclose the `geometry` and that all particles lie inside it, or an error will
be raised at runtime.
2. You must also ensure that particles do not self-interact through the periodic
boundaries. This is usually achieved for simple pair potentials by padding
the box size by the largest cutoff radius. Failure to do so may result in
unphysical interactions.
interactions required to keep a solute bounded in a geometry, and more
complex interactions can be specified, for example, by writing custom
external fields.

Similar caveats apply to these methods as for
`hoomd.mpcd.stream.BounceBack`. In particular:

1. The simulation box is periodic, but the `geometry` may impose
non-periodic boundary conditions. You must ensure that the box is
sufficiently large to enclose the `geometry` and that all particles lie
inside it, or an error will be raised at runtime.
2. You must also ensure that particles do not self-interact through the
periodic boundaries. This is usually achieved for simple pair potentials
by padding the box size by the largest cutoff radius. Failure to do so
may result in unphysical interactions.
3. Bounce-back rules do not always enforce no-slip conditions at surfaces
properly. It may still be necessary to add additional "ghost" MD particles in
the surface to achieve the right boundary conditions and reduce density
fluctuations.
properly. It may still be necessary to add additional "ghost" MD
particles in the surface to achieve the right boundary conditions and
reduce density fluctuations.

Warning:

This method does not support anisotropic integration because
torques are not computed for collisions with the boundary.
Rigid bodies will also not be treated correctly because the
integrator is not aware of the extent of the particles. The surface
reflections are treated as point particles. These conditions are too
complicated to validate easily, so it is the user's responsibility to
choose the `filter` correctly.
This method does not support anisotropic integration because torques are
not computed for collisions with the boundary. Rigid bodies will also
not be treated correctly because the integrator is not aware of the
extent of the particles. The surface reflections are treated as point
particles. These conditions are too complicated to validate easily, so
it is the user's responsibility to choose the `filter` correctly.

.. rubric:: Example:

.. code-block:: python

plates = hoomd.mpcd.geometry.ParallelPlates(H=3.0)
nve = hoomd.mpcd.methods.BounceBack(
filter=hoomd.filter.All(),
geometry=plates)
filter=hoomd.filter.All(), geometry=plates)
simulation.operations.integrator.methods.append(nve)

Attributes:
filter (hoomd.filter.filter_like): Subset of particles on which to apply
this method (*read only*).

geometry (hoomd.mpcd.geometry.Geometry): Surface to bounce back from (*read only*).
geometry (hoomd.mpcd.geometry.Geometry): Surface to bounce back from
(*read only*).

"""

Expand Down
3 changes: 2 additions & 1 deletion hoomd/mpcd/pytest/test_collide.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import pytest

import hoomd
from hoomd.conftest import pickling_check
import pytest


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/pytest/test_fill.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import pytest

import hoomd
from hoomd.conftest import pickling_check
import numpy as np
import pytest


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions hoomd/mpcd/pytest/test_force.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import numpy as np

import hoomd
from hoomd.conftest import pickling_check
import numpy as np
import pytest


def test_block_force(simulation_factory):
Expand Down
3 changes: 2 additions & 1 deletion hoomd/mpcd/pytest/test_geometry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import pytest

import hoomd
from hoomd.conftest import pickling_check
import pytest


@pytest.fixture
Expand Down
5 changes: 2 additions & 3 deletions hoomd/mpcd/pytest/test_integrator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import pytest

import hoomd
from hoomd.conftest import pickling_check

import numpy as np
import pytest


@pytest.fixture
def make_simulation(simulation_factory):
Expand Down
7 changes: 4 additions & 3 deletions hoomd/mpcd/pytest/test_methods.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Copyright (c) 2009-2023 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import hoomd
from hoomd.conftest import pickling_check
import numpy as np
import pytest

import hoomd
from hoomd.conftest import pickling_check


@pytest.fixture
def snap():
Expand Down Expand Up @@ -103,7 +104,7 @@ def test_step_slip(self, simulation_factory, snap, integrator):
snap.particles.velocity,
[[1.0, -1.0, -1.0], [-1.0, -1.0, -1.0]])

# take another step, reflecting the perpendicular motion of second particle
# take another step, reflecting perpendicular motion of second particle
sim.run(1)
snap = sim.state.get_snapshot()
if snap.communicator.rank == 0:
Expand Down
Loading
Loading