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

Source Code for Module gui.user_functions.residue

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010-2011 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 residue user function GUI elements.""" 
 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, molecule_loop, residue_loop 
 31  from generic_fns.pipes import cdp_name, pipe_names 
 32   
 33  # GUI module imports. 
 34  from base import UF_base, UF_page 
 35  from gui.misc import gui_to_int, gui_to_str, str_to_gui 
 36  from gui.paths import WIZARD_IMAGE_PATH 
 37  from gui.user_functions.mol_res_spin import Mol_res_spin 
 38   
 39   
 40  # The container class. 
41 -class Residue(UF_base):
42 """The container class for holding all GUI elements.""" 43
44 - def copy(self):
45 """The residue.copy user function.""" 46 47 # Execute the wizard. 48 wizard = self.create_wizard(size_x=700, size_y=600, name='residue.copy', uf_page=Copy_page) 49 wizard.run()
50 51
52 - def create(self, mol_name=None):
53 """The residue.create user function. 54 55 @param mol_name: The starting molecule name. 56 @type mol_name: str 57 """ 58 59 # Initialise the wizard. 60 wizard, page = self.create_wizard(size_x=700, size_y=500, name='residue.create', uf_page=Create_page, return_page=True) 61 62 # Store the defaults. 63 page.defaults['mol_name'] = str_to_gui(mol_name) 64 65 # Execute the wizard. 66 wizard.run()
67 68
69 - def delete(self, mol_name=None, res_num=None, res_name=None):
70 """The residue.delete user function. 71 72 @param mol_name: The starting molecule name. 73 @type mol_name: str 74 @param res_num: The starting residue number. 75 @type res_num: str 76 @param res_name: The starting residue name. 77 @type res_name: str 78 """ 79 80 # Initialise the wizard. 81 wizard, page = self.create_wizard(size_x=600, size_y=400, name='residue.delete', uf_page=Delete_page, return_page=True) 82 83 # Default molecule name. 84 if mol_name: 85 page.mol_name.SetValue(str_to_gui(mol_name)) 86 87 # Default residue. 88 if res_name: 89 page.res_name.SetValue(str_to_gui(res_name)) 90 if res_num: 91 page.res_num.SetValue(str_to_gui(res_num)) 92 93 # Execute the wizard. 94 wizard.run()
95 96 97
98 -class Copy_page(UF_page, Mol_res_spin):
99 """The residue.copy() user function page.""" 100 101 # Some class variables. 102 image_path = WIZARD_IMAGE_PATH + 'residue.png' 103 uf_path = ['residue', 'copy'] 104
105 - def add_contents(self, sizer):
106 """Add the residue specific GUI elements. 107 108 @param sizer: A sizer object. 109 @type sizer: wx.Sizer instance 110 """ 111 112 # The source pipe. 113 self.pipe_from = self.combo_box(sizer, "The source data pipe:", evt_fn=self.update_mol_list, tooltip=self.uf._doc_args_dict['pipe_from']) 114 115 # The molecule selection. 116 self.mol_from = self.combo_box(sizer, "The source molecule:", evt_fn=self.update_res_list) 117 118 # The residue selection. 119 self.res_from = self.combo_box(sizer, "The source residue:") 120 121 # The destination pipe. 122 self.pipe_to = self.combo_box(sizer, "The destination data pipe name:", tooltip=self.uf._doc_args_dict['pipe_to'], evt_fn=self.update_mol_list) 123 124 # The destination molecule name. 125 self.mol_to = self.combo_box(sizer, "The destination molecule name:") 126 127 # The new residue number. 128 self.res_num_to = self.input_field(sizer, "The new residue number:", tooltip='If left blank, the new residue will have the same number as the old.') 129 130 # The new residue name. 131 self.res_name_to = self.input_field(sizer, "The new residue name:", tooltip='If left blank, the new residue will have the same name as the old.')
132 133
134 - def on_display(self):
135 """Update the pipe name lists.""" 136 137 # Set the default pipe name. 138 if not gui_to_str(self.pipe_from.GetValue()): 139 self.pipe_from.SetValue(str_to_gui(cdp_name())) 140 if not gui_to_str(self.pipe_to.GetValue()): 141 self.pipe_to.SetValue(str_to_gui(cdp_name())) 142 143 # Clear the previous data. 144 self.pipe_from.Clear() 145 self.pipe_to.Clear() 146 147 # The list of pipe names. 148 for name in pipe_names(): 149 self.pipe_from.Append(str_to_gui(name)) 150 self.pipe_to.Append(str_to_gui(name)) 151 152 # Update the molecule list. 153 self.update_mol_list()
154 155
156 - def on_execute(self):
157 """Execute the user function.""" 158 159 # Get the pipe names. 160 pipe_from = gui_to_str(self.pipe_from.GetValue()) 161 pipe_to = gui_to_str(self.pipe_to.GetValue()) 162 163 # The residue names. 164 res_from = self._get_res_id(suffix='_from') 165 res_to = self._get_res_id(suffix='_to') 166 if res_to == '': 167 res_to = None 168 169 # Copy the molecule. 170 self.execute('residue.copy', pipe_from=pipe_from, res_from=res_from, pipe_to=pipe_to, res_to=res_to)
171 172
173 - def update_mol_list(self, event=None):
174 """Update the list of molecules. 175 176 @param event: The wx event. 177 @type event: wx event 178 """ 179 180 # The source data pipe. 181 pipe_from = gui_to_str(self.pipe_from.GetValue()) 182 pipe_to = gui_to_str(self.pipe_to.GetValue()) 183 184 # Clear the previous data. 185 self.mol_from.Clear() 186 self.mol_to.Clear() 187 188 # The list of molecule names. 189 if cdp_name(): 190 for mol in molecule_loop(pipe=pipe_from): 191 self.mol_from.Append(str_to_gui(mol.name)) 192 for mol in molecule_loop(pipe=pipe_to): 193 self.mol_to.Append(str_to_gui(mol.name)) 194 195 # Update the residues too. 196 self.update_res_list()
197 198
199 - def update_res_list(self, event=None):
200 """Update the list of molecules. 201 202 @param event: The wx event. 203 @type event: wx event 204 """ 205 206 # The source data pipe and molecule name. 207 pipe_from = gui_to_str(self.pipe_from.GetValue()) 208 mol_from = generate_spin_id(mol_name=gui_to_str(self.mol_from.GetValue())) 209 210 # Clear the previous data. 211 self.res_from.Clear() 212 213 # Nothing to do. 214 if mol_from == '': 215 return 216 217 # The list of molecule names. 218 if cdp_name(): 219 for res in residue_loop(mol_from, pipe=pipe_from): 220 self.res_from.Append(str_to_gui("%s %s" % (res.num, res.name)))
221 222 223
224 -class Create_page(UF_page, Mol_res_spin):
225 """The residue.create() user function page.""" 226 227 # Some class variables. 228 image_path = WIZARD_IMAGE_PATH + 'residue.png' 229 uf_path = ['residue', 'create'] 230
231 - def add_contents(self, sizer):
232 """Add the residue specific GUI elements. 233 234 @param sizer: A sizer object. 235 @type sizer: wx.Sizer instance 236 """ 237 238 # Molecule and residue selections. 239 self.mol_name = self.combo_box(sizer, "The molecule:", [], tooltip=self.uf._doc_args_dict['mol_name']) 240 241 # The residue name input. 242 self.res_name = self.input_field(sizer, "The name of the residue:", tooltip=self.uf._doc_args_dict['res_name']) 243 244 # The type selection. 245 self.res_num = self.input_field(sizer, "The residue number:", tooltip=self.uf._doc_args_dict['res_num'])
246 247
248 - def on_display(self):
249 """Update the molecule list.""" 250 251 # Clear the previous data. 252 self.mol_name.Clear() 253 254 # The list of molecule names. 255 if cdp_name(): 256 for mol in molecule_loop(): 257 if mol.name != None: 258 self.mol_name.Append(str_to_gui(mol.name)) 259 260 # The default molecule. 261 if self.defaults.has_key('mol_name') and self.defaults['mol_name']: 262 self.mol_name.SetStringSelection(self.defaults['mol_name'])
263 264
265 - def on_execute(self):
266 """Execute the user function.""" 267 268 # Get the spin info. 269 mol_name = gui_to_str(self.mol_name.GetValue()) 270 res_num = gui_to_int(self.res_num.GetValue()) 271 res_name = gui_to_str(self.res_name.GetValue()) 272 273 # Set the name. 274 self.execute('residue.create', res_name=res_name, res_num=res_num, mol_name=mol_name)
275 276 277
278 -class Delete_page(UF_page, Mol_res_spin):
279 """The residue.delete() user function page.""" 280 281 # Some class variables. 282 image_path = WIZARD_IMAGE_PATH + 'residue.png' 283 uf_path = ['residue', 'delete'] 284
285 - def add_contents(self, sizer):
286 """Add the residue specific GUI elements. 287 288 @param sizer: A sizer object. 289 @type sizer: wx.Sizer instance 290 """ 291 292 # The residue selection. 293 self.mol = self.combo_box(sizer, "The molecule:", [], self._update_residues) 294 self.res = self.combo_box(sizer, "The residue:", [])
295 296
297 - def on_display(self):
298 """Clear and update the residue and molecule lists.""" 299 300 # Clear the previous data. 301 self.mol.Clear() 302 self.res.Clear() 303 304 # The list of molecule names. 305 if cdp_name(): 306 for mol in molecule_loop(): 307 self.mol.Append(str_to_gui(mol.name))
308 309
310 - def on_execute(self):
311 """Execute the user function.""" 312 313 # The residue ID. 314 id = self._get_res_id() 315 316 # Nothing to do. 317 if not id: 318 return 319 320 # Delete the residue. 321 self.execute('residue.delete', res_id=id) 322 323 # Update. 324 self._update_residues(None)
325