lammpsio.Snapshot¶
- class lammpsio.Snapshot(N, box, step=None, num_types=None)¶
Particle configuration.
A
Snapshotholds the data forNparticles, the simulationBox, and the timestep.- Parameters:
Example
Here is a 3-particle configuration in a cubic box centered at the origin at step 10:
snapshot = lammpsio.Snapshot( N=3, box=lammpsio.Box([-5, -5, -5], [5, 5, 5]), step=10 )
All values of indexes follow the LAMMPS 1-indexed convention, but the arrays themselves are 0-indexed.
Snapshotwill lazily initialize these per-particle arrays as they are accessed to save memory. Hence, accessing a per-particle property will allocate it to default values. If you want to check if an attribute has been set, use the correspondinghas_method instead (e.g.,has_positionto check if thepositiondata is allocated):snapshot.position = [[0, 0, 0], [1, -1, 1], [1.5, 2.5, -3.5]] snapshot.typeid[2] = 2 if not snapshot.has_mass(): snapshot.mass = [2., 2., 10.]
Methods:
from_hoomd_gsd(frame)Create from a HOOMD GSD frame.
Check if configuration has angles.
Check if configuration has bonds.
Check if configuration has charges.
Check if configuration has dihedrals.
has_id()Check if configuration has particle IDs.
Check if configuration has images.
Check if configuration has impropers.
has_mass()Check if configuration has masses.
Check if configuration has molecule tags.
Check if configuration has positions.
Check if configuration has types.
Check if configuration has velocities.
reorder(order[, check_order])Reorder the particles in place.
to_hoomd_gsd([type_map])Create a HOOMD GSD frame.
Attributes:
Number of particles.
Angle data.
Bond data.
Simulation box.
Charges.
Dihedral data.
Particle IDs.
Images.
Improper data.
Masses.
Molecule tags.
Number of atom types.
Positions.
Simulation time step.
Labels for
typeid.Types.
Velocities.
- classmethod from_hoomd_gsd(frame)¶
Create from a HOOMD GSD frame.
- Parameters:
frame (
gsd.hoomd.Frame) – HOOMD GSD frame to convert.- Returns:
Snapshot– Snapshot created from HOOMD GSD frame.dict – A map from the
Snapshot.typeidto the HOOMD type.Deprecated since version 0.7.0: Use
Snapshot.type_labelinstead.
Example
Create snapshot from a GSD file:
frame = gsd.hoomd.Frame() frame.configuration.box = [10, 10, 10, 0, 0, 0] frame.particles.N = 3 snapshot, type_map = lammpsio.Snapshot.from_hoomd_gsd(frame)
This creates a
Snapshotfrom the provided HOOMD GSD frame as well as the corresponding dictionary of typeids mapped from the HOOMD GSD frame.
- to_hoomd_gsd(type_map=None)¶
Create a HOOMD GSD frame.
- Parameters:
type_map (dict) –
A map from the
Snapshot.typeidto a HOOMD type. If not specified, the typeids are used as the types.Deprecated since version 0.7.0: Use
Snapshot.type_labelinstead.- Returns:
Converted HOOMD GSD frame.
- Return type:
Example
Convert snapshot to a GSD file:
frame = snapshot.to_hoomd_gsd()
This creates a GSD frame for the HOOMD-blue simulation package from the
Snapshotobject.
- property id¶
Particle IDs.
The default value on initialization runs from 1 to N.
- Type:
(N,)
numpy.ndarrayofint
- has_id()¶
Check if configuration has particle IDs.
- Returns:
Trueif particle IDs have been initialized.- Return type:
- property position¶
Positions.
The default value on initialization is 0 for all entries.
- Type:
(N, 3)
numpy.ndarrayoffloat
- has_position()¶
Check if configuration has positions.
- Returns:
Trueif positions have been initialized.- Return type:
- property image¶
Images.
The default value on initialization is 0 for all entries.
- Type:
(N, 3)
numpy.ndarrayofint
- has_image()¶
Check if configuration has images.
- Returns:
Trueif images have been initialized.- Return type:
- property velocity¶
Velocities.
The default value on initialization is 0 for all entries.
- Type:
(N, 3)
numpy.ndarrayoffloat
- has_velocity()¶
Check if configuration has velocities.
- Returns:
Trueif velocities have been initialized.- Return type:
- property molecule¶
Molecule tags.
The default value on initialization is 0 for all entries.
- Type:
(N,)
numpy.ndarrayofint
- has_molecule()¶
Check if configuration has molecule tags.
- Returns:
Trueif molecule tags have been initialized.- Return type:
- property typeid¶
Types.
The default value on initialization is 1 for all entries.
- Type:
(N,)
numpy.ndarrayofint
- has_typeid()¶
Check if configuration has types.
- Returns:
Trueif types have been initialized.- Return type:
- property charge¶
Charges.
The default value on initialization is 0 for all entries.
- Type:
(N,)
numpy.ndarrayoffloat
- has_charge()¶
Check if configuration has charges.
- Returns:
Trueif charges have been initialized.- Return type:
- property mass¶
Masses.
The default value on initialization is 1 for all entries.
- Type:
(N,)
numpy.ndarrayoffloat
- has_mass()¶
Check if configuration has masses.
- Returns:
Trueif masses have been initialized.- Return type:
- has_bonds()¶
Check if configuration has bonds.
- Returns:
Trueif bonds is initialized and there is at least one bond.- Return type:
- has_angles()¶
Check if configuration has angles.
- Returns:
Trueif angles is initialized and there is at least one angle.- Return type:
- has_dihedrals()¶
Check if configuration has dihedrals.
- Returns:
Trueif dihedrals is initialized and there is at least one dihedral.- Return type:
- has_impropers()¶
Check if configuration has impropers.
- Returns:
Trueif impropers is initialized and there is at least one improper.- Return type:
- reorder(order, check_order=True)¶
Reorder the particles in place.
- Parameters:
Example
Reorder the particles in a snapshot
snapshot.bonds = lammpsio.Bonds(N=3, num_types=1) bond_id = [1, 3, 2] members = [[1, 2], [2, 3], [3, 1]] typeid = [1, 1, 1] snapshot.bonds.id = bond_id snapshot.bonds.typeid = typeid snapshot.bonds.members = members snapshot.bonds.reorder(numpy.sort(numpy.array(bond_id)) - 1, check_order=True)
This reorders the particle data with the same ordering as the bonds. To ensure only the right unique indexes are used, the
check_orderparameter is set to True. In LAMMPS, all the IDs are 1-indexed, while, Python is 0-indexed. Thus thebond_idis also decreased by 1 to match the Python convention.