schrodinger.application.desmond.packages.traj module¶
Molecular dynamics trajectory handling module Define common APIs for various trajectory formats. Basic trajectory handling algorithms are also implemented here.
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.desmond.packages.traj.Fmt(value)[source]¶
Bases:
enum.Enum
Trajectory format enum
- AUTO = 0¶
- DTR = 1¶
- XTC = 2¶
- schrodinger.application.desmond.packages.traj.get_fmt(fname, format=Fmt.AUTO)[source]¶
Returns the format based on the given trajectory file name (
fname
) and the format specification (format
). If the format specification is definite (i.e., notFmt.AUTO
), this function will trivially return the value offormat
, otherwise it will check thefname
’s value, determining the format, and return the result.- Parameters
fname (
str
) – Trajectory file nameformat (
Fmt
) – Trajectory format specification
:rtype :
Fmt
:return: The format of the given trajectoryfname
- schrodinger.application.desmond.packages.traj.get_trajectory_extname(format=Fmt.AUTO, ref_fname=None)[source]¶
- class schrodinger.application.desmond.packages.traj.Source(reader, name='sometraj')[source]¶
Bases:
object
- CACHE_LIMIT_BYTES = 1000000000.0¶
- __init__(reader, name='sometraj')[source]¶
reader
specifies where to retrieve a trajectory frame when it’s needed but currently NOT in the memory (in other words, it’s not cached by this source). A reader could potentially be a file reader, a string reader, a socket reader, a database dealer, etc., as long as it satisfies the duck-typing requirements (see below). And interestingly, the probably simplest reader is anothertrajectory
(i.e., a list ofFrame
objects) in memory.Duck typing for
readers
.Random access
reader[index]
should return theindex
-th frame. Hereindex
is zero-based, of Python style (i.e., -1 means the last frame, etc.).len
supportlen(reader)
should return the total number of frames.
If a reader doesn’t support the duck typing as specified above, a subclass can be created to bypass the typing requirements. See
DtrSource
below as an example.
- property name¶
- retrieve_frame(index)[source]¶
Retrieves the
index
-th frame from the source.index
is zero-based. This method assumes the source allows random access to frames.- Raise
IndexError
ifindex
is out of range, orIOError
if the trajectory reader is closed.
- close()[source]¶
Closes down the trajectory reader. A couple of points to note:
Once this method is called, this
Source
object can only retrieve frames that are internally cached. Attempting to retrieve uncached frames will incur anIOError
. Normally we do NOT know which frames are cached, so to be safe this method should be called only when we are done with the trajectory.Normally, only some
Frame
objects reference aSource
object, if all theFrame
objects are garbaged, theSource
object will be garbaged automatically, and there is no need to call thisclose
method separately.
- class schrodinger.application.desmond.packages.traj.DtrSource(reader, name='sometraj')[source]¶
Bases:
schrodinger.application.desmond.packages.traj.Source
- CACHE_LIMIT_BYTES = 1000000000.0¶
- __init__(reader, name='sometraj')¶
reader
specifies where to retrieve a trajectory frame when it’s needed but currently NOT in the memory (in other words, it’s not cached by this source). A reader could potentially be a file reader, a string reader, a socket reader, a database dealer, etc., as long as it satisfies the duck-typing requirements (see below). And interestingly, the probably simplest reader is anothertrajectory
(i.e., a list ofFrame
objects) in memory.Duck typing for
readers
.Random access
reader[index]
should return theindex
-th frame. Hereindex
is zero-based, of Python style (i.e., -1 means the last frame, etc.).len
supportlen(reader)
should return the total number of frames.
If a reader doesn’t support the duck typing as specified above, a subclass can be created to bypass the typing requirements. See
DtrSource
below as an example.
- clear_cache()¶
- close()¶
Closes down the trajectory reader. A couple of points to note:
Once this method is called, this
Source
object can only retrieve frames that are internally cached. Attempting to retrieve uncached frames will incur anIOError
. Normally we do NOT know which frames are cached, so to be safe this method should be called only when we are done with the trajectory.Normally, only some
Frame
objects reference aSource
object, if all theFrame
objects are garbaged, theSource
object will be garbaged automatically, and there is no need to call thisclose
method separately.
- property name¶
- retrieve_frame(index)¶
Retrieves the
index
-th frame from the source.index
is zero-based. This method assumes the source allows random access to frames.- Raise
IndexError
ifindex
is out of range, orIOError
if the trajectory reader is closed.
- used_space()¶
- class schrodinger.application.desmond.packages.traj.XtcSource(*args, **kwargs)[source]¶
Bases:
schrodinger.application.desmond.packages.traj.Source
- __init__(*args, **kwargs)[source]¶
reader
specifies where to retrieve a trajectory frame when it’s needed but currently NOT in the memory (in other words, it’s not cached by this source). A reader could potentially be a file reader, a string reader, a socket reader, a database dealer, etc., as long as it satisfies the duck-typing requirements (see below). And interestingly, the probably simplest reader is anothertrajectory
(i.e., a list ofFrame
objects) in memory.Duck typing for
readers
.Random access
reader[index]
should return theindex
-th frame. Hereindex
is zero-based, of Python style (i.e., -1 means the last frame, etc.).len
supportlen(reader)
should return the total number of frames.
If a reader doesn’t support the duck typing as specified above, a subclass can be created to bypass the typing requirements. See
DtrSource
below as an example.
- CACHE_LIMIT_BYTES = 1000000000.0¶
- clear_cache()¶
- close()¶
Closes down the trajectory reader. A couple of points to note:
Once this method is called, this
Source
object can only retrieve frames that are internally cached. Attempting to retrieve uncached frames will incur anIOError
. Normally we do NOT know which frames are cached, so to be safe this method should be called only when we are done with the trajectory.Normally, only some
Frame
objects reference aSource
object, if all theFrame
objects are garbaged, theSource
object will be garbaged automatically, and there is no need to call thisclose
method separately.
- property name¶
- retrieve_frame(index)¶
Retrieves the
index
-th frame from the source.index
is zero-based. This method assumes the source allows random access to frames.- Raise
IndexError
ifindex
is out of range, orIOError
if the trajectory reader is closed.
- used_space()¶
- class schrodinger.application.desmond.packages.traj.Frame(source: Optional[schrodinger.application.desmond.packages.traj.Source], index: Optional[int])[source]¶
Bases:
object
This class, as its name suggests, represents a single trajectory frame. So far, we allow a frame to be mutated in the following ways:
Assign a new chemical time
Reduce to a subset of particles
Coordinates of all particles are translated
We call changes generally as
decorations
. They might not make into the frame data, or at least not immediately. Why? This avoids making multiple expensive copies of the data.- __init__(source: Optional[schrodinger.application.desmond.packages.traj.Source], index: Optional[int])[source]¶
- copy()[source]¶
Return a copy of this
Frame
object. The position and velocity arrays will be copied.
- property natoms¶
- property nactive¶
- property is_gcmc¶
Return whether the frame is from a gcmc simulation
- pos(i=None)[source]¶
Return the position vector(s).
i can be any of the following types:
None: Return the whole position-vector array;
int:
i
should be a GID, and this function return position vector of the particlei
.Iterable:
i
should be a “list” of GIDs, and this function returns a NEW numpy array of position-vectors of the specified particles.
- vel(i=None)[source]¶
Return the velocity vector(s). This method may throw if this frame doesn’t have velocity data.
i can be any of the following types:
None: Return the whole position-vector array;
int:
i
should be a GID, and this function return position vector of the particlei
.Iterable:
i
should be a “list” of GIDs, and this function returns a NEW numpy array of position-vectors of the specified particles.
- hijackPos(impos)[source]¶
Tentatively replace the internal position array of this
Frame
object with an external numpy arrayimpos
. We can call the external array “imposter”. After calling this method, thepos
method will return values from the imposter until the imposter is removed (by callinghijackPos(None)
). The imposter should be a Nx3 numpy array, where N can be of any size. Note the impacts on other methods of this class:pos Use
impos
.- copy The entire
impos
array will be copied into the copy of this
Frame
object.
- copy The entire
- reduce Still function in the same way, but note that the
impos
array will not be changed by these methods.
- reduce Still function in the same way, but note that the
moveby The same as
reduce
- write Still function in the same way, note that it’s the internal
position array, not
impos
, that will be written out.
- Parameters
impos (
None
, ornumpy.ndarray
of size Nx3, where N is arbitray number) – The position array to tentatively replac the internal position array in thisFrame
object. If the value isNone
, we remove the “imposter” and recover the internal position array.
- property time¶
- property box¶
- property orig_index¶
- reduce(indices, copy=True)[source]¶
Keep only the atoms specified by
indices
, the other atoms will be deleted from this frame. The caller needs to ensure theindices
order matches with the msys model of the reduced system.- Parameters
copy – If true, this function will make a copy of this frame and reduce atoms in this copy, and finally return the copy.
- class schrodinger.application.desmond.packages.traj.MaeFrameReader(mae_fnames: List[str], cms_model: Cms, frame_template: schrodinger.application.desmond.packages.traj.Frame)[source]¶
Bases:
object
This class reads a number of MAE files into a sequence of “bare-metal” frame objects. See docstring of
MaeSource
below for more detail.- __init__(mae_fnames: List[str], cms_model: Cms, frame_template: schrodinger.application.desmond.packages.traj.Frame)[source]¶
- class schrodinger.application.desmond.packages.traj.MaeSource(mae_fnames: List[str], cms_model: Cms, frame_template: schrodinger.application.desmond.packages.traj.Frame)[source]¶
Bases:
schrodinger.application.desmond.packages.traj.Source
This is to reverse-convert a list of MAE (or CMS) files into a single trajectory file. The molecular structure in each MAE file will become a single frame in the trajectory. If an MAE file contains multiple CTs, only the first one will be used.
CAVEATS: This kind of conversions always have some caveats, which in this particular case are the following:
Velocities are not always present in either the trajectory frame template or the MAE file. In either case, the velocities will not be saved into the resultant frame.
Since we generally don’t a priori know the exact force field to be used, it’s difficult/impossible to predict about the pseudoatoms. So if they exist in the trajectory frame, their positions will not be set. This is normally not a problem for MD simulations the pseudoatoms’ positions are normally determined on the fly in MD simulations.
The time of each frame is arbitrarily set to the index of the frame.
This will not work properly for GCMC systems where the number of active atoms in the frame template happens to differ from that of the structures in the MAE files.
- __init__(mae_fnames: List[str], cms_model: Cms, frame_template: schrodinger.application.desmond.packages.traj.Frame)[source]¶
reader
specifies where to retrieve a trajectory frame when it’s needed but currently NOT in the memory (in other words, it’s not cached by this source). A reader could potentially be a file reader, a string reader, a socket reader, a database dealer, etc., as long as it satisfies the duck-typing requirements (see below). And interestingly, the probably simplest reader is anothertrajectory
(i.e., a list ofFrame
objects) in memory.Duck typing for
readers
.Random access
reader[index]
should return theindex
-th frame. Hereindex
is zero-based, of Python style (i.e., -1 means the last frame, etc.).len
supportlen(reader)
should return the total number of frames.
If a reader doesn’t support the duck typing as specified above, a subclass can be created to bypass the typing requirements. See
DtrSource
below as an example.
- CACHE_LIMIT_BYTES = 1000000000.0¶
- clear_cache()¶
- close()¶
Closes down the trajectory reader. A couple of points to note:
Once this method is called, this
Source
object can only retrieve frames that are internally cached. Attempting to retrieve uncached frames will incur anIOError
. Normally we do NOT know which frames are cached, so to be safe this method should be called only when we are done with the trajectory.Normally, only some
Frame
objects reference aSource
object, if all theFrame
objects are garbaged, theSource
object will be garbaged automatically, and there is no need to call thisclose
method separately.
- property name¶
- nframes()¶
Returns the total number of frames in this trajectory source.
- retrieve_frame(index)¶
Retrieves the
index
-th frame from the source.index
is zero-based. This method assumes the source allows random access to frames.- Raise
IndexError
ifindex
is out of range, orIOError
if the trajectory reader is closed.
- used_space()¶
- schrodinger.application.desmond.packages.traj.read_traj(inp, format=Fmt.AUTO, return_iter=False)[source]¶
Lazy load trajectory.
- schrodinger.application.desmond.packages.traj.write_traj(tr, fname, format=Fmt.AUTO)[source]¶
- Parameters
fname (
str
) – Output file nameformat (
Fmt
) – Trajectory file format
- schrodinger.application.desmond.packages.traj.merge(*arg)[source]¶
Merge a list of trajectories. If there is any overlapped frames among these trajectories, the ones from the latter trajectory (higher index in the
arg
list) will be kept.
- schrodinger.application.desmond.packages.traj.concat(first_time, delta_time, *args)[source]¶
Concatenate a list of trajectories or iterators and reassign the chemical time for each frame. Results are yielded.
- Parameters
first_time (
float
) – Chemical time of the first frame.delta_time (
float
) – The chemical time interval between two successive frames.args – trajectories as iterables
- schrodinger.application.desmond.packages.traj.extract_subsystem(tr, gids)[source]¶
Extract the subsystem as specified by the
gids
for each frame in the given trajectorytr
, and return a new trajectory for the subsystem. The original trajectory is not mutated in any way by this function. Inactive atoms in GCMC trajectory cannot be extracted.- Parameters
tr (
list
ofFrame
) – Original trajectorygids (
list
ofint
) – A list of gids that specifies the subsystem.
- Return type
list
- Returns
A new trajectory for the subsystem