[Chimera-users] Script to open density from Coot in Chimera.

Oliver Clarke olibclarke at gmail.com
Mon May 23 07:12:42 PDT 2016


Hi all,

Posting this in case it is useful to anyone else who uses both programs.
This script will allow Coot to open the currently displayed molecules/maps
in Chimera, and adjust display settings appropriately for taking a picture
of electron density.

Either put the appended code in your coot.py and use from the scripting
interface, or place this longer script (
https://www.dropbox.com/s/0b4bebwxw0p9x0e/oli_custom.py?dl=0) in your
~/.coot-preferences directory, which will add a new "Custom" menu including
this option under the "Display" submenu (as well as a bunch of other stuff,
and some extra custom key bindings).

The orientation of the molecules should be correct after loading in
Chimera, but the zoom and clipping may require some adjustment (I am not
sure exactly how to match these precisely between the two programs). The
script will only load a fragment of the maps (the same region that is
displayed in Coot), but this has the advantage that it takes advantage of
Coot's ability to deal with crystal symmetry, so it can be used at crystal
contacts with no problems. Let me know if you run into any bugs!

Cheers,
Oli.

Code:
#Open displayed models and maps in Chimera, set map levels and view
def open_in_chimera():
  if find_exe("chimera"): #If chimera exists do stuff, else raise an error
    import subprocess
    pwd=os.getcwd() #Dir from which coot was launched
    cofr=rotation_centre() #3-membered list [x,y,z]
    make_directory_maybe("coot-chimera") #Put coot droppings here
    coot_chimera_path=pwd+"/coot-chimera/"
    check_path=coot_chimera_path+"chimera_launcher.cmd" #Chimera run script
that will be written later
    check_path2=coot_chimera_path+"matrix.txt" #Orientation matrix for
chimera input
    view_number=add_view_here("tmp")
#     initial_zoom=zoom_factor() #Coot's zoom factor. 100 is the initial
state, zooming out gets larger, in gets smaller.
#     reset_view()
    zoom=zoom_factor()
#     go_to_view_number(view_number,1)
#     scale_factor=initial_zoom/base_zoom
#     chimera_scale=base_zoom/initial_zoom
    chimera_scale=100.0/zoom #Approx - breaks down when initial views upon
loading mol in Coot or Chimera are different
    map_radius=get_map_radius() #We'll use this to export a map_radius
sized fragment
    if os.path.isfile(check_path): #if chimera script exists, delete it.
      os.remove(check_path)
    if os.path.isfile(check_path2): #same for matrix.txt
      os.remove(check_path2)
    map_list=map_molecule_list()
    mol_list=model_molecule_list()
    matrix_list=view_matrix() #9-membered list of rotation matrix elements.
    with open(check_path2,"a") as matrix_file: #Write orientation matrix
(specify first pdb as model, then use matrixcopy to apply to all others).
Translation vector in last column is 0,0,0 because we will take care of
that separately.
      matrix_file.write("Model {model_id}.0\n".format(model_id=mol_list[0]))
      matrix_file.write("\t {a} {b} {c}
0.0\n".format(a=matrix_list[0],b=matrix_list[1],c=matrix_list[2]))
      matrix_file.write("\t {a} {b} {c}
0.0\n".format(a=matrix_list[3],b=matrix_list[4],c=matrix_list[5]))
      matrix_file.write("\t {a} {b} {c}
0.0\n".format(a=matrix_list[6],b=matrix_list[7],c=matrix_list[8]))
    with open(check_path,"a") as cmd_file: #Start writing stuff to chimera
launch script.
      for mol_id in model_molecule_list():
        if mol_is_displayed(mol_id):

file_name=coot_chimera_path+"mol_{mol_id}.pdb".format(mol_id=mol_id)
          write_pdb_file(mol_id,file_name)
          path_to_file=file_name
          model_id=mol_id
          cmd_file.write("open #{model_id}
{mol}\n".format(model_id=model_id,mol=path_to_file))
          cmd_file.write("color gold #{model_id}; color byhet #{model_id};
ca_and_sidechains #{model_id}; disp ~protein\n".format(model_id=model_id))
          cmd_file.write("matrixset matrix.txt\n")
          cmd_file.write("matrixcopy #{mol_id0}
#{mol_id}\n".format(mol_id0=mol_list[0],mol_id=model_id))
      map_id0=mol_id
      for map_id in map_molecule_list():
        if map_is_displayed(map_id):
          map_level=get_contour_level_absolute(map_id)
          if map_is_difference_map(map_id):
            model_id=map_id0+map_id #make sure that the assigned model
number of each map is unique and does not overlap with those of pdbs.
            if map_id==0:
              model_id=model_id+1

file_name=coot_chimera_path+"diff_map_{model_id}.mrc".format(model_id=model_id)
            path_to_file=file_name

export_map_fragment(map_id,cofr[0],cofr[1],cofr[2],map_radius,file_name)
            cmd_file.write("open #{model_id} {diff_map}
\n".format(model_id=model_id,diff_map=path_to_file))
            cmd_file.write("volume #{model_id} capfaces false style mesh
meshlighting false squaremesh false color \"#08882eefa222\" step 1 ;  sop
cap off ;  set depthCue ;  set dcStart 0.2 ;  set dcEnd 1 ;  background
solid white ; set showcofr ;  cofr view ;  clip on; volume #{model_id}
level -{map_level} color #da1200000000 level {map_level} color
#0000bda00000 \n".format(model_id=model_id,map_level=map_level))
            cmd_file.write("matrixset matrix.txt\n")
            cmd_file.write("matrixcopy #{mol_id0}
#{model_id}\n".format(mol_id0=mol_list[0],model_id=model_id))
          else:
            model_id=map_id0+map_id
            if map_id==0:
              model_id=model_id+1

file_name=coot_chimera_path+"map_{model_id}.mrc".format(model_id=model_id)

export_map_fragment(map_id,cofr[0],cofr[1],cofr[2],map_radius,file_name)
            path_to_file=file_name
            cmd_file.write("open #{model_id} {map}
\n".format(model_id=model_id,map=path_to_file))
            cmd_file.write("volume #{model_id} capfaces false style mesh
meshlighting false squaremesh false color \"#08882eefa222\" step 1 ;  sop
cap off ;  set depthCue ;  set dcStart 0.2 ;  set dcEnd 1 ;  background
solid white ; set showcofr ;  cofr view ;  clip on; volume #{model_id}
level {map_level} \n".format(model_id=model_id,map_level=map_level))
            cmd_file.write("matrixset matrix.txt\n")
            cmd_file.write("matrixcopy #{mol_id0}
#{model_id}\n".format(mol_id0=mol_list[0],model_id=model_id))
      cmd_file.write("~sel; cofr {x},{y},{z} coordinatesystem #{mol_id0};
ac mc; center sel; cofr sel;  clip hither 5 fromCenter true; clip yon -5
fromCenter true; cofr view; ~set showcofr; del sel; scale
{chimera_scale}".format(x=cofr[0],y=cofr[1],z=cofr[2],mol_id0=mol_list[0],chimera_scale=chimera_scale))
    chimera_exe=find_exe("chimera")
    info_dialog("Opening in Chimera...\nOrientation should be right but you
will probably need to \nadjust the scale and clipping to get the same view
as in Coot. \n If you can't see anything, try zooming out.")
    subprocess.Popen(["chimera",check_path])
  else:
    info_dialog("Sorry, you need UCSF Chimera installed and accessible from
the terminal for this to work!")
#This works okay, though adjustment of zoom and clipping still not ideal.
#would it be possible to add a subprocess.communicate() to use Coot as a
controller for Chimera?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20160523/8fb20c75/attachment.html>


More information about the Chimera-users mailing list