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

Source Code for Module pipe_control.pymol_control

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2004,2006-2014 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  """Module for interfacing with PyMOL.""" 
 24   
 25  # Dependency check module. 
 26  import dep_check 
 27   
 28  # Python module imports. 
 29  if dep_check.pymol_module: 
 30      import pymol 
 31  from os import F_OK, access, close, getcwd, pardir, sep 
 32  PIPE, Popen = None, None 
 33  if dep_check.subprocess_module: 
 34      from subprocess import PIPE, Popen 
 35  from tempfile import mkstemp 
 36  from time import sleep 
 37  from warnings import warn 
 38   
 39  # relax module imports. 
 40  from lib.errors import RelaxError, RelaxNoPdbError, RelaxNoSequenceError 
 41  from lib.warnings import RelaxWarning 
 42  from lib.io import delete, file_root, get_file_path, open_read_file, open_write_file, test_binary 
 43  from lib.structure.files import find_pdb_files 
 44  from pipe_control.mol_res_spin import exists_mol_res_spin_data 
 45  from pipe_control.pipes import check_pipe 
 46  from pipe_control.result_files import add_result_file 
 47  from specific_analyses.api import return_api 
 48  from status import Status; status = Status() 
 49   
 50   
51 -class Pymol:
52 """The PyMOL execution object.""" 53
54 - def __init__(self, exec_mode=None):
55 """Set up the PyMOL execution object. 56 57 @keyword exec_mode: The execution mode which can be either 'module' or 'external'. 58 @type exec_mode: None or str 59 """ 60 61 # Variable for storing the pymol command history. 62 self.command_history = "" 63 64 # The pymol mode of operation. 65 self.exec_mode = exec_mode 66 if not exec_mode: 67 if dep_check.pymol_module: 68 self.exec_mode = 'module' 69 self.open = False 70 else: 71 self.exec_mode = 'external'
72 73
74 - def clear_history(self):
75 """Clear the PyMOL command history.""" 76 77 self.command_history = ""
78 79
80 - def exec_cmd(self, command=None, store_command=True):
81 """Execute a PyMOL command. 82 83 @param command: The PyMOL command to send into the program. 84 @type command: str 85 @param store_command: A flag specifying if the command should be stored in the history 86 variable. 87 @type store_command: bool 88 """ 89 90 # Reopen the GUI if needed. 91 if not self.running(): 92 self.open_gui() 93 94 # Execute the command. 95 if self.exec_mode == 'module': 96 pymol.cmd.do(command) 97 else: 98 self.pymol.write(command + '\n') 99 100 # Place the command in the command history. 101 if store_command: 102 self.command_history = self.command_history + command + "\n"
103 104
105 - def open_gui(self):
106 """Open the PyMOL GUI.""" 107 108 # Use the PyMOL python modules. 109 if self.exec_mode == 'module': 110 # Open the GUI. 111 pymol.finish_launching() 112 self.open = True 113 114 # Otherwise execute PyMOL on the command line. 115 if self.exec_mode == 'external': 116 # Test that the PyMOL binary exists. 117 test_binary('pymol') 118 119 # Python 2.3 and earlier. 120 if Popen == None: 121 raise RelaxError("The subprocess module is not available in this version of Python.") 122 123 # Open PyMOL as a pipe. 124 self.pymol = Popen(['pymol', '-qpK'], stdin=PIPE).stdin 125 126 # Execute the command history. 127 if len(self.command_history) > 0: 128 self.exec_cmd(self.command_history, store_command=0) 129 return 130 131 # Test if the PDB file has been loaded. 132 if hasattr(cdp, 'structure'): 133 self.open_pdb()
134 135
136 - def open_pdb(self):
137 """Open the PDB file in PyMOL.""" 138 139 # Test if PyMOL is running. 140 if not self.running(): 141 return 142 143 # Reinitialise PyMOL. 144 self.exec_cmd("reinitialize") 145 146 # Open the PDB files. 147 open_files = [] 148 for model in cdp.structure.structural_data: 149 for mol in model.mol: 150 # No file path. 151 if not hasattr(mol, 'file_name'): 152 warn(RelaxWarning("Cannot display the current molecular data in PyMOL as it has not been exported as a PDB file.")) 153 continue 154 155 # The file path as the current directory. 156 file_path = None 157 if access(mol.file_name, F_OK): 158 file_path = mol.file_name 159 160 # The file path using the relative path. 161 if file_path == None and hasattr(mol, 'file_path') and mol.file_path != None: 162 file_path = mol.file_path + sep + mol.file_name 163 if not access(file_path, F_OK): 164 file_path = None 165 166 # The file path using the absolute path. 167 if file_path == None and hasattr(mol, 'file_path_abs') and mol.file_path_abs != None: 168 file_path = mol.file_path_abs + sep + mol.file_name 169 if not access(file_path, F_OK): 170 file_path = None 171 172 # Hmmm, maybe the absolute path no longer exists and we are in a results subdirectory? 173 if file_path == None and hasattr(mol, 'file_path') and mol.file_path != None: 174 file_path = pardir + sep + mol.file_path + sep + mol.file_name 175 if not access(file_path, F_OK): 176 file_path = None 177 178 # Fall back to the current directory. 179 if file_path == None: 180 file_path = mol.file_name 181 182 # Already loaded. 183 if file_path in open_files: 184 continue 185 186 # Already loaded. 187 if file_path in open_files: 188 continue 189 190 # Open the file in PyMOL. 191 self.exec_cmd("load " + file_path) 192 193 # Add to the open file list. 194 open_files.append(file_path)
195 196
197 - def running(self):
198 """Test if PyMOL is running. 199 200 @return: Whether the Molmol pipe is open or not. 201 @rtype: bool 202 """ 203 204 # Test if PyMOL module interface is already running. 205 if self.exec_mode == 'module': 206 return self.open 207 208 # Test if command line PyMOL is already running. 209 if self.exec_mode == 'external': 210 # Pipe exists. 211 if not hasattr(self, 'pymol'): 212 return False 213 214 # Test if the pipe has been broken. 215 try: 216 self.pymol.write('\n') 217 except IOError: 218 return False 219 220 # PyMOL is running. 221 return True
222 223 224 225 # Initialise the Pymol executable object. 226 pymol_obj = Pymol('external') 227 """Pymol data container instance.""" 228 229 230
231 -def cartoon():
232 """Apply the PyMOL cartoon style and colour by secondary structure.""" 233 234 # Test if the current data pipe exists. 235 check_pipe() 236 237 # Test for the structure. 238 if not hasattr(cdp, 'structure'): 239 raise RelaxNoPdbError 240 241 # Loop over the PDB files. 242 open_files = [] 243 for model in cdp.structure.structural_data: 244 for mol in model.mol: 245 # Identifier. 246 pdb_file = mol.file_name 247 if mol.file_path: 248 pdb_file = mol.file_path + sep + pdb_file 249 id = file_root(pdb_file) 250 251 # Already loaded. 252 if pdb_file in open_files: 253 continue 254 255 # Add to the open file list. 256 open_files.append(pdb_file) 257 258 # Hide everything. 259 pymol_obj.exec_cmd("cmd.hide('everything'," + repr(id) + ")") 260 261 # Show the cartoon style. 262 pymol_obj.exec_cmd("cmd.show('cartoon'," + repr(id) + ")") 263 264 # Colour by secondary structure. 265 pymol_obj.exec_cmd("util.cbss(" + repr(id) + ", 'red', 'yellow', 'green')")
266 267
268 -def command(command):
269 """Function for sending PyMOL commands to the program pipe. 270 271 @param command: The command to send into the program. 272 @type command: str 273 """ 274 275 # Pass the command to PyMOL. 276 pymol_obj.exec_cmd(command)
277 278
279 -def cone_pdb(file=None):
280 """Display the cone geometric object. 281 282 @keyword file: The name of the file containing the cone geometric object. 283 @type file: str 284 """ 285 286 # Read in the cone PDB file. 287 pymol_obj.exec_cmd("load " + file) 288 289 # The object ID. 290 id = file_root(file) 291 292 # The cone axes. 293 represent_cone_axis(id=id) 294 295 # The cone object. 296 represent_cone_object(id=id)
297 298
299 -def create_macro(data_type=None, style="classic", colour_start=None, colour_end=None, colour_list=None):
300 """Create an array of PyMOL commands. 301 302 @keyword data_type: The data type to map to the structure. 303 @type data_type: str 304 @keyword style: The style of the macro. 305 @type style: str 306 @keyword colour_start: The starting colour of the linear gradient. 307 @type colour_start: str or RBG colour array (len 3 with vals from 0 to 1) 308 @keyword colour_end: The ending colour of the linear gradient. 309 @type colour_end: str or RBG colour array (len 3 with vals from 0 to 1) 310 @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. 311 @type colour_list: str or None 312 @return: The list of PyMOL commands. 313 @rtype: list of str 314 """ 315 316 # Get the specific macro. 317 api = return_api() 318 commands = api.pymol_macro(data_type, style, colour_start, colour_end, colour_list) 319 320 # Return the macro commands. 321 return commands
322 323
324 -def frame_order(ave_pos="ave_pos", rep="frame_order", sim="simulation.pdb.gz", dir=None):
325 """Display the frame order results (geometric object, average position and Brownian simulation). 326 327 @keyword ave_pos: The file root of the average molecule structure. 328 @type ave_pos: str or None 329 @keyword rep: The file root of the PDB representation of the frame order dynamics to create. 330 @type rep: str or None 331 @keyword sim: The full Brownian diffusion file name. 332 @type sim: str or None 333 @keyword dir: The name of the directory where the files are located. 334 @type dir: str or None 335 """ 336 337 # The path. 338 path = getcwd() 339 if dir != None: 340 path = dir + sep 341 342 # First disable everything, so that the original domain positions and structures and previous frame order results are not shown by default. 343 pymol_obj.exec_cmd("disable all") 344 345 # Set up the respective objects. 346 if ave_pos: 347 frame_order_ave_pos(root=ave_pos, path=path) 348 if rep: 349 frame_order_geometric(root=rep, path=path) 350 if sim: 351 frame_order_sim(file=sim, path=path) 352 353 # Centre all objects and zoom. 354 pymol_obj.exec_cmd("center animate=3") 355 pymol_obj.exec_cmd("zoom animate=3")
356 357
358 -def frame_order_ave_pos(root=None, path=None):
359 """Display the PDB structure for the frame order average domain position. 360 361 @keyword root: The file root of the PDB file containing the frame order average structure. 362 @type root: str 363 """ 364 365 # Find all PDB files. 366 pdb_files = find_pdb_files(path=path, file_root=root) 367 pdb_files += find_pdb_files(path=path, file_root=root+'_sim') 368 369 # Read in the PDB files. 370 for file in pdb_files: 371 pymol_obj.exec_cmd("load " + file) 372 373 # The object ID. 374 id = file_root(file) 375 376 # Disable the MC simulation representation - the user can find this out for themselves. 377 pymol_obj.exec_cmd("disable %s_sim" % root)
378 379
380 -def frame_order_sim(file=None, path=None):
381 """Display the PDB structure for the frame order Brownian simulation. 382 383 @keyword root: The full Brownian diffusion file name. 384 @type root: str 385 """ 386 387 # Find all PDB files. 388 pdb_files = find_pdb_files(path=path, file_root=file) 389 390 # Read in the PDB files. 391 for file in pdb_files: 392 pymol_obj.exec_cmd("load " + file)
393 394
395 -def frame_order_geometric(root=None, path=None):
396 """Display the frame order geometric object. 397 398 @keyword root: The file root of the PDB file containing the frame order geometric object. 399 @type root: str 400 """ 401 402 # Find all PDB files. 403 pdb_files = find_pdb_files(path=path, file_root=root) 404 pdb_files += find_pdb_files(path=path, file_root=root+'_A') 405 pdb_files += find_pdb_files(path=path, file_root=root+'_B') 406 pdb_files += find_pdb_files(path=path, file_root=root+'_sim') 407 pdb_files += find_pdb_files(path=path, file_root=root+'_sim_A') 408 pdb_files += find_pdb_files(path=path, file_root=root+'_sim_B') 409 410 # Read in the PDB files. 411 for file in pdb_files: 412 # Read in the PDB file. 413 pymol_obj.exec_cmd("load " + file) 414 415 # The object ID. 416 id = file_root(file) 417 418 # First hide everything. 419 pymol_obj.exec_cmd("select %s" % id) 420 pymol_obj.exec_cmd("hide ('sele')") 421 pymol_obj.exec_cmd("cmd.delete('sele')") 422 423 # Set up the titles. 424 represent_titles(id=id) 425 426 # Set up the pivot points. 427 represent_pivots(id=id) 428 429 # Set up the rotor objects. 430 represent_rotor_object(id=id) 431 432 # Set up the cone axis. 433 represent_cone_axis(id=id) 434 435 # Set up the cone object. 436 represent_cone_object(id=id) 437 438 # Disable the MC simulation representation - the user can find this out for themselves. 439 pymol_obj.exec_cmd("disable %s_sim" % root) 440 pymol_obj.exec_cmd("disable %s_sim_A" % root) 441 pymol_obj.exec_cmd("disable %s_sim_B" % root)
442 443
444 -def macro_apply(data_type=None, style="classic", colour_start_name=None, colour_start_rgb=None, colour_end_name=None, colour_end_rgb=None, colour_list=None):
445 """Execute a PyMOL macro. 446 447 @keyword data_type: The data type to map to the structure. 448 @type data_type: str 449 @keyword style: The style of the macro. 450 @type style: str 451 @keyword colour_start_name: The name of the starting colour of the linear gradient. 452 @type colour_start_name: str 453 @keyword colour_start_rgb: The RGB array starting colour of the linear gradient. 454 @type colour_start_rgb: RBG colour array (len 3 with vals from 0 to 1) 455 @keyword colour_end_name: The name of the ending colour of the linear gradient. 456 @type colour_end_name: str 457 @keyword colour_end_rgb: The RGB array ending colour of the linear gradient. 458 @type colour_end_rgb: RBG colour array (len 3 with vals from 0 to 1) 459 @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. 460 @type colour_list: str or None 461 """ 462 463 # Test if the current data pipe exists. 464 check_pipe() 465 466 # Test if sequence data exists. 467 if not exists_mol_res_spin_data(): 468 raise RelaxNoSequenceError 469 470 # Check the arguments. 471 if colour_start_name != None and colour_start_rgb != None: 472 raise RelaxError("The starting colour name and RGB colour array cannot both be supplied.") 473 if colour_end_name != None and colour_end_rgb != None: 474 raise RelaxError("The ending colour name and RGB colour array cannot both be supplied.") 475 476 # Merge the colour args. 477 if colour_start_name != None: 478 colour_start = colour_start_name 479 else: 480 colour_start = colour_start_rgb 481 if colour_end_name != None: 482 colour_end = colour_end_name 483 else: 484 colour_end = colour_end_rgb 485 486 # Clear the PyMOL history first. 487 pymol_obj.clear_history() 488 489 # Create the macro. 490 commands = create_macro(data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list) 491 492 # Save the commands as a temporary file, execute it, then delete it. 493 try: 494 # Temp file name. 495 tmpfile_handle, tmpfile = mkstemp(suffix='.pml') 496 497 # Open the file. 498 file = open(tmpfile, 'w') 499 500 # Loop over the commands and write them. 501 for command in commands: 502 file.write("%s\n" % command) 503 file.close() 504 505 # Execute the macro. 506 pymol_obj.exec_cmd("@%s" % tmpfile) 507 508 # Wait a bit for PyMOL to catch up (it takes time for PyMOL to start and the macro to execute). 509 sleep(3) 510 511 # Delete the temporary file (no matter what). 512 finally: 513 # Close the open file handle on the OS level. 514 close(tmpfile_handle) 515 516 # Delete the temporary file. 517 delete(tmpfile, fail=False)
518 519
520 -def macro_run(file=None, dir=None):
521 """Execute the PyMOL macro from the given text file. 522 523 @keyword file: The name of the macro file to execute. 524 @type file: str 525 @keyword dir: The name of the directory where the macro file is located. 526 @type dir: str 527 """ 528 529 # Open the file for reading. 530 file_path = get_file_path(file, dir) 531 file = open_read_file(file, dir) 532 533 # Loop over the commands and apply them. 534 for command in file.readlines(): 535 pymol_obj.exec_cmd(command)
536 537
538 -def macro_write(data_type=None, style="classic", colour_start_name=None, colour_start_rgb=None, colour_end_name=None, colour_end_rgb=None, colour_list=None, file=None, dir=None, force=False):
539 """Create a PyMOL macro file. 540 541 @keyword data_type: The data type to map to the structure. 542 @type data_type: str 543 @keyword style: The style of the macro. 544 @type style: str 545 @keyword colour_start_name: The name of the starting colour of the linear gradient. 546 @type colour_start_name: str 547 @keyword colour_start_rgb: The RGB array starting colour of the linear gradient. 548 @type colour_start_rgb: RBG colour array (len 3 with vals from 0 to 1) 549 @keyword colour_end_name: The name of the ending colour of the linear gradient. 550 @type colour_end_name: str 551 @keyword colour_end_rgb: The RGB array ending colour of the linear gradient. 552 @type colour_end_rgb: RBG colour array (len 3 with vals from 0 to 1) 553 @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. 554 @type colour_list: str or None 555 @keyword file: The name of the macro file to create. 556 @type file: str 557 @keyword dir: The name of the directory to place the macro file into. 558 @type dir: str 559 @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. 560 @type force: bool 561 """ 562 563 # Test if the current data pipe exists. 564 check_pipe() 565 566 # Test if sequence data exists. 567 if not exists_mol_res_spin_data(): 568 raise RelaxNoSequenceError 569 570 # Check the arguments. 571 if colour_start_name != None and colour_start_rgb != None: 572 raise RelaxError("The starting colour name and RGB colour array cannot both be supplied.") 573 if colour_end_name != None and colour_end_rgb != None: 574 raise RelaxError("The ending colour name and RGB colour array cannot both be supplied.") 575 576 # Merge the colour args. 577 if colour_start_name != None: 578 colour_start = colour_start_name 579 else: 580 colour_start = colour_start_rgb 581 if colour_end_name != None: 582 colour_end = colour_end_name 583 else: 584 colour_end = colour_end_rgb 585 586 # Create the macro. 587 commands = create_macro(data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list) 588 589 # File name. 590 if file == None: 591 file = data_type + '.pml' 592 593 # Open the file for writing. 594 file_path = get_file_path(file, dir) 595 file = open_write_file(file, dir, force) 596 597 # Loop over the commands and write them. 598 for command in commands: 599 file.write(command + "\n") 600 601 # Close the file. 602 file.close() 603 604 # Add the file to the results file list. 605 add_result_file(type='pymol', label='PyMOL', file=file_path)
606 607
608 -def represent_cone_axis(id=None):
609 """Set up the PyMOL cone axis representation. 610 611 @keyword id: The PyMOL object ID. 612 @type id: str 613 """ 614 615 # Sanity check. 616 if id == None: 617 raise RelaxError("The PyMOL object ID must be supplied.") 618 619 # Select the AXE residues. 620 pymol_obj.exec_cmd("select (%s & resn AXE)" % id) 621 622 # Show the vector as a stick. 623 pymol_obj.exec_cmd("show stick, 'sele'") 624 625 # Colour it blue. 626 pymol_obj.exec_cmd("color cyan, 'sele'") 627 628 # Select the atom used for labelling. 629 pymol_obj.exec_cmd("select (%s & resn AXE and symbol N)" % id) 630 631 # Hide the atom. 632 pymol_obj.exec_cmd("hide ('sele')") 633 634 # Label using the atom name. 635 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 636 637 # Remove the selection. 638 pymol_obj.exec_cmd("cmd.delete('sele')")
639 640
641 -def represent_cone_object(id=None):
642 """Set up the PyMOL cone object representation. 643 644 @keyword id: The PyMOL object ID. 645 @type id: str 646 """ 647 648 # Sanity check. 649 if id == None: 650 raise RelaxError("The PyMOL object ID must be supplied.") 651 652 # Select the CON and CNE residues. 653 pymol_obj.exec_cmd("select (%s & resn CON,CNE)" % id) 654 655 # Hide everything. 656 pymol_obj.exec_cmd("hide ('sele')") 657 658 # Show as 'sticks'. 659 pymol_obj.exec_cmd("show sticks, 'sele'") 660 661 # Colour it white. 662 pymol_obj.exec_cmd("color white, 'sele'") 663 664 # Shorten the stick width from 0.25 to 0.15. 665 pymol_obj.exec_cmd("set stick_radius, 0.15, 'sele'") 666 667 # Set a bit of transparency. 668 pymol_obj.exec_cmd("set stick_transparency, 0.3, 'sele'") 669 670 # Remove the selection. 671 pymol_obj.exec_cmd("cmd.delete('sele')")
672 673
674 -def represent_pivots(id=None):
675 """Set up the PyMOL pivot object representation. 676 677 @keyword id: The PyMOL object ID. 678 @type id: str 679 """ 680 681 # Sanity check. 682 if id == None: 683 raise RelaxError("The PyMOL object ID must be supplied.") 684 685 # Select the PIV residues. 686 pymol_obj.exec_cmd("select (%s & resn PIV)" % id) 687 688 # Hide the atom. 689 pymol_obj.exec_cmd("hide ('sele')") 690 691 # Label using the atom name. 692 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 693 694 # Remove the selection. 695 pymol_obj.exec_cmd("cmd.delete('sele')")
696 697
698 -def represent_titles(id=None):
699 """Set up the PyMOL title object representation. 700 701 @keyword id: The PyMOL object ID. 702 @type id: str 703 """ 704 705 # Sanity check. 706 if id == None: 707 raise RelaxError("The PyMOL object ID must be supplied.") 708 709 # Frame order representation A. 710 pymol_obj.exec_cmd("select (%s & resn TLE & name a)" % id) 711 pymol_obj.exec_cmd("hide ('sele')") 712 pymol_obj.exec_cmd("label 'sele', 'Representation A'") 713 pymol_obj.exec_cmd("cmd.delete('sele')") 714 715 # Frame order representation B. 716 pymol_obj.exec_cmd("select (%s & resn TLE & name b)" % id) 717 pymol_obj.exec_cmd("hide ('sele')") 718 pymol_obj.exec_cmd("label 'sele', 'Representation B'") 719 pymol_obj.exec_cmd("cmd.delete('sele')") 720 721 # Frame order MC sim representation. 722 pymol_obj.exec_cmd("select (%s & resn TLE & name mc)" % id) 723 pymol_obj.exec_cmd("hide ('sele')") 724 pymol_obj.exec_cmd("label 'sele', 'MC sim representation'") 725 pymol_obj.exec_cmd("cmd.delete('sele')") 726 727 # Frame order MC sim representation A. 728 pymol_obj.exec_cmd("select (%s & resn TLE & name mc-a)" % id) 729 pymol_obj.exec_cmd("hide ('sele')") 730 pymol_obj.exec_cmd("label 'sele', 'MC sim representation A'") 731 pymol_obj.exec_cmd("cmd.delete('sele')") 732 733 # Frame order MC sim representation B. 734 pymol_obj.exec_cmd("select (%s & resn TLE & name mc-b)" % id) 735 pymol_obj.exec_cmd("hide ('sele')") 736 pymol_obj.exec_cmd("label 'sele', 'MC sim representation B'") 737 pymol_obj.exec_cmd("cmd.delete('sele')")
738 739
740 -def represent_rotor_object(id=None):
741 """Set up the PyMOL rotor object representation. 742 743 @keyword id: The PyMOL object ID. 744 @type id: str 745 """ 746 747 # Sanity check. 748 if id == None: 749 raise RelaxError("The PyMOL object ID must be supplied.") 750 751 # Rotor objects: Set up the rotor axis. 752 pymol_obj.exec_cmd("select (%s & resn RTX)" % id) 753 pymol_obj.exec_cmd("show stick, 'sele'") 754 pymol_obj.exec_cmd("color red, 'sele'") 755 pymol_obj.exec_cmd("cmd.delete('sele')") 756 757 # Rotor objects: Display the central point. 758 pymol_obj.exec_cmd("select (%s & name CTR)" % id) 759 pymol_obj.exec_cmd("show spheres, 'sele'") 760 pymol_obj.exec_cmd("color red, 'sele'") 761 pymol_obj.exec_cmd("set sphere_scale, 0.3, 'sele'") 762 pymol_obj.exec_cmd("cmd.delete('sele')") 763 764 # Rotor objects: Set up the propellers. 765 pymol_obj.exec_cmd("select (%s & resn RTB)" % id) 766 pymol_obj.exec_cmd("show line, 'sele'") 767 pymol_obj.exec_cmd("cmd.delete('sele')") 768 pymol_obj.exec_cmd("select (%s & resn RTB & name BLD)" % id) 769 pymol_obj.exec_cmd("show spheres, 'sele'") 770 pymol_obj.exec_cmd("set sphere_scale, 0.1, 'sele'") 771 pymol_obj.exec_cmd("cmd.delete('sele')") 772 773 # Rotor objects: The labels. 774 pymol_obj.exec_cmd("select (%s & resn RTL)" % id) 775 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 776 pymol_obj.exec_cmd("cmd.delete('sele')")
777 778
779 -def tensor_pdb(file=None):
780 """Display the diffusion tensor geometric structure. 781 782 @keyword file: The name of the file containing the diffusion tensor geometric object. 783 @type file: str 784 """ 785 786 # Test if the current data pipe exists. 787 check_pipe() 788 789 # Read in the tensor PDB file. 790 pymol_obj.exec_cmd("load " + file) 791 792 793 # The tensor object. 794 #################### 795 796 # Select the TNS residue. 797 pymol_obj.exec_cmd("select resn TNS") 798 799 # Hide everything. 800 pymol_obj.exec_cmd("hide ('sele')") 801 802 # Show as 'sticks'. 803 pymol_obj.exec_cmd("show sticks, 'sele'") 804 805 806 # Centre of mass. 807 ################# 808 809 # Select the COM residue. 810 pymol_obj.exec_cmd("select resn COM") 811 812 # Show the centre of mass as the dots representation. 813 pymol_obj.exec_cmd("show dots, 'sele'") 814 815 # Colour it blue. 816 pymol_obj.exec_cmd("color blue, 'sele'") 817 818 819 # The diffusion tensor axes. 820 ############################ 821 822 # Select the AXS residue. 823 pymol_obj.exec_cmd("select resn AXS") 824 825 # Hide everything. 826 pymol_obj.exec_cmd("hide ('sele')") 827 828 # Show as 'sticks'. 829 pymol_obj.exec_cmd("show sticks, 'sele'") 830 831 # Colour it cyan. 832 pymol_obj.exec_cmd("color cyan, 'sele'") 833 834 # Select the N atoms of the AXS residue (used to display the axis labels). 835 pymol_obj.exec_cmd("select (resn AXS and elem N)") 836 837 # Label the atoms. 838 pymol_obj.exec_cmd("label 'sele', name") 839 840 841 842 # Monte Carlo simulations. 843 ########################## 844 845 # Select the SIM residue. 846 pymol_obj.exec_cmd("select resn SIM") 847 848 # Colour it. 849 pymol_obj.exec_cmd("colour cyan, 'sele'") 850 851 852 # Clean up. 853 ########### 854 855 # Remove the selection. 856 pymol_obj.exec_cmd("cmd.delete('sele')")
857 858
859 -def vector_dist(file=None):
860 """Display the XH bond vector distribution. 861 862 @keyword file: The vector distribution PDB file. 863 @type file: str 864 """ 865 866 # Test if the current data pipe exists. 867 check_pipe() 868 869 # The file root. 870 id = file_root(file) 871 872 # Read in the vector distribution PDB file. 873 pymol_obj.exec_cmd("load " + file) 874 875 876 # Create a surface. 877 ################### 878 879 # Select the vector distribution. 880 pymol_obj.exec_cmd("cmd.show('surface', " + repr(id) + ")")
881 882
883 -def view():
884 """Start PyMOL.""" 885 886 # Open PyMOL. 887 if pymol_obj.running(): 888 raise RelaxError("PyMOL is already running.") 889 else: 890 pymol_obj.open_gui()
891