schrodinger.application.desmond.packages.topo module¶
Functionalities to handle molecular topologies
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.desmond.packages.topo.DuckFrame(model)¶
Bases:
objectA duck-type frame with limited interface.
We can duck-type a msys model (i.e., a
msys.Systemobject) into aDuckFrameobject, example:dfr = DuckFrame(msys_model)
Changes on the
DuckFrame' object should NOT affect the original `modelobject.- __init__(model)¶
Copy the coordinates, the velocities, and the box matrix of the original model.
FIXME: We only support
msys.Systemtype ofmodelfor now.
- pos(i=None)¶
Return the position vector(s).
i can be any of the following types:
None: Return the whole position-vector array;int:ishould be a GID, and this function return position vector of the particlei.Iterable:ishould be a “list” of GIDs, and this function returns a NEW numpy array of position-vectors of the specified particles.
- vel()¶
- property natoms¶
- property nactive¶
- property box¶
Return a row-majored 3x3 matrix. The primitive cell vectors are the rows of the matrix, which should be consistent with
traj.Frame.box.
- schrodinger.application.desmond.packages.topo.cms_atom(cms_model)¶
Returns an iterator through all atoms in a CMS model. At each iteration, we get a tuple of
(fsys_atom, comp_atom, comp_ct, ct_index), wherefsys_atom: atom in full-system CT
comp_atom: atom in component CT
comp_ct: component CT to which
comp_atombelongct_index: index of the component CT
The iterator breaks right before returning any inactive atoms, unlike the function below that returns indices of all atoms (including inactive atoms).
- schrodinger.application.desmond.packages.topo.cms_atom_index(cms_model)¶
Returns an iterator through all atom indices in a CMS model. At each iteration, we get a tuple of
(fsys_atom_index, comp_atom_index, comp_ct, ct_index), wherefsys_atom_index: atom index in full-system CT
comp_atom_index: atom index in component CT
comp_ct: component CT to which
comp_atom_indexbelongct_index: index of the component CT
This function differs from the above in that it returns indices of all atoms including inactive atoms. Note that the
fsys_atom_indexfor inactive atoms is merely a “projected” index as the fullsystem CT doesn’t really contain any inactive atoms.
- schrodinger.application.desmond.packages.topo.aid_match(cms_model)¶
- Return type
1D ‘1-indexed’
numpy.ndarrayof ints- Returns
Returns an array of atom indices. Index = 1-based atom index as in the full-system CT, value = index of the matched atom (0 means not matched).
- schrodinger.application.desmond.packages.topo.pseudoatom_match(msys_model, cms_model)¶
This function will find the match between pseudoatoms and return it as two lists of pseudoatom indices. The first list is for the reference CT, and the second for the mutant CT.
match = pseudoatom_match(msys_model, cms_model) j = match[0][i]
where
jis the matched pseudoatom’s index in the ffio_pseudo block of the mutant CT,iis the pseudoatom’s index in that of the reference CT. If i-th pseudoatom is not matched, j’s value is zero.match[0][0]is always 0, which is junk and should be ignored.j = match[1][i]
is similar, except that
iis of the mutant CT, andjis of the reference CT.For non-alchemical-FEP systems, this function returns
[].- Return type
[list[int], list[int]]or[]
- schrodinger.application.desmond.packages.topo.set_original_index_property(cms_model)¶
For each atom in the full-system CT, add an atom-level property: constants.ORIGINAL_INDEX, and set its value to the atom’s ID.
- schrodinger.application.desmond.packages.topo.find_traj_path(cms_model, base_dir=None)¶
Return path of the trajectory file or dir, whose name was saved into a CT-level property in the output cms file. Return
Noneis valid path cannot be found.Note that this function is temporary. In the long run the coupling between trajectory directory and cms file will be removed. The user should be explicit about where the trajectory file/folder is.
If you are developing a new command line tool, please do not rely on this function to get the trajectory path. Instead, explicitly pass in the trajectory path. See an example below: $SCHRODINGER/run analyze_simulation.py -h
- Return type
strorNone
- schrodinger.application.desmond.packages.topo.find_traj_path_from_cms_path(cms_path)¶
Return path of the trajectory directory/file that is “associated” with the given CMS file. This works only if both are in the same parent directory.
- Parameters
cms_path (
str) – Path to the CMS file- Returns
Path to the trajectory directory or file.
- Return type
strorNone
- schrodinger.application.desmond.packages.topo.read_cms(fname=None, from_string=None, remove_inactive_atoms_in_fsys=True)¶
Read a .cms file from the given file name
fname, or from a string buffer. How does this differ fromcms.Cms(fname)?Here, two models will be created for the given .cms file. So you will get 2-tuple return value: The first member is the msys model, and the second is the cms model.
The cms model returned by this function will give you correct gids, whereas the model returned by
cms.Cms(fname)might not do so when there are virtual sites.The cms model returned by this function will have three extra attributes:
pseudoatomsThis is a map from the gid of a physical atom to that of its pseudoatom(s).pseudomatchThis is pseudoatom match between the two alchemical molecules. (See the docstring ofpseudoatom_matchfor detail)
Will we unite this with
cms.Cms(fname)? Maybe. But I don’t see a strong motivation right now, and I don’t want to overengineer. -YW (May 26, 2016)FIXME:
msys.LoadMAE(...)is unbelievably slow and may take up to 10 sec for typically-sized alchemical FEP systems.
- schrodinger.application.desmond.packages.topo.extract_subsystem(cms_model, asl)¶
We need to clarify on what we call
subsystemhere. First, let’s review the hierarchical structure of a chemical system in the cms model:At the most top level is the whole system.
Under that are a number of CTs (connectivity tables). Each CT contains one molecule (usually in the case of macromolecules), or more (the most obvious example is the water CT, which include thousands of water molecules).
Under that are chains, which belong to the same molecule but not necessarily covalently bonded.
Under that are residues, groups, atoms, pseudoatoms, …, which we don’t have to go into the detail.
Despite of the fact that there are already a lot of concepts to grasp, it’s still sometimes inadequate to describe a portion of the system. The problem arises mainly due to the fact that the cms model contains force field data: When we do atom selections, we have to keep that in mind, we won’t be able to create a valid .cms file if we select a number of atoms that don’t match the force field data.
To address that problem, we introduce an extra concept that sits between the CT and the molecule levels in the hierarchy. We can call it
instance, and it refers to a single complete substructure that matches the ffio. For example, in a protein CT, the ffio describe the whole protein structure, and so the instance there is the whole protein, and the CT contains only 1 instance; whereas in a water CT, the ffio describes only a single water molecule, and thus the instance is a single water molecule, and the CT contains a number of instances.With that, we now define a subsystem as follows: A subsystem is a portion of the original system, containing 1 or more instances of any types as defined in the original system. By this definition, a subsystem should always be a valid cms model.
We allow users to specify a subsystem using ASL, but how do we deal with cases where the ASL expression doesn’t include a complete set of atoms in their respective instances? For now, we will simply automatically expand the selection to the whole instance. This is good enough for most cases, I think. Of course, in future we should have no problem to be more sophisticated in deciding to expand or shrink the selection.
- Parameters
cms_model (
cms.Cms) – A cms model generated byread_cms(see above). Won’t be mutated.asl (
str) – ASL expression to specify the subsystem.
- Return type
(new-cms-model, seletion-in-aid)
- Returns
Returns a new
cms.Cmsobject (the inputcms_modelwill not be mutated), and an unsorted list of aids of the selected atoms. The newcms.Cmsis guaranteed to contain no inactive atoms.
- schrodinger.application.desmond.packages.topo.matched_gids(cms_model, sub_cms, sub_msys)¶
Return GIDs of
cms_modelthat match the GIDs ofsub_cmsand preserve the ordering, which is essential for trajectory extraction/reduction.- Parameters
cms_model (
cms.Cms) – Original system wheresubsystemwas extracted fromsub_cms (
cms.Cms) – A subsystem extracted fromcms_model. The atoms are expected to have a property calledi_des_orig_aid, and the values should be the AIDs incms_model.sub_msys (
msys.System) – This object must matchsub_cms.
@rtype:
listofint
- schrodinger.application.desmond.packages.topo.comp_atoms(cms_model)¶
A coroutine to iterate through all atoms in all component CTs of the
cms_model.
- schrodinger.application.desmond.packages.topo.update_ct_box(ct, box)¶
Given a
ct, set the following CT-level properties using the values frombox:"r_chorus_box_ax", "r_chorus_box_ay", "r_chorus_box_az", "r_chorus_box_bx", "r_chorus_box_by", "r_chorus_box_bz", "r_chorus_box_cx", "r_chorus_box_cy", "r_chorus_box_cz",
- Return type
structure.Structure- Returns
The same input
ctobject, with its “r_chorus_box_*” CT-level properties updated.
- schrodinger.application.desmond.packages.topo.update_ct(ct, cms_model, fr, allaid_gids=None, is_fullsystem=True, update_vel=False)¶
Updates coordinates and simulation-box-matrix of the input
ctwith the given trajectory frame. Herecms_modelandfrshould correspond to the same simulation, andctcould be full system CT, component CT, or other subsystems extracted from the system. Note GCMC systems with multiple types of solvent are not supported.- Parameters
ct (
structure.Structure) – structure to be updatedcms_model (
cms.Cms) – It should be generated by theread_cmsfunction.allaid_gids (
numpy.ndarray, orlistofintorNone. The caller needs to make sure that its length and order match the atoms inct.Nonemeanscms_model.allaid_gidsis used.) – GIDs of all AIDsis_fullsystem (
bool) – whether or not this represents a fullsystem CT. Knowing this can keep us from doing extra workupdate_vel (
bool) – Update the atom velocities.
- Return type
structure.Structure- Returns
The same input
ctobject, with the atom coordinates and simulation box matrix updated from the frame.
- Example:
fsys_ct = cms_model.fsys_ct.copy() update_ct(fsys_ct, cms_model, tr[i])
- schrodinger.application.desmond.packages.topo.update_fsys_ct_from_frame_GF(fsys_ct, cms_model, fr, frames_to_smooth=None, aids_to_smooth=None, update_vel=False)¶
This function is the future version of
update_fsys_ct_from_frameand the difference is thatfsys_ctwill be inactive-free.
- schrodinger.application.desmond.packages.topo.update_fsys_ct_from_frame(fsys_ct, cms_model, fr, frames_to_smooth=None, aids_to_smooth=None)¶
Update a full system CT using a frame object, including atom positions, simulation box, atom-level properties i_des_atom_domain and i_m_visibility. If inactive atoms are present, they are labelled and set invisible. If
frames_to_smoothis given, the smoothed coordinates are used to update the full system CT’s coordinates instead.- Parameters
frames_to_smooth (
listoftraj.Frame) – Frames whose atom coordinates are to be smoothed to update the atom coordinates infsys_ct. Note it should containfr.aids_to_smooth (
listofintorNone) – AIDs of atoms whose coordinates are to be smoothed. IfNone, default to non-solvent atoms.
- schrodinger.application.desmond.packages.topo.get_active_fsys_ct_from_frame(fsys_ct, cms_model, fr)¶
Return a
Structureobject that contains only the active atoms from the given framefr. Note that the atom coordinates in the inputfsys_ctare updated with those from the frame. For GCMC simulations, this active full system CT is extracted from the input full system CT to exclude inactive (inactive) atoms. A new Structure object will be returned in this case. For normal MD simulations, the active full system CT is the entire system, and the updatedfsys_ctobject will be returned. This function has the same interface asupdate_ct.- Parameters
fsys_ct – full system CT
- schrodinger.application.desmond.packages.topo.set_atom_velocity(atom, vel)¶
This function will set the following atom properties:
r_ffio_x_vel r_ffio_y_vel r_ffio_z_vel
with
vel[0],vel[1], andvel[2], respectively.
- schrodinger.application.desmond.packages.topo.update_cms_physical(cms_model, pos, vel, box)¶
Update the physical data of a cms model. The physical data include all atom positions and velocities and also the box matrix.
- Parameters
cms_model (
cms.Cms) – The cms model to be updated. This model should be created by theread_cmsfunction, and its atom count and order should match to thepos,velinputs.
- schrodinger.application.desmond.packages.topo.check_consistency(cms_model, frame)¶
Return
Noneifcms_modelandframeare consistent, or astrobject describing the inconsistency if they are not consistent.- Parameters
cms_model (
cms.Cms) – It should be generated by theread_cmsfunction.
- schrodinger.application.desmond.packages.topo.update_cms(cms_model, frame, update_pseudoatoms=True)¶
Update the given
cms_modelwith the atom coordinates and the simulation box matrix from a simulation frameframe. For GCMC systems, it also updates the CT-level property ‘i_des_active_total’.N.B.: If you call this function for every frame of a long trajectory, you might find this function is quite slow. Also keep in mind that its performance has a strong dependency on the number of atoms in the system. If all you want is a full-system CT with atom coordinates updated by the trajectory frame, consider using the
get_active_fsys_ct_from_frameorupdate_ctfunctions above, which are much faster.The input
cms_modelandframeobjects should match. When in doubt, callcheck_consistency.- Parameters
cms_model (
cms.Cms) – It should be generated by theread_cmsfunction.- Return type
structure.Structure- Returns
The same input
cms_modelobject, with the atom coordinates and the simulation box matrix updated from the frame.
- schrodinger.application.desmond.packages.topo.update_msys(msys_model, frame)¶
Updates the given msys model
msys_modelwith the atom coordinates and velocities and the simulation box matrix from a simulation frameframe.- Return type
msys.System- Returns
The same input
msys_modelobject, with the atom coordinates, velocities and the simulation box matrix updated from the frame.
- schrodinger.application.desmond.packages.topo.get_aids_with_virtuals(cms_model)¶
- Returns
a set of full-system AIDs that have virtual sites attached to them.
- Return type
set of
int
- schrodinger.application.desmond.packages.topo.aids2gids(cms_model, aids, include_pseudoatoms=True)¶
Convert a list of atom IDs (
aids) into a list of gids. If any selected atoms have pseudoatoms associated to them, the pseudoatoms will be included into the list of gids. It puts all pseudoatoms’ GIDs after all physical atoms’ GIDs with arbitrary ordering.- Parameters
cms_model (
cms.Cms) – A cms model generated byread_cms(see above).- Return type
listofint- Returns
A list of gids of the selected particles
- schrodinger.application.desmond.packages.topo.asl2gids(cms_model, asl, include_pseudoatoms=True)¶
Evaluate an ASL expression, and return a list of gids of particles selected by
asl. If any selected atoms have pseudoatoms associated to them, the pseudoatoms will be included into the list of gids.- Parameters
cms_model (
cms.Cms) – A cms model generated byread_cms(see above).asl (
str) – An ASL expression
- Return type
listofint- Returns
An unsorted list of gids of the selected particles
- schrodinger.application.desmond.packages.topo.make_glued_topology(msys_model, cms_model)¶
Add glued topology to msys_model, which contains with extra bonds based on proximity of the solute molecules. It works with
_pfx_applyto properly center disjoint solute molecules (e.g., proteins with missing segments, dimers) The assumption is that the input cms_model has the correct spatial configurations.
- schrodinger.application.desmond.packages.topo.make_whole(msys_model, tr)¶
In MD simulation, molecules can be broken due to the periodic boundary condition, which makes some atoms be at one side of the simulation box and the other atoms at the opposite side. This function will edit the atom coordinates so to make broken molecules whole again for each frame of the MD trajectory
tr.- Parameters
msys_model (msys.System) – The msys model, which must be consistent with the trajectory in terms of the molecular topology. This object will not be mutated.
tr (
list) – The simulation trajectory to be modified
- Return type
list- Returns
Modified simulation trajectory
- schrodinger.application.desmond.packages.topo.glue(msys_model, gids, tr)¶
First, make-whole all molecules in the simulation system, and then glue the selected molecules together.
- Parameters
msys_model (msys.System) – The msys model, which must be consistent with the trajectory in terms of the molecular topology. This object will not be mutated.
gids (
list) – A list of gids to specify the molecules to be gluedtr (
list) – The simulation trajectory to be modified
- Return type
list- Returns
Modified simulation trajectory
- schrodinger.application.desmond.packages.topo.center(msys_model, gids, tr, dims=None)¶
This function will do what
gluedoes, but it will do one more thing: It will translate the coordinates of all atoms so that the specified molecules will be placed at the center (origin) of the simulation box.- Parameters
msys_model (msys.System) – The msys model, which must be consistent with the trajectory in terms of the molecular topology. This object will not be mutated.
gids (
list) – A list of gids to specify the molecules to be glued and centeredtr (
list) – The simulation trajectory to be modifieddim (
Noneorlistofint, e.g., [2] for z axis, [0, 1] for x-y plane. If set toNone, center on all three spatial dimensions) – dimensions to be centered on
- Return type
list- Returns
Modified simulation trajectory
- schrodinger.application.desmond.packages.topo.superimpose(msys_model, gids, tr, ref_pos, weights=None)¶
This function will do what
centerdoes, but in addition it will align and superimpose all the coordinates in the frame with respect to a reference coordinates (ref_pos). This operation will be applied to all frames in the trajectory.- Parameters
msys_model (msys.System) – The msys model, which must be consistent with the trajectory in terms of the molecular topology. This object will not be mutated.
gids (
list) – A list of gids to specify the molecules to be glued and centeredtr (
list) – The simulation trajectory to be modifiedref_pos (
numpy.array. 3xN matrix, where N is length ofgids.) – Reference coordinates used for alignmentsweights (
listor None) – Atom weights used for alignments. If it’sNone, all atoms will be weighted equally.
- Return type
list- Returns
Modified simulation trajectory
- schrodinger.application.desmond.packages.topo.make_whole_cms(msys_model, cms_model)¶
Similar to
make_whole(see above), but on a cms model instead of a simulation trajectory.Both
msys_modelandcms_modelmust be previously obtained through theread_cmsfunction. They both should have the same atom coordinates and the same simulation box matrix.- Return type
structure.Structure- Returns
Modified cms model
- schrodinger.application.desmond.packages.topo.glue_cms(msys_model, gids, cms_model)¶
Similar to
glue(see above), but on a cms model instead of a simulation trajectory.Both
msys_modelandcms_modelmust be previously obtained through theread_cmsfunction. They both should have the same atom coordinates and the same simulation box matrix.- Return type
structure.Structure- Returns
Modified cms model
- schrodinger.application.desmond.packages.topo.center_cms(msys_model, gids, cms_model, dims=None)¶
Similar to
center(see above), but on a cms model instead of a simulation trajectory.Both
msys_modelandcms_modelmust be previously obtained through theread_cmsfunction. They both should have the same atom coordinates and the same simulation box matrix.- Parameters
dim (
Noneorlistofint, e.g., [2] for z axis, [0, 1] for x-y plane. If set toNone, center on all three spatial dimensions) – dimensions to be centered on- Return type
structure.Structure- Returns
Modified cms model
- schrodinger.application.desmond.packages.topo.superimpose_cms(msys_model, gids, cms_model, ref_pos, weights=None)¶
Similar to
superimpose(see above), but on a cms model instead of a simulation trajectory.Both
msys_modelandcms_modelmust be previously obtained through theread_cmsfunction. They both should have the same atom coordinates and the same simulation box matrix.- Return type
structure.Structure- Returns
Modified cms model
- schrodinger.application.desmond.packages.topo.is_dynamic_asl(cms_model, asl) bool¶
Return True if ASL could evaluate to different results on different frames.