moleculekit.projections.metricdihedral module#

exception moleculekit.projections.metricdihedral.AtomNotFoundException#

Bases: Exception

class moleculekit.projections.metricdihedral.Dihedral(atom1, atom2, atom3, atom4, dihedraltype=None, check_valid=True)#

Bases: object

Class to store atoms defining a dihedral angle.

Parameters:
  • atom1 (dict) – Dictionary describing the first atom of the dihedral with keys such as “name”, “resid”, “segid”, “insertion” and “chain”.

  • atom2 (dict) – Dictionary describing the second atom of the dihedral.

  • atom3 (dict) – Dictionary describing the third atom of the dihedral.

  • atom4 (dict) – Dictionary describing the fourth atom of the dihedral.

  • dihedraltype (str | None) – A label describing the type of the dihedral angle (e.g. “phi”, “psi”, “chi1”).

  • check_valid (bool) – If True, validate the atom dictionary keys and fill in missing keys with default values.

Example

>>> # Using the helper functions to construct a dihedral object
>>> d1 = Dihedral.phi(mol, 5, 6, segid='P0')
>>> d2 = Dihedral.chi1(mol, 12, segid='P0') # Defining segid
>>> d3 = Dihedral.chi1(mol, 38, chain='X') # Defining chain
>>> # Manual construction
>>> atom1 = {'name': 'N', 'resid': 5, 'segid': 'P'}
>>> atom2 = {'name': 'CA', 'resid': 3, 'segid': 'P', 'chain': 'A', 'insertion': 'B'}
>>> atom3 = {'name': 'C', 'resid': 46, 'segid': 'P', 'chain': 'X'}
>>> atom4 = {'name': 'O', 'resid': 2, 'segid': 'P'}
>>> d = Dihedral(atom1, atom2, atom3, atom4)
static chi1(mol, res, segid=None, chain=None, insertion=None, ff='amber')#

Constructs a Dihedral object corresponding to the chi1 angle of a residue

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res (int) – The resid of the residue

  • segid (str | None) – The segment id of the residue

  • chain (str | None) – The chain letter of the residue

  • insertion (str | None) – The insertion letter of the residue

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static chi2(mol, res, segid=None, chain=None, insertion=None, ff='amber')#

Constructs a Dihedral object corresponding to the chi2 angle of a residue

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res (int) – The resid of the residue

  • segid (str | None) – The segment id of the residue

  • chain (str | None) – The chain letter of the residue

  • insertion (str | None) – The insertion letter of the residue

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”; the two differ for the chi2 atoms of some residues.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static chi3(mol, res, segid=None, chain=None, insertion=None, ff='amber')#

Constructs a Dihedral object corresponding to the chi3 angle of a residue

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res (int) – The resid of the residue

  • segid (str | None) – The segment id of the residue

  • chain (str | None) – The chain letter of the residue

  • insertion (str | None) – The insertion letter of the residue

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static chi4(mol, res, segid=None, chain=None, insertion=None, ff='amber')#

Constructs a Dihedral object corresponding to the chi4 angle of a residue

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res (int) – The resid of the residue

  • segid (str | None) – The segment id of the residue

  • chain (str | None) – The chain letter of the residue

  • insertion (str | None) – The insertion letter of the residue

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static chi5(mol, res, segid=None, chain=None, insertion=None, ff='amber')#

Constructs a Dihedral object corresponding to the chi5 angle of a residue

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res (int) – The resid of the residue

  • segid (str | None) – The segment id of the residue

  • chain (str | None) – The chain letter of the residue

  • insertion (str | None) – The insertion letter of the residue

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static dihedralsToIndexes(mol, dihedrals, sel='all')#

Converts dihedral objects to atom indexes of a given Molecule

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain atom information

  • dihedrals (list) – A single dihedral or a list of Dihedral objects

  • sel (str | ndarray) – Atom selection to restrict the application of the selections (a selection string, boolean mask, or integer index array). See more here

Returns:

indexes – A list containing a list of atoms that correspond to each dihedral.

Return type:

list of lists

Examples

