Hi,
I'd like to write a little extension to open the currently displayed models and maps in UCSF Chimera, to facilitate quickly making a publication quality figure of a view found in Coot. I have most of this written (see appended code), and as far as it goes it works - it saves the appropriate pdbs and map fragments, and writes and launches a script to load them in Chimera with appropriate display settings. However, there are three things I can't quite get yet, and I wonder if anyone out there has a suggestion:
1. What is the meaning of the number returned by zoom_factor(), i.e. what is this number related to? I would like to relate this to the scale factor that needs to be applied in Chimera. Seems like the number is bigger the further I am zoomed out, but beyond that I'm stumped. Maybe distance of "camera" to center of rotation?
2. General python question I guess - any easy way I can run this in the background so that the view can still be manipulated in Coot? I tried launching it in a thread but didn't have much luck (the thread seems to launch without error but Chimera does not open).
3. Is there any way from the scripting interface to retrieve the clipping parameters, i.e. how thick of a slab Coot is displaying?
Related to the last point, I'm curious about how Coot adjusts the clipping - it seems like Coot adjusts the thickness of the slab used for clipping as the zoom factor is adjusted (so if you zoom out the whole molecule is unclipped, whereas if you zoom in to a residue the clipping planes are maybe 5 Å apart) - is there any documentation/description of this anywhere? Mostly curious because I wish other molecular graphics programs did this, as it is a much more natural way to view the molecule of interest.
Cheers,
Oli.
Code:
def open_in_chimera():
if find_exe("chimera"):
import subprocess
pwd=os.getcwd()
cofr=rotation_centre()
make_directory_maybe("coot-chimera")
coot_chimera_path=pwd+"/coot-chimera/"
check_path=coot_chimera_path+"chimera_launcher.cmd"
check_path2=coot_chimera_path+"matrix.txt"
zoom=zoom_factor()
#this must be relatable to chimera scale command somehow, presumably inverse - zoomfactor is
#bigger when further away
if os.path.isfile(check_path):
os.remove(check_path)
if os.path.isfile(check_path2):
os.remove(check_path2)
map_list=map_molecule_list()
matrix_list=view_matrix()
with open(check_path2,"a") as matrix_file:
matrix_file.write("Model {model_id}.0\n".format(model_id=map_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:
for map_id in map_molecule_list():
if map_is_displayed(map_id):
if map_is_difference_map(map_id):
file_name=coot_chimera_path+"diff_map_{map_id}.mrc".format(map_id=map_id)
export_map_fragment(map_id,cofr[0],cofr[1],cofr[2],20,file_name)
path_to_file=file_name
cmd_file.write("open #{map_id} {diff_map} \n".format(map_id=map_id,diff_map=path_to_file))
cmd_file.write("volume #{map_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; diffmap_sig #{map_id} 3\n".format(map_id=map_id))
cmd_file.write("matrixset matrix.txt\n")
cmd_file.write("matrixcopy #{map_id0} #{map_id}\n".format(map_id0=map_list[0],map_id=map_id))
else:
file_name=coot_chimera_path+"map_{map_id}.mrc".format(map_id=map_id)
export_map_fragment(map_id,cofr[0],cofr[1],cofr[2],20,file_name)
path_to_file=file_name
cmd_file.write("open #{map_id} {map} \n".format(map_id=map_id,map=path_to_file))
cmd_file.write("volume #{map_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; map_sig #{map_id} 1\n".format(map_id=map_id))
cmd_file.write("matrixset matrix.txt\n")
cmd_file.write("matrixcopy #{map_id0} #{map_id}\n".format(map_id0=map_list[0],map_id=map_id))
mol_id0=map_id
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)
save_coordinates(mol_id,file_name)
path_to_file=file_name
model_id=mol_id0+mol_id
if mol_id==0:
model_id=model_id+1
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 #{map_id0} #{mol_id}\n".format(map_id0=map_list[0],mol_id=model_id))
cmd_file.write("~sel; cofr {x},{y},{z} coordinatesystem #{model_id}; ac mc; center sel; cofr sel; clip yon -5 fromCenter true; clip hither 5 fromCenter true; cofr view; ~set showcofr; del sel".format(x=cofr[0],y=cofr[1],z=cofr[2],model_id=model_id))
chimera_exe=find_exe("chimera")
subprocess.call(["chimera",check_path])
else:
info_dialog("Sorry, you need UCSF Chimera installed and accessible from the terminal for this to work!")
|