Little help to write a python script

I have previously written command scripts for chimera. Now, I need to do something more complicated that, I believe, is not possible to do from the command line. This is the task: I have a list of 100 electron density maps. 1- I want to display each map, one by one. 2- Change the default threshold. 3- Save an image of the current volume. 4- Close the current volume and open the next model. Has anyone done this before? An example of a python script that can do this or something similar could help me a lot. Thanks in advance.

Hi Eduardo, You are right you need a Python script -- there is no command to set density map threshold levels. I've attached a script to make map images. I threw in a bunch of optional lines to add color, smoothing, white background, ..., that you can just precede with a "#" character if you do not want them. There is also a much more complicated script for making images of maps that is used for the Virus Particle Explorer web site, producing for example: http://mmtsb1.scripps.edu/emdb/em_info_page.php?vipPDB=em_1115 You can get that script from the Chimera experimental features web page. Look for Virus EM Map Images: http://www.cgl.ucsf.edu/chimera/experimental/experimental.html I will be on vacation until June 6 - 27. Others on the chimera-users list may be able to help you if you have further script questions. Tom # ----------------------------------------------------------------------------- # Script to make images of maps at specific contour levels. # def make_map_image(map_path, level, image_path): from chimera import runCommand as run, viewer run('open ' + map_path) # Open map. # Set threshold level from VolumeViewer import volume_dialog d = volume_dialog(create = True) dr = d.focus_region dr.set_parameters(surface_levels = [level]) # Set contour level # Set some other display options color = (1,.8,.2,1) # Red, green, blue, opacity (0-1 scale). dr.set_parameters(surface_colors = [color]) ro = dr.rendering_options ro.surface_smoothing = True # Smoother surfaces. # dr.representation = 'mesh' # Mesh instead of a solid surface. # ro.square_mesh = True # Square mesh instead of triangles. d.show_data_regions([dr]) run('turn x 90') # Rotate 90 deg about x axis. run('set bg_color white') # White background color run('scale 1.5') # Zoom in. run('windowsize 512 512') # Set window size. viewer.showSilhouette = True # Surface edge highlights run('copy file %s png' % image_path) # Save image. # run('copy file %s png raytrace rtwait rtclean' % image_path) # Save raytraced image. run('close session') # ----------------------------------------------------------------------------- # map_dir = '/usr/local/src/chimera-demos/volume/emd' maps = (('emd_1007.map', 35.0), # File name and threshold ('emd_1046.map', 0.1), ('emd_1282.map', 0.15), ) image_dir = '/usr/local/src/chimera-demos/volume/emd/images' from os.path import join for map_file, level in maps: map_path = join(map_dir, map_file) image_file = map_file.split('.')[0] + '.png' # Replace suffix with .png image_path = join(image_dir, image_file) make_map_image(map_path, level, image_path)

Tom, I don't suppose there is a way to command chimera via python to crop regions and save them from a density map? I have been using Volume Viewer to define specific regions ('region min max...') and then cropping, and saving. I do this b/c it saves the proper origin for re-insertion into the map at a later time, and models I make with Path Tracer will also be properly oriented in the 'mother tomogram', etc. am I able to do the same thing via py script? have fun on your vacation, -Jeff -- ------------------------------------------------------------- Jeff Triffo Auer Group, Donner Lab, Lawrence Berkeley National Laboratory Raphael Group, Bioengineering Department, Rice University Medical Scientist Training Program (MSTP), Baylor College of Medicine phone (Berkeley): 510-486-7940 fax (Berkeley): 510-486-6488

Hi Jeff, Nearly everything Chimera does can be done from Python. Even the Chimera C++ code is called from Python. Attached is a script to save a subregion of a map. Tom # ----------------------------------------------------------------------------- # Script to open a map and save a rectangular subregion. The subregion origin # within the original map is saved so it will be placed in its original # location when both maps are opened in Chimera. # def save_subregion(map_path, ijk_min, ijk_max, subregion_path): from VolumeData import open_file, Grid_Subregion, mrc data = open_file(map_path) subregion_data = Grid_Subregion(data, ijk_min, ijk_max) mrc.write_mrc2000_grid_data(subregion_data, subregion_path) # ----------------------------------------------------------------------------- # map_path = '/usr/local/src/chimera-demos/volume/emd/emd_1007.map' ijk_min = (50,60,45) # Indices in map array. ijk_max = (70,75,91) # New map will be size (21,16,47). subreg_path = '/usr/local/src/chimera-demos/volume/emd/emd_1007_piece.map' save_subregion(map_path, ijk_min, ijk_max, subreg_path)
participants (3)
-
Eduardo Sanz Garcia
-
Tom Goddard
-
William Jeffrey Triffo