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

Source Code for Module user_functions.molmol

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2004,2006,2009-2012,2019 Edward d'Auvergne               # 
  4  # Copyright (C) 2008 Sebastien Morin                                          # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The molmol user function definitions for interacting with Molmol.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28   
 29  # relax module imports. 
 30  import colour 
 31  from graphics import WIZARD_IMAGE_PATH 
 32  from pipe_control import molmol 
 33  from specific_analyses.model_free.uf import classic_style_doc 
 34  from user_functions.data import Uf_info; uf_info = Uf_info() 
 35  from user_functions.objects import Desc_container 
 36  from user_functions.wildcards import WILDCARD_MOLMOL_MACRO, WILDCARD_STRUCT_PDB 
 37   
 38   
 39   
 40  # The user function class. 
 41  uf_class = uf_info.add_class('molmol') 
 42  uf_class.title = "Class for interfacing with Molmol." 
 43  uf_class.menu_text = "&molmol" 
 44  uf_class.gui_icon = "relax.molmol" 
 45   
 46   
 47  # The molmol.clear_history user function. 
 48  uf = uf_info.add_uf('molmol.clear_history') 
 49  uf.title = "Clear the Molmol command history." 
 50  uf.title_short = "Clear Molmol history.""" 
 51  # Description. 
 52  uf.desc.append(Desc_container()) 
 53  uf.desc[-1].add_paragraph("This will clear the Molmol history from memory.") 
 54  uf.backend = molmol.molmol_obj.clear_history 
 55  uf.menu_text = "clear_&history" 
 56  uf.wizard_size = (600, 300) 
 57  uf.wizard_apply_button = False 
 58  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
 59   
 60   
 61  # The molmol.command user function. 
 62  uf = uf_info.add_uf('molmol.command') 
 63  uf.title = "Execute a user supplied Molmol command." 
 64  uf.title_short = "Molmol command execution." 
 65  uf.add_keyarg( 
 66      name = "command", 
 67      basic_types = ["str"], 
 68      desc_short = "Molmol command", 
 69      desc = "The Molmol command to execute." 
 70  ) 
 71  # Description. 
 72  uf.desc.append(Desc_container()) 
 73  uf.desc[-1].add_paragraph("This allows Molmol commands to be passed to the program.  This can be useful for automation or scripting.") 
 74  # Prompt examples. 
 75  uf.desc.append(Desc_container("Prompt examples")) 
 76  uf.desc[-1].add_paragraph("To reinitialise the Molmol instance, type:") 
 77  uf.desc[-1].add_prompt("relax> molmol.command(\"InitAll yes\")") 
 78  uf.backend = molmol.command 
 79  uf.menu_text = "&command" 
 80  uf.gui_icon = "oxygen.actions.edit-rename" 
 81  uf.wizard_size = (700, 400) 
 82  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
 83   
 84   
 85  # The molmol.macro_apply user function. 
 86  uf = uf_info.add_uf('molmol.macro_apply') 
 87  uf.title = "Execute Molmol macros." 
 88  uf.title_short = "Molmol macro execution." 
 89  uf.display = True 
 90  uf.add_keyarg( 
 91      name = "data_type", 
 92      basic_types = ["str"], 
 93      desc_short = "data type", 
 94      desc = "The data type to map to the structure." 
 95  ) 
 96  uf.add_keyarg( 
 97      name = "style", 
 98      default = "classic", 
 99      basic_types = ["str"], 
100      desc_short = "style", 
101      desc = "The style of the macro.", 
102      wiz_element_type = "combo", 
103      wiz_combo_choices = ["classic"], 
104      wiz_read_only = True 
105  ) 
106  uf.add_keyarg( 
107      name = "colour_start_name", 
108      basic_types = ["str"], 
109      desc_short = "starting colour (by name)", 
110      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.", 
111      can_be_none = True 
112  ) 
113  uf.add_keyarg( 
114      name = "colour_start_rgb", 
115      basic_types = ["number"], 
116      container_types = ["list"], 
117      dim = (3,), 
118      desc_short = "starting colour (RGB colour array)", 
119      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.", 
120      can_be_none = True 
121  ) 
122  uf.add_keyarg( 
123      name = "colour_end_name", 
124      basic_types = ["str"], 
125      desc_short = "ending colour (by name)", 
126      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.", 
127      can_be_none = True 
128  ) 
129  uf.add_keyarg( 
130      name = "colour_end_rgb", 
131      basic_types = ["number"], 
132      container_types = ["list"], 
133      dim = (3,), 
134      desc_short = "ending colour (RGB colour array)", 
135      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.", 
136      can_be_none = True 
137  ) 
138  uf.add_keyarg( 
139      name = "colour_list", 
140      basic_types = ["str"], 
141      desc_short = "colour list", 
142      desc = "The colour list to search for the colour names.  This can be either 'molmol' or 'x11'.", 
143      wiz_element_type = "combo", 
144      wiz_combo_choices = ["molmol", "x11"], 
145      wiz_read_only = True, 
146      can_be_none = True 
147  ) 
148  # Description. 
149  uf.desc.append(Desc_container()) 
150  uf.desc[-1].add_paragraph("This allows spin specific values to be mapped to a structure through Molmol macros.  Currently only the 'classic' style, which is described below, is available.") 
151  uf.desc.append(colour._linear_gradient_doc) 
152  uf.desc.append(classic_style_doc) 
153  uf.desc.append(colour.__molmol_colours_doc__) 
154  uf.desc.append(colour.__x11_colours_doc__) 
155  # Prompt examples. 
156  uf.desc.append(Desc_container("Prompt examples")) 
157  uf.desc[-1].add_paragraph("To map the order parameter values, S2, onto the structure using the classic style, type:") 
158  uf.desc[-1].add_prompt("relax> molmol.macro_apply('s2')") 
159  uf.desc[-1].add_prompt("relax> molmol.macro_apply(data_type='s2')") 
160  uf.desc[-1].add_prompt("relax> molmol.macro_apply(data_type='s2', style=\"classic\")") 
161  uf.backend = molmol.macro_apply 
162  uf.menu_text = "&macro_apply" 
163  uf.gui_icon = "relax.molmol" 
164  uf.wizard_size = (1000, 750) 
165  uf.wizard_height_desc = 400 
166  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
167   
168   
169  # The molmol.macro_run user function. 
170  uf = uf_info.add_uf('molmol.macro_run') 
171  uf.title = "Open and execute the Molmol macro file." 
172  uf.title_short = "Molmol macro file execution." 
173  uf.display = True 
174  uf.add_keyarg( 
175      name = "file", 
176      arg_type = "file sel read", 
177      desc_short = "Molmol macro file", 
178      desc = "The name of the Molmol macro file.", 
179      wiz_filesel_wildcard = WILDCARD_MOLMOL_MACRO, 
180  ) 
181  uf.add_keyarg( 
182      name = "dir", 
183      default = "molmol", 
184      arg_type = "dir", 
185      desc_short = "directory name", 
186      desc = "The directory name.", 
187      can_be_none = True 
188  ) 
189  # Description. 
190  uf.desc.append(Desc_container()) 
191  uf.desc[-1].add_paragraph("This user function is for opening and running a Molmol macro located within a text file.") 
192  # Prompt examples. 
193  uf.desc.append(Desc_container("Prompt examples")) 
194  uf.desc[-1].add_paragraph("To execute the macro file 's2.mac' located in the directory 'molmol', type:") 
195  uf.desc[-1].add_prompt("relax> molmol.macro_run(file='s2.mac')") 
196  uf.desc[-1].add_prompt("relax> molmol.macro_run(file='s2.mac', dir='molmol')") 
197  uf.backend = molmol.macro_run 
198  uf.menu_text = "macro_&run" 
199  uf.gui_icon = "oxygen.actions.document-open" 
200  uf.wizard_size = (700, 400) 
201  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
202   
203   
204  # The molmol.macro_write user function. 
205  uf = uf_info.add_uf('molmol.macro_write') 
206  uf.title = "Create Molmol macros." 
207  uf.title_short = "Molmol macro creation." 
208  uf.add_keyarg( 
209      name = "data_type", 
210      basic_types = ["str"], 
211      desc_short = "data type", 
212      desc = "The data type to map to the structure." 
213  ) 
214  uf.add_keyarg( 
215      name = "style", 
216      default = "classic", 
217      basic_types = ["str"], 
218      desc_short = "style", 
219      desc = "The style of the macro.", 
220      wiz_element_type = "combo", 
221      wiz_combo_choices = ["classic"], 
222      wiz_read_only = True, 
223  ) 
224  uf.add_keyarg( 
225      name = "colour_start_name", 
226      basic_types = ["str"], 
227      desc_short = "starting colour (by name)", 
228      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.", 
229      can_be_none = True 
230  ) 
231  uf.add_keyarg( 
232      name = "colour_start_rgb", 
233      basic_types = ["number"], 
234      container_types = ["list"], 
235      dim = (3,), 
236      desc_short = "starting colour (RGB colour array)", 
237      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.", 
238      can_be_none = True 
239  ) 
240  uf.add_keyarg( 
241      name = "colour_end_name", 
242      basic_types = ["str"], 
243      desc_short = "ending colour (by name)", 
244      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.", 
245      can_be_none = True 
246  ) 
247  uf.add_keyarg( 
248      name = "colour_end_rgb", 
249      basic_types = ["number"], 
250      container_types = ["list"], 
251      dim = (3,), 
252      desc_short = "ending colour (RGB colour array)", 
253      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.", 
254      can_be_none = True 
255  ) 
256  uf.add_keyarg( 
257      name = "colour_list", 
258      basic_types = ["str"], 
259      desc_short = "colour list", 
260      desc = "The colour list to search for the colour names.  This can be either 'molmol' or 'x11'.", 
261      wiz_element_type = "combo", 
262      wiz_combo_choices = ["molmol", "x11"], 
263      wiz_read_only = True, 
264      can_be_none = True 
265  ) 
266  uf.add_keyarg( 
267      name = "file", 
268      arg_type = "file sel write", 
269      desc_short = "file name", 
270      desc = "The optional name of the file.", 
271      wiz_filesel_wildcard = WILDCARD_MOLMOL_MACRO, 
272      can_be_none = True 
273  ) 
274  uf.add_keyarg( 
275      name = "dir", 
276      default = "molmol", 
277      arg_type = "dir", 
278      desc_short = "directory name", 
279      desc = "The optional directory to save the file to.", 
280      can_be_none = True 
281  ) 
282  uf.add_keyarg( 
283      name = "force", 
284      default = False, 
285      basic_types = ["bool"], 
286      desc_short = "force flag", 
287      desc = "A flag which, if set to True, will cause the file to be overwritten." 
288  ) 
289  # Description. 
290  uf.desc.append(Desc_container()) 
291  uf.desc[-1].add_paragraph("This allows residues specific values to be mapped to a structure through the creation of a Molmol '*.mac' macro which can be executed in Molmol by clicking on 'File, Macro, Execute User...'.  Currently only the 'classic' style, which is described below, is available.") 
292  uf.desc.append(colour._linear_gradient_doc) 
293  uf.desc.append(classic_style_doc) 
294  uf.desc.append(colour.__molmol_colours_doc__) 
295  uf.desc.append(colour.__x11_colours_doc__) 
296  # Prompt examples. 
297  uf.desc.append(Desc_container("Prompt examples")) 
298  uf.desc[-1].add_paragraph("To create a Molmol macro mapping the order parameter values, S2, onto the structure using the classic style, type:") 
299  uf.desc[-1].add_prompt("relax> molmol.macro_write('s2')") 
300  uf.desc[-1].add_prompt("relax> molmol.macro_write(data_type='s2')") 
301  uf.desc[-1].add_prompt("relax> molmol.macro_write(data_type='s2', style=\"classic\", file='s2.mac', dir='molmol')") 
302  uf.backend = molmol.macro_write 
303  uf.menu_text = "macro_&write" 
304  uf.gui_icon = "oxygen.actions.document-save" 
305  uf.wizard_size = (1000, 750) 
306  uf.wizard_height_desc = 350 
307  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
308   
309   
310  # The molmol.ribbon user function. 
311  uf = uf_info.add_uf('molmol.ribbon') 
312  uf.title = "Apply the Molmol ribbon style." 
313  uf.title_short = "Molmol ribbon style application." 
314  # Description. 
315  uf.desc.append(Desc_container()) 
316  uf.desc[-1].add_paragraph("This applies the Molmol ribbon style which is equivalent to clicking on 'ribbon' in the Molmol side menu.  To do this, the following commands are executed:") 
317  uf.desc[-1].add_list_element("CalcAtom 'H'") 
318  uf.desc[-1].add_list_element("CalcAtom 'HN'") 
319  uf.desc[-1].add_list_element("CalcSecondary") 
320  uf.desc[-1].add_list_element("XMacStand ribbon.mac") 
321  # Prompt examples. 
322  uf.desc.append(Desc_container("Prompt examples")) 
323  uf.desc[-1].add_paragraph("To apply the ribbon style to the PDB file loaded, type:") 
324  uf.desc[-1].add_prompt("relax> molmol.ribbon()") 
325  uf.backend = molmol.ribbon 
326  uf.menu_text = "ri&bbon" 
327  uf.wizard_size = (700, 500) 
328  uf.wizard_height_desc = 450 
329  uf.wizard_apply_button = False 
330  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
331   
332   
333  # The molmol.tensor_pdb user function. 
334  uf = uf_info.add_uf('molmol.tensor_pdb') 
335  uf.title = "Display the diffusion tensor PDB geometric object over the loaded PDB." 
336  uf.title_short = "Diffusion tensor and structure display." 
337  uf.add_keyarg( 
338      name = "file", 
339      arg_type = "file sel read", 
340      desc_short = "file name", 
341      desc = "The name of the PDB file containing the tensor geometric object.", 
342      wiz_filesel_wildcard = WILDCARD_STRUCT_PDB, 
343  ) 
344  # Description. 
345  uf.desc.append(Desc_container()) 
346  uf.desc[-1].add_paragraph("In executing this user function, a PDB file must have previously been loaded , a geometric object or polygon representing the Brownian rotational diffusion tensor will be overlain with the loaded PDB file and displayed within Molmol.  The PDB file containing the geometric object must be created using the complementary structure.create_diff_tensor_pdb user function.") 
347  uf.desc[-1].add_paragraph("To display the diffusion tensor, the multiple commands will be executed.  To overlay the structure with the diffusion tensor, everything will be selected and reoriented and moved to their original PDB frame positions:") 
348  uf.desc[-1].add_list_element("SelectAtom ''") 
349  uf.desc[-1].add_list_element("SelectBond ''") 
350  uf.desc[-1].add_list_element("SelectAngle ''") 
351  uf.desc[-1].add_list_element("SelectDist ''") 
352  uf.desc[-1].add_list_element("SelectPrim ''") 
353  uf.desc[-1].add_list_element("RotateInit") 
354  uf.desc[-1].add_list_element("MoveInit") 
355  uf.desc[-1].add_paragraph("Next the tensor PDB file is read in, selected, and the covalent bonds of the PDB CONECT records calculated:") 
356  uf.desc[-1].add_list_element("ReadPdb file") 
357  uf.desc[-1].add_list_element("SelectMol '@file'") 
358  uf.desc[-1].add_list_element("CalcBond 1 1 1") 
359  uf.desc[-1].add_paragraph("Then only the atoms and bonds of the geometric object are selected and the 'ball/stick' style applied:") 
360  uf.desc[-1].add_list_element("SelectAtom '0'") 
361  uf.desc[-1].add_list_element("SelectBond '0'") 
362  uf.desc[-1].add_list_element("SelectAtom ':TNS'") 
363  uf.desc[-1].add_list_element("SelectBond ':TNS'") 
364  uf.desc[-1].add_list_element("XMacStand ball_stick.mac") 
365  uf.desc[-1].add_paragraph("The appearance is finally touched up:") 
366  uf.desc[-1].add_list_element("RadiusAtom 1") 
367  uf.desc[-1].add_list_element("SelectAtom ':TNS@C*'") 
368  uf.desc[-1].add_list_element("RadiusAtom 1.5") 
369  uf.backend = molmol.tensor_pdb 
370  uf.menu_text = "&tensor_pdb" 
371  uf.wizard_height_desc = 550 
372  uf.wizard_size = (1000, 750) 
373  uf.wizard_apply_button = False 
374  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
375   
376   
377  # The molmol.view user function. 
378  uf = uf_info.add_uf('molmol.view') 
379  uf.title = "View the collection of molecules from the loaded PDB file." 
380  uf.title_short = "Molecule viewing." 
381  # Description. 
382  uf.desc.append(Desc_container()) 
383  uf.desc[-1].add_paragraph("This will simply launch Molmol.") 
384  # Prompt examples. 
385  uf.desc.append(Desc_container("Prompt examples")) 
386  uf.desc[-1].add_prompt("relax> molmol.view()") 
387  uf.backend = molmol.view 
388  uf.menu_text = "&view" 
389  uf.wizard_size = (600, 300) 
390  uf.wizard_apply_button = False 
391  uf.wizard_image = WIZARD_IMAGE_PATH + 'molmol' + sep + 'molmol_logo.png' 
392