def update_object_list(self): """ update the internal state list """ # purge list of removed objects pubObj = self.cmd.get_names("public_objects") object_list_copy = self.object_list.copy() for x in object_list_copy: if x not in pubObj: del self.object_list[x] # for all VOLUME type objects not known to the list for x in self.cmd.get_names("public_objects"): if "object:volume"==cmd.get_type(x): if x not in self.object_list.keys(): if self.cmd.get_volume_is_updated(x) == 0: continue # make a default pair for this volume object tmpMap = VolumeHist(self.cmd.get_volume_histogram(x,self.cmd),nBins=64) tmpRamp = ColorRamp(360,name=x) self.object_list[x] = (tmpRamp,tmpMap) if self.ramp_update.has_key(x) and self.ramp_update[x]: tmpRamp.addColor(0, (0,0,1,0)) tmpRamp.addColor(359, (0,0,1,0)) for data, alpha, col, kind in self.ramp_update[x]: self.addWithoutGUINow(x, data, alpha, col, kind=kind) self.ramp_update[x] = [] tmpRamp.updateRamp() self.cmd.volume_color(x, tmpRamp.getRamp()) self.cmd.set_volume_ramp(x, tmpRamp.getRampList()) else: ramp_list = self.cmd.get_volume_ramp(x, self.cmd) if ramp_list: while ramp_list: tmpRamp.addColor(ramp_list[0], (ramp_list[1], ramp_list[2], ramp_list[3], ramp_list[4])) ramp_list = ramp_list[5:] else: tmpRamp.addColor(0, (0,0,1,0)) tmpRamp.addColor(359, (0,0,1,0)) tmpRamp.addColor(200, (0.0, 0.0, 1.0, 0.0)) tmpRamp.addColor(210, (0.0, 0.8, 1.0, 0.2)) tmpRamp.addColor(220, (0.0, 0.0, 1.0, 0.0)) else: # need to regenerate the histogram (tmpRamp,tmpMap) = self.object_list[x] tmpMap = VolumeHist(self.cmd.get_volume_histogram(x,self.cmd),nBins=64) self.object_list[x] = (tmpRamp,tmpMap) if len(self.object_list.keys())!=0: # guaranteed to exist k = self.object_list.keys()[0] self.active_ramp, self.active_map = self.object_list[k] self.active = k self.update_transferframe()
def volume_esp(name, map, stops=[0.1, 1.0], neg='red', pos='blue', opacity=0.2, quiet=1): ''' DESCRIPTION Create a volume object from a map object with default coloring for electrostatic potential (similar to positive and negative isosurface). ARGUMENTS name = string: name for the new volume object map = string: name of the map object to use stops = list of floats: 2 or 3 values in standard deviations for creating the volume ramp {default: [0.1, 1.0]} neg = string: color for negative volume {default: red} pos = string: color for positive volume {default: blue} opacity = float: maximum opacity in volume ramp {default: 0.2} SEE ALSO volume ''' from .setting import set_temporary opacity, quiet = float(opacity), int(quiet) if isinstance(stops, str): stops = cmd.safe_list_eval(stops) try: from pymol.colorramping import ColorRamp except ImportError: print(' Warning: volume_esp is deprecated') stdevD = cmd.get_volume_histogram(map, 0)[3] stops = [s * stdevD for s in stops] ramp = [ -stops[1], neg, opacity, -stops[0], neg, 0.0, stops[0], pos, 0.0, stops[1], pos, opacity, ] if len(stops) == 3: ramp = [-stops[2], neg, opacity] + ramp + [stops[2], pos, opacity] cmd.volume(name, map, ramp, quiet=quiet) return c_neg = cmd.get_color_tuple(neg) c_pos = cmd.get_color_tuple(pos) c_pos_0 = c_pos + (0.0,) c_pos_1 = c_pos + (opacity,) c_neg_0 = c_neg + (0.0,) c_neg_1 = c_neg + (opacity,) if len(stops) == 2: cstops = [(c_neg_1, -999), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]), (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_1, 999)] elif len(stops) == 3: cstops = [(c_neg_0, -999), (c_neg_0, -stops[2]), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]), (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_0, stops[2]), (c_pos_0, 999)] else: print(' Error: need 2 or 3 stops') raise CmdException cmd.volume(name, map, quiet=quiet) # get_volume_histogram returns zeros without refresh with set_temporary(suspend_updates='off'): cmd.refresh() minD, maxD, meanD, stdevD = cmd.get_volume_histogram(name)[:4] v_ramp = [] c_ramp = ColorRamp(360) for c, s in cstops: i = int(360 * ((s * stdevD) - minD) / (maxD - minD)) i = min(max(i, 0), 359) v_ramp.append(i) v_ramp.extend(c) c_ramp.addColor(i, c) cmd.set_volume_ramp(name, v_ramp) cmd.volume_color(name, c_ramp.getRamp()) cmd.recolor(name)
def volume_esp(name, map, stops=[0.1, 1.0], neg='red', pos='blue', opacity=0.2, quiet=1): ''' DESCRIPTION Create a volume object from a map object with default coloring for electrostatic potential (similar to positive and negative isosurface). ARGUMENTS name = string: name for the new volume object map = string: name of the map object to use stops = list of floats: 2 or 3 values in standard deviations for creating the volume ramp {default: [0.1, 1.0]} neg = string: color for negative volume {default: red} pos = string: color for positive volume {default: blue} opacity = float: maximum opacity in volume ramp {default: 0.2} SEE ALSO volume ''' from .setting import set_temporary opacity, quiet = float(opacity), int(quiet) if isinstance(stops, str): stops = cmd.safe_list_eval(stops) try: from pymol.colorramping import ColorRamp except ImportError: print(' Warning: volume_esp is deprecated') stdevD = cmd.get_volume_histogram(map, 0)[3] stops = [s * stdevD for s in stops] ramp = [ -stops[1], neg, opacity, -stops[0], neg, 0.0, stops[0], pos, 0.0, stops[1], pos, opacity, ] if len(stops) == 3: ramp = [-stops[2], neg, opacity] + ramp + [stops[2], pos, opacity] cmd.volume(name, map, ramp, quiet=quiet) return c_neg = cmd.get_color_tuple(neg) c_pos = cmd.get_color_tuple(pos) c_pos_0 = c_pos + (0.0, ) c_pos_1 = c_pos + (opacity, ) c_neg_0 = c_neg + (0.0, ) c_neg_1 = c_neg + (opacity, ) if len(stops) == 2: cstops = [(c_neg_1, -999), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]), (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_1, 999)] elif len(stops) == 3: cstops = [(c_neg_0, -999), (c_neg_0, -stops[2]), (c_neg_1, -stops[1]), (c_neg_0, -stops[0]), (c_pos_0, stops[0]), (c_pos_1, stops[1]), (c_pos_0, stops[2]), (c_pos_0, 999)] else: print(' Error: need 2 or 3 stops') raise CmdException cmd.volume(name, map, quiet=quiet) # get_volume_histogram returns zeros without refresh with set_temporary(suspend_updates='off'): cmd.refresh() minD, maxD, meanD, stdevD = cmd.get_volume_histogram(name)[:4] v_ramp = [] c_ramp = ColorRamp(360) for c, s in cstops: i = int(360 * ((s * stdevD) - minD) / (maxD - minD)) i = min(max(i, 0), 359) v_ramp.append(i) v_ramp.extend(c) c_ramp.addColor(i, c) cmd.set_volume_ramp(name, v_ramp) cmd.volume_color(name, c_ramp.getRamp()) cmd.recolor(name)
def update_object_list(self): """ update the internal state list """ # purge list of removed objects pubObj = self.cmd.get_names("public_objects") object_list_copy = self.object_list.copy() for x in object_list_copy: if x not in pubObj: del self.object_list[x] # for all VOLUME type objects not known to the list for x in self.cmd.get_names("public_objects"): if "object:volume" == cmd.get_type(x): if x not in self.object_list.keys(): if self.cmd.get_volume_is_updated(x) == 0: continue # make a default pair for this volume object tmpMap = VolumeHist(self.cmd.get_volume_histogram( x, self.cmd), nBins=64) tmpRamp = ColorRamp(360, name=x) self.object_list[x] = (tmpRamp, tmpMap) if self.ramp_update.has_key(x) and self.ramp_update[x]: tmpRamp.addColor(0, (0, 0, 1, 0)) tmpRamp.addColor(359, (0, 0, 1, 0)) for data, alpha, col, kind in self.ramp_update[x]: self.addWithoutGUINow(x, data, alpha, col, kind=kind) self.ramp_update[x] = [] tmpRamp.updateRamp() self.cmd.volume_color(x, tmpRamp.getRamp()) self.cmd.set_volume_ramp(x, tmpRamp.getRampList()) else: ramp_list = self.cmd.get_volume_ramp(x, self.cmd) if ramp_list: while ramp_list: tmpRamp.addColor(ramp_list[0], (ramp_list[1], ramp_list[2], ramp_list[3], ramp_list[4])) ramp_list = ramp_list[5:] else: tmpRamp.addColor(0, (0, 0, 1, 0)) tmpRamp.addColor(359, (0, 0, 1, 0)) tmpRamp.addColor(200, (0.0, 0.0, 1.0, 0.0)) tmpRamp.addColor(210, (0.0, 0.8, 1.0, 0.2)) tmpRamp.addColor(220, (0.0, 0.0, 1.0, 0.0)) else: # need to regenerate the histogram (tmpRamp, tmpMap) = self.object_list[x] tmpMap = VolumeHist(self.cmd.get_volume_histogram( x, self.cmd), nBins=64) self.object_list[x] = (tmpRamp, tmpMap) if len(self.object_list.keys()) != 0: # guaranteed to exist k = self.object_list.keys()[0] self.active_ramp, self.active_map = self.object_list[k] self.active = k self.update_transferframe()