Package gui :: Package user_functions :: Module mol_res_spin
[hide private]
[frames] | no frames]

Source Code for Module gui.user_functions.mol_res_spin

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010-2012 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  # Module docstring. 
 24  """The molecule, residue, spin base classes.""" 
 25   
 26  # Python module imports. 
 27  from string import split 
 28   
 29  # relax module imports. 
 30  from generic_fns.mol_res_spin import generate_spin_id, residue_loop, spin_loop 
 31  from generic_fns.pipes import cdp_name 
 32   
 33  # GUI module imports. 
 34  from base import UF_base 
 35  from gui.misc import gui_to_int, gui_to_str, str_to_gui 
 36  from gui.paths import WIZARD_IMAGE_PATH 
 37   
 38   
39 -class Mol_res_spin:
40 """The molecule, residue, spin base class.""" 41
42 - def _get_res_id(self, suffix=''):
43 """Generate the residue ID from the residue selection. 44 45 @keyword suffix: The suffix to be added to the residue data structure name. 46 @type suffix: str 47 @return: The residue ID string. 48 @rtype: str 49 """ 50 51 # The molecule name. 52 obj = getattr(self, 'mol'+suffix) 53 mol_name = str(obj.GetValue()) 54 if mol_name == '': 55 mol_name = None 56 57 # The residue info. 58 res_info = self._get_res_info(suffix) 59 if not res_info: 60 return 61 res_num, res_name = res_info 62 63 # Generate and return the ID. 64 return generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name)
65 66
67 - def _get_res_info(self, suffix=''):
68 """Extract the residue info from the residue selection. 69 70 @keyword suffix: The suffix to be added to the residue data structure name. 71 @type suffix: str 72 @return: The residue number and name from the residue selection self.res. 73 @rtype: int, str 74 """ 75 76 # Single residue object. 77 if hasattr(self, 'res'+suffix): 78 # The residue info. 79 obj = getattr(self, 'res'+suffix) 80 res = gui_to_str(obj.GetValue()) 81 82 # Nothing. 83 if not res: 84 return None, None 85 86 # Split. 87 res_num, res_name = split(res) 88 89 # Convert. 90 if res_name in ['', 'None']: 91 res_name = None 92 if res_num == '': 93 res_num = None 94 else: 95 res_num = int(res_num) 96 97 # 2 objects. 98 else: 99 # The residue number. 100 obj = getattr(self, 'res_num'+suffix) 101 res_num = gui_to_int(obj.GetValue()) 102 103 # The residue name. 104 obj = getattr(self, 'res_name'+suffix) 105 res_name = gui_to_str(obj.GetValue()) 106 107 # Return the number and name. 108 return res_num, res_name
109 110
111 - def _get_spin_id(self, suffix=''):
112 """Generate the spin ID from the molecule, residue, and spin selection. 113 114 @keyword suffix: The suffix to be added to the spin data structure name. 115 @type suffix: str 116 @return: The spin ID string. 117 @rtype: str 118 """ 119 120 # The molecule name. 121 obj = getattr(self, 'mol'+suffix) 122 mol_name = str(obj.GetValue()) 123 if mol_name == '': 124 mol_name = None 125 126 # The residue info. 127 res_num, res_name = self._get_res_info(suffix=suffix) 128 129 # The spin info. 130 spin_info = self._get_spin_info(suffix=suffix) 131 if not spin_info: 132 return 133 spin_num, spin_name = spin_info 134 135 # Generate and return the ID. 136 return generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name)
137 138
139 - def _get_spin_info(self, suffix=''):
140 """Extract the spin info from the spin selection. 141 142 @keyword suffix: The suffix to be added to the spin data structure name. 143 @type suffix: str 144 @return: The spin number and name from the spin selection self.spin. 145 @rtype: int, str 146 """ 147 148 # Single spin object. 149 if hasattr(self, 'spin'+suffix): 150 # The spin info. 151 obj = getattr(self, 'spin'+suffix) 152 spin = str(obj.GetValue()) 153 154 # Nothing. 155 if spin == '': 156 return None, None 157 158 # Split. 159 spin_num, spin_name = split(spin) 160 161 # Convert. 162 if spin_name == '': 163 spin_name = None 164 if spin_num == '': 165 spin_num = None 166 else: 167 spin_num = int(spin_num) 168 169 # 2 objects. 170 else: 171 # The spin number. 172 obj = getattr(self, 'spin_num'+suffix) 173 spin_num = gui_to_int(obj.GetValue()) 174 175 # The spin name. 176 obj = getattr(self, 'spin_name'+suffix) 177 spin_name = gui_to_str(obj.GetValue()) 178 179 # Return the number and name. 180 return spin_num, spin_name
181 182
183 - def _update_residues(self, event):
184 """Update the residue combo box self.res. 185 186 @param event: The wx event. 187 @type event: wx event 188 """ 189 190 # Clear the previous data. 191 self.res.Clear() 192 193 # Clear the text. 194 self.res.SetValue(str_to_gui('')) 195 196 # The molecule ID. 197 mol = gui_to_str(self.mol.GetValue()) 198 if mol: 199 mol_id = generate_spin_id(mol) 200 else: 201 mol_id = None 202 203 # The list of residue names. 204 if cdp_name(): 205 for res in residue_loop(mol_id): 206 self.res.Append(str_to_gui("%s %s" % (res.num, res.name)))
207 208
209 - def _update_spins(self, event):
210 """Update the spin combo box self.spin. 211 212 @param event: The wx event. 213 @type event: wx event 214 """ 215 216 # Clear the previous data. 217 self.spin.Clear() 218 219 # Clear the text. 220 self.spin.SetValue(str_to_gui('')) 221 222 # Get the residue ID. 223 res_id = self._get_res_id() 224 if not res_id: 225 return 226 227 # Build the list of spin names. 228 if cdp_name(): 229 for spin in spin_loop(res_id): 230 self.spin.Append(str_to_gui("%s %s" % (spin.num, spin.name)))
231