# # Copy a series of map files to a single Chimera map (HDF5) file. # Use compression and optionally crop and threshold and change the value type # for each map. # # runscript compress.py *.mrc out.cmap 14,213,0,511,539,144 150 int16 1.5,1.5,2.4 # # The arguments are input map files, output map name, subregion bounds # (xmin,ymin,zmin,xmax,ymax,zmax), threshold, new value type, and grid spacing. # Arguments subregion, threshold, new value type, grid spacing can be # specified as the string none or omitted. # # This was written to compress map time series for Bessel beam cell motion # data from Lillian Fritz-Laylin. # def compress_maps(input_files, output_file, subregion = None, threshold = None, value_type = None, grid_spacing = None): for i,p in enumerate(input_files): run('open %s' % p) m = 0 # Model id number if subregion != 'none': run('vop scale #%d subregion %s' % (m, subregion)) m += 1 if threshold != 'none': run('vop threshold #%d min %s' % (m, threshold)) m += 1 if value_type != 'none': run('vop scale #%d valueType %s' % (m, value_type)) m += 1 if grid_spacing != 'none': run('volume #%d voxelSize %s' % (m, grid_spacing)) mp = chimera.openModels.list(id = m)[0] mp.data.name = '%04d' % i run('volume #%d save %s saveFormat cmap compress true append true' % (m, output_file)) run('close all') def run(command): from chimera import replyobj, runCommand replyobj.status(command) replyobj.info(command + '\n') runCommand(command) if not 'arguments' in locals() or len(arguments) < 2 or len(arguments) > 6: import Commands raise Commands.CommandError('Require 5 arguments: runscript compress.py ' ' ' ' ') import glob input_files = glob.glob(arguments[0]) input_files.sort() args = tuple((None if a == 'none' else a) for a in arguments[1:]) compress_maps(input_files, *args)