Package user_functions :: Module pymol_control
[hide private]
[frames] | no frames]

Source Code for Module user_functions.pymol_control

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program 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 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """The pymol user function definitions for interacting with PyMOL.""" 
 24   
 25  # Python module imports. 
 26  from os import sep 
 27  import dep_check 
 28  if dep_check.wx_module: 
 29      from wx import FD_OPEN, FD_SAVE 
 30  else: 
 31      FD_OPEN = -1 
 32      FD_SAVE = -1 
 33   
 34  # relax module imports. 
 35  import colour 
 36  from graphics import WIZARD_IMAGE_PATH 
 37  from pipe_control import pymol_control 
 38  from specific_analyses.model_free.pymol import Pymol 
 39  from user_functions.data import Uf_info; uf_info = Uf_info() 
 40  from user_functions.objects import Desc_container 
 41   
 42   
 43  # The user function class. 
 44  uf_class = uf_info.add_class('pymol') 
 45  uf_class.title = "Class for interfacing with PyMOL." 
 46  uf_class.menu_text = "&pymol" 
 47  uf_class.gui_icon = "relax.pymol_icon" 
 48   
 49   
 50  # The pymol.cartoon user function. 
 51  uf = uf_info.add_uf('pymol.cartoon') 
 52  uf.title = "Apply the PyMOL cartoon style and colour by secondary structure." 
 53  uf.title_short = "PyMOL cartoon style application." 
 54  # Description. 
 55  uf.desc.append(Desc_container()) 
 56  uf.desc[-1].add_paragraph("This applies the PyMOL cartoon style which is equivalent to hiding everything and clicking on show cartoon.  It also colours the cartoon with red helices, yellow strands, and green loops.  The following commands are executed:") 
 57  uf.desc[-1].add_list_element("cmd.hide('everything', file)") 
 58  uf.desc[-1].add_list_element("cmd.show('cartoon', file)") 
 59  uf.desc[-1].add_list_element("util.cbss(file, 'red', 'yellow', 'green')") 
 60  uf.desc[-1].add_paragraph("where file is the file name without the '.pdb' extension.") 
 61  # Prompt examples. 
 62  uf.desc.append(Desc_container("Prompt examples")) 
 63  uf.desc[-1].add_paragraph("To apply this user function, type:") 
 64  uf.desc[-1].add_prompt("relax> pymol.cartoon()") 
 65  uf.backend = pymol_control.cartoon 
 66  uf.menu_text = "cart&oon" 
 67  uf.wizard_size = (700, 500) 
 68  uf.wizard_height_desc = 450 
 69  uf.wizard_apply_button = False 
 70  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
 71   
 72   
 73  # The pymol.clear_history user function. 
 74  uf = uf_info.add_uf('pymol.clear_history') 
 75  uf.title = "Clear the PyMOL command history.""" 
 76  uf.title_short = "Clear PyMOL history.""" 
 77  # Description. 
 78  uf.desc.append(Desc_container()) 
 79  uf.desc[-1].add_paragraph("This will clear the Pymol history from memory.") 
 80  uf.backend = pymol_control.pymol_obj.clear_history 
 81  uf.menu_text = "clear_&history" 
 82  uf.wizard_size = (600, 350) 
 83  uf.wizard_apply_button = False 
 84  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
 85   
 86   
 87  # The pymol.command user function. 
 88  uf = uf_info.add_uf('pymol.command') 
 89  uf.title = "Execute a user supplied PyMOL command." 
 90  uf.title_short = "PyMOL command execution." 
 91  uf.add_keyarg( 
 92      name = "command", 
 93      py_type = "str", 
 94      desc_short = "PyMOL command", 
 95      desc = "The PyMOL command to execute." 
 96  ) 
 97  # Description. 
 98  uf.desc.append(Desc_container()) 
 99  uf.desc[-1].add_paragraph("This allows PyMOL commands to be passed to the program.  This can be useful for automation or scripting.") 
