Package bmrblib :: Package kinetics :: Module relax_base
[hide private]
[frames] | no frames]

Source Code for Module bmrblib.kinetics.relax_base

  1  ############################################################################# 
  2  #                                                                           # 
  3  # The BMRB library.                                                         # 
  4  #                                                                           # 
  5  # Copyright (C) 2009 Edward d'Auvergne                                      # 
  6  #                                                                           # 
  7  # This program 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 3 of the License, or         # 
 10  # (at your option) any later version.                                       # 
 11  #                                                                           # 
 12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.     # 
 19  #                                                                           # 
 20  ############################################################################# 
 21   
 22  # Module docstring. 
 23  """Base classes for the relaxation data.""" 
 24   
 25  # relax module imports. 
 26  from bmrblib.base_classes import BaseSaveframe, TagCategory 
 27   
 28   
29 -class RelaxSaveframe(BaseSaveframe):
30 """The heteronuclear Rx data saveframe baseclass.""" 31
32 - def loop(self):
33 """Loop over the Rx saveframes, yielding the relaxation data. 34 35 @return: The relaxation data consisting of the proton frequency, residue numbers, residue 36 names, atom names, values, and errors. 37 @rtype: tuple of float, list of int, list of str, list of str, list of float, list of 38 float 39 """ 40 41 # Set up the version specific variables. 42 self.specific_setup() 43 44 # Get the saveframe name. 45 sf_name = getattr(self, 'cat_name')[0] 46 47 # Loop over all datanodes. 48 for datanode in self.datanodes: 49 # Find the Heteronuclear Rx saveframes via the SfCategory tag index. 50 found = False 51 for index in range(len(datanode.tagtables[0].tagnames)): 52 # First match the tag names. 53 if datanode.tagtables[0].tagnames[index] == self.heteronuclRxlist.create_tag_label(self.heteronuclRxlist.tag_names['SfCategory']): 54 # Then the tag value. 55 if datanode.tagtables[0].tagvalues[index][0] == sf_name: 56 found = True 57 break 58 59 # Skip the datanode. 60 if not found: 61 continue 62 63 # Get general info. 64 frq = self.heteronuclRxlist.read(datanode.tagtables[0]) 65 66 # Get the Rx info. 67 entity_ids, res_nums, res_names, atom_names, values, errors = self.Rx.read(datanode.tagtables[1]) 68 69 # Yield the data. 70 yield frq, entity_ids, res_nums, res_names, atom_names, values, errors
71 72
73 - def specific_setup(self):
74 """Method called by self.add() to set up any version specific data.""" 75 76 self.cat_name = [self.label+'_relaxation']
77 78 79
80 -class HeteronuclRxList(TagCategory):
81 """Base class for the HeteronuclRxList tag categories.""" 82
83 - def read(self, tagtable):
84 """Extract the HeteronuclRxList tag category info. 85 86 @param tagtable: The HeteronuclRxList tagtable. 87 @type tagtable: Tagtable instance 88 @return: The proton frequency in Hz. 89 @rtype: float 90 """ 91 92 # The general info. 93 frq = float(tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['SpectrometerFrequency1H'])][0]) * 1e6 94 95 # Return the data. 96 return frq
97 98
99 -class Rx(TagCategory):
100 """Base class for the Rx tag categories.""" 101
102 - def create(self):
103 """Create the Rx tag category.""" 104 105 # Keys and objects. 106 info = [ 107 ['RxID', 'data_ids'], 108 ['AssemblyAtomID', 'assembly_atom_ids'], 109 ['EntityAssemblyID', 'entity_assembly_ids'], 110 ['EntityID', 'entity_ids'], 111 ['CompIndexID', 'res_nums'], 112 ['SeqID', 'seq_id'], 113 ['CompID', 'res_names'], 114 ['AtomID', 'atom_names'], 115 ['AtomType', 'atom_types'], 116 ['AtomIsotopeNumber', 'isotope'], 117 ['Val', 'data'], 118 ['ValErr', 'errors'], 119 ['HeteronuclRxListID', 'rx_inc_list'] 120 ] 121 122 # Get the TabTable. 123 table = self.create_tag_table(info) 124 125 # Add the tagtable to the save frame. 126 self.sf.frame.tagtables.append(table)
127 128
129 - def read(self, tagtable):
130 """Extract the Rx tag category info. 131 132 @param tagtable: The Rx tagtable. 133 @type tagtable: Tagtable instance 134 @return: The residue numbers, residue names, atom names, values, and errors. 135 @rtype: tuple of list of int, list of str, list of str, list of float, list of 136 float 137 """ 138 139 # The entity info. 140 entity_ids = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['EntityID'])] 141 res_nums = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['CompIndexID'])] 142 res_names = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['CompID'])] 143 atom_names = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['AtomID'])] 144 values = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['Val'])] 145 errors = tagtable.tagvalues[tagtable.tagnames.index(self.tag_names_full['ValErr'])] 146 147 # Convert the residue numbers to ints and the values and errors to floats. 148 for i in range(len(res_nums)): 149 res_nums[i] = int(res_nums[i]) 150 if values[i] == '?': 151 values[i] = None 152 else: 153 values[i] = float(values[i]) 154 if errors[i] == '?': 155 errors[i] = None 156 else: 157 errors[i] = float(errors[i]) 158 159 # Return the data. 160 return entity_ids, res_nums, res_names, atom_names, values, errors
161 162
163 - def tag_setup(self, tag_category_label=None, sep=None):
164 """Replacement method for setting up the tag names. 165 166 @keyword tag_category_label: The tag name prefix specific for the tag category. 167 @type tag_category_label: None or str 168 @keyword sep: The string separating the tag name prefix and suffix. 169 @type sep: str 170 """ 171 172 # Execute the base class tag_setup() method. 173 TagCategory.tag_setup(self, tag_category_label=tag_category_label, sep=sep) 174 175 # Tag names for the relaxation data. 176 self.tag_names['RxID'] = None 177 self.tag_names['AssemblyAtomID'] = 'Assembly_atom_ID' 178 self.tag_names['EntityAssemblyID'] = 'Entity_assembly_ID' 179 self.tag_names['EntityID'] = 'Entity_ID' 180 self.tag_names['CompIndexID'] = 'Residue_seq_code' 181 self.tag_names['SeqID'] = 'Seq_ID' 182 self.tag_names['CompID'] = 'Residue_label' 183 self.tag_names['AtomID'] = 'Atom_name' 184 self.tag_names['AtomType'] = 'Atom_type' 185 self.tag_names['AtomIsotopeNumber'] = 'Atom_isotope_number' 186 self.tag_names['Val'] = self.sf.label+'_value' 187 self.tag_names['ValErr'] = self.sf.label+'_value_error' 188 self.tag_names['HeteronuclRxListID'] = 'Heteronucl_'+self.sf.label+'_list_ID'
189