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

Source Code for Module gui.user_functions.spin

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-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 spin 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, spin_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_bool, gui_to_int, gui_to_list, 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 Spin(UF_base):
42 """The container class for holding all GUI elements.""" 43
44 - def copy(self):
45 """The spin.copy user function.""" 46 47 # Execute the wizard. 48 wizard = self.create_wizard(size_x=700, size_y=600, name='spin.copy', uf_page=Copy_page) 49 wizard.run()
50 51
52 - def create(self, mol_name=None, res_num=None, res_name=None):
53 """The spin.create user function. 54 55 @param mol_name: The starting molecule name. 56 @type mol_name: str 57 @param res_num: The starting residue number. 58 @type res_num: str 59 @param res_name: The starting residue name. 60 @type res_name: str 61 """ 62 63 # Create the wizard. 64 wizard, page = self.create_wizard(size_x=600, size_y=400, name='spin.create', uf_page=Create_page, return_page=True) 65 66 # Store the defaults. 67 page.defaults['mol'] = str_to_gui(mol_name) 68 page.defaults['res'] = str_to_gui("%s %s" % (res_num, res_name)) 69 70 # Execute the wizard. 71 wizard.run()
72 73
74 - def create_pseudo(self):
75 """The spin.create_pseudo user function.""" 76 77 # Execute the wizard. 78 wizard = self.create_wizard(size_x=800, size_y=600, name='spin.create_pseudo', uf_page=Create_pseudo_page) 79 wizard.run()
80 81
82 - def delete(self, mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None):
83 """The spin.delete user function. 84 85 @param mol_name: The starting molecule name. 86 @type mol_name: str 87 @param res_num: The starting residue number. 88 @type res_num: str 89 @param res_name: The starting residue name. 90 @type res_name: str 91 @param spin_num: The starting spin number. 92 @type spin_num: str 93 @param spin_name: The starting spin name. 94 @type spin_name: str 95 """ 96 97 # Create the wizard. 98 wizard, page = self.create_wizard(size_x=600, size_y=400, name='spin.delete', uf_page=Delete_page, return_page=True) 99 100 # Default molecule name. 101 if mol_name: 102 page.mol.SetValue(str_to_gui(mol_name)) 103 104 # Default residue. 105 if res_num or res_name: 106 page.res.SetValue(str_to_gui("%s %s" % (res_num, res_name))) 107 108 # Default spin. 109 if spin_num or spin_name: 110 page.spin.SetValue(str_to_gui("%s %s" % (spin_num, spin_name))) 111 112 # Execute the wizard. 113 wizard.run()
114 115
116 - def display(self):
117 """The spin.display user function.""" 118 119 # Execute the wizard. 120 wizard = self.create_wizard(size_x=800, size_y=600, name='spin.display', uf_page=Display_page) 121 wizard.run()
122 123
124 - def element(self):
125 """The spin.element user function.""" 126 127 # Execute the wizard. 128 wizard = self.create_wizard(size_x=800, size_y=600, name='spin.element', uf_page=Element_page) 129 wizard.run()
130 131
132 - def name(self):
133 """The spin.name user function.""" 134 135 # Execute the wizard. 136 wizard = self.create_wizard(size_x=800, size_y=600, name='spin.name', uf_page=Name_page) 137 wizard.run()
138 139
140 - def number(self):
141 """The spin.number user function.""" 142 143 # Execute the wizard. 144 wizard = self.create_wizard(size_x=800, size_y=600, name='spin.number', uf_page=Number_page) 145 wizard.run()
146 147 148
149 -class Copy_page(UF_page, Mol_res_spin):
150 """The spin.copy() user function page.""" 151 152 # Some class variables. 153 image_path = WIZARD_IMAGE_PATH + 'spin.png' 154 uf_path = ['spin', 'copy'] 155
156 - def add_contents(self, sizer):
157 """Add the page specific GUI elements. 158 159 @param sizer: A sizer object. 160 @type sizer: wx.Sizer instance 161 """ 162 163 # The source pipe. 164 self.pipe_from = self.combo_box(sizer, "The source data pipe:", tooltip=self.uf._doc_args_dict['pipe_from'], evt_fn=self.update_mol_list) 165 166 # The molecule selection. 167 self.mol_from = self.combo_box(sizer, "The source molecule:", evt_fn=self.update_res_list) 168 169 # The residue selection. 170 self.res_from = self.combo_box(sizer, "The source residue:", evt_fn=self.update_spin_list) 171 172 # The spin selection. 173 self.spin_from = self.combo_box(sizer, "The source spin:") 174 175 # The destination pipe. 176 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) 177 178 # The destination molecule name. 179 self.mol_to = self.combo_box(sizer, "The destination molecule name:") 180 181 # The destination residue. 182 self.res_num_to = self.input_field(sizer, "The new residue number:") 183 self.res_name_to = self.input_field(sizer, "The new residue name:") 184 185 # The destination spin. 186 self.spin_num_to = self.input_field(sizer, "The new spin number:", tooltip='If left blank, the new spin will have the same number as the old.') 187 self.spin_name_to = self.input_field(sizer, "The new spin name:", tooltip='If left blank, the new spin will have the same name as the old.')
188 189
190 - def on_display(self):
191 """Update the UI.""" 192 193 # Set the default pipe name. 194 if not gui_to_str(self.pipe_from.GetValue()): 195 self.pipe_from.SetValue(str_to_gui(cdp_name())) 196 if not gui_to_str(self.pipe_to.GetValue()): 197 self.pipe_to.SetValue(str_to_gui(cdp_name())) 198 199 # Clear the previous data. 200 self.pipe_from.Clear() 201 self.pipe_to.Clear() 202 203 # The list of pipe names. 204 for name in pipe_names(): 205 self.pipe_from.Append(str_to_gui(name)) 206 self.pipe_to.Append(str_to_gui(name)) 207 208 # Update the molecule list. 209 self.update_mol_list()
210 211
212 - def on_execute(self):
213 """Execute the user function.""" 214 215 # Get the pipe names. 216 pipe_from = gui_to_str(self.pipe_from.GetValue()) 217 pipe_to = gui_to_str(self.pipe_to.GetValue()) 218 219 # The spin names. 220 spin_from = self._get_spin_id(suffix='_from') 221 spin_to = self._get_spin_id(suffix='_to') 222 if spin_to == '': 223 spin_to = None 224 225 # Copy the spin. 226 self.execute('spin.copy', pipe_from=pipe_from, spin_from=spin_from, pipe_to=pipe_to, spin_to=spin_to)
227 228
229 - def update_mol_list(self, event=None):
230 """Update the list of molecules. 231 232 @param event: The wx event. 233 @type event: wx event 234 """ 235 236 # The source data pipe. 237 pipe_from = gui_to_str(self.pipe_from.GetValue()) 238 pipe_to = gui_to_str(self.pipe_to.GetValue()) 239 240 # Clear the previous data. 241 self.mol_from.Clear() 242 self.mol_to.Clear() 243 244 # The list of molecule names. 245 if cdp_name(): 246 for mol in molecule_loop(pipe=pipe_from): 247 self.mol_from.Append(str_to_gui(mol.name)) 248 for mol in molecule_loop(pipe=pipe_to): 249 self.mol_to.Append(str_to_gui(mol.name)) 250 251 # Update the residues too. 252 self.update_res_list()
253 254
255 - def update_res_list(self, event=None):
256 """Update the list of residues. 257 258 @param event: The wx event. 259 @type event: wx event 260 """ 261 262 # The source data pipe and molecule name. 263 pipe_from = gui_to_str(self.pipe_from.GetValue()) 264 mol_from = generate_spin_id(mol_name=gui_to_str(self.mol_from.GetValue())) 265 266 # Clear the previous data. 267 self.res_from.Clear() 268 269 # Nothing to do. 270 if mol_from == '': 271 return 272 273 # The list of molecule names. 274 if cdp_name(): 275 for res in residue_loop(mol_from, pipe=pipe_from): 276 self.res_from.Append(str_to_gui("%s %s" % (res.num, res.name))) 277 278 # Update the spins too. 279 self.update_spin_list()
280 281
282 - def update_spin_list(self, event=None):
283 """Update the list of spins. 284 285 @param event: The wx event. 286 @type event: wx event 287 """ 288 289 # The source data pipe and molecule name. 290 pipe_from = gui_to_str(self.pipe_from.GetValue()) 291 res_from = self._get_res_id(suffix='_from') 292 293 # Clear the previous data. 294 self.spin_from.Clear() 295 296 # Nothing to do. 297 if res_from == '': 298 return 299 300 # The list of molecule names. 301 if cdp_name(): 302 for spin in spin_loop(res_from, pipe=pipe_from): 303 self.spin_from.Append(str_to_gui("%s %s" % (spin.num, spin.name)))
304 305 306
307 -class Create_page(UF_page, Mol_res_spin):
308 """The spin.create() user function page.""" 309 310 # Some class variables. 311 image_path = WIZARD_IMAGE_PATH + 'spin.png' 312 uf_path = ['spin', 'create'] 313
314 - def add_contents(self, sizer):
315 """Add the page specific GUI elements. 316 317 @param sizer: A sizer object. 318 @type sizer: wx.Sizer instance 319 """ 320 321 # Molecule and residue selections. 322 self.mol = self.combo_box(sizer, "The molecule:", [], self._update_residues) 323 self.res = self.combo_box(sizer, "The residue:", []) 324 325 # The spin name input. 326 self.spin_name = self.input_field(sizer, "The name of the spin:", tooltip=self.uf._doc_args_dict['spin_name']) 327 328 # The type selection. 329 self.spin_num = self.input_field(sizer, "The spin number:", tooltip=self.uf._doc_args_dict['spin_num'])
330 331
332 - def on_display(self):
333 """Clear all data and then update the list of molecule names.""" 334 335 # Clear the previous data. 336 self.mol.Clear() 337 self.res.Clear() 338 339 # The list of molecule names. 340 if cdp_name(): 341 for mol in molecule_loop(): 342 if mol.name != None: 343 self.mol.Append(str_to_gui(mol.name)) 344 345 # The default molecule. 346 if self.defaults.has_key('mol') and self.defaults['mol']: 347 self.mol.SetStringSelection(self.defaults['mol']) 348 349 # Update the residue list. 350 self._update_residues(None) 351 352 # The default residue. 353 if self.defaults.has_key('res') and self.defaults['res']: 354 self.res.SetStringSelection(self.defaults['res'])
355 356
357 - def on_execute(self):
358 """Execute the user function.""" 359 360 # Get the spin info. 361 mol_name = gui_to_str(self.mol.GetValue()) 362 res_num, res_name = self._get_res_info() 363 spin_num = gui_to_int(self.spin_num.GetValue()) 364 spin_name = gui_to_str(self.spin_name.GetValue()) 365 366 # Set the name. 367 self.execute('spin.create', spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
368 369 370
371 -class Create_pseudo_page(UF_page, Mol_res_spin):
372 """The spin.create_pseudo() user function page.""" 373 374 # Some class variables. 375 image_path = WIZARD_IMAGE_PATH + 'spin.png' 376 uf_path = ['spin', 'create_pseudo'] 377
378 - def add_contents(self, sizer):
379 """Add the page specific GUI elements. 380 381 @param sizer: A sizer object. 382 @type sizer: wx.Sizer instance 383 """ 384 385 # The name and number of the spin. 386 self.spin_name = self.input_field(sizer, "The pseudo-spin name:", tooltip=self.uf._doc_args_dict['spin_name']) 387 self.spin_num = self.input_field(sizer, "The pseudo-spin number:", tooltip=self.uf._doc_args_dict['spin_num']) 388 389 # The spin ID. 390 self.res_id = self.spin_id_element(sizer, desc="The residue ID string:", choices=[]) 391 392 # The members. 393 self.members = self.input_field(sizer, "The pseudo-spin members:", tooltip=self.uf._doc_args_dict['members']) 394 395 # The pos averaging. 396 self.averaging = self.combo_box(sizer, "The positional averaging:", tooltip=self.uf._doc_args_dict['averaging'], choices=['linear']) 397 self.averaging.SetValue(str_to_gui('linear'))
398 399
400 - def on_execute(self):
401 """Execute the user function.""" 402 403 # Get the values. 404 spin_name = gui_to_str(self.spin_name.GetValue()) 405 spin_num = gui_to_int(self.spin_num.GetValue()) 406 res_id = gui_to_str(self.res_id.GetValue()) 407 members = gui_to_list(self.members.GetValue()) 408 averaging = gui_to_str(self.averaging.GetValue()) 409 410 # Execute. 411 self.execute('spin.create_pseudo', spin_name=spin_name, spin_num=spin_num, res_id=res_id, members=members, averaging=averaging)
412 413 414
415 -class Delete_page(UF_page, Mol_res_spin):
416 """The spin.delete() user function page.""" 417 418 # Some class variables. 419 image_path = WIZARD_IMAGE_PATH + 'spin.png' 420 uf_path = ['spin', 'delete'] 421
422 - def add_contents(self, sizer):
423 """Add the page specific GUI elements. 424 425 @param sizer: A sizer object. 426 @type sizer: wx.Sizer instance 427 """ 428 429 # Molecule, residue and spin selections. 430 self.mol = self.combo_box(sizer, "The molecule:", [], self._update_residues) 431 self.res = self.combo_box(sizer, "The residue:", [], self._update_spins) 432 self.spin = self.combo_box(sizer, "The spin:", [])
433 434
435 - def on_display(self):
436 """Clear the spin data and update the mol list.""" 437 438 # Clear the previous data. 439 self.mol.Clear() 440 self.res.Clear() 441 self.spin.Clear() 442 443 # The list of molecule names. 444 if cdp_name(): 445 for mol in molecule_loop(): 446 self.mol.Append(str_to_gui(mol.name))
447 448
449 - def on_execute(self):
450 """Execute the user function.""" 451 452 # Get the spin ID. 453 id = self._get_spin_id() 454 455 # Nothing to do. 456 if not id: 457 return 458 459 # Delete the spin. 460 self.execute('spin.delete', spin_id=id) 461 462 # Update the spin list. 463 self._update_spins(None)
464 465 466
467 -class Display_page(UF_page, Mol_res_spin):
468 """The spin.display() user function page.""" 469 470 # Some class variables. 471 image_path = WIZARD_IMAGE_PATH + 'spin.png' 472 uf_path = ['spin', 'display'] 473
474 - def add_contents(self, sizer):
475 """Add the page specific GUI elements. 476 477 @param sizer: A sizer object. 478 @type sizer: wx.Sizer instance 479 """ 480 481 # The spin ID. 482 self.spin_id = self.spin_id_element(sizer, desc="Restrict to the spin ID:")
483 484
485 - def on_execute(self):
486 """Execute the user function.""" 487 488 # Get the values. 489 spin_id = gui_to_str(self.spin_id.GetValue()) 490 491 # Execute. 492 self.execute('spin.display', spin_id=spin_id)
493 494 495
496 -class Element_page(UF_page, Mol_res_spin):
497 """The spin.element() user function page.""" 498 499 # Some class variables. 500 image_path = WIZARD_IMAGE_PATH + 'spin.png' 501 uf_path = ['spin', 'element'] 502
503 - def add_contents(self, sizer):
504 """Add the page specific GUI elements. 505 506 @param sizer: A sizer object. 507 @type sizer: wx.Sizer instance 508 """ 509 510 # The spin ID. 511 self.spin_id = self.spin_id_element(sizer, desc="Restrict the element setting to the spins:") 512 513 # The element. 514 self.element = self.combo_box(sizer, "The element:", tooltip=self.uf._doc_args_dict['element'], choices=['H', 'N', 'C', 'O', 'P'], read_only=False) 515 516 # The force flag. 517 self.force = self.boolean_selector(sizer, "The force flag:", tooltip=self.uf._doc_args_dict['force'], default=False)
518 519
520 - def on_execute(self):
521 """Execute the user function.""" 522 523 # Get the values. 524 spin_id = gui_to_str(self.spin_id.GetValue()) 525 element = gui_to_str(self.element.GetValue()) 526 force = gui_to_bool(self.force.GetValue()) 527 528 # Execute. 529 self.execute('spin.element', spin_id=spin_id, element=element, force=force)
530 531 532
533 -class Name_page(UF_page, Mol_res_spin):
534 """The spin.name() user function page.""" 535 536 # Some class variables. 537 image_path = WIZARD_IMAGE_PATH + 'spin.png' 538 uf_path = ['spin', 'name'] 539
540 - def add_contents(self, sizer):
541 """Add the page specific GUI elements. 542 543 @param sizer: A sizer object. 544 @type sizer: wx.Sizer instance 545 """ 546 547 # The name. 548 self.name = self.input_field(sizer, "The name:", tooltip=self.uf._doc_args_dict['name']) 549 550 # The force flag. 551 self.force = self.boolean_selector(sizer, "The force flag:", tooltip=self.uf._doc_args_dict['force'], default=False) 552 553 # The spin ID. 554 self.spin_id = self.spin_id_element(sizer, desc="Restrict the naming to the spins:")
555 556
557 - def on_execute(self):
558 """Execute the user function.""" 559 560 # Get the values. 561 spin_id = gui_to_str(self.spin_id.GetValue()) 562 name = gui_to_str(self.name.GetValue()) 563 force = gui_to_bool(self.force.GetValue()) 564 565 # Execute. 566 self.execute('spin.name', spin_id=spin_id, name=name, force=force)
567 568 569
570 -class Number_page(UF_page, Mol_res_spin):
571 """The spin.number() user function page.""" 572 573 # Some class variables. 574 image_path = WIZARD_IMAGE_PATH + 'spin.png' 575 uf_path = ['spin', 'number'] 576
577 - def add_contents(self, sizer):
578 """Add the page specific GUI elements. 579 580 @param sizer: A sizer object. 581 @type sizer: wx.Sizer instance 582 """ 583 584 # The spin ID. 585 self.spin_id = self.spin_id_element(sizer, desc="Restrict the numbering to the spins:") 586 587 # The number. 588 self.number = self.input_field(sizer, "The number:", tooltip=self.uf._doc_args_dict['number']) 589 590 # The force flag. 591 self.force = self.boolean_selector(sizer, "The force flag:", tooltip=self.uf._doc_args_dict['force'], default=False)
592 593
594 - def on_execute(self):
595 """Execute the user function.""" 596 597 # Get the values. 598 spin_id = gui_to_str(self.spin_id.GetValue()) 599 number = gui_to_int(self.number.GetValue()) 600 force = gui_to_bool(self.force.GetValue()) 601 602 # Execute. 603 self.execute('spin.number', spin_id=spin_id, number=number, force=force)
604