Biskit :: Trajectory :: Trajectory :: Class Trajectory
[hide private]
[frames] | no frames]

Class Trajectory

source code

Manage many conformations of one molecule. Read coordinates and PDB infos from many PDB files, superimpose all coordinates to reference structure, calculate pairwise RMSD of all conformations ..

Instance Methods [hide private]
  __init__(self, pdbs=None, refpdb=None, rmwat=1, castAll=0, verbose=1)
Collect coordinates into Numpy array.
str version(self)
Version of class.
  __create(self, pdbs, refpdb, rmwat=0, castAll=0)
Initiate and create necessary variables.
PDBModel OR Trajectory __getitem__(self, i)
Get a single frame and facilitete slicing of tajectories.
int __len__(self)
Number of frames in the trajectory.
  __setstate__(self, state)
called for unpickling the object.
  __defaults(self)
backwards compatibility to earlier pickled trajectories
  __getstate__(self)
Called before pickling the object.
PDBModel avgModel(self)
Returna a PDBModel with coordinates that are the average of all frames.
array __collectFrames(self, pdbs, castAll=0)
Read coordinates from list of pdb files.
PDBModel getRef(self)
Returns reference PDBModel
PDBModel setRef(self, refModel)
Assign new reference model.
Trajectory concat(self, *traj)
Concatenate this with other trajectories.
Trajectory concatAtoms(self, *traj)
Concatenate 2 trajectories of same (frame) length 'horizontally', i.e.
int lenFrames(self)
Returns number of frames in trajectory
int lenAtoms(self)
Returns number of atoms in frames
list[1|0] atomMask(self, what)
Get atom mask.
[int] resMap(self, force=0)
A list with residue numbers mapped to each position.
Trajectory takeFrames(self, indices)
Return a copy of the trajectory containing only the specified frames.
Trajectory clone(self)
Copy trajectory.
Trajectory compressFrames(self, mask)
Compress trajectory with a frame mask.
  replaceContent(self, traj)
Replace content of this trajectory by content of given traj.
  keepFrames(self, indices)
in-place version of takeFrames.
  removeFrames(self, indices)
Remove given frames from this trajectory object.
Trajectory takeAtoms(self, indices, returnClass=None)
Take atoms from frames:
Trajectory compressAtoms(self, aMask, returnClass=None)
Get copy of this trajectory with only atoms marked 1 in aMask.
  keepAtoms(self, indices)
in-place version of takeAtoms.
array removeAtoms(self, what)
Remove atoms from all frames of trajectory and from reference structure.
Trajectory takeChains(self, chainLst, returnClass=None)
Extract some chains from complete Trajectory.
  fit(self, mask=None, ref=None, n_it=1, prof='rms', verbose=1, fit=1, **profInfos)
Superimpose all coordinate frames on reference coordinates.
  transform(self, *rt)
Apply given transformation to all frames (in place).
  blockFit2ref(self, refModel=None, mask=None, conv=1e-6)
Fit trajectory until convergence onto it's own average and then transform the average of all frames onto the reference.
  writePdb(self, index, fname)
Write (possibly transformed) coordinates back to pdb.
  writePdbs(self, fname, frames=None)
Write coordinates to an NMR-style MODEL/ENDMDL pdb file.
  writeCrd(self, fname, frames=None)
Write frames to Amber crd file (w/o box info).
PDBModel getPDBModel(self, index)
Get PDBModel object for a particular frame of the trajectory.
  setProfile(self, name, prof, mask=None, default=None, asarray=1, comment=None, **moreInfo)
Add/override profile.
  profile(self, name, default=None)
Get the values of a profile:
  profileInfo(self, name)
GEt information associated with a profile:
  setProfileInfo(self, name, **args)
Add/Override infos about a given profile:
[1|0] profile2mask(self, profName, cutoff_min=None, cutoff_max=None)
Create a mask from a profile with optional cutoff values.
biggles.FramedPlot plotProfile(self, *name, **args)
Create a biggles.FramedPlot objetc from a profile.
array pairwiseRmsd(self, aMask=None, noFit=0)
Calculate rmsd between each 2 coordinate frames.
array getFluct_global(self, mask=None)
Get RMS of each atom from it's average position in trajectory.
[ int ], [ int ] __resWindow(self, res, n_neighbores, rchainMap=None, left_allowed=None, right_allowed=None)
Get indices of all atoms of a residue and some atoms of its neighboring residues (if they belong to the same chain).
array getFluct_local(self, mask=None, border_res=1, left_atoms=['C'], right_atoms=['N'], verbose=1)
Get mean displacement of each atom from it's average position after fitting of each residue to the reference backbone coordinates of itself and selected atoms of neighboring residues to the right and left.
array residusMaximus(self, atomValues, mask=None)
Take list of value per atom, return list where all atoms of any residue are set to the highest value of any atom in that residue.
[float] getGammaFluct(self, fluctList=None)
Set value of all atoms of each residue to fluctuation of its gamma atom ( CG, SG, OG ).
[float] getResFluct(self, atomFluctList=None)
Convert list of atomic fluctuations to list of residue fluctuation.
[-1|0|1] __cmpLists(self, l1, l2)
Compare to lists by their first, then second, etc item.
-1|0|+1 __cmpFileNames(self, f1, f2)
Compare 2 file names by the numbers contained in them using the regular expression ex_numbers (or as strings, if no numbers are found):
[int] argsortFrames(self)
Prepare sorting list by file names.
  sortFrames(self, sortList=None)
Apply to a trajectory object to sort the frames and names according to the sortList.
  sortAtoms(self, f_cmp=None)
Sorts atoms WITHIN residues in reference and all frames.
[float] __takePca(self, indices)
extract PCA results for certain frames.
[float] __compressPca(self, fMask)
Compress PCA results using a frame mask.
dict getPca(self, aMask=None, fMask=None, fit=1)
Get the results form a principal component analysis.
array, array, array pca(self, atomMask=None, frameMask=None, fit=1)
Calculate principal components of trajectory frames.
Trajectory pcMovie(self, ev, steps, factor=1., ref=0, morph=1)
Morph between the two extreme values of a single principal component.

Class Variables [hide private]
  ex_numbers = re.compile('\D*([0-9]+)\D*')

Method Details [hide private]

__init__(self, pdbs=None, refpdb=None, rmwat=1, castAll=0, verbose=1)
(Constructor)

source code 

Collect coordinates into Numpy array. By default, the atom content of the first PDB is compared to the reference PDB to look for atoms that have to be removed or re-ordered. It is assumed that the other PDB files in the list have an identical atom content/layout and the same re-ordering / removing is applied to all of them. Set castAll to 1, in order to check each PDB seperately.
Parameters:
  • pdbs ([ str ] OR [ PDBModel ]) - file names of all conformations OR PDBModels
  • refpdb (str) - file name of reference pdb
  • rmwat (0|1) - skip all TIP3, HOH, Cl-, Na+ from all files (default: 1)
  • castAll (0|1) - re-analyze atom content of each frame (default: 0)
  • verbose (1|0) - verbosity level (default: 1)

version(self)

source code 

Version of class.
Returns: str
version

__create(self, pdbs, refpdb, rmwat=0, castAll=0)

source code 

Initiate and create necessary variables.
Parameters:
  • pdbs ([ str ] OR [ PDBModel ]) - file names of all conformations OR PDBModels
  • refpdb (str) - file name of reference pdb
  • rmwat (0|1) - skip all TIP3, HOH, Cl-, Na+ from all files (default: 1)
  • castAll (0|1) - re-analyze atom content of each frame (default: 0)

__getitem__(self, i)
(Indexing operator)

source code 

Get a single frame and facilitete slicing of tajectories.
Parameters:
  • i (int OR [int]) - index OR SliceTyp
Returns: PDBModel OR Trajectory
model OR trajectory
Raises:
  • TrajError - if out of memory OR invalid index

__len__(self)
(Length operator)

source code 

Number of frames in the trajectory.
Returns: int
length

__setstate__(self, state)

