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

Source Code for Module generic_fns.angles

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 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 
 24  from Numeric import dot 
 25   
 26   
27 -class Angles:
28 - def __init__(self, relax):
29 """Class containing the function to calculate the XH vector from the loaded structure.""" 30 31 self.relax = relax
32 33
34 - def angles(self, run):
35 """Function for calculating the XH vector from the loaded structure.""" 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 # Isotropic diffusion. 57 if self.relax.data.diff[self.run].type == 'iso': 58 return 59 60 # Axially symmetric diffusion. 61 elif self.relax.data.diff[self.run].type == 'axial': 62 self.axial() 63 64 # Fully anisotropic diffusion. 65 elif self.relax.data.diff[self.run].type == 'aniso': 66 raise RelaxError, "No coded yet."
67 68
69 - def axial(self):
70 """Function for calculating the angle alpha 71 72 The angle alpha is between the XH vector and the main axis of the axially symmetric 73 diffusion tensor. 74 """ 75 76 # Loop over the sequence. 77 for i in xrange(len(self.relax.data.res[self.run])): 78 # Test if the vector has been calculated. 79 if not hasattr(self.relax.data.res[self.run][i], 'xh_vect'): 80 print "No angles could be calculated for residue '" + `self.relax.data.res[self.run][i].num` + " " + self.relax.data.res[self.run][i].name + "'." 81 continue 82 83 # Calculate alpha. 84 self.relax.data.res[self.run][i].alpha = acos(dot(self.relax.data.diff[self.run].axis_unit, self.relax.data.res[self.run][i].xh_vect)) 85 86 # Print out. 87 print `self.relax.data.res[self.run][i].num` + " " + self.relax.data.res[self.run][i].name + ": alpha = " + `360.0 * self.relax.data.res[self.run][i].alpha / (2.0 * pi)` + " deg."
88 89
90 - def wrap_angles(self, angle, lower, upper):
91 """Convert the given angle to be between the lower and upper values.""" 92 93 while 1: 94 if angle > upper: 95 angle = angle - upper 96 elif angle < lower: 97 angle = angle + upper 98 else: 99 break 100 101 return angle
102