Sampling Dihedral Angles¶
The torsion sampler is the basic object used to sample the backbone torsion angles phi and psi. It can be used to calculate the probability distributions of backbone torsion angles from structures and save them, as well as loading distributions and drawing from them. It uses distributions specific for triplets of residues, so that when drawing a phi/psi pair for a certain residue, the distribution from which the pair is drawn also depends on the identity of the residues before and after the residue in question. The distributions of the sampler are internally stored in a vector, so that most methods which need to access a specific distribution can either take 3 residue names or an index as input.
As a showcase example, we randomly sample from a given torsion sample and store the resulting samples as a scatter plot:
from promod3 import loop
from ost import conop
# this requires matplotlib and numpy
import matplotlib
# change next line, if you wish to use a GUI-based plot-output
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
# load a default sampler
t_sampler = loop.LoadTorsionSampler()
# dihedral angles will be stored in here
phi = list()
psi = list()
# draw from a random distribution
for i in range(1000):
dihedral_pair = t_sampler.Draw(conop.ALA,
conop.PRO,
conop.ALA)
phi.append(dihedral_pair[0])
psi.append(dihedral_pair[1])
# and plot it
plt.xlim(-np.pi, np.pi)
plt.ylim(-np.pi, np.pi)
plt.plot(phi, psi, '.')
plt.xlabel("phi", fontsize='large')
plt.ylabel("psi", fontsize='large')
plt.title("ALA-PRO-ALA")
# store plot as png file
plt.savefig("torsion_plot.png")
Defining Amino Acid triplets¶
Since the torsion sampler considers triplets of amino acids, we need to define them. This is done with the so called torsion group definitions. Three strings represent the according positions of the consecutive amino acids. They are combined by “-”. It is either possible to use the keyword “all”, or write out all allowed amino acids by their three letter code and separate them by “,”. An example would be: “all- VAL,ILE-PRO”. There are cases where a tripeptide can match several group definitions. The list of group definitions is iterated for every combination of three consecutive amino acids and the first hit is decisive.
The Torsion Sampler Class¶
- class promod3.loop.TorsionSampler(group_definitions, bins_per_dimension, seed)¶
Basic object used to sample the backbone torsion angles phi and psi.
- Parameters:
- Raises:
RuntimeException
when there is a possible combination of the 20 standard amino acids not matching any of the group definitions.
- ExtractStatistics(view)¶
Extracts backbone torsion angles from the structure and adds them to the appropriate histograms in the sampler.
- Parameters:
view (
ost.mol.EntityView
) – structure from which parameters will be extracted
- UpdateDistributions()¶
Recalculates the probability distributions from the histograms.
- static Load(filename, seed)¶
- static LoadPortable(filename, seed)¶
Loads raw binary file generated with
Save()
(optimized for fast reading) / portable file generated withSavePortable()
(slower but less machine-dependent).- Parameters:
- Returns:
A torsion sampler
- Return type:
- Raises:
RuntimeError
if file cannot be opened or if file cannot be parsed (see here for details).
- Save(filename)¶
- SavePortable(filename)¶
Saves a raw / portable binary representation. Use portable files for distribution and convert locally to raw files. See here for details.
- Parameters:
filename (
str
) – Path to the file where the sampler will be saved- Raises:
RuntimeError
if file cannot be opened.
- GetHistogramIndex(before, central, after)¶
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for the central residueafter (
ost.conop.AminoAcid
) – id of the residue after central
- Returns:
The index of the histogram corresponding to the triplet of residues specified.
- GetHistogramIndices(sequence)¶
- Parameters:
sequence (
str
) – Sequence of length n from which histogram indices should created.- Returns:
List of length n-2 containing histogram indices of all consecutive amino acid triplets in sequence
- Raises:
RuntimeError
if sequence contains non standard amino acid
- Draw(before, central, after)¶
Draws a pair of dihedral angles for the central residue from the distribution specific for such a triplet of residues.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which torsion angles will be drawnafter (
ost.conop.AminoAcid
) – id of the residue after central
- Returns:
A pair of phi/psi angles
- Draw(index)¶
Draws a pair of dihedral angles from the distribution specified by the index.
- Parameters:
index (
int
) – The index of the distribution from which a phi/psi pair will be drawn.- Returns:
A pair of phi/psi angles
- DrawPhiGivenPsi(before, central, after, psi)¶
Draws a phi angle for the central residue from the conditional distribution P( phi | psi ) specific for such a triplet of residues.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which the phi will be drawnafter (
ost.conop.AminoAcid
) – id of the residue after centralpsi (
float
) – psi angle
- Returns:
An angle
- DrawPhiGivenPsi(index, psi)¶
Draws a phi angle from the conditional distribution P( phi | psi ) specified by the index.
- DrawPsiGivenPhi(before, central, after, phi)¶
Draws a phi angle for the central residue from the conditional distribution P( psi | phi ) specific for such a triplet of residues.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which the psi angle will be drawnafter (
ost.conop.AminoAcid
) – id of the residue after centralphi (
float
) – phi angle
- Returns:
An angle
- DrawPsiGivenPhi(index, phi)¶
Draws a phi angle from the conditional distribution P( psi | phi ) specified by the index.
- GetProbability(before, central, after, phi, psi)¶
Returns the probability of a specific pair of phi/psi angles for the central residue from the corresponding distribution.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which the probability is calculated.after (
ost.conop.AminoAcid
) – id of the residue after centralphi (
float
) – phi anglepsi (
float
) – psi angle
- Returns:
A probability
- GetProbability(index, phi, psi)¶
Returns the probability of a specific pair of phi/psi angles calulated from the distribution specified by index.
- GetPhiProbabilityGivenPsi(before, central, after, phi, psi)¶
Returns P( phi | psi ) for the central residue from the corresponding distribution.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which the probability is calculated.after (
ost.conop.AminoAcid
) – id of the residue after centralphi (
float
) – phi anglepsi (
float
) – psi angle
- Returns:
A probability
- GetPsiProbabilityGivenPhi(before, central, after, psi, phi)¶
Returns P( psi | phi ) for the central residue from the corresponding distribution.
- Parameters:
before (
ost.conop.AminoAcid
) – id of the residue before centralcentral (
ost.conop.AminoAcid
) – id of the residue for which the probability is calculated.after (
ost.conop.AminoAcid
) – id of the residue after centralpsi (
float
) – phi anglephi (
float
) – psi angle
- Returns:
A probability
- GetPhiProbabilityGivenPsi(index, phi, psi)¶
Returns P( phi | psi ) for the central residue from the corresponding distribution.
- GetPsiProbabilityGivenPhi(index, psi, phi)¶
Returns P( psi | phi ) for the central residue from the corresponding distribution.
- GetBinsPerDimension()¶
Returns the number of bins per dimension of the distributions.
- Return type: