Package generic_fns :: Module angles
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.angles

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2005 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  from math import acos, pi, sin 
 24  from Numeric import dot 
 25   
 26   
27 -class Angles:
28 - def __init__(self, relax):
29 """Class containing the functions relating to angles.""" 30 31 self.relax = relax
32 33
34 - def angles(self, run):
35 """Function for calculating the angle defining the XH vector in the diffusion frame.""" 36 37 # Test if the run exists. 38 if not run in self.relax.data.run_names: 39 raise RelaxNoRunError, run 40 41 # Test if the PDB file has been loaded. 42 if not self.relax.data.pdb.has_key(run): 43 raise RelaxNoPdbError, run 44 45 # Test if sequence data is loaded. 46 if not self.relax.data.res.has_key(run): 47 raise RelaxNoSequenceError, run 48 49 # Test if the diffusion tensor data is loaded. 50 if not self.relax.data.diff.has_key(run): 51 raise RelaxNoTensorError, run 52 53 # Arguments. 54 self.run = run 55 56 # Sphere. 57 if self.relax.data.diff[self.run].type == 'sphere': 58 return 59 60 # Spheroid. 61 elif self.relax.data.diff[self.run].type == 'spheroid': 62 self.spheroid_frame() 63 64 # Ellipsoid. 65 elif self.relax.data.diff[self.run].type == 'ellipsoid': 66 raise RelaxError, "No coded yet."
67 68
69 - def ellipsoid_frame(self, run=None):
70 """Function for calculating the spherical angles of the XH vector in the ellipsoid frame.""" 71 72 # Arguments. 73 self.run = run 74 75 # Get the unit vectors Dx, Dy, and Dz of the diffusion tensor axes. 76 Dx, Dy, Dz = self.relax.generic.diffusion_tensor.unit_axes() 77 78 # Loop over the sequence. 79 for i in xrange(len(self.relax.data.res[self.run])): 80 # Test if the vector exists. 81 if not hasattr(self.relax.data.res[self.run][i], 'xh_vect'): 82 print "No angles could be calculated for residue '" + `self.relax.data.res[self.run][i].num` + " " + self.relax.data.res[self.run][i].name + "'." 83 continue 84 85 # dz and dx direction cosines. 86 dz = dot(Dz, self.relax.data.res[self.run][i].xh_vect) 87 dx = dot(Dx, self.relax.data.res[self.run][i].xh_vect) 88 89 # Calculate the polar angle theta. 90 self.relax.data.res[self.run][i].theta = acos(dz) 91 92 # Calculate the azimuthal angle phi. 93 self.relax.data.res[self.run][i].phi = acos(dx / sin(self.relax.data.res[self.run][i].theta))
94 95
96 - def spheroid_frame(self, run=None):
97 """Function for calculating the angle alpha of the XH vector within the spheroid frame.""" 98 99 # Arguments. 100 self.run = run 101 102 # Get the unit vector Dpar of the diffusion tensor axis. 103 Dpar = self.relax.generic.diffusion_tensor.unit_axes() 104 105 # Loop over the sequence. 106 for i in xrange(len(self.relax.data.res[self.run])): 107 # Test if the vector exists. 108 if not hasattr(self.relax.data.res[self.run][i], 'xh_vect'): 109 print "No angles could be calculated for residue '" + `self.relax.data.res[self.run][i].num` + " " + self.relax.data.res[self.run][i].name + "'." 110 continue 111 112 # Calculate alpha. 113 self.relax.data.res[self.run][i].alpha = acos(dot(Dpar, self.relax.data.res[self.run][i].xh_vect))
114 115
116 - def wrap_angles(self, angle, lower, upper):
117 """Convert the given angle to be between the lower and upper values.""" 118 119 while 1: 120 if angle > upper: 121 angle = angle - upper 122 elif angle < lower: 123 angle = angle + upper 124 else: 125 break 126 127 return angle
128