source code 

called for unpickling the object.

__defaults(self)

source code 

backwards compatibility to earlier pickled trajectories

__getstate__(self)

source code 

Called before pickling the object.

avgModel(self)

source code 

Returna a PDBModel with coordinates that are the average of all frames.
Returns: PDBModel
PDBModel with average structure of trajectory (no fitting!) this trajectory's ref is the source of result model

__collectFrames(self, pdbs, castAll=0)

source code 

Read coordinates from list of pdb files.
Parameters:
  • pdbs ([str]) - list of file names
  • castAll (0|1) - analyze atom content of each frame for casting (default: 0)
Returns: array
frames x (N x 3) Numpy array (of float)

getRef(self)

source code 
Returns: PDBModel
reference PDBModel

setRef(self, refModel)

source code 

Assign new reference model.
Parameters:
  • refModel (PDBModel) - PDBModel with same number of atoms as in the frames.
Returns: PDBModel
old reference PDBModel

concat(self, *traj)

source code 

Concatenate this with other trajectories. The ref model of the new Trajectory is a 'semi-deep' copy of this trajectorie's model. (see PDBModel.take() ):
  concat( traj [, traj2, traj3, ..] ) -> Trajectory 
Parameters:
  • traj (Trajectories) - one or more Trajectory with identical atoms as this one
Returns: Trajectory
concatenated trajecties

concatAtoms(self, *traj)

source code 

Concatenate 2 trajectories of same (frame) length 'horizontally', i.e. for each frame the coordinates of one are appended to the coordinates of the other. The ref model of the new trajectory is a 'semi-deep' copy of this trajectory's model (see PDBModel.take() ):
 concatAtoms( traj1 [traj2, traj3..]) -> Trajectory
Parameters:
  • traj (Trajectories) - one or more Trajectory of the same number of frames
Returns: Trajectory
trajectory with concatenated atoms

lenFrames(self)

source code 
Returns: int
number of frames in trajectory

lenAtoms(self)

source code 
Returns: int
number of atoms in frames

atomMask(self, what)

source code 

Get atom mask.
Parameters:
  • what (any) - Create the mask using:
                 - funct( self.ref.atoms[i] ) -> int
                 - list int ( indices )
                 - mask
                 - list of str (atom names)
    
Returns: list[1|0]
list of 1|0 1 x N_atoms

resMap(self, force=0)

source code 

A list with residue numbers mapped to each position. i.e. [00001111222222222333..]
Parameters:
  • force (1|0) - calculate even if it already been calculated
Returns: [int]
list of int

takeFrames(self, indices)

source code 

Return a copy of the trajectory containing only the specified frames.
Parameters:
  • indices ([int]) - positions to take
Returns: Trajectory
copy of this Trajectory (fewer frames, semi-deep copy of ref)

clone(self)

source code 

Copy trajectory.
Returns: Trajectory
Trajectory (or sub-class), copy of this trajectory

compressFrames(self, mask)

source code 

Compress trajectory with a frame mask.
Parameters:
  • mask ([1|0]) - frame mask, 1 x N_frames
Returns: Trajectory
copy of this Trajectory (fewer frames, semi-deep copy of ref)

replaceContent(self, traj)

source code 

Replace content of this trajectory by content of given traj. No deep-copying, only references are taken.
Parameters:
  • traj (trajectory) - trajectory

keepFrames(self, indices)

source code 

in-place version of takeFrames. keepFrames( indices ) -> None
Parameters:
  • indices ([int]) - frame numbers

removeFrames(self, indices)

source code 

Remove given frames from this trajectory object.
Parameters:
  • indices ([int]) - frame numbers

takeAtoms(self, indices, returnClass=None)

source code 

Take atoms from frames:
 takeAtoms( indices, type=None ) -> copy of Trajectory
Parameters:
  • indices ([int]) - list of atom indices
  • returnClass (class OR None) - default: None, same class as this object
Returns: Trajectory
copy of this Trajectory (with fewer atoms)

compressAtoms(self, aMask, returnClass=None)

source code 

