gsd.hoomd module¶
hoomd schema reference implementation
The main package gsd.hoomd
is a reference implementation of the
GSD schema hoomd
. It is a simple, but high performance and memory
efficient, reader and writer for the schema. See HOOMD examples
for full examples.
create()
- Create a hoomd schema GSD file (deprecated).open()
- Open a hoomd schema GSD file.HOOMDTrajectory
- Read and write hoomd schema GSD files.Snapshot
- Store the state of a single frame.ConfigurationData
- Store configuration data in a snapshot.ParticleData
- Store particle data in a snapshot.BondData
- Store topology data in a snapshot.
-
class
gsd.hoomd.
BondData
(M)¶ Store bond data chunks.
Users should not need to instantiate this class. Use the
bonds
,angles
,dihedrals
, orimpropers
attribute of aSnapshot
.Instances resulting from file read operations will always store per bond quantities in numpy arrays of the defined types. User created snapshots can provide input data as python lists, tuples, numpy arrays of different types, etc… Such input elements will be converted to the appropriate array type by
validate()
which is called when writing a frame.Note
M varies depending on the type of bond. The same python class represents all types of bonds.
Type M Bond 2 Angle 3 Dihedral 4 Improper 4 -
N
¶ int – Number of particles in the snapshot (
bonds/N
,angles/N
,dihedrals/N
,impropers/N
,pairs/N
).
-
types
¶ list[str] – Names of the particle types (
bonds/types
,angles/types
,dihedrals/types
,impropers/types
,pairs/types
).
-
typeid
¶ numpy.ndarray[uint32, ndim=1, mode=’c’] – N length array defining bond type ids (
bonds/typeid
,angles/typeid
,dihedrals/typeid
,impropers/typeid
,pairs/types
).
-
group
¶ numpy.ndarray[uint32, ndim=2, mode=’c’] – NxM array defining tags in the particle bonds (
bonds/group
,angles/group
,dihedrals/group
,impropers/group
,pairs/group
).
-
validate
()¶ Validate all attributes.
First, convert every per bond attribute to a numpy array of the proper type. Then validate that all attributes have the correct dimensions.
Ignore any attributes that are
None
.Warning
Per bond attributes that are not contiguous numpy arrays will be replaced with contiguous numpy arrays of the appropriate type.
-
-
class
gsd.hoomd.
ConfigurationData
¶ Store configuration data.
Users should not need to instantiate this class. Use the
configuration
attribute of aSnapshot
.-
step
¶ int – Time step of this frame (
configuration/step
).
-
dimensions
¶ int – Number of dimensions (
configuration/dimensions
).
-
box
¶ numpy.ndarray[float, ndim=1, mode=’c’] – Box dimensions (
configuration/box
) - [lx, ly, lz, xy, xz, yz].
-
validate
()¶ Validate all attributes.
First, convert every array attribute to a numpy array of the proper type. Then validate that all attributes have the correct dimensions.
Ignore any attributes that are
None
.Warning
Array attributes that are not contiguous numpy arrays will be replaced with contiguous numpy arrays of the appropriate type.
-
-
class
gsd.hoomd.
ConstraintData
¶ Store constraint data chunks.
Users should not need to instantiate this class. Use the
constraints
, attribute of aSnapshot
.Instances resulting from file read operations will always store per constraint quantities in numpy arrays of the defined types. User created snapshots can provide input data as python lists, tuples, numpy arrays of different types, etc… Such input elements will be converted to the appropriate array type by
validate()
which is called when writing a frame.-
N
¶ int – Number of particles in the snapshot (
constraints/N
).
-
value
¶ numpy.ndarray[float32, ndim=1, mode=’c’] – N length array defining constraint lengths (
constraints/value
).
-
group
¶ numpy.ndarray[uint32, ndim=2, mode=’c’] – Nx2 array defining tags in the particle constraints (
constraints/group
).
-
validate
()¶ Validate all attributes.
First, convert every per constraint attribute to a numpy array of the proper type. Then validate that all attributes have the correct dimensions.
Ignore any attributes that are
None
.Warning
Per bond attributes that are not contiguous numpy arrays will be replaced with contiguous numpy arrays of the appropriate type.
-
-
class
gsd.hoomd.
HOOMDTrajectory
(file)¶ Read and write hoomd gsd files.
Parameters: file ( gsd.fl.GSDFile
) – File to access.Create hoomd GSD files with
create()
.-
append
(snapshot)¶ Append a snapshot to a hoomd gsd file.
Parameters: snapshot ( Snapshot
) – Snapshot to append.Write the given snapshot to the file at the current frame and increase the frame counter. Do not attempt to write any fields that are
None
. For all non-None
fields, scan them and see if they match the initial frame or the default value. If the given data differs, write it out to the frame. If it is the same, do not write it out as it can be instantiated either from the value at the initial frame or the default value.
-
extend
(iterable)¶ Append each item of the iterable to the file.
Parameters: iterable – An iterable object the provides Snapshot
instances. This could be another HOOMDTrajectory, a generator that modifies snapshots, or a simple list of snapshots.
-
read_frame
(idx)¶ Read the frame at the given index from the file.
Parameters: idx (int) – Frame index to read. Returns: Snapshot
with the frame dataReplace any data chunks not present in the given frame with either data from frame 0, or initialize from default values if not in frame 0. Cache frame 0 data to avoid file read overhead. Return any default data as non-writable numpy arrays.
-
truncate
()¶ Remove all frames from the file.
-
-
class
gsd.hoomd.
ParticleData
¶ Store particle data chunks.
Users should not need to instantiate this class. Use the
particles
attribute of aSnapshot
.Instances resulting from file read operations will always store per particle quantities in numpy arrays of the defined types. User created snapshots can provide input data as python lists, tuples, numpy arrays of different types, etc… Such input elements will be converted to the appropriate array type by
validate()
which is called when writing a frame.-
N
¶ int – Number of particles in the snapshot (
particles/N
).
-
types
¶ list[str] – Names of the particle types (
particles/types
).
-
position
¶ numpy.ndarray[float, ndim=2, mode=’c’] – Nx3 array defining particle position (
particles/position
).
-
orientation
¶ numpy.ndarray[float, ndim=2, mode=’c’] – Nx4 array defining particle position (
particles/orientation
).
-
typeid
¶ numpy.ndarray[uint32, ndim=1, mode=’c’] – N length array defining particle type ids (
particles/typeid
).
-
mass
¶ numpy.ndarray[float, ndim=1, mode=’c’] – N length array defining particle masses (
particles/mass
).
-
charge
¶ numpy.ndarray[float, ndim=1, mode=’c’] – N length array defining particle charges (
particles/charge
).
-
diameter
¶ numpy.ndarray[float, ndim=1, mode=’c’] – N length array defining particle diameters (
particles/diameter
).
-
body
¶ numpy.ndarray[int32, ndim=1, mode=’c’] – N length array defining particle bodies (
particles/body
).
-
moment_inertia
¶ numpy.ndarray[float, ndim=2, mode=’c’] – Nx3 array defining particle moments of inertia (
particles/moment_inertia
).
-
velocity
¶ numpy.ndarray[float, ndim=2, mode=’c’] – Nx3 array defining particle velocities (
particles/velocity
).
-
angmom
¶ numpy.ndarray[float, ndim=2, mode=’c’] – Nx4 array defining particle angular momenta (
particles/angmom
).
-
image
¶ numpy.ndarray[int32, ndim=2, mode=’c’] – Nx3 array defining particle images (
particles/image
).
-
validate
()¶ Validate all attributes.
First, convert every per particle attribute to a numpy array of the proper type. Then validate that all attributes have the correct dimensions.
Ignore any attributes that are
None
.Warning
Per particle attributes that are not contiguous numpy arrays will be replaced with contiguous numpy arrays of the appropriate type.
-
-
class
gsd.hoomd.
Snapshot
¶ Top level snapshot container.
-
configuration
¶ ConfigurationData
– Configuration data.
-
particles
¶ ParticleData
– Particle data snapshot.
-
pairs (
py:class: BondData): Special pair interactions snapshot
-
state
¶ dict – Dictionary containing state data
See the HOOMD schema specification for details on entries in the state dictionary. Entries in this dict are the chunk name without the state prefix. For example,
state/hpmc/sphere/radius
is stored in the dictionary entrystate['hpmc/sphere/radius']
.-
validate
()¶ Validate all contained snapshot data.
-
-
gsd.hoomd.
create
(name, snapshot=None)¶ Create a hoomd gsd file from the given snapshot.
Parameters: Deprecated since version 1.2: As of version 1.2, you can create and open hoomd GSD files in the same call to
open()
.create()
is kept for backwards compatibility.Danger
The file is overwritten if it already exists.
-
gsd.hoomd.
open
(name, mode='rb')¶ Open a hoomd schema GSD file.
The return value of
open()
can be used as a context manager.Parameters: Returns: An
HOOMDTrajectory
instance that accesses the file name with the given mode.Valid values for mode:
mode description 'rb'
Open an existing file for reading. 'rb+'
Open an existing file for reading and writing. Inefficient for large files. 'wb'
Open a file for writing. Creates the file if needed, or overwrites an existing file. 'wb+'
Open a file for reading and writing. Creates the file if needed, or overwrites an existing file. Inefficient for large files. 'xb'
Create a gsd file exclusively and opens it for writing. Raise an FileExistsError
exception if it already exists.'xb+'
Create a gsd file exclusively and opens it for reading and writing. Raise an FileExistsError
exception if it already exists. Inefficient for large files.'ab'
Open an existing file for writing. Does not create or overwrite existing files. New in version 1.2.