1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """The spin user function GUI elements."""
25
26
27 from string import split
28
29
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
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
42 """The container class for holding all GUI elements."""
43
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
64 wizard, page = self.create_wizard(size_x=600, size_y=400, name='spin.create', uf_page=Create_page, return_page=True)
65
66
67 page.defaults['mol'] = str_to_gui(mol_name)
68 page.defaults['res'] = str_to_gui("%s %s" % (res_num, res_name))
69
70
71 wizard.run()
72
73
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
98 wizard, page = self.create_wizard(size_x=600, size_y=400, name='spin.delete', uf_page=Delete_page, return_page=True)
99
100
101 if mol_name:
102 page.mol.SetValue(str_to_gui(mol_name))
103
104
105 if res_num or res_name:
106 page.res.SetValue(str_to_gui("%s %s" % (res_num, res_name)))
107
108
109 if spin_num or spin_name:
110 page.spin.SetValue(str_to_gui("%s %s" % (spin_num, spin_name)))
111
112
113 wizard.run()
114
115
122
123
130
131
138
139
146
147
148
149 -class Copy_page(UF_page, Mol_res_spin):
150 """The spin.copy() user function page."""
151
152
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
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
167 self.mol_from = self.combo_box(sizer, "The source molecule:", evt_fn=self.update_res_list)
168
169
170 self.res_from = self.combo_box(sizer, "The source residue:", evt_fn=self.update_spin_list)
171
172
173 self.spin_from = self.combo_box(sizer, "The source spin:")
174
175
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
179 self.mol_to = self.combo_box(sizer, "The destination molecule name:")
180
181
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
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
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
200 self.pipe_from.Clear()
201 self.pipe_to.Clear()
202
203
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
209 self.update_mol_list()
210
211
212 - def on_execute(self):
213 """Execute the user function."""
214
215
216 pipe_from = gui_to_str(self.pipe_from.GetValue())
217 pipe_to = gui_to_str(self.pipe_to.GetValue())
218
219
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
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
237 pipe_from = gui_to_str(self.pipe_from.GetValue())
238 pipe_to = gui_to_str(self.pipe_to.GetValue())
239
240
241 self.mol_from.Clear()
242 self.mol_to.Clear()
243
244
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
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
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
267 self.res_from.Clear()
268
269
270 if mol_from == '':
271 return
272
273
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
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
290 pipe_from = gui_to_str(self.pipe_from.GetValue())
291 res_from = self._get_res_id(suffix='_from')
292
293
294 self.spin_from.Clear()
295
296
297 if res_from == '':
298 return
299
300
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
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
322 self.mol = self.combo_box(sizer, "The molecule:", [], self._update_residues)
323 self.res = self.combo_box(sizer, "The residue:", [])
324
325
326 self.spin_name = self.input_field(sizer, "The name of the spin:", tooltip=self.uf._doc_args_dict['spin_name'])
327
328
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
336 self.mol.Clear()
337 self.res.Clear()
338
339
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
346 if self.defaults.has_key('mol') and self.defaults['mol']:
347 self.mol.SetStringSelection(self.defaults['mol'])
348
349
350 self._update_residues(None)
351
352
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
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
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
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
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
390 self.res_id = self.spin_id_element(sizer, desc="The residue ID string:", choices=[])
391
392
393 self.members = self.input_field(sizer, "The pseudo-spin members:", tooltip=self.uf._doc_args_dict['members'])
394
395
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
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
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
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
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
439 self.mol.Clear()
440 self.res.Clear()
441 self.spin.Clear()
442
443
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
453 id = self._get_spin_id()
454
455
456 if not id:
457 return
458
459
460 self.execute('spin.delete', spin_id=id)
461
462
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
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
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
489 spin_id = gui_to_str(self.spin_id.GetValue())
490
491
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
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
511 self.spin_id = self.spin_id_element(sizer, desc="Restrict the element setting to the spins:")
512
513
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
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
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
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
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
548 self.name = self.input_field(sizer, "The name:", tooltip=self.uf._doc_args_dict['name'])
549
550
551 self.force = self.boolean_selector(sizer, "The force flag:", tooltip=self.uf._doc_args_dict['force'], default=False)
552
553
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
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
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
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
585 self.spin_id = self.spin_id_element(sizer, desc="Restrict the numbering to the spins:")
586
587
588 self.number = self.input_field(sizer, "The number:", tooltip=self.uf._doc_args_dict['number'])
589
590
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
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
603 self.execute('spin.number', spin_id=spin_id, number=number, force=force)
604