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

Source Code for Module pipe_control.pymol_control

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 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, getcwd, pardir, sep 
 32  PIPE, Popen = None, None 
 33  if dep_check.subprocess_module: 
 34      from subprocess import PIPE, Popen 
 35  from tempfile import mktemp 
 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 = "%s.pml" % mktemp() 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 # Delete the file. 514 delete(tmpfile, fail=False)
515 516
517 -def macro_run(file=None, dir=None):
518 """Execute the PyMOL macro from the given text file. 519 520 @keyword file: The name of the macro file to execute. 521 @type file: str 522 @keyword dir: The name of the directory where the macro file is located. 523 @type dir: str 524 """ 525 526 # Open the file for reading. 527 file_path = get_file_path(file, dir) 528 file = open_read_file(file, dir) 529 530 # Loop over the commands and apply them. 531 for command in file.readlines(): 532 pymol_obj.exec_cmd(command)
533 534
535 -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):
536 """Create a PyMOL macro file. 537 538 @keyword data_type: The data type to map to the structure. 539 @type data_type: str 540 @keyword style: The style of the macro. 541 @type style: str 542 @keyword colour_start_name: The name of the starting colour of the linear gradient. 543 @type colour_start_name: str 544 @keyword colour_start_rgb: The RGB array starting colour of the linear gradient. 545 @type colour_start_rgb: RBG colour array (len 3 with vals from 0 to 1) 546 @keyword colour_end_name: The name of the ending colour of the linear gradient. 547 @type colour_end_name: str 548 @keyword colour_end_rgb: The RGB array ending colour of the linear gradient. 549 @type colour_end_rgb: RBG colour array (len 3 with vals from 0 to 1) 550 @keyword colour_list: The colour list to search for the colour names. Can be either 'molmol' or 'x11'. 551 @type colour_list: str or None 552 @keyword file: The name of the macro file to create. 553 @type file: str 554 @keyword dir: The name of the directory to place the macro file into. 555 @type dir: str 556 @keyword force: Flag which if set to True will cause any pre-existing file to be overwritten. 557 @type force: bool 558 """ 559 560 # Test if the current data pipe exists. 561 check_pipe() 562 563 # Test if sequence data exists. 564 if not exists_mol_res_spin_data(): 565 raise RelaxNoSequenceError 566 567 # Check the arguments. 568 if colour_start_name != None and colour_start_rgb != None: 569 raise RelaxError("The starting colour name and RGB colour array cannot both be supplied.") 570 if colour_end_name != None and colour_end_rgb != None: 571 raise RelaxError("The ending colour name and RGB colour array cannot both be supplied.") 572 573 # Merge the colour args. 574 if colour_start_name != None: 575 colour_start = colour_start_name 576 else: 577 colour_start = colour_start_rgb 578 if colour_end_name != None: 579 colour_end = colour_end_name 580 else: 581 colour_end = colour_end_rgb 582 583 # Create the macro. 584 commands = create_macro(data_type=data_type, style=style, colour_start=colour_start, colour_end=colour_end, colour_list=colour_list) 585 586 # File name. 587 if file == None: 588 file = data_type + '.pml' 589 590 # Open the file for writing. 591 file_path = get_file_path(file, dir) 592 file = open_write_file(file, dir, force) 593 594 # Loop over the commands and write them. 595 for command in commands: 596 file.write(command + "\n") 597 598 # Close the file. 599 file.close() 600 601 # Add the file to the results file list. 602 add_result_file(type='pymol', label='PyMOL', file=file_path)
603 604
605 -def represent_cone_axis(id=None):
606 """Set up the PyMOL cone axis representation. 607 608 @keyword id: The PyMOL object ID. 609 @type id: str 610 """ 611 612 # Sanity check. 613 if id == None: 614 raise RelaxError("The PyMOL object ID must be supplied.") 615 616 # Select the AXE residues. 617 pymol_obj.exec_cmd("select (%s & resn AXE)" % id) 618 619 # Show the vector as a stick. 620 pymol_obj.exec_cmd("show stick, 'sele'") 621 622 # Colour it blue. 623 pymol_obj.exec_cmd("color cyan, 'sele'") 624 625 # Select the atom used for labelling. 626 pymol_obj.exec_cmd("select (%s & resn AXE and symbol N)" % id) 627 628 # Hide the atom. 629 pymol_obj.exec_cmd("hide ('sele')") 630 631 # Label using the atom name. 632 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 633 634 # Remove the selection. 635 pymol_obj.exec_cmd("cmd.delete('sele')")
636 637
638 -def represent_cone_object(id=None):
639 """Set up the PyMOL cone object representation. 640 641 @keyword id: The PyMOL object ID. 642 @type id: str 643 """ 644 645 # Sanity check. 646 if id == None: 647 raise RelaxError("The PyMOL object ID must be supplied.") 648 649 # Select the CON and CNE residues. 650 pymol_obj.exec_cmd("select (%s & resn CON,CNE)" % id) 651 652 # Hide everything. 653 pymol_obj.exec_cmd("hide ('sele')") 654 655 # Show as 'sticks'. 656 pymol_obj.exec_cmd("show sticks, 'sele'") 657 658 # Colour it white. 659 pymol_obj.exec_cmd("color white, 'sele'") 660 661 # Shorten the stick width from 0.25 to 0.15. 662 pymol_obj.exec_cmd("set stick_radius, 0.15, 'sele'") 663 664 # Set a bit of transparency. 665 pymol_obj.exec_cmd("set stick_transparency, 0.3, 'sele'") 666 667 # Remove the selection. 668 pymol_obj.exec_cmd("cmd.delete('sele')")
669 670
671 -def represent_pivots(id=None):
672 """Set up the PyMOL pivot object representation. 673 674 @keyword id: The PyMOL object ID. 675 @type id: str 676 """ 677 678 # Sanity check. 679 if id == None: 680 raise RelaxError("The PyMOL object ID must be supplied.") 681 682 # Select the PIV residues. 683 pymol_obj.exec_cmd("select (%s & resn PIV)" % id) 684 685 # Hide the atom. 686 pymol_obj.exec_cmd("hide ('sele')") 687 688 # Label using the atom name. 689 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 690 691 # Remove the selection. 692 pymol_obj.exec_cmd("cmd.delete('sele')")
693 694
695 -def represent_titles(id=None):
696 """Set up the PyMOL title object representation. 697 698 @keyword id: The PyMOL object ID. 699 @type id: str 700 """ 701 702 # Sanity check. 703 if id == None: 704 raise RelaxError("The PyMOL object ID must be supplied.") 705 706 # Frame order representation A. 707 pymol_obj.exec_cmd("select (%s & resn TLE & name a)" % id) 708 pymol_obj.exec_cmd("hide ('sele')") 709 pymol_obj.exec_cmd("label 'sele', 'Representation A'") 710 pymol_obj.exec_cmd("cmd.delete('sele')") 711 712 # Frame order representation B. 713 pymol_obj.exec_cmd("select (%s & resn TLE & name b)" % id) 714 pymol_obj.exec_cmd("hide ('sele')") 715 pymol_obj.exec_cmd("label 'sele', 'Representation B'") 716 pymol_obj.exec_cmd("cmd.delete('sele')") 717 718 # Frame order MC sim representation. 719 pymol_obj.exec_cmd("select (%s & resn TLE & name mc)" % id) 720 pymol_obj.exec_cmd("hide ('sele')") 721 pymol_obj.exec_cmd("label 'sele', 'MC sim representation'") 722 pymol_obj.exec_cmd("cmd.delete('sele')") 723 724 # Frame order MC sim representation A. 725 pymol_obj.exec_cmd("select (%s & resn TLE & name mc-a)" % id) 726 pymol_obj.exec_cmd("hide ('sele')") 727 pymol_obj.exec_cmd("label 'sele', 'MC sim representation A'") 728 pymol_obj.exec_cmd("cmd.delete('sele')") 729 730 # Frame order MC sim representation B. 731 pymol_obj.exec_cmd("select (%s & resn TLE & name mc-b)" % id) 732 pymol_obj.exec_cmd("hide ('sele')") 733 pymol_obj.exec_cmd("label 'sele', 'MC sim representation B'") 734 pymol_obj.exec_cmd("cmd.delete('sele')")
735 736
737 -def represent_rotor_object(id=None):
738 """Set up the PyMOL rotor object representation. 739 740 @keyword id: The PyMOL object ID. 741 @type id: str 742 """ 743 744 # Sanity check. 745 if id == None: 746 raise RelaxError("The PyMOL object ID must be supplied.") 747 748 # Rotor objects: Set up the rotor axis. 749 pymol_obj.exec_cmd("select (%s & resn RTX)" % id) 750 pymol_obj.exec_cmd("show stick, 'sele'") 751 pymol_obj.exec_cmd("color red, 'sele'") 752 pymol_obj.exec_cmd("cmd.delete('sele')") 753 754 # Rotor objects: Display the central point. 755 pymol_obj.exec_cmd("select (%s & name CTR)" % id) 756 pymol_obj.exec_cmd("show spheres, 'sele'") 757 pymol_obj.exec_cmd("color red, 'sele'") 758 pymol_obj.exec_cmd("set sphere_scale, 0.3, 'sele'") 759 pymol_obj.exec_cmd("cmd.delete('sele')") 760 761 # Rotor objects: Set up the propellers. 762 pymol_obj.exec_cmd("select (%s & resn RTB)" % id) 763 pymol_obj.exec_cmd("show line, 'sele'") 764 pymol_obj.exec_cmd("cmd.delete('sele')") 765 pymol_obj.exec_cmd("select (%s & resn RTB & name BLD)" % id) 766 pymol_obj.exec_cmd("show spheres, 'sele'") 767 pymol_obj.exec_cmd("set sphere_scale, 0.1, 'sele'") 768 pymol_obj.exec_cmd("cmd.delete('sele')") 769 770 # Rotor objects: The labels. 771 pymol_obj.exec_cmd("select (%s & resn RTL)" % id) 772 pymol_obj.exec_cmd("cmd.label(\"sele\",\"name\")") 773 pymol_obj.exec_cmd("cmd.delete('sele')")
774 775
776 -def tensor_pdb(file=None):
777 """Display the diffusion tensor geometric structure. 778 779 @keyword file: The name of the file containing the diffusion tensor geometric object. 780 @type file: str 781 """ 782 783 # Test if the current data pipe exists. 784 check_pipe() 785 786 # Read in the tensor PDB file. 787 pymol_obj.exec_cmd("load " + file) 788 789 790 # The tensor object. 791 #################### 792 793 # Select the TNS residue. 794 pymol_obj.exec_cmd("select resn TNS") 795 796 # Hide everything. 797 pymol_obj.exec_cmd("hide ('sele')") 798 799 # Show as 'sticks'. 800 pymol_obj.exec_cmd("show sticks, 'sele'") 801 802 803 # Centre of mass. 804 ################# 805 806 # Select the COM residue. 807 pymol_obj.exec_cmd("select resn COM") 808 809 # Show the centre of mass as the dots representation. 810 pymol_obj.exec_cmd("show dots, 'sele'") 811 812 # Colour it blue. 813 pymol_obj.exec_cmd("color blue, 'sele'") 814 815 816 # The diffusion tensor axes. 817 ############################ 818 819 # Select the AXS residue. 820 pymol_obj.exec_cmd("select resn AXS") 821 822 # Hide everything. 823 pymol_obj.exec_cmd("hide ('sele')") 824 825 # Show as 'sticks'. 826 pymol_obj.exec_cmd("show sticks, 'sele'") 827 828 # Colour it cyan. 829 pymol_obj.exec_cmd("color cyan, 'sele'") 830 831 # Select the N atoms of the AXS residue (used to display the axis labels). 832 pymol_obj.exec_cmd("select (resn AXS and elem N)") 833 834 # Label the atoms. 835 pymol_obj.exec_cmd("label 'sele', name") 836 837 838 839 # Monte Carlo simulations. 840 ########################## 841 842 # Select the SIM residue. 843 pymol_obj.exec_cmd("select resn SIM") 844 845 # Colour it. 846 pymol_obj.exec_cmd("colour cyan, 'sele'") 847 848 849 # Clean up. 850 ########### 851 852 # Remove the selection. 853 pymol_obj.exec_cmd("cmd.delete('sele')")
854 855
856 -def vector_dist(file=None):
857 """Display the XH bond vector distribution. 858 859 @keyword file: The vector distribution PDB file. 860 @type file: str 861 """ 862 863 # Test if the current data pipe exists. 864 check_pipe() 865 866 # The file root. 867 id = file_root(file) 868 869 # Read in the vector distribution PDB file. 870 pymol_obj.exec_cmd("load " + file) 871 872 873 # Create a surface. 874 ################### 875 876 # Select the vector distribution. 877 pymol_obj.exec_cmd("cmd.show('surface', " + repr(id) + ")")
878 879
880 -def view():
881 """Start PyMOL.""" 882 883 # Open PyMOL. 884 if pymol_obj.running(): 885 raise RelaxError("PyMOL is already running.") 886 else: 887 pymol_obj.open_gui()
888