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 molecule, residue, and spin containers for the spin viewer."""
25
26
27
28 from re import search
29 from string import replace, split
30 import wx
31
32
33 from generic_fns.mol_res_spin import return_spin
34
35
36 from gui import paths
37 from gui.misc import str_to_gui
38
39
40
42 """The molecule, residue, and spin container window."""
43
44 - def __init__(self, gui, parent=None, id=None):
45 """Set up the container GUI element.
46
47 @param gui: The gui object.
48 @type gui: wx object
49 @keyword parent: The parent GUI element that this is to be attached to.
50 @type parent: wx object
51 @keyword id: The ID number.
52 @type id: int
53 """
54
55
56 self.gui = gui
57
58
59 wx.Window.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
60
61
62 self.SetMinSize((500, 500))
63
64
65 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
66 self.SetSizer(self.main_sizer)
67
68
69 self.container = Root(self.main_sizer, self)
70
71
72 self.Bind(wx.EVT_SIZE, self._resize)
73
74
76 """Resize the tree element.
77
78 @param event: The wx event.
79 @type event: wx event
80 """
81
82
83 self.Layout()
84 self.Refresh()
85
86
88 """Display the info for the selected container.
89
90 @param info: The information list consisting of the container type ('root', 'mol', 'res', or 'spin'), the molecule name, the residue number, the residue name, the spin number, and the spin name. The name and number information is dropped when not needed.
91 @type info: list of str and int
92 """
93
94
95 self.main_sizer.Clear(deleteWindows=True)
96
97
98 if info == 'root' or info == None:
99 self.container = Root(self.main_sizer, self)
100
101
102 elif info['type'] == 'mol':
103 self.container = Molecule(self.main_sizer, self, mol_name=info['mol_name'], mol_id=info['id'], select=info['select'])
104
105
106 elif info['type'] == 'res':
107 self.container = Residue(self.main_sizer, self, mol_name=info['mol_name'], res_num=info['res_num'], res_name=info['res_name'], res_id=info['id'], select=info['select'])
108
109
110 elif info['type'] == 'spin':
111 self.container = Spin(self.main_sizer, self, mol_name=info['mol_name'], res_num=info['res_num'], res_name=info['res_name'], spin_num=info['spin_num'], spin_name=info['spin_name'], spin_id=info['id'], select=info['select'])
112
113
114 self.Layout()
115 self.Refresh()
116
117
118
120 """The base class for the molecule, residue, and spin containers."""
121
122
123 border = 10
124
125 - def create_head_text(self, text):
126 """Generate the wx.StaticText object for header text.
127
128 @param text: The text of the subtitle.
129 @type text: str
130 @return: The subtitle object.
131 @rtype: wx.StaticText instance
132 """
133
134
135 text = unicode(text)
136
137
138 text = replace(text, '&', '&&')
139
140
141 obj = wx.StaticText(self.parent, -1, text)
142
143
144 obj.SetFont(wx.Font(pointSize=12, family=wx.FONTFAMILY_ROMAN, style=wx.ITALIC, weight=wx.NORMAL, face='Times'))
145
146
147 return obj
148
149
151 """Generate the subtitle wx.StaticText object.
152
153 @param text: The text of the subtitle.
154 @type text: str
155 @return: The subtitle object.
156 @rtype: wx.StaticText instance
157 """
158
159
160 text = unicode(text)
161
162
163 text = replace(text, '&', '&&')
164
165
166 obj = wx.StaticText(self.parent, -1, text)
167
168
169 obj.SetFont(wx.Font(pointSize=16, family=wx.FONTFAMILY_ROMAN, style=wx.ITALIC, weight=wx.NORMAL, face='Times'))
170
171
172 return obj
173
174
176 """Generate the title wx.StaticText object.
177
178 @param text: The text of the subtitle.
179 @type text: str
180 @return: The subtitle object.
181 @rtype: wx.StaticText instance
182 """
183
184
185 title = wx.StaticText(self.parent, -1, text)
186
187
188 title.SetFont(wx.Font(pointSize=32, family=wx.FONTFAMILY_ROMAN, style=wx.ITALIC, weight=wx.NORMAL, face='Times'))
189
190
191 return title
192
193
194
196 """The molecule container."""
197
198 - def __init__(self, box, parent, mol_name=None, mol_id=None, select=True):
199 """Set up the molecule container.
200
201 @param box: The box sizer element to pack the contents into.
202 @type box: wx object
203 @param parent: The parent GUI element.
204 @type parent: wx object
205 @keyword mol_name: The name of the molecule.
206 @type mol_name: str
207 @keyword mol_id: The molecule ID string.
208 @type mol_id: str
209 @keyword select: The selection state.
210 @type select: bool
211 """
212
213
214 self.parent = parent
215 self.mol_name = mol_name
216 self.mol_id = mol_id
217 self.select = select
218
219
220 sizer = self.header_molecule()
221
222
223 box.Add(sizer, 0, wx.ALL|wx.EXPAND, border=self.border)
224
225
226 line = wx.StaticLine(self.parent, -1, (25, 50))
227 box.Add(line, 0, wx.EXPAND|wx.ALL, border=self.border)
228
229
231 """Create the header for the molecule container.
232
233 @return: The sizer containing the header.
234 @rtype: wx.Sizer instance
235 """
236
237
238 sizer = wx.BoxSizer(wx.HORIZONTAL)
239
240
241 text_sizer = wx.BoxSizer(wx.VERTICAL)
242
243
244 title = self.create_title("Molecule container")
245 text_sizer.Add(title, 0, wx.LEFT, 0)
246
247
248 text_sizer.AddSpacer(30)
249
250
251 grid_sizer = wx.FlexGridSizer(2, 2, 5, 50)
252 grid_sizer.Add(self.create_head_text("Molecule:"), 0, wx.ADJUST_MINSIZE, 0)
253 grid_sizer.Add(self.create_head_text(self.mol_name), 0, wx.ADJUST_MINSIZE, 0)
254 grid_sizer.Add(self.create_head_text("Molecule ID string:"), 0, wx.ADJUST_MINSIZE, 0)
255 grid_sizer.Add(self.create_head_text("'%s'" % self.mol_id), 0, wx.ADJUST_MINSIZE, 0)
256 text_sizer.Add(grid_sizer, 0, wx.LEFT, 0)
257
258
259 sizer.Add(text_sizer, 1, wx.ALL|wx.EXPAND, 0)
260
261
262 sizer.AddStretchSpacer()
263
264
265 if self.select:
266 path = paths.WIZARD_IMAGE_PATH + 'molecule.png'
267 else:
268 path = paths.WIZARD_IMAGE_PATH + 'molecule_grey.png'
269 image = wx.StaticBitmap(self.parent, -1, wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
270 sizer.Add(image, 0, wx.RIGHT, 0)
271
272
273 return sizer
274
275
276
278 """The residue container."""
279
280 - def __init__(self, box, parent, mol_name=None, res_num=None, res_name=None, res_id=None, select=True):
281 """Set up the residue container.
282
283 @param box: The box sizer element to pack the contents into.
284 @type box: wx object
285 @param parent: The parent GUI element.
286 @type parent: wx object
287 @keyword mol_name: The molecule name.
288 @type mol_name: str
289 @keyword res_num: The residue number.
290 @type res_num: str
291 @keyword res_name: The residue name.
292 @type res_name: str
293 @keyword res_id: The residue ID string.
294 @type res_id: str
295 @keyword select: The selection state.
296 @type select: bool
297 """
298
299
300 self.parent = parent
301 self.mol_name = mol_name
302 self.res_num = res_num
303 self.res_name = res_name
304 self.res_id = res_id
305 self.select = select
306
307
308 sizer = self.header_residue()
309
310
311 box.Add(sizer, 0, wx.ALL|wx.EXPAND, border=self.border)
312
313
314 line = wx.StaticLine(self.parent, -1, (25, 50))
315 box.Add(line, 0, wx.EXPAND|wx.ALL, border=self.border)
316
317
319 """Create the header for the residue container.
320
321 @return: The sizer containing the header.
322 @rtype: wx.Sizer instance
323 """
324
325
326 sizer = wx.BoxSizer(wx.HORIZONTAL)
327
328
329 text_sizer = wx.BoxSizer(wx.VERTICAL)
330
331
332 title = self.create_title("Residue container")
333 text_sizer.Add(title, 0, wx.LEFT, 0)
334
335
336 text_sizer.AddSpacer(30)
337
338
339 grid_sizer = wx.FlexGridSizer(4, 2, 5, 50)
340 grid_sizer.Add(self.create_head_text("Molecule:"), 0, wx.ADJUST_MINSIZE, 0)
341 grid_sizer.Add(self.create_head_text(self.mol_name), 0, wx.ADJUST_MINSIZE, 0)
342 grid_sizer.Add(self.create_head_text("Residue number:"), 0, wx.ADJUST_MINSIZE, 0)
343 grid_sizer.Add(self.create_head_text(self.res_num), 0, wx.ADJUST_MINSIZE, 0)
344 grid_sizer.Add(self.create_head_text("Residue name:"), 0, wx.ADJUST_MINSIZE, 0)
345 grid_sizer.Add(self.create_head_text(self.res_name), 0, wx.ADJUST_MINSIZE, 0)
346 grid_sizer.Add(self.create_head_text("Residue ID string:"), 0, wx.ADJUST_MINSIZE, 0)
347 grid_sizer.Add(self.create_head_text("'%s'" % self.res_id), 0, wx.ADJUST_MINSIZE, 0)
348 text_sizer.Add(grid_sizer, 0, wx.LEFT, 0)
349
350
351 sizer.Add(text_sizer, 1, wx.ALL|wx.EXPAND, 0)
352
353
354 sizer.AddStretchSpacer()
355
356
357 if self.select:
358 path = paths.WIZARD_IMAGE_PATH + 'residue.png'
359 else:
360 path = paths.WIZARD_IMAGE_PATH + 'residue_grey.png'
361 image = wx.StaticBitmap(self.parent, -1, wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
362 sizer.Add(image, 0, wx.RIGHT, 0)
363
364
365 return sizer
366
367
368
369 -class Spin(Container_base):
370 """The spin container."""
371
372 - def __init__(self, box, parent, mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None, spin_id=None, select=True):
373 """Set up the spin container.
374
375 @param box: The box sizer element to pack the contents into.
376 @type box: wx object
377 @param parent: The parent GUI element.
378 @type parent: wx object
379 @keyword mol_name: The molecule name.
380 @type mol_name: str
381 @keyword res_num: The residue number.
382 @type res_num: str
383 @keyword res_name: The residue name.
384 @type res_name: str
385 @keyword spin_num: The spin number.
386 @type spin_num: str
387 @keyword spin_name: The spin name.
388 @type spin_name: str
389 @keyword spin_id: The spin ID string.
390 @type spin_id: str
391 @keyword select: The selection state.
392 @type select: bool
393 """
394
395
396 self.parent = parent
397 self.mol_name = mol_name
398 self.res_num = res_num
399 self.res_name = res_name
400 self.spin_num = spin_num
401 self.spin_name = spin_name
402 self.spin_id = spin_id
403 self.select = select
404
405
406 sizer = self.header_spin()
407
408
409 box.Add(sizer, 0, wx.ALL|wx.EXPAND, border=self.border)
410
411
412 line = wx.StaticLine(self.parent, -1, (25, 50))
413 box.Add(line, 0, wx.EXPAND|wx.ALL, border=self.border)
414
415
416 sizer2 = self.spin_vars()
417 box.Add(sizer2, 1, wx.ALL|wx.EXPAND, border=self.border)
418
419
421 """Create the header for the spin container.
422
423 @return: The sizer containing the header.
424 @rtype: wx.Sizer instance
425 """
426
427
428 sizer = wx.BoxSizer(wx.HORIZONTAL)
429
430
431 text_sizer = wx.BoxSizer(wx.VERTICAL)
432
433
434 title = self.create_title("Spin container")
435 text_sizer.Add(title, 0, wx.LEFT, 0)
436
437
438 text_sizer.AddSpacer(30)
439
440
441 grid_sizer = wx.FlexGridSizer(6, 2, 5, 50)
442 grid_sizer.Add(self.create_head_text("Molecule:"), 0, wx.ADJUST_MINSIZE, 0)
443 grid_sizer.Add(self.create_head_text(self.mol_name), 0, wx.ADJUST_MINSIZE, 0)
444 grid_sizer.Add(self.create_head_text("Residue number:"), 0, wx.ADJUST_MINSIZE, 0)
445 grid_sizer.Add(self.create_head_text(self.res_num), 0, wx.ADJUST_MINSIZE, 0)
446 grid_sizer.Add(self.create_head_text("Residue name:"), 0, wx.ADJUST_MINSIZE, 0)
447 grid_sizer.Add(self.create_head_text(self.res_name), 0, wx.ADJUST_MINSIZE, 0)
448 grid_sizer.Add(self.create_head_text("Spin number:"), 0, wx.ADJUST_MINSIZE, 0)
449 grid_sizer.Add(self.create_head_text(self.spin_num), 0, wx.ADJUST_MINSIZE, 0)
450 grid_sizer.Add(self.create_head_text("Spin name:"), 0, wx.ADJUST_MINSIZE, 0)
451 grid_sizer.Add(self.create_head_text(self.spin_name), 0, wx.ADJUST_MINSIZE, 0)
452 grid_sizer.Add(self.create_head_text("Spin ID string:"), 0, wx.ADJUST_MINSIZE, 0)
453 grid_sizer.Add(self.create_head_text("'%s'" % self.spin_id), 0, wx.ADJUST_MINSIZE, 0)
454 text_sizer.Add(grid_sizer, 0, wx.LEFT, 0)
455
456
457 sizer.Add(text_sizer, 1, wx.ALL|wx.EXPAND, 0)
458
459
460 sizer.AddStretchSpacer()
461
462
463 if self.select:
464 path = paths.WIZARD_IMAGE_PATH + 'spin.png'
465 else:
466 path = paths.WIZARD_IMAGE_PATH + 'spin_grey.png'
467 image = wx.StaticBitmap(self.parent, -1, wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
468 sizer.Add(image, 0, wx.RIGHT, 0)
469
470
471 return sizer
472
473
475 """Create the variable table for the spin container.
476
477 @keyword blacklist: A list of spin container objects to blacklist from the variable display table.
478 @type blacklist: list of str
479 @return: The sizer containing the table.
480 @rtype: wx.Sizer instance
481 """
482
483
484 sizer = wx.BoxSizer(wx.VERTICAL)
485
486
487 title = self.create_subtitle("Spin container contents")
488 sizer.Add(title, 0, wx.LEFT, 0)
489
490
491 sizer.AddSpacer(20)
492
493
494 table = wx.ListCtrl(self.parent, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT)
495
496
497 table.InsertColumn(0, "Variable")
498 table.InsertColumn(1, "Value")
499 table.InsertColumn(2, "Type")
500
501
502 table.SetColumnWidth(0, 300)
503 table.SetColumnWidth(1, 200)
504 table.SetColumnWidth(2, 200)
505
506
507 spin = return_spin(self.spin_id)
508
509
510 blacklist += ['is_empty']
511
512
513 for name in dir(spin):
514
515 if search('^_', name):
516 continue
517
518
519 if name in blacklist:
520 continue
521
522
523 obj = getattr(spin, name)
524
525
526 obj_type = split(str(type(obj)), "'")[1]
527
528
529 if obj_type in ['list', 'numpy.ndarray'] and len(obj) > 1:
530
531 table.Append((str_to_gui(name), str_to_gui("[%s," % obj[0]), str_to_gui(obj_type)))
532
533
534 for i in range(1, len(obj)-1):
535 table.Append((str_to_gui(''), str_to_gui(" %s," % obj[i]), str_to_gui('')))
536
537
538 table.Append((str_to_gui(''), str_to_gui(" %s]" % obj[-1]), str_to_gui('')))
539
540
541 elif obj_type == 'dict':
542
543 keys = sorted(obj.keys())
544
545
546 if len(keys) < 2:
547 table.Append((str_to_gui(name), str_to_gui(obj), str_to_gui(obj_type)))
548 continue
549
550
551 table.Append((str_to_gui(name), str_to_gui("{'%s': %s," % (keys[0], obj[keys[0]])), str_to_gui(obj_type)))
552
553
554 for i in range(1, len(keys)-1):
555 table.Append((str_to_gui(''), str_to_gui(" '%s': %s," % (keys[i], obj[keys[i]])), str_to_gui('')))
556
557
558 table.Append((str_to_gui(''), str_to_gui(" '%s': %s}" % (keys[-1], obj[keys[-1]])), str_to_gui('')))
559
560
561 else:
562 table.Append((str_to_gui(name), str_to_gui(obj), str_to_gui(obj_type)))
563
564
565 sizer.Add(table, 1, wx.ALL|wx.EXPAND, 0)
566
567
568 return sizer
569
570
571
572 -class Root(Container_base):
573 """The root container."""
574
576 """Set up the root container.
577
578 @param box: The box sizer element to pack the contents into.
579 @type box: wx object
580 @param parent: The parent GUI element.
581 @type parent: wx object
582 """
583
584
585 self.parent = parent
586
587
588 sizer = wx.BoxSizer(wx.VERTICAL)
589
590
591 title = self.create_title("The spin view window")
592 sizer.Add(title, 0, wx.LEFT, 0)
593
594
595 box.Add(sizer, 0, wx.ALL|wx.EXPAND, border=self.border)
596