Get copy of this trajectory with only atoms marked 1 in aMask.
Parameters:
  • aMask ([1|0]) - atom mask [10011100101111...], lst 1 x N_atoms of 1(keep) or 0
  • returnClass (class) - default: None, same class as this object
Returns: Trajectory
copy of Trajectory with fewer atoms

keepAtoms(self, indices)

source code 

in-place version of takeAtoms. keepAtoms( indices ) -> None
Parameters:
  • indices ([int]) - atom numbers

removeAtoms(self, what)

source code 

Remove atoms from all frames of trajectory and from reference structure.
Parameters:
  • what (any) - Specify what atoms to remove:
                 - function( atom_dict ) -> 1 || 0    or (1..remove)
                 - list of int [4, 5, 6, 200, 201..], indices of atoms
                     to remove
                 - list of int [11111100001101011100..N_atoms], mask
                     (1..remove)
                 - int, remove atom with this index
    
Returns: array
N.array(1 x N_atoms_old) of 0||1, mask used to compress the atoms and xyz arrays. This mask can be used to apply the same change to another array of same dimension as the old(!) xyz and atoms.

takeChains(self, chainLst, returnClass=None)

source code 

Extract some chains from complete Trajectory.
Parameters:
  • chainLst ([int]) - chains to isolate
  • returnClass (class) - default: None, same class as this object
Returns: Trajectory
Trajectory with only those chains

fit(self, mask=None, ref=None, n_it=1, prof='rms', verbose=1, fit=1, **profInfos)

source code 

Superimpose all coordinate frames on reference coordinates. Put rms values in a profile. If n_it > 1, the fraction of atoms considered for the fit is put into a profile called |prof|_considered (i.e. by default 'rms_considered').
Parameters:
  • mask ([1|0]) - atom mask, atoms to consider default: [all]
  • ref (PDBModel) - use as reference, default: None, average Structure
  • n_it (int) - number of fit iterations, kicking out outliers on the way 1 -> classic single fit, 0 -> until convergence (default: 1)
  • prof (str) - save rms per frame in profile of this name, ['rms']
  • verbose (1|0) - print progress info to STDERR (default: 1)
  • fit (1|0) - transform frames after match, otherwise just calc rms (default: 1)
  • profInfos (key=value) - additional key=value pairs for rms profile info []

transform(self, *rt)

source code 

Apply given transformation to all frames (in place).
Parameters:
  • rt (array( 4 x 4 ) OR array(3 x 3), array(3 x 1)) - rotation translation matrix

blockFit2ref(self, refModel=None, mask=None, conv=1e-6)

source code 

Fit trajectory until convergence onto it's own average and then transform the average of all frames onto the reference. To be used with parallell trajectories.
Parameters:
  • refModel (PDBModel) - Reference model (default: None)
  • mask ([1|0]) - atom mask to apply before fitting (default: None, all atoms)
  • conv (float) - convergence cutoff creterion (default: 1e-6)

writePdb(self, index, fname)

source code 

Write (possibly transformed) coordinates back to pdb.
Parameters:
  • index (int) - frame index in trajectory
  • fname (str) - name of new file

writePdbs(self, fname, frames=None)

source code 

Write coordinates to an NMR-style MODEL/ENDMDL pdb file.
Parameters:
  • fname (str) - name of new file
  • frames ([int]) - frame indices (default: None, all)

writeCrd(self, fname, frames=None)

source code 

Write frames to Amber crd file (w/o box info).
Parameters:
  • fname (str) - output file name
  • frames ([int]) - frame indices (default: all)

getPDBModel(self, index)

source code 

Get PDBModel object for a particular frame of the trajectory.
Parameters:
  • index (int) - frame index
Returns: PDBModel
model

setProfile(self, name, prof, mask=None, default=None, asarray=1, comment=None, **moreInfo)

source code 