>>> dihs = []
>>> dihs.append(Dihedral.phi(mol, 1, 2))
>>> dihs.append(Dihedral.psi(mol, 2, 3))
>>> indexes = Dihedral.dihedralsToIndexes(mol, dihs)
static omega(mol, res1, res2, segid=None, chain=None, insertion1=None, insertion2=None, ff='amber')#

Constructs a Dihedral object corresponding to the omega angle of res1 and res2

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res1 (int) – The resid of the first residue containing the CA C atoms

  • res2 (int) – The resid of the second residue containing the N CA atoms

  • segid (str | None) – The segment id of the residues

  • chain (str | None) – The chain letter of the residues

  • insertion1 (str | None) – The insertion letter of residue 1

  • insertion2 (str | None) – The insertion letter of residue 2

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static phi(mol, res1, res2, segid=None, chain=None, insertion1=None, insertion2=None, ff='amber')#

Constructs a Dihedral object corresponding to the phi angle of res1 and res2

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res1 (int) – The resid of the first residue containing the C atom

  • res2 (int) – The resid of the second residue containing the N CA C atoms

  • segid (str | None) – The segment id of the residues

  • chain (str | None) – The chain letter of the residues

  • insertion1 (str | None) – The insertion letter of residue 1

  • insertion2 (str | None) – The insertion letter of residue 2

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

static proteinDihedrals(mol, sel='protein or resname ACE NME', dih=('psi', 'phi'), ff='amber')#

Returns a list of tuples containing the four resid/atom pairs for each dihedral of the protein

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • sel (str | ndarray) – Atom selection to restrict the atoms for which to calculate dihedrals (a selection string, boolean mask, or integer index array; e.g. only one of many chains). See more here

  • dih (tuple) – A tuple of the dihedral types we want to calculate (phi, psi, omega, chi1, chi2, chi3, chi4, chi5)

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm” (this only affects some chi2 sidechain atom names).

Returns:

dihedrals – A list of Dihedral objects

Return type:

list of Dihedral objects

static psi(mol, res1, res2, segid=None, chain=None, insertion1=None, insertion2=None, ff='amber')#

Constructs a Dihedral object corresponding to the psi angle of res1 and res2

Parameters:
  • mol (Molecule) – A Molecule object from which to obtain structural information

  • res1 (int) – The resid of the first residue containing the N CA C atoms

  • res2 (int) – The resid of the second residue containing the N atom

  • segid (str | None) – The segment id of the residues

  • chain (str | None) – The chain letter of the residues

  • insertion1 (str | None) – The insertion letter of residue 1

  • insertion2 (str | None) – The insertion letter of residue 2

  • ff (str) – The force field whose atom-naming convention to use when selecting the dihedral atoms. Either “amber” or “charmm”.

Returns:

dihedral – A Dihedral object

Return type:

Dihedral object

class moleculekit.projections.metricdihedral.MetricDihedral(dih=None, sincos=True, protsel='protein or resname ACE NME')#

Bases: Projection

Calculates a set of dihedral angles from trajectories

Parameters:
  • dih (list | None) – You can provide your own list of Dihedral objects. See example.

  • sincos (bool) – Set to True to return the dihedral angles as their sine and cosine components. Makes them periodic.

  • protsel (str | ndarray) – Atom selection for the protein segment for which to calculate dihedral angles (a selection string, boolean mask, or integer index array). Resids should be unique within that segment. See more here

Examples

>>> mol = Molecule('3PTB')
>>> mol.filter('not insertion A')
>>> met = MetricDihedral()
>>> met.project(mol)
>>> # More complicated example
>>> dih = []
>>> dih.append(Dihedral.chi1(mol, 45))
>>> dih.append(Dihedral.psi(mol, 29, 30))
>>> met = MetricDihedral(dih, protsel='protein and segid 0')
>>> met.project(mol)
>>> met.getMapping(mol)
getMapping(mol)#

Returns the description of each projected dimension.

Parameters:

mol (Molecule) – A Molecule object which will be used to calculate the descriptions of the projected dimensions.

Returns:

map – A DataFrame containing the descriptions of each dimension

Return type:

DataFrame object

project(mol)#

Project molecule.

Parameters:

mol (Molecule) – A Molecule object to project.

Returns:

data – An array containing the projected data.

Return type:

ndarray