import chimera import MeasureVolume import VolumeViewer #read threshold level from active model #then set all the other models to that value om = chimera.openModels max_volume=1000000 model_active = VolumeViewer.active_volume() max_volume = MeasureVolume.surface_model_volume_and_area(model_active)[0] for model in om.list(): s = model.matrix_value_statistics(read_matrix = False) print 'matrix data statisctics = ', s # if s is None or s.minimum is None or s.maximum is None: # min_text = max_text = '?' # else: # min_text = float_format(s.minimum, 3) # max_text = float_format(s.maximum, 3) #print s.minimum, s.maximum # set the start to 3/4 towards one end # and then step size of 1/100 should do it coarse_step=10 step = float((s.maximum + s.minimum)/(2*coarse_step)) step_fine = float(step/100) level = model.surface_levels level[0] = s.maximum model.set_parameters(surface_levels = level) model.show() #returns volume, area, hole_count volume = MeasureVolume.surface_model_volume_and_area(model)[0] print volume, level #coarse volume threshold while volume < max_volume: print volume, level[0], max_volume, max_volume - volume, step level[0] = level[0] - step model.set_parameters(surface_levels = level) model.show() volume = MeasureVolume.surface_model_volume_and_area(model)[0] print volume, level[0], max_volume, max_volume - volume print #fine setting while volume > max_volume: print volume, level[0], max_volume, max_volume - volume, step level[0] = level[0] + step_fine model.set_parameters(surface_levels = level) model.show() volume = MeasureVolume.surface_model_volume_and_area(model)[0] print volume, level[0], max_volume, max_volume - volume print print '------------------------------------------------------------'