Add/override profile.
Parameters:
  • name (str) - profile name
  • prof ([any]) - list of values
  • mask ([0|1]) - list 1 x N_items of 0|1, if there are less values than items, provide mask for missing values, N.sum(mask)==N_items
  • default (any) - value for items masked.
  • asarray (0|1|2) - store as list (0), as array (2) or store numbers as array but everything else as list (1) (default: 1)
  • comment (str) - goes into info[name]['comment']
  • moreInfo () - additional key-value pairs for info[name]
Raises:

profile(self, name, default=None)

source code 

Get the values of a profile:
 get( name ) -> list of values
Parameters:
  • name (str) - profile name
  • default (any) - default result if no profile is found
Raises:

profileInfo(self, name)

source code 

GEt information associated with a profile:
 profileInfo( name ) -> dict with infos about profile
Guaranteed infos: 'version'->str, 'comment'->str, 'changed'->1|0
Parameters:
  • name (str) - profile name
Raises:

setProfileInfo(self, name, **args)

source code 

Add/Override infos about a given profile:
 e.g. setInfo('relASA', comment='new', params={'bin':'whatif'})
Parameters:
  • name (str) - profile name
Raises:

profile2mask(self, profName, cutoff_min=None, cutoff_max=None)

source code 

Create a mask from a profile with optional cutoff values.
Parameters:
  • profName (str) - profile name
  • cutoff_min (float) - lower cutoff value (default: None)
  • cutoff_max (float) - upper cutoff value (default: None)
Returns: [1|0]
mask lenFrames x 1|0

plotProfile(self, *name, **args)

source code 

Create a biggles.FramedPlot objetc from a profile. Display the plot with biggles.FramedPlot.show():
 plotProfile(name1, [name2, ..],[arg1=x, arg2=y])->biggles.FramedPlot
Parameters:
  • name (str) - profile name
Returns: biggles.FramedPlot
plot object

pairwiseRmsd(self, aMask=None, noFit=0)

source code 

Calculate rmsd between each 2 coordinate frames.
Parameters:
  • aMask ([1|0]) - atom mask
Returns: array
frames x frames array of float

getFluct_global(self, mask=None)

source code 

Get RMS of each atom from it's average position in trajectory. The frames should be superimposed (fit() ) to a reference.
Parameters:
  • mask ([1|0]) - N x 1 list/Numpy array of 0|1, (N=atoms), atoms to be considered.
Returns: array
Numpy array ( N_unmasked x 1 ) of float.

__resWindow(self, res, n_neighbores, rchainMap=None, left_allowed=None, right_allowed=None)

source code 

Get indices of all atoms of a residue and some atoms of its neighboring residues (if they belong to the same chain).
Parameters:
  • res (int) - residue index
  • n_neighbores (int) - number of residues to include right and left
  • right_allowed (array) - array 1 x N_atoms of 1|0, possible neighbore atoms
  • left_allowed (array) - array 1 x N_atoms of 1|0, possible neighbore atoms
  • rchainMap (array) - array 1 x N_residues of int, chain id of each res
Returns: [ int ], [ int ]
atoms of res, atoms of neighbores

getFluct_local(self, mask=None, border_res=1, left_atoms=['C'], right_atoms=['N'], verbose=1)

source code 

Get mean displacement of each atom from it's average position after fitting of each residue to the reference backbone coordinates of itself and selected atoms of neighboring residues to the right and left.
Parameters:
  • mask (array) - N_atoms x 1 array of 0||1, atoms for which fluctuation should be calculated
  • border_res (int) - number of neighboring residues to use for fitting
  • left_atoms ([str]) - atoms (names) to use from these neighbore residues
  • right_atoms ([str]) - atoms (names) to use from these neighbore residues
Returns: array
Numpy array ( N_unmasked x 1 ) of float

residusMaximus(self, atomValues, mask=None)

source code 

Take list of value per atom, return list where all atoms of any residue are set to the highest value of any atom in that residue. (after applying mask)
Parameters:
  • atomValues ([ float ]) - list 1 x N, values per atom
  • mask ([1|0]) - list 1 x N, 0|1, 'master' atoms of each residue
Returns: array
Numpy array 1 x N of float

getGammaFluct(self, fluctList=None)

source code 

