schrodinger.application.matsci.cg_mapping module¶
Utilities for mapping CG structures to AA
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.application.matsci.cg_mapping.get_chiral_hash(x)¶
- schrodinger.application.matsci.cg_mapping.get_chiral_pair(x)¶
- class schrodinger.application.matsci.cg_mapping.ATOM_DEFINITION(prop_name, idx, name, numberstr)¶
Bases:
tuple
- __contains__(key, /)¶
Return key in self.
- __len__()¶
Return len(self).
- count(value, /)¶
Return number of occurrences of value.
- idx¶
Alias for field number 1
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- name¶
Alias for field number 2
- numberstr¶
Alias for field number 3
- prop_name¶
Alias for field number 0
- schrodinger.application.matsci.cg_mapping.get_cg_particle_indices(atom)¶
Return a list of CG particle indices for the given atom.
- Parameters
atom (schrodinger.structure._StructureAtom) – the atom
- Return type
list
- Returns
CG particle indices
- exception schrodinger.application.matsci.cg_mapping.NonContiguousBondingError(msg='Particles containing atoms that are not contiguously bonded are currently not supported.', *args, **kwargs)¶
Bases:
Exception
Exception to handle non contiguous bonding in CG
- __init__(msg='Particles containing atoms that are not contiguously bonded are currently not supported.', *args, **kwargs)¶
Exception with default error message
- args¶
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- schrodinger.application.matsci.cg_mapping.extract_and_contract(struct, idxs=None, pbc=None, fast=False)¶
From the given indices and structure extract a structure and contract it according to the PBC.
- Parameters
struct (structure.Structure) – the structure from which to extract
idxs (set or None) – a set of integer atom indices defining the structure to be extracted or None in which case all indices will be used
pbc (
schrodinger.infra.structure.PBC
) – A pre-computed PBC for the structurefast (bool) – True if the computation should be done on a throw-away structure that will not be used for more than a center of mass calculation, False if the extracted structure must preserve properties such as atom formal charge and structure properties.
- Return type
- Returns
the extracted and contracted structure
- schrodinger.application.matsci.cg_mapping.get_center_of_mass_weight(atom)¶
Return the weight of the atom used for the center of mass calculation.
- Parameters
atom (schrodinger.structure._StructureAtom) – the atom
- Return type
float
- Returns
the weight of the atom in amu
- schrodinger.application.matsci.cg_mapping.center_of_mass(struct, idxs=None, pbc=None)¶
Return the center of mass of the given indices in the given structure accounting for if the structure has a PBC.
- Parameters
struct (structure.Structure) – the structure containing the atoms for which the center of mass is needed
idxs (set or None) – a set of integer atom indices for which the center of mass is needed or None in which case all atoms will be used
pbc (
schrodinger.infra.structure.PBC
) – A pre-computed PBC for the structure
- Return type
numpy.array
- Returns
the center of mass
- class schrodinger.application.matsci.cg_mapping.Particle¶
Bases:
object
Create a coarse grain particle.
- __init__()¶
Create an instance.
- setXYZ(xyz=None, astructure=None, pbc=None)¶
Set the position of the given particle.
- Parameters
xyz (numpy.array or None) – the position of the particle or None if there isn’t one
astructure (structure.Structure or None) – the structure from which the parent structure will be extracted and for which the center of mass is needed or None if there isn’t one
pbc (
schrodinger.infra.structure.PBC
) – A pre-computed PBC for the structure
- setVDWRadius(vdw_radius=None)¶
Set the VDW radius in Ang.
- Parameters
vdw_radius (float or None) – the VDW radius of the given particle in Ang. or None if there isn’t one
- setAtomicWeight(atomic_weight=None)¶
Set the atomic weight in g/mol.
- Parameters
atomic_weight (float or None) – the atomic weight of the given particle in g/mol or None if there isn’t one
- setFormalCharge(formal_charge=None)¶
Set the formal charge.
- Parameters
formal_charge (int) – the formal charge of the given particle or None if there isn’t one
- setPartialCharge(partial_charge=None)¶
Set the partial charge.
- Parameters
partial_charge (float) – the partial charge of the given particle or None if there isn’t one
- setParentStructure(astructure)¶
Set the parent structure.
- Parameters
astructure (structure.Structure) – the structure from which the parent structure will be extracted
- setParentStructureStr()¶
Set the parent structure string.
- setParentIndices(parent_indices)¶
Set the parent indices.
- Parameters
parent_indices (list) – the parent indices, i.e. indices of the parent atomic structure for this particle
- setParentCutBonds(astructure)¶
Set the parent cut bonds.
- Parameters
astructure (structure.Structure) – the structure from which the parent structure was extracted and thus for which the bonding information is needed
- setFormula(formula=None)¶
Set the formula of the given particle.
- Parameters
formula (str or None) – the formula for the given particle or None if there isn’t one
- setName(name)¶
Set the name of the given particle.
- Parameters
name (str) – name of the particle
- setRGBColor(rgb_color)¶
Set the RGB color of the given particle.
- Parameters
rgb_color (tuple) – a triple of integers in [0, 255] that give an RGB color for the given particle
- setAtomType(atom_type)¶
Set the atom type of the given particle.
- Parameters
atom_type (int) – atom type of the given particle
- setKey(key)¶
Set the key of the given particle, this is the key that indicates the parent structure string.
- Parameters
key (str) – key of the given particle
- defineAtom(astructure, index)¶
Define the given atom.
- Parameters
astructure (structure.Structure) – the structure containing the atom to define
index (int) – index of the atom to define
- static getParentIndices(cg_structure, cg_idx)¶
Return the parent indices for the given coarse grain particle index in the given coarse grain structure.
- Parameters
cg_structure (structure.Structure) – the coarse grain structure
cg_idx (int) – the coarse grain particle index
- Return type
tuple
- Returns
the parent indices for the given coarse grain particle index
- static getParentCutBonds(cg_structure, cg_idx, reverse=False)¶
Return the parent cut bonds for the given coarse grain particle index in the given coarse grain structure.
- Parameters
cg_structure (structure.Structure) – the coarse grain structure
cg_idx (int) – the coarse grain particle index
reverse (bool) – by default the first atom index of a pair from the returned tuple of pairs is for the particle with the given index and the second atom index of the pair is for the outside particle, if reverse is True it reverses this ordering
- Return type
tuple
- Returns
the parent cut bonds for the given coarse grain particle index
- static getParentBonds(cg_structure, cg_idx_i, cg_idx_j)¶
Return the parent bonds between the given coarse grain particles indices in the given coarse grain structure.
- Parameters
cg_structure (structure.Structure) – the coarse grain structure
cg_idx_i (int) – the first coarse grain particle index
cg_idx_j (int) – the second coarse grain particle index
- Return type
tuple
- Returns
the parent bonds between the given coarse grain particle indices
- class schrodinger.application.matsci.cg_mapping.CoarseGrainBond(name_1, idx_1, name_2, idx_2)¶
Bases:
object
Manage a coarse grain bond.
- FORMAT_START = '('¶
- FORMAT_END = ')'¶
- DUMMY_ELEMENT = 'DU'¶
- __init__(name_1, idx_1, name_2, idx_2)¶
Create an instance.
- Parameters
name_1 (str) – the name of particle 1
idx_1 (int) – the index particle 1
name_2 (str) – the name of particle 2
idx_2 (int) – the index particle 2
- setParentData(cg_structure)¶
Set the parent data.
- Parameters
cg_structure (structure.Structure) – the CG model
- getAllParentIndices()¶
Return a tuple containing all parent indices.
- Return type
tuple
- Returns
contains all parent indices
- setSmiles(st)¶
Set a unique SMILES for the parent indices.
- Parameters
st (structure.Structure) – the parent model
- setDefaultParticleLabels(st)¶
Set the default particle labels for the two coarse grain particles.
- Parameters
st (structure.Structure) – the parent model
- setChiralHash(st)¶
Set the chiral hash.
- Parameters
st (structure.Structure) – the parent model
- setParentBondsHash(st)¶
Set the parent bonds hash.
- Parameters
st (structure.Structure) – the parent model
- static formatParticleLabel(label)¶
Format the particle label.
- Parameters
label (str) – the label to format
- Return type
str
- Returns
the formated label
- class schrodinger.application.matsci.cg_mapping.CGMapperMixin¶
Bases:
object
A common mixin class for mapping all-atoms molecules to coarse-grain
- getAtomPolymerNames(atom, name)¶
Get the polymer names for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which the names are needed
name (str) – polymer monomer name
- Return type
list
- Returns
polymer names
- getAtomResidueNames(atom, name)¶
Get the residue names for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which the names are needed
name (str) – residue name
- Return type
list
- Returns
residue names
- getAtomDefinitions(atom, existing_definitions)¶
Get the definitions for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which definition data is needed
existing_definitions (list) – Each item of the list is a (name, number) tuple from DEFINITION_KEYS that should be searched on the atom.
- Return type
list
- Returns
list of ATOM_DEFINITION for the passed atom
- trimDefinitionDict(definition_dict)¶
Trim the given definition dictionary to get rid of redundant definitions.
- Parameters
definition_dict (OrderedDict) – keys are particle type strings, values are tuples of tuples of integers of particle occurrences
- static getUniqueDefNames(atom_definitions)¶
Gets the dictionary of names where the a single atom definition name is being used by multiple properties
- Parameters
atom_definitions (list(AtomDefinition)) – List of all atom definitions
- Returns
The dictionaries have keys as the definition names and the values of first dict is the property used by the definition and second dictionary values are list of properties ignored by the definition
- Return type
dict, dict
- getDefinitionDict(warn_logger=None)¶
Get definition dict.
- Parameters
warn_logger (function) – If passed the warnings generated during generation of definitions will be passed to this function as a string
- Return type
OrderedDict
- Returns
keys are particle type strings, values are tuples of tuples of integers of particle occurrences
- areContiguous(indices)¶
Return True if for the given indices the atoms are contiguously bonded, False otherwise.
- Parameters
indices (tuple) – the indices to check
- getParticles(particles, aname, acolor, aatom_type, akey)¶
Return list of particle objects.
- Parameters
particles (list) – contains particle indices as lists of atom indices
aname (str) – name for the particles
acolor (tuple) – a triple of integers in [0, 255] that give an RGB color for the particles
aatom_type (int) – atom type for the particles
akey (str) – a structure property key indicating the parent structure string
- Return type
list
- Returns
contains Particle instances
- inheritProperties(cg_structure)¶
Inherit properties for the CG model from the parent structure.
- Parameters
cg_structure (structure.Structure) – the CG model
- markParticleAtoms(particle_index, atom_indices)¶
Mark the atoms in the structure by particle index.
- Parameters
particle_index (int) – the particle index
atom_indices (list) – contains the atom indices for this particle
- buildCGFromParticles(all_particles, allow_unassigned=False)¶
Build coarse grain structure from the particle
- Parameters
all_particles (list) – list of lists of
Particles
, where each list corresponds to each mapping groupallow_unassigned (bool) – If False particles not mapped will be ignored, if True they will be ignored leading to no CG bond creation.
- Return type
- Returns
the new CG model
- getAssignedAndUnassigned(all_particles)¶
Get currently mapped (assigned) and upmapped (unassigned) atoms in the all-atom structure.
- Parameters
all_particles (list) – list of lists of
Particles
, where each list corresponds to each mapping group- Return type
tuple(set, set)
- Returns
tuple where first element is indexes of all-atom atoms that have been assigned mapping scheme and second are the atoms that have not been assigned any mapping scheme
- categorizeBonds()¶
Return a dictionary of categorized bonds.
- Return type
OrderedDict
- Returns
sorted keys where keys are pair tuples of coarse grain particle names, values are OrderedDicts where keys are (SMILES, chiral_hash) tuples and values are lists of CoarseGrainBond
- class schrodinger.application.matsci.cg_mapping.CGMapper(struct)¶
Bases:
schrodinger.application.matsci.cg_mapping.CGMapperMixin
Class create a mapped coarse grain model from an all-atom structure.
- TYPE_MAX = 400¶
- __init__(struct)¶
Initiate CGMapper class.
- Parameters
struct (structure.Structure) – All-atom structure to be mapped to CG
- getMappedParticles()¶
Create
Particles
for the assigned mapping scheme.- Return type
list(Particles)
- Returns
list of lists of
Particles
, where each list corresponds to each mapping group
- validateAllAssigned(all_particles)¶
Check if all the atoms in the structure have been assigned mapping scheme.
- Parameters
all_particles (list) – list of lists of
Particles
, where each list corresponds to each mapping group- Raise
ValueError if all particle have not been assigned names
- markCGBonds()¶
CG bonds that are mapped to same named atoms but resulted from different all-atom bonding environment will be marked as unique. Thus, resulting in individual parameters for each.
- areContiguous(indices)¶
Return True if for the given indices the atoms are contiguously bonded, False otherwise.
- Parameters
indices (tuple) – the indices to check
- buildCGFromParticles(all_particles, allow_unassigned=False)¶
Build coarse grain structure from the particle
- Parameters
all_particles (list) – list of lists of
Particles
, where each list corresponds to each mapping groupallow_unassigned (bool) – If False particles not mapped will be ignored, if True they will be ignored leading to no CG bond creation.
- Return type
- Returns
the new CG model
- categorizeBonds()¶
Return a dictionary of categorized bonds.
- Return type
OrderedDict
- Returns
sorted keys where keys are pair tuples of coarse grain particle names, values are OrderedDicts where keys are (SMILES, chiral_hash) tuples and values are lists of CoarseGrainBond
- getAssignedAndUnassigned(all_particles)¶
Get currently mapped (assigned) and upmapped (unassigned) atoms in the all-atom structure.
- Parameters
all_particles (list) – list of lists of
Particles
, where each list corresponds to each mapping group- Return type
tuple(set, set)
- Returns
tuple where first element is indexes of all-atom atoms that have been assigned mapping scheme and second are the atoms that have not been assigned any mapping scheme
- getAtomDefinitions(atom, existing_definitions)¶
Get the definitions for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which definition data is needed
existing_definitions (list) – Each item of the list is a (name, number) tuple from DEFINITION_KEYS that should be searched on the atom.
- Return type
list
- Returns
list of ATOM_DEFINITION for the passed atom
- getAtomPolymerNames(atom, name)¶
Get the polymer names for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which the names are needed
name (str) – polymer monomer name
- Return type
list
- Returns
polymer names
- getAtomResidueNames(atom, name)¶
Get the residue names for this atom.
- Parameters
atom (structure._StructureAtom) – the atom for which the names are needed
name (str) – residue name
- Return type
list
- Returns
residue names
- getDefinitionDict(warn_logger=None)¶
Get definition dict.
- Parameters
warn_logger (function) – If passed the warnings generated during generation of definitions will be passed to this function as a string
- Return type
OrderedDict
- Returns
keys are particle type strings, values are tuples of tuples of integers of particle occurrences
- getParticles(particles, aname, acolor, aatom_type, akey)¶
Return list of particle objects.
- Parameters
particles (list) – contains particle indices as lists of atom indices
aname (str) – name for the particles
acolor (tuple) – a triple of integers in [0, 255] that give an RGB color for the particles
aatom_type (int) – atom type for the particles
akey (str) – a structure property key indicating the parent structure string
- Return type
list
- Returns
contains Particle instances
- static getUniqueDefNames(atom_definitions)¶
Gets the dictionary of names where the a single atom definition name is being used by multiple properties
- Parameters
atom_definitions (list(AtomDefinition)) – List of all atom definitions
- Returns
The dictionaries have keys as the definition names and the values of first dict is the property used by the definition and second dictionary values are list of properties ignored by the definition
- Return type
dict, dict
- inheritProperties(cg_structure)¶
Inherit properties for the CG model from the parent structure.
- Parameters
cg_structure (structure.Structure) – the CG model
- mapCGStructure(cg_names, allow_unassigned, unique_bonds)¶
Map the passed cg_names to a coarse grain structure and build it from the all-atom structure.
- Parameters
list – list of cg_names to be mapped
allow_unassigned (bool) – if True, not all atoms are required to be mapped to the CG model. In case of False a check would be done and ValueError will be raised if all atoms were not assigned mapping
unique_bonds (bool) – if True CG bonds that are mapped to same named atoms but resulted from different all-atom bonding environment will be marked as unique. If False the bonds will be considered indistinguishable
- markParticleAtoms(particle_index, atom_indices)¶
Mark the atoms in the structure by particle index.
- Parameters
particle_index (int) – the particle index
atom_indices (list) – contains the atom indices for this particle
- trimDefinitionDict(definition_dict)¶
Trim the given definition dictionary to get rid of redundant definitions.
- Parameters
definition_dict (OrderedDict) – keys are particle type strings, values are tuples of tuples of integers of particle occurrences