Snapshot

class hoomd.Snapshot(communicator=None)

Self-contained copy of the simulation State.

Parameters:

communicator (Communicator) – MPI communicator to be used when accessing the snapshot.

See State and gsd.hoomd.Frame for detailed documentation on the components of Snapshot.

Note

Snapshot is duck-type compatible with gsd.hoomd.Frame except that arrays in Snapshot are not assignable. You can edit their contents: e.g. snapshot.particles.typeid[:] == 0.

Warning

Data is only present on the root rank:

if snapshot.communicator.rank == 0:
    pos = snapshot.particles.position[0]

Example:

snapshot = hoomd.Snapshot()
communicator

MPI communicator.

Type:

Communicator

property angles

Angles.

angles.N

Number of angles.

Type:

int

angles.types

Names of the angle types

Type:

list[str]

angles.typeid

Angle type id.

Type:

(N,) numpy.ndarray of uint32

angles.group

Tags of the particles in the angle.

Type:

(N, 3) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.angles.N = 1
    snapshot.angles.group[:] = [[0, 1, 2]]
    snapshot.angles.types = ["A-B-B"]
    snapshot.angles.typeid[:] = [0]
property bonds

Bonds.

bonds.N

Number of bonds.

Type:

int

bonds.types

Names of the bond types

Type:

list[str]

bonds.typeid

Bond type id.

Type:

(N,) numpy.ndarray of uint32

bonds.group

Tags of the particles in the bond.

Type:

(N, 2) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.bonds.N = 2
    snapshot.bonds.group[:] = [[0, 1], [2, 3]]
    snapshot.bonds.types = ["A-B"]
    snapshot.bonds.typeid[:] = [0, 0]
property configuration

Snapshot box configuration.

dimensions

Number of dimensions

Type:

int

box

Simulation box parameters [Lx, Ly, Lz, xy, xz, yz].

Type:

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

Note

box accepts any values that Box.from_box allows when setting.

See also

Box

Example:

snapshot.configuration.box = [10, 20, 30, 0.1, 0.2, 0.3]
property constraints

Constraints.

constraints.N

Number of constraints.

Type:

int

constraints.value

Constraint length.

Type:

(N, ) numpy.ndarray of float

constraints.group

Tags of the particles in the constraint.

Type:

(N, 2) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.constraints.N = 2
    snapshot.constraints.group[:] = [[0, 1], [2, 3]]
    snapshot.constraints.value[:] = [1, 1]
property dihedrals

Dihedrals.

dihedrals.N

Number of dihedrals.

Type:

int

dihedrals.types

Names of the dihedral types

Type:

list[str]

dihedrals.typeid

Dihedral type id.

Type:

(N,) numpy.ndarray of uint32

dihedrals.group

Tags of the particles in the dihedral.

Type:

(N, 4) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.dihedrals.N = 1
    snapshot.dihedrals.group[:] = [[0, 1, 2, 3]]
    snapshot.dihedrals.types = ["A-B-B-A"]
    snapshot.dihedrals.typeid[:] = [0]
classmethod from_gsd_frame(gsd_snap, communicator)

Constructs a hoomd.Snapshot from a gsd.hoomd.Frame object.

Parameters:

Tip

Use Simulation.create_state_from_gsd to efficiently initialize the system state from a GSD file.

Note

from_gsd_frame only accesses the gsd_snap argument on rank 0. In MPI simulations, avoid duplicating memory and file reads by reading GSD files only on rank 0 and passing gsd_snap=None on other ranks.

property impropers

Impropers.

impropers.N

Number of impropers.

Type:

int

impropers.types

Names of the improper types

Type:

list[str]

impropers.typeid

Improper type id.

Type:

(N,) numpy.ndarray of uint32

impropers.group

Tags of the particles in the improper.

Type:

(N, 4) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

if snapshot.communicator.rank == 0:
    snapshot.impropers.N = 1
    snapshot.impropers.group[:] = [[0, 1, 2, 3]]
    snapshot.impropers.types = ["A-B-B-A"]
    snapshot.impropers.typeid[:] = [0]
property mpcd

MPCD data.

mpcd.N

Number of MPCD particles.

Type:

int

mpcd.position

Particle position \([\mathrm{length}]\).

Type:

(N, 3) numpy.ndarray of float

mpcd.velocity

Particle velocity \([\mathrm{velocity}]\).

Type:

(N, 3) numpy.ndarray of float

mpcd.types

Names of the particle types.

Type:

list[str]

mpcd.typeid

Particle type id.

Type:

(N, ) numpy.ndarray of uint32

mpcd.mass

Particle mass.

Type:

float

Note

Set N to change the size of the arrays.

Note

This attribute is only available when HOOMD-blue is built with the MPCD component.

property pairs

Special pairs.

pairs.N

Number of special pairs.

Type:

int

pairs.types

Names of the special pair types

Type:

list[str]

pairs.typeid

Special pair type id.

Type:

(N,) numpy.ndarray of uint32

pairs.group

Tags of the particles in the special pair.

Type:

(N, 2) numpy.ndarray of uint32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.pairs.N = 2
    snapshot.pairs.group[:] = [[0, 1], [2, 3]]
    snapshot.pairs.types = ["A-B"]
    snapshot.pairs.typeid[:] = [0, 0]
property particles

Particles.

particles.N

Number of particles in the snapshot.

Type:

int

particles.types

Names of the particle types.

Type:

list[str]

particles.position

Particle position \([\mathrm{length}]\).

Type:

(N, 3) numpy.ndarray of float

particles.orientation

Particle orientation.

Type:

(N, 4) numpy.ndarray of float

particles.typeid

Particle type id.

Type:

(N, ) numpy.ndarray of uint32

particles.mass

Particle mass \([\mathrm{mass}]\).

Type:

(N, ) numpy.ndarray of float

particles.charge

Particle charge \([\mathrm{charge}]\).

Type:

(N, ) numpy.ndarray of float

particles.diameter

Particle diameter \([\mathrm{length}]\).

Type:

(N, ) numpy.ndarray of float

particles.body

Particle body.

Type:

(N, ) numpy.ndarray of int32

particles.moment_inertia

Particle moment of inertia \([\mathrm{mass} \cdot \mathrm{length}^2]\).

Type:

(N, 3) numpy.ndarray of float

particles.velocity

Particle velocity \([\mathrm{velocity}]\).

Type:

(N, 3) numpy.ndarray of float

particles.angmom

Particle angular momentum \([\mathrm{mass} \cdot \mathrm{velocity} \cdot \mathrm{length}]\).

Type:

(N, 4) numpy.ndarray of float

particles.image

Particle image.

Type:

(N, 3) numpy.ndarray of int32

Note

Set N to change the size of the arrays.

Example:

if snapshot.communicator.rank == 0:
    snapshot.particles.N = 4
    snapshot.particles.position[:] = [[0, 0, 0],
                                    [1, 0, 0],
                                    [0, 1, 0],
                                    [0, 0, 1]]
    snapshot.particles.types = ['A', 'B']
    snapshot.particles.typeid[:] = [0, 1, 1, 0]
replicate(nx, ny, nz=1)

Replicate the snapshot along the periodic box directions.

Parameters:
  • nx (int) – Number of times to replicate in the x direction.

  • ny (int) – Number of times to replicate in the y direction.

  • nz (int) – Number of times to replicate in the z direction.

Performs the same operation as State.replicate on a Snapshot.

Returns:

self

Example:

snapshot.replicate(nx=2, ny=2, nz=2)
wrap()

Wrap particles into the snapshot box.

Returns:

self

Example:

snapshot.wrap()