Set value of all atoms of each residue to fluctuation of its gamma atom ( CG, SG, OG ).
Parameters:
  • fluctList ([float]) - 1x N, precalculated list of values or None (will be calculated new)
Returns: [float]
Numpy array 1 x N of float

getResFluct(self, atomFluctList=None)

source code 

Convert list of atomic fluctuations to list of residue fluctuation.
Parameters:
  • atomFluctList ([float]) - array 1 x N_atoms of float
Returns: [float]
array 1 x N_residues of float
Raises:
  • TrajError - if result length <> N_residues:

__cmpLists(self, l1, l2)

source code 

Compare to lists by their first, then second, etc item.
Parameters:
  • l1 ([float]) - list
  • l2 ([float]) - list
Returns: [-1|0|1]
result of comparison (-1 == l1[i] < l2[i])

__cmpFileNames(self, f1, f2)

source code 

Compare 2 file names by the numbers contained in them using the regular expression ex_numbers (or as strings, if no numbers are found):
  f1, f2 - strings, e.g. 'frame_1_188.pdb'
Parameters:
  • f1 (str) - file name
  • f2 (str) - file name
Returns: -1|0|+1
result of comparison (-1 == f1 < f2)

argsortFrames(self)

source code 

Prepare sorting list by file names. Assuming the file names contains some numbers seperated by non-number characters. Sorting is done after Nr1 then Nr2 then..
Returns: [int]
list of frame sort order

sortFrames(self, sortList=None)

source code 

Apply to a trajectory object to sort the frames and names according to the sortList.
Parameters:
  • sortList ([int]) - list to sort after (default: None)
Raises:
  • TrajError - if sortList doesn't fit number of frames or names

sortAtoms(self, f_cmp=None)

source code 

Sorts atoms WITHIN residues in reference and all frames.
Parameters:
  • f_cmp (function) - atom comparison function f_cmp( atoms[i], atoms[j]) -> -1|0|+1 (default: alphabetic ordering by atom['name'] )
Raises:
  • PDBModelError - if sorting has changed number of atoms in reference

__takePca(self, indices)

source code 

extract PCA results for certain frames.
Parameters:
  • indices ([int]) - frame indecies
Returns: [float]
list of pca values

__compressPca(self, fMask)

source code 

Compress PCA results using a frame mask.
Parameters:
  • fMask ([1|0]) - frame mask
Returns: [float]
list of pca values

getPca(self, aMask=None, fMask=None, fit=1)

source code 

Get the results form a principal component analysis.
Parameters:
  • aMask ([1|0]) - 1 x N_atoms of 1|0, atom mask, default: last one used
  • fMask ([1|0]) - 1 x N_frames of 1|0, frame mask, default: all
  • fit (1|0) - fit to average structure before doing the PC analysis (default: 1)
Returns: dict
Dictionary with results from the PC analysis:
          dic {'p': projection of each frame in PC space,
               'e': list of eigen values,
               'fit':.., 'aMask':.., 'fMask':.. parameters used}

pca(self, atomMask=None, frameMask=None, fit=1)

source code 

Calculate principal components of trajectory frames.
Parameters:
  • atomMask ([1|0]) - 1 x N_atoms, [111001110..] atoms to consider (default: all)
  • frameMask ([1|0]) - 1 x N_frames, [001111..] frames to consider (default all )
Returns: array, array, array
(N_frames x N_frames), (1 x N_frames), projection of each frame in PC space, eigenvalue of each PC

pcMovie(self, ev, steps, factor=1., ref=0, morph=1)

source code 

Morph between the two extreme values of a single principal component.
Parameters:
  • ev (int) - EigenVector to visualize
  • steps (int) - number of intermediate frames
  • factor (float) - exageration factor (default: 1 = No exageration)
  • ref (int) - take other eigenvecors from this frame (default: 1)
  • morph (1|0) - morph between min and max (1) or take real values (0) (default: 1)
Returns: Trajectory
Trajectory with frames visualizing the morphing.

Class Variable Details [hide private]

ex_numbers

Value:
re.compile('\D*([0-9]+)\D*')