6.9. LAMMPS DCD trajectory and DATA I/O — MDAnalysis.coordinates.LAMMPS
¶
Classes to read and write LAMMPS DCD binary trajectories and LAMMPS DATA files. Trajectories can be read regardless of system-endianness as this is auto-detected.
LAMMPS can write DCD trajectories but unlike a CHARMM trajectory (which is often called a DCD even though CHARMM itself calls them “trj”) the time unit is not fixed to be the AKMA time unit (20 AKMA is 0.978 picoseconds or 1 AKMA = 4.888821e-14 s) but can depend on settings in LAMMPS. The most common case for biomolecular simulations appears to be that the time step is recorded in femtoseconds (command units real in the input file) and lengths in ångströms. Other cases are unit-less Lennard-Jones time units.
This presents a problem for MDAnalysis because it cannot autodetect
the unit from the file. By default we are assuming that the unit for
length is the ångström and for the time is the femtosecond. If this is
not true then the user should supply the appropriate units in the
keywords timeunit and/or lengthunit to DCDWriter
and
Universe
(which then calls
DCDReader
).
6.9.1. Example: Loading a LAMMPS simulation¶
To load a LAMMPS simulation from a LAMMPS data file (using the
DATAParser
) together with a
LAMMPS DCD with “real” provide the keyword format=”LAMMPS”:
>>> u = MDAnalysis.Universe("lammps.data", "lammps_real.dcd", format="LAMMPS")
If the trajectory uses units nano then use
>>> u = MDAnalysis.Universe("lammps.data", "lammps_nano.dcd", format="LAMMPS",
... lengthunit="nm", timeunit="ns")
To scan through a trajectory to find a desirable frame and write to a LAMMPS data file,
>>> for ts in u.trajectory:
... # analyze frame
... if take_this_frame == True:
... with mda.Writer('frame.data') as W:
... W.write(u.atoms)
... break
Note
Lennard-Jones units are not implemented. See MDAnalysis.units
for other recognized values and the documentation for the LAMMPS
units command.
6.9.2. Classes¶
-
class
MDAnalysis.coordinates.LAMMPS.
DCDReader
(dcdfilename, **kwargs)[source]¶ Read a LAMMPS DCD trajectory.
The units can be set from the constructor with the keyword arguments timeunit and lengthunit. The defaults are “fs” and “Angstrom”, corresponding to LAMMPS units style “real”. See
MDAnalysis.units
for other recognized values.-
OtherWriter
(filename, **kwargs)¶ Returns a writer appropriate for filename.
Sets the default keywords start, step and dt (if available). n_atoms is always set from
Reader.n_atoms
.See also
Reader.Writer()
-
Writer
(filename, **kwargs)[source]¶ Returns a DCDWriter for filename with the same parameters as this DCD.
Defaults for all values are obtained from the DCDReader itself but all values can be changed through keyword arguments.
Parameters: - filename (str) – filename of the output DCD trajectory
- n_atoms (int (optional)) – number of atoms
- start (int (optional)) – number of the first recorded MD step
- step (int (optional)) – indicate that step MD steps (!) make up one trajectory frame
- delta (float (optional)) – MD integrator time step (!), in AKMA units
- dt (float (optional)) – Override step and delta so that the DCD records that
dt ps lie between two frames. (It sets step “ = 1“ and
delta “ = AKMA(dt)“.) The default is
None
, in which case step and delta are used. - remarks (str (optional)) – string that is stored in the DCD header
Returns: Return type: Note
The keyword arguments set the low-level attributes of the DCD according to the CHARMM format. The time between two frames would be delta * step!
Here step is really the number of MD integrator time steps that occured after this frame, including the frame itself that is the coordinate snapshot and delta is the integrator stime step. The DCD file format contains this information so it needs to be provided here.
See also
-
add_auxiliary
(auxname, auxdata, format=None, **kwargs)¶ Add auxiliary data to be read alongside trajectory.
Auxiliary data may be any data timeseries from the trajectory additional to that read in by the trajectory reader. auxdata can be an
AuxReader
instance, or the data itself as e.g. a filename; in the latter case an appropriateAuxReader
is guessed from the data/file format. An appropriate format may also be directly provided as a key word argument.On adding, the AuxReader is initially matched to the current timestep of the trajectory, and will be updated when the trajectory timestep changes (through a call to
next()
or jumping timesteps withtrajectory[i]
).The representative value(s) of the auxiliary data for each timestep (as calculated by the
AuxReader
) are stored in the current timestep in thets.aux
namespace under auxname; e.g. to add additional pull force data stored in pull-force.xvg:u = MDAnalysis.Universe(PDB, XTC) u.trajectory.add_auxiliary('pull', 'pull-force.xvg')
The representative value for the current timestep may then be accessed as
u.trajectory.ts.aux.pull
oru.trajectory.ts.aux['pull']
.See also
Note
Auxiliary data is assumed to be time-ordered, with no duplicates. See the Auxiliary API.
-
aux_list
¶ Lists the names of added auxiliary data.
-
check_slice_indices
(start, stop, step)¶ Check frame indices are valid and clip to fit trajectory.
The usage follows standard Python conventions for
range()
but see the warning below.Parameters: - start (int or None) – Starting frame index (inclusive).
None
corresponds to the default of 0, i.e., the initial frame. - stop (int or None) – Last frame index (exclusive).
None
corresponds to the default of n_frames, i.e., it includes the last frame of the trajectory. - step (int or None) – step size of the slice,
None
corresponds to the default of 1, i.e, include every frame in the range start, stop.
Returns: start, stop, step – Integers representing the slice
Return type: Warning
The returned values start, stop and step give the expected result when passed in
range()
but gives unexpected behavior when passed in aslice
whenstop=None
andstep=-1
This can be a problem for downstream processing of the output from this method. For example, slicing of trajectories is implemented by passing the values returned by
check_slice_indices()
torange()
range(start, stop, step)
and using them as the indices to randomly seek to. On the other hand, in
MDAnalysis.analysis.base.AnalysisBase
the values returned bycheck_slice_indices()
are used to splice the trajectory by creating aslice
instanceslice(start, stop, step)
This creates a discrepancy because these two lines are not equivalent:
range(10, -1, -1) # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] range(10)[slice(10, -1, -1)] # []
- start (int or None) – Starting frame index (inclusive).
-
convert_forces_from_native
(force, inplace=True)¶ Conversion of forces array force from native to base units
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_forces_to_native
(force, inplace=True)¶ Conversion of force array force from base to native units.
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_pos_from_native
(x, inplace=True)¶ Conversion of coordinate array x from native units to base units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_pos_to_native
(x, inplace=True)¶ Conversion of coordinate array x from base units to native units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_from_native
(t, inplace=True)¶ Convert time t from native units to base units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned (although note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.) In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_to_native
(t, inplace=True)¶ Convert time t from base units to native units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool, optional) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned. (Also note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_velocities_from_native
(v, inplace=True)¶ Conversion of velocities array v from native to base units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
convert_velocities_to_native
(v, inplace=True)¶ Conversion of coordinate array v from base to native units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
correl
(*args, **kwds)¶ correl is deprecated! This method will be removed in 0.17
Populate a
TimeseriesCollection
object with time series computed from the trajectory.Calling this method will iterate through the whole trajectory and perform the calculations prescribed in timeseries.
Parameters: - timeseries (
MDAnalysis.core.Timeseries.TimeseriesCollection
) – TheMDAnalysis.core.Timeseries.TimeseriesCollection
that defines what kind of computations should be performed on the data in this trajectory. - start (int (optional)) – Begin reading the trajectory at frame index start (where 0 is the index
of the first frame in the trajectory); the default
None
starts at the beginning. - stop (int (optional)) – End reading the trajectory at frame index stop-1, i.e, stop is excluded.
The trajectory is read to the end with the default
None
. - step (int (optional)) – Step size for reading; the default
None
is equivalent to 1 and means to read every frame.
Note
The correl functionality is only implemented for DCD trajectories and the
DCDReader
.Deprecated since version 0.16.0: skip has been deprecated in favor of the standard keyword step.
- timeseries (
-
dt
¶ Time between two trajectory frames in picoseconds.
-
frame
¶ Frame number of the current time step.
This is a simple short cut to
Timestep.frame
.
-
get_aux_attribute
(auxname, attrname)¶ Get the value of attrname from the auxiliary auxname
Parameters: See also
-
get_aux_descriptions
(auxnames=None)¶ Get descriptions to allow reloading the specified auxiliaries.
If no auxnames are provided, defaults to the full list of added auxiliaries.
Passing the resultant description to
add_auxiliary()
will allow recreation of the auxiliary. e.g., to duplicate all auxiliaries into a second trajectory:descriptions = trajectory_1.get_aux_descriptions() for aux in descriptions: trajectory_2.add_auxiliary(**aux)
Returns: List of dictionaries of the args/kwargs describing each auxiliary. Return type: list
-
iter_as_aux
(auxname)¶ Iterate through timesteps for which there is at least one assigned step from the auxiliary auxname within the cutoff specified in auxname.
See also
-
iter_auxiliary
(auxname, start=None, stop=None, step=None, selected=None)¶ Iterate through the auxiliary auxname independently of the trajectory.
Will iterate over the specified steps of the auxiliary (defaults to all steps). Allows to access all values in an auxiliary, including those out of the time range of the trajectory, without having to also iterate through the trajectory.
After interation, the auxiliary will be repositioned at the current step.
Parameters: - auxname (str) – Name of the auxiliary to iterate over.
- stop, step) ((start,) – Options for iterating over a slice of the auxiliary.
- selected (lst | ndarray, optional) – List of steps to iterate over.
Yields: AuxStep
objectSee also
-
next
()¶ Forward one step to next frame.
-
next_as_aux
(auxname)¶ Move to the next timestep for which there is at least one step from the auxiliary auxname within the cutoff specified in auxname.
This allows progression through the trajectory without encountering
NaN
representative values (unless these are specifically part of the auxiliary data).If the auxiliary cutoff is not set, where auxiliary steps are less frequent (
auxiliary.dt > trajectory.dt
), this allows progression at the auxiliary pace (rounded to nearest timestep); while if the auxiliary steps are more frequent, this will work the same as callingnext()
.See the Auxiliary API.
See also
-
rename_aux
(auxname, new)¶ Change the name of the auxiliary auxname to new.
Provided there is not already an auxiliary named new, the auxiliary name will be changed in ts.aux namespace, the trajectory’s list of added auxiliaries, and in the auxiliary reader itself.
Parameters: Raises: ValueError
– If the name new is already in use by an existing auxiliary.
-
rewind
()¶ Position at beginning of trajectory
-
set_aux_attribute
(auxname, attrname, new)¶ Set the value of attrname in the auxiliary auxname.
Parameters: See also
-
time
¶ Time of the current frame in MDAnalysis time units (typically ps).
This is either read straight from the Timestep, or calculated as time =
Timestep.frame
*Timestep.dt
-
timeseries
(asel=None, start=None, stop=None, step=None, skip=None, format=u’afc’)[source]¶ Return a subset of coordinate data for an AtomGroup
Parameters: - asel (
AtomGroup
) – TheAtomGroup
to read the coordinates from. Defaults to None, in which case the full set of coordinate data is returned. - start (int (optional)) – Begin reading the trajectory at frame index start (where 0 is the index
of the first frame in the trajectory); the default
None
starts at the beginning. - stop (int (optional)) – End reading the trajectory at frame index stop-1, i.e, stop is excluded.
The trajectory is read to the end with the default
None
. - step (int (optional)) – Step size for reading; the default
None
is equivalent to 1 and means to read every frame. - format (str (optional)) – the order/shape of the return data array, corresponding to (a)tom, (f)rame, (c)oordinates all six combinations of ‘a’, ‘f’, ‘c’ are allowed ie “fac” - return array where the shape is (frame, number of atoms, coordinates)
Deprecated since version 0.16.0: skip has been deprecated in favor of the standard keyword step.
- asel (
-
totaltime
¶ Total length of the trajectory
The time is calculated as
(n_frames - 1) * dt
, i.e., we assume that the first frame no time as elapsed. Thus, a trajectory with two frames will be considered to have a length of a single time step dt and a “trajectory” with a single frame will be reported as length 0.
-
-
class
MDAnalysis.coordinates.LAMMPS.
DCDWriter
(*args, **kwargs)[source]¶ Write a LAMMPS DCD trajectory.
The units can be set from the constructor with the keyword arguments timeunit and lengthunit. The defaults are “fs” and “Angstrom”. See
MDAnalysis.units
for other recognized values.-
convert_dimensions_to_unitcell
(ts, _ts_order=[0, 2, 5, 4, 3, 1])[source]¶ Read dimensions from timestep ts and return appropriate native unitcell.
See also
Timestep.dimensions
-
convert_forces_from_native
(force, inplace=True)¶ Conversion of forces array force from native to base units
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_forces_to_native
(force, inplace=True)¶ Conversion of force array force from base to native units.
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_pos_from_native
(x, inplace=True)¶ Conversion of coordinate array x from native units to base units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_pos_to_native
(x, inplace=True)¶ Conversion of coordinate array x from base units to native units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_from_native
(t, inplace=True)¶ Convert time t from native units to base units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned (although note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.) In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_to_native
(t, inplace=True)¶ Convert time t from base units to native units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool, optional) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned. (Also note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_velocities_from_native
(v, inplace=True)¶ Conversion of velocities array v from native to base units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
convert_velocities_to_native
(v, inplace=True)¶ Conversion of coordinate array v from base to native units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
has_valid_coordinates
(criteria, x)¶ Returns
True
if all values are within limit values of their formats.Due to rounding, the test is asymmetric (and min is supposed to be negative):
min < x <= maxParameters: - criteria (dict) – dictionary containing the max and min values in native units
- x (numpy.ndarray) –
(x, y, z)
coordinates of atoms selected to be written out
Returns: Return type:
-
write
(obj)¶ Write current timestep, using the supplied obj.
Parameters: obj ( AtomGroup
orUniverse
or aTimestep
) – write coordinate information associate with objNote
The size of the obj must be the same as the number of atoms provided when setting up the trajectory.
-
write_next_timestep
(ts=None)[source]¶ Write a new timestep to the DCD file.
Parameters: ts (Timestep (optional)) – Timestep object containing coordinates to be written to DCD file; by default it uses the current Timestep associated with the Writer.
Raises: ValueError
– if wrong number of atoms suppliedNoDataError
– if no coordinates to be written.
Changed in version 0.7.5: Raises
ValueError
instead of genericException
if wrong number of atoms supplied andNoDataError
if no coordinates to be written.
-
-
class
MDAnalysis.coordinates.LAMMPS.
DATAReader
(filename, **kwargs)[source]¶ Reads a single frame of coordinate information from a LAMMPS DATA file.
New in version 0.9.0.
Changed in version 0.11.0: Frames now 0-based instead of 1-based
-
OtherWriter
(filename, **kwargs)¶ Returns a writer appropriate for filename.
Sets the default keywords start, step and dt (if available). n_atoms is always set from
Reader.n_atoms
.See also
Reader.Writer()
-
Writer
(filename, **kwargs)¶ A trajectory writer with the same properties as this trajectory.
-
add_auxiliary
(auxname, auxdata, format=None, **kwargs)¶ Add auxiliary data to be read alongside trajectory.
Auxiliary data may be any data timeseries from the trajectory additional to that read in by the trajectory reader. auxdata can be an
AuxReader
instance, or the data itself as e.g. a filename; in the latter case an appropriateAuxReader
is guessed from the data/file format. An appropriate format may also be directly provided as a key word argument.On adding, the AuxReader is initially matched to the current timestep of the trajectory, and will be updated when the trajectory timestep changes (through a call to
next()
or jumping timesteps withtrajectory[i]
).The representative value(s) of the auxiliary data for each timestep (as calculated by the
AuxReader
) are stored in the current timestep in thets.aux
namespace under auxname; e.g. to add additional pull force data stored in pull-force.xvg:u = MDAnalysis.Universe(PDB, XTC) u.trajectory.add_auxiliary('pull', 'pull-force.xvg')
The representative value for the current timestep may then be accessed as
u.trajectory.ts.aux.pull
oru.trajectory.ts.aux['pull']
.See also
Note
Auxiliary data is assumed to be time-ordered, with no duplicates. See the Auxiliary API.
-
aux_list
¶ Lists the names of added auxiliary data.
-
check_slice_indices
(start, stop, step)¶ Check frame indices are valid and clip to fit trajectory.
The usage follows standard Python conventions for
range()
but see the warning below.Parameters: - start (int or None) – Starting frame index (inclusive).
None
corresponds to the default of 0, i.e., the initial frame. - stop (int or None) – Last frame index (exclusive).
None
corresponds to the default of n_frames, i.e., it includes the last frame of the trajectory. - step (int or None) – step size of the slice,
None
corresponds to the default of 1, i.e, include every frame in the range start, stop.
Returns: start, stop, step – Integers representing the slice
Return type: Warning
The returned values start, stop and step give the expected result when passed in
range()
but gives unexpected behavior when passed in aslice
whenstop=None
andstep=-1
This can be a problem for downstream processing of the output from this method. For example, slicing of trajectories is implemented by passing the values returned by
check_slice_indices()
torange()
range(start, stop, step)
and using them as the indices to randomly seek to. On the other hand, in
MDAnalysis.analysis.base.AnalysisBase
the values returned bycheck_slice_indices()
are used to splice the trajectory by creating aslice
instanceslice(start, stop, step)
This creates a discrepancy because these two lines are not equivalent:
range(10, -1, -1) # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] range(10)[slice(10, -1, -1)] # []
- start (int or None) – Starting frame index (inclusive).
-
convert_forces_from_native
(force, inplace=True)¶ Conversion of forces array force from native to base units
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_forces_to_native
(force, inplace=True)¶ Conversion of force array force from base to native units.
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_pos_from_native
(x, inplace=True)¶ Conversion of coordinate array x from native units to base units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_pos_to_native
(x, inplace=True)¶ Conversion of coordinate array x from base units to native units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_from_native
(t, inplace=True)¶ Convert time t from native units to base units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned (although note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.) In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_to_native
(t, inplace=True)¶ Convert time t from base units to native units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool, optional) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned. (Also note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_velocities_from_native
(v, inplace=True)¶ Conversion of velocities array v from native to base units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
convert_velocities_to_native
(v, inplace=True)¶ Conversion of coordinate array v from base to native units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
dt
¶ Time between two trajectory frames in picoseconds.
-
frame
¶ Frame number of the current time step.
This is a simple short cut to
Timestep.frame
.
-
get_aux_attribute
(auxname, attrname)¶ Get the value of attrname from the auxiliary auxname
Parameters: See also
-
get_aux_descriptions
(auxnames=None)¶ Get descriptions to allow reloading the specified auxiliaries.
If no auxnames are provided, defaults to the full list of added auxiliaries.
Passing the resultant description to
add_auxiliary()
will allow recreation of the auxiliary. e.g., to duplicate all auxiliaries into a second trajectory:descriptions = trajectory_1.get_aux_descriptions() for aux in descriptions: trajectory_2.add_auxiliary(**aux)
Returns: List of dictionaries of the args/kwargs describing each auxiliary. Return type: list
-
iter_as_aux
(auxname)¶ Iterate through timesteps for which there is at least one assigned step from the auxiliary auxname within the cutoff specified in auxname.
See also
-
iter_auxiliary
(auxname, start=None, stop=None, step=None, selected=None)¶ Iterate through the auxiliary auxname independently of the trajectory.
Will iterate over the specified steps of the auxiliary (defaults to all steps). Allows to access all values in an auxiliary, including those out of the time range of the trajectory, without having to also iterate through the trajectory.
After interation, the auxiliary will be repositioned at the current step.
Parameters: - auxname (str) – Name of the auxiliary to iterate over.
- stop, step) ((start,) – Options for iterating over a slice of the auxiliary.
- selected (lst | ndarray, optional) – List of steps to iterate over.
Yields: AuxStep
objectSee also
-
next_as_aux
(auxname)¶ Move to the next timestep for which there is at least one step from the auxiliary auxname within the cutoff specified in auxname.
This allows progression through the trajectory without encountering
NaN
representative values (unless these are specifically part of the auxiliary data).If the auxiliary cutoff is not set, where auxiliary steps are less frequent (
auxiliary.dt > trajectory.dt
), this allows progression at the auxiliary pace (rounded to nearest timestep); while if the auxiliary steps are more frequent, this will work the same as callingnext()
.See the Auxiliary API.
See also
-
rename_aux
(auxname, new)¶ Change the name of the auxiliary auxname to new.
Provided there is not already an auxiliary named new, the auxiliary name will be changed in ts.aux namespace, the trajectory’s list of added auxiliaries, and in the auxiliary reader itself.
Parameters: Raises: ValueError
– If the name new is already in use by an existing auxiliary.
-
set_aux_attribute
(auxname, attrname, new)¶ Set the value of attrname in the auxiliary auxname.
Parameters: See also
-
time
¶ Time of the current frame in MDAnalysis time units (typically ps).
This is either read straight from the Timestep, or calculated as time =
Timestep.frame
*Timestep.dt
-
totaltime
¶ Total length of the trajectory
The time is calculated as
(n_frames - 1) * dt
, i.e., we assume that the first frame no time as elapsed. Thus, a trajectory with two frames will be considered to have a length of a single time step dt and a “trajectory” with a single frame will be reported as length 0.
-
-
class
MDAnalysis.coordinates.LAMMPS.
DATAWriter
(filename, convert_units=None, **kwargs)[source]¶ Write out the current time step as a LAMMPS DATA file.
This writer supports the sections Atoms, Masses, Velocities, Bonds, Angles, Dihedrals, and Impropers. This writer will write the header and these sections (if applicable). Atoms section is written in the “full” sub-style if charges are available or “molecular” sub-style if they are not. Molecule id is set to 0 for all atoms.
Note
This writer assumes “conventional” or “real” LAMMPS units where length is measured in Angstroms and velocity is measured in Angstroms per femtosecond. To write in different units, specify lengthunit
If atom types are not already positive integers, the user must set them to be positive integers, because the writer will not automatically assign new types.
To preserve numerical atom types when writing a selection, the Masses section will have entries for each atom type up to the maximum atom type. If the universe does not contain atoms of some type in {1, … max(atom_types)}, then the mass for that type will be set to 1.
In order to write bonds, each selected bond type must be explicitly set to an integer >= 1.
Set up a DATAWriter
Parameters: filename (str) – output filename -
close
()¶ Close the trajectory file.
-
convert_dimensions_to_unitcell
(ts, inplace=True)¶ Read dimensions from timestep ts and return appropriate unitcell.
The default is to return
[A,B,C,alpha,beta,gamma]
; if this is not appropriate then this method has to be overriden.
-
convert_forces_from_native
(force, inplace=True)¶ Conversion of forces array force from native to base units
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_forces_to_native
(force, inplace=True)¶ Conversion of force array force from base to native units.
Parameters: - force (array_like) – Forces to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input force is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.7.
-
convert_pos_from_native
(x, inplace=True)¶ Conversion of coordinate array x from native units to base units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_pos_to_native
(x, inplace=True)¶ Conversion of coordinate array x from base units to native units.
Parameters: - x (array_like) – Positions to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input x is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_from_native
(t, inplace=True)¶ Convert time t from native units to base units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned (although note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.) In-place operations improve performance because allocating new arrays is avoided.
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_time_to_native
(t, inplace=True)¶ Convert time t from base units to native units.
Parameters: - t (array_like) – Time values to transform
- inplace (bool, optional) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input t is modified in place and also returned. (Also note that scalar values t are passed by value in Python and hence an in-place modification has no effect on the caller.)
Changed in version 0.7.5: Keyword inplace can be set to
False
so that a modified copy is returned unless no conversion takes place, in which case the reference to the unmodified x is returned.
-
convert_velocities_from_native
(v, inplace=True)¶ Conversion of velocities array v from native to base units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
convert_velocities_to_native
(v, inplace=True)¶ Conversion of coordinate array v from base to native units
Parameters: - v (array_like) – Velocities to transform
- inplace (bool (optional)) – Whether to modify the array inplace, overwriting previous data
Note
By default, the input v is modified in place and also returned. In-place operations improve performance because allocating new arrays is avoided.
New in version 0.7.5.
-
has_valid_coordinates
(criteria, x)¶ Returns
True
if all values are within limit values of their formats.Due to rounding, the test is asymmetric (and min is supposed to be negative):
min < x <= maxParameters: - criteria (dict) – dictionary containing the max and min values in native units
- x (numpy.ndarray) –
(x, y, z)
coordinates of atoms selected to be written out
Returns: Return type:
-
write
(*args, **kwargs)[source]¶ Write selection at current trajectory frame to file.
The sections for Atoms, Masses, Velocities, Bonds, Angles, Dihedrals, and Impropers (if these are defined) are written. The Atoms section is written in the “full” sub-style if charges are available or “molecular” sub-style if they are not. Molecule id in atoms section is set to to 0.
No other sections are written to the DATA file. As of this writing, other sections are not parsed into the topology by the
DATAReader
.Note
If the selection includes a partial fragment, then only the bonds, angles, etc. whose atoms are contained within the selection will be included.
Parameters:
-