100  # Prompt examples. 
101  uf.desc.append(Desc_container("Prompt examples")) 
102  uf.desc[-1].add_paragraph("To reinitialise the PyMOL instance, type:") 
103  uf.desc[-1].add_prompt("relax> pymol.command(\"reinitialise\")") 
104  uf.backend = pymol_control.command 
105  uf.menu_text = "&command" 
106  uf.gui_icon = "oxygen.actions.edit-rename" 
107  uf.wizard_size = (700, 400) 
108  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
109   
110   
111  # The pymol.cone_pdb user function. 
112  uf = uf_info.add_uf('pymol.cone_pdb') 
113  uf.title = "Display the cone PDB geometric object." 
114  uf.title_short = "Cone PDB geometric object display." 
115  uf.add_keyarg( 
116      name = "file", 
117      py_type = "str", 
118      arg_type = "file sel", 
119      desc_short = "file name", 
120      desc = "The name of the PDB file containing the cone geometric object.", 
121      wiz_filesel_wildcard = "PDB files (*.pdb)|*.pdb;*.PDB", 
122      wiz_filesel_style = FD_OPEN 
123  ) 
124  # Description. 
125  uf.desc.append(Desc_container()) 
126  uf.desc[-1].add_paragraph("The PDB file containing the geometric object must be created using the complementary frame_order.cone_pdb or n_state_model.cone_pdb user functions.") 
127  uf.desc[-1].add_paragraph("The cone PDB file is read in using the command:") 
128  uf.desc[-1].add_list_element("load file") 
129  uf.desc[-1].add_paragraph("The average CoM-pivot point vector, the residue 'AVE' is displayed using the commands:") 
130  uf.desc[-1].add_list_element("select resn AVE") 
131  uf.desc[-1].add_list_element("show sticks, 'sele'") 
132  uf.desc[-1].add_list_element("color blue, 'sele'") 
133  uf.desc[-1].add_paragraph("The cone object, the residue 'CON', is displayed using the commands:") 
134  uf.desc[-1].add_list_element("select resn CON") 
135  uf.desc[-1].add_list_element("hide ('sele')") 
136  uf.desc[-1].add_list_element("show sticks, 'sele'") 
137  uf.desc[-1].add_list_element("color white, 'sele'") 
138  uf.backend = pymol_control.cone_pdb 
139  uf.menu_text = "cone_&pdb" 
140  uf.wizard_height_desc = 500 
141  uf.wizard_size = (900, 700) 
142  uf.wizard_apply_button = False 
143  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
144   
145   
146  # The pymol.macro_apply user function. 
147  uf = uf_info.add_uf('pymol.macro_apply') 
148  uf.title = "Execute PyMOL macros." 
149  uf.title_short = "PyMOL macro execution." 
150  uf.display = True 
151  uf.add_keyarg( 
152      name = "data_type", 
153      py_type = "str", 
154      desc_short = "data type", 
155      desc = "The data type to map to the structure." 
156  ) 
157  uf.add_keyarg( 
158      name = "style", 
159      default = "classic", 
160      py_type = "str", 
161      desc_short = "style", 
162      desc = "The style of the macro.", 
163      wiz_element_type = "combo", 
164      wiz_combo_choices = ["classic"], 
165      wiz_read_only = True, 
166  ) 
167  uf.add_keyarg( 
168      name = "colour_start_name", 
169      py_type = "str", 
170      desc_short = "starting colour (by name)", 
171      desc = "The name of the starting colour of the linear colour gradient.  This can be either one of the X11 or one of the Molmol colour names listed in the description.  If this is set, then the starting colour RGB colour array cannot be given.", 
172      can_be_none = True 
173  ) 
174  uf.add_keyarg( 
175      name = "colour_start_rgb", 
176      py_type = "num_list", 
177      dim = 3, 
178      desc_short = "starting colour (RGB colour array)", 
179      desc = "The starting colour of the linear colour gradient.  This is an RGB colour array with values ranging from 0 to 1.  If this is set, then the starting colour name cannot be given.", 
180      can_be_none = True 
181  ) 
182  uf.add_keyarg( 
183      name = "colour_end_name", 
184      py_type = "str", 
185      desc_short = "ending colour (by name)", 
186      desc = "The name of the ending colour of the linear colour gradient.  This can be either one of the X11 or one of the Molmol colour names listed in the description.  If this is set, then the ending colour RGB colour array cannot be given.", 
187      can_be_none = True 
188  ) 
189  uf.add_keyarg( 
190      name = "colour_end_rgb", 
191      py_type = "num_list", 
192      dim = 3, 
193      desc_short = "ending colour (RGB colour array)", 
194      desc = "The ending colour of the linear colour gradient.  This is an RGB colour array with values ranging from 0 to 1.  If this is set, then the ending colour name cannot be given.", 
195      can_be_none = True 
196  ) 
197  uf.add_keyarg( 
198      name = "colour_list", 
199      py_type = "str", 
200      desc_short = "colour list", 
201      desc = "The colour list to search for the colour names.  This can be either 'molmol' or 'x11'.", 
202      wiz_element_type = "combo", 
203      wiz_combo_choices = ["molmol", "x11"], 
204      wiz_read_only = True, 
205      can_be_none = True 
206  ) 
207  # Description. 
208  uf.desc.append(Desc_container()) 
209  uf.desc[-1].add_paragraph("This allows spin specific values to be mapped to a structure through PyMOL macros.  Currently only the 'classic' style, which is described below, is available.") 
210  uf.desc.append(colour._linear_gradient_doc) 
211  uf.desc.append(Pymol.classic_style_doc) 
212  uf.desc.append(colour.__molmol_colours_doc__) 
213  uf.desc.append(colour.__x11_colours_doc__) 
214  # Prompt examples. 
215  uf.desc.append(Desc_container("Prompt examples")) 
216  uf.desc[-1].add_paragraph("To map the order parameter values, S2, onto the structure using the classic style, type:") 
217  uf.desc[-1].add_prompt("relax> pymol.macro_apply('s2')") 
218  uf.desc[-1].add_prompt("relax> pymol.macro_apply(data_type='s2')") 
219  uf.desc[-1].add_prompt("relax> pymol.macro_apply(data_type='s2', style=\"classic\")") 
220  uf.backend = pymol_control.macro_apply 
221  uf.menu_text = "&macro_apply" 
222  uf.gui_icon = "relax.pymol_icon" 
223  uf.wizard_height_desc = 400 
224  uf.wizard_size = (1000, 750) 
225  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
226   
227   
228  # The pymol.macro_run user function. 
229  uf = uf_info.add_uf('pymol.macro_run') 
230  uf.title = "Open and execute the PyMOL macro file." 
231  uf.title_short = "PyMOL macro file execution." 
232  uf.display = True 
233  uf.add_keyarg( 
234      name = "file", 
235      py_type = "str", 
236      arg_type = "file sel", 
237      desc_short = "file name", 
238      desc = "The name of the PyMOL macro file.", 
239      wiz_filesel_wildcard = "PyMOL macro files (*.pml)|*.pml;*.PML", 
240      wiz_filesel_style = FD_OPEN 
241  ) 
242  uf.add_keyarg( 
243      name = "dir", 
244      default = "pymol", 
245      py_type = "str", 
246      arg_type = "dir", 
247      desc_short = "directory name", 
248      desc = "The directory name.", 
249      can_be_none = True 
250  ) 
251  # Description. 
252  uf.desc.append(Desc_container()) 
253  uf.desc[-1].add_paragraph("This user function is for opening and running a PyMOL macro located within a text file.") 
254  # Prompt examples. 
255  uf.desc.append(Desc_container("Prompt examples")) 
256  uf.desc[-1].add_paragraph("To execute the macro file 's2.pml' located in the directory 'pymol', type:") 
257  uf.desc[-1].add_prompt("relax> pymol.macro_run(file='s2.pml')") 
258  uf.desc[-1].add_prompt("relax> pymol.macro_run(file='s2.pml', dir='pymol')") 
259  uf.backend = pymol_control.macro_run 
260  uf.menu_text = "macro_&run" 
261  uf.gui_icon = "oxygen.actions.document-open" 
262  uf.wizard_size = (700, 400) 
263  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
264   
265   
266  # The pymol.macro_write user function. 
267  uf = uf_info.add_uf('pymol.macro_write') 
268  uf.title = "Create PyMOL macros." 
269  uf.title_short = "PyMOL macro creation." 
270  uf.add_keyarg( 
271      name = "data_type", 
272      py_type = "str", 
273      desc_short = "data type", 
274      desc = "The data type to map to the structure." 
275  ) 
276  uf.add_keyarg( 
277      name = "style", 
278      default = "classic", 
279      py_type = "str", 
280      desc_short = "style", 
281      desc = "The style of the macro.", 
282      wiz_element_type = "combo", 
283      wiz_combo_choices = ["classic"], 
284      wiz_read_only = True, 
285  ) 
286  uf.add_keyarg( 
287      name = "colour_start_name", 
288      py_type = "str", 
289      desc_short = "starting colour (by name)", 
290      desc = "The name of the starting colour of the linear colour gradient.  This can be either one of the X11 or one of the Molmol colour names listed in the description.  If this is set, then the starting colour RGB colour array cannot be given.", 
291      can_be_none = True 
292  ) 
293  uf.add_keyarg( 
294      name = "colour_start_rgb", 
295      py_type = "num_list", 
296      dim = 3, 
297      desc_short = "starting colour (RGB colour array)", 
298      desc = "The starting colour of the linear colour gradient.  This is an RGB colour array with values ranging from 0 to 1.  If this is set, then the starting colour name cannot be given.", 
299      can_be_none = True 
300  ) 
301  uf.add_keyarg( 
302      name = "colour_end_name", 
303      py_type = "str", 
304      desc_short = "ending colour (by name)", 
305      desc = "The name of the ending colour of the linear colour gradient.  This can be either one of the X11 or one of the Molmol colour names listed in the description.  If this is set, then the ending colour RGB colour array cannot be given.", 
306      can_be_none = True 
307  ) 
308  uf.add_keyarg( 
309      name = "colour_end_rgb", 
310      py_type = "num_list", 
311      dim = 3, 
312      desc_short = "ending colour (RGB colour array)", 
313      desc = "The ending colour of the linear colour gradient.  This is an RGB colour array with values ranging from 0 to 1.  If this is set, then the ending colour name cannot be given.", 
314      can_be_none = True 
315  ) 
316  uf.add_keyarg( 
317      name = "colour_list", 
318      py_type = "str", 
319      desc_short = "colour list", 
320      desc = "The colour list to search for the colour names.  This can be either 'molmol' or 'x11'.", 
321      wiz_element_type = "combo", 
322      wiz_combo_choices = ["molmol", "x11"], 
323      wiz_read_only = True, 
324      can_be_none = True 
325  ) 
326  uf.add_keyarg( 
327      name = "file", 
328      py_type = "str", 
329      arg_type = "file sel", 
330      desc_short = "file name", 
331      desc = "The optional name of the file.", 
332      wiz_filesel_wildcard = "PyMOL macro files (*.pml)|*.pml;*.PML", 
333      wiz_filesel_style = FD_SAVE, 
334      can_be_none = True 
335  ) 
336  uf.add_keyarg( 
337      name = "dir", 
338      default = "pymol", 
339      py_type = "str", 
340      arg_type = "dir", 
341      desc_short = "directory name", 
342      desc = "The optional directory to save the file to.", 
343      can_be_none = True 
344  ) 
345  uf.add_keyarg( 
346      name = "force", 
347      default = False, 
348      py_type = "bool", 
349      desc_short = "force flag", 
350      desc = "A flag which, if set to True, will cause the file to be overwritten." 
351  ) 
352  # Description. 
353  uf.desc.append(Desc_container()) 
354  uf.desc[-1].add_paragraph("This allows residues specific values to be mapped to a structure through the creation of a PyMOL macro which can be executed in PyMOL by clicking on 'File, Macro, Execute User...'.  Currently only the 'classic' style, which is described below, is available.") 
355  uf.desc.append(colour._linear_gradient_doc) 
356  uf.desc.append(Pymol.classic_style_doc) 
357  uf.desc.append(colour.__molmol_colours_doc__) 
358  uf.desc.append(colour.__x11_colours_doc__) 
359  # Prompt examples. 
360  uf.desc.append(Desc_container("Prompt examples")) 
361  uf.desc[-1].add_paragraph("To create a PyMOL macro mapping the order parameter values, S2, onto the structure using the classic style, type:") 
362  uf.desc[-1].add_prompt("relax> pymol.macro_write('s2')") 
363  uf.desc[-1].add_prompt("relax> pymol.macro_write(data_type='s2')") 
364  uf.desc[-1].add_prompt("relax> pymol.macro_write(data_type='s2', style=\"classic\", file='s2.pml', dir='pymol')") 
365  uf.backend = pymol_control.macro_write 
366  uf.menu_text = "macro_&write" 
367  uf.gui_icon = "oxygen.actions.document-save" 
368  uf.wizard_height_desc = 330 
369  uf.wizard_size = (1000, 750) 
370  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
371   
372   
373  # The pymol.tensor_pdb user function. 
374  uf = uf_info.add_uf('pymol.tensor_pdb') 
375  uf.title = "Display the diffusion tensor PDB geometric object over the loaded PDB." 
376  uf.title_short = "Diffusion tensor and structure display." 
377  uf.add_keyarg( 
378      name = "file", 
379      py_type = "str_or_inst", 
380      arg_type = "file sel", 
381      desc_short = "file name", 
382      desc = "The name of the PDB file containing the tensor geometric object.", 
383      wiz_filesel_wildcard = "PDB files (*.pdb)|*.pdb;*.PDB", 
384      wiz_filesel_style = FD_OPEN 
385  ) 
386  # Description. 
387  uf.desc.append(Desc_container()) 
388  uf.desc[-1].add_paragraph("In executing this user function, a PDB file must have previously been loaded into this data pipe a geometric object or polygon representing the Brownian rotational diffusion tensor will be overlain with the loaded PDB file and displayed within PyMOL.  The PDB file containing the geometric object must be created using the complementary structure.create_diff_tensor_pdb user function.") 
389  uf.desc[-1].add_paragraph("The tensor PDB file is read in using the command:") 
390  uf.desc[-1].add_list_element("load file") 
391  uf.desc[-1].add_paragraph("The centre of mass residue 'COM' is displayed using the commands:") 
392  uf.desc[-1].add_list_element("select resn COM") 
393  uf.desc[-1].add_list_element("show dots, 'sele'") 
394  uf.desc[-1].add_list_element("color blue, 'sele'") 
395  uf.desc[-1].add_paragraph("The axes of the diffusion tensor, the residue 'AXS', is displayed using the commands:") 
396  uf.desc[-1].add_list_element("select resn AXS") 
397  uf.desc[-1].add_list_element("hide ('sele')") 
398  uf.desc[-1].add_list_element("show sticks, 'sele'") 
399  uf.desc[-1].add_list_element("color cyan, 'sele'") 
400  uf.desc[-1].add_list_element("label 'sele', name") 
401  uf.desc[-1].add_paragraph("The simulation axes, the residues 'SIM', are displayed using the commands:") 
402  uf.desc[-1].add_list_element("select resn SIM") 
403  uf.desc[-1].add_list_element("colour cyan, 'sele'") 
404  uf.backend = pymol_control.tensor_pdb 
405  uf.menu_text = "&tensor_pdb" 
406  uf.wizard_height_desc = 550 
407  uf.wizard_size = (1000, 750) 
408  uf.wizard_apply_button = False 
409  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
410   
411   
412  # The pymol.vector_dist user function. 
413  uf = uf_info.add_uf('pymol.vector_dist') 
414  uf.title = "Display the PDB file representation of the XH vector distribution." 
415  uf.title_short = "XH vector distribution display." 
416  uf.add_keyarg( 
417      name = "file", 
418      default = "XH_dist.pdb", 
419      py_type = "str", 
420      arg_type = "file sel", 
421      desc_short = "file name", 
422      desc = "The name of the PDB file containing the vector distribution.", 
423      wiz_filesel_wildcard = "PDB files (*.pdb)|*.pdb;*.PDB", 
424      wiz_filesel_style = FD_OPEN 
425  ) 
426  # Description. 
427  uf.desc.append(Desc_container()) 
428  uf.desc[-1].add_paragraph("A PDB file of the macromolecule must have previously been loaded as the vector distribution will be overlain with the macromolecule within PyMOL.  The PDB file containing the vector distribution must be created using the complementary structure.create_vector_dist user function.") 
429  uf.desc[-1].add_paragraph("The vector distribution PDB file is read in using the command:") 
430  uf.desc[-1].add_list_element("load file") 
431  uf.backend = pymol_control.vector_dist 
432  uf.menu_text = "vector_&dist" 
433  uf.wizard_size = (800, 500) 
434  uf.wizard_height_desc = 450 
435  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
436   
437  # The pymol.view user function. 
438  uf = uf_info.add_uf('pymol.view') 
439  uf.title = "View the collection of molecules from the loaded PDB file." 
440  uf.title_short = "Molecule viewing." 
441  # Description. 
442  uf.desc.append(Desc_container()) 
443  uf.desc[-1].add_paragraph("This will simply launch Pymol.") 
444  # Prompt examples. 
445  uf.desc.append(Desc_container("Prompt examples")) 
446  uf.desc[-1].add_prompt("relax> pymol.view()") 
447  uf.backend = pymol_control.view 
448  uf.menu_text = "&view" 
449  uf.wizard_size = (600, 350) 
450  uf.wizard_apply_button = False 
451  uf.wizard_image = WIZARD_IMAGE_PATH + 'pymol' + sep + 'pymol.png' 
452