def load_grid(fname, prefix='aa', ramp='jet'): cmd.volume_ramp_new('ramp_jet', [ 0.00, 0.00, 0.00, 1.00, 0.00, 25.00, 0.06, 0.93, 1.00, 0.05, 50.00, 0.49, 0.51, 1.00, 0.15, 75.00, 1.00, 1.00, 0.00, 0.23, 90.00, 0.80, 0.18, 1.00, 0.48, 100.00, 0.98, 0.01, 1.00, 1.00, ]) cmd.volume_ramp_new('ramp_delta', [ -1.0, 1.00, 0.00, 0.00, 0.00, -0.4, 1.00, 1.00, 0.00, 1.0, -0.2, 1.00, 0.00, 0.00, 0.00, 0.2, 0.00, 0.00, 1.00, 0.00, 0.4, 0.00, 1.00, 1.00, 1.0, 1.0, 0.00, 0.00, 1.00, 0.00 ]) F = h5py.File(fname, 'r') grid = F['step'][()] origin = F['origin'][()] NUCS = set(F.keys()) protected = set(['origin', 'step', 'atypes']) NUCS -= protected for i in NUCS: data = F[i][()] b = Brick.from_numpy(data, grid, origin) bname = prefix + '_' + i cmd.load_brick(b, bname) volname = bname + '_volume' cmd.volume(volname, bname) cmd.volume_color(volname, 'ramp_jet')
def testVolColor(self): sele = 'vol1' mapname = 'map1' self._make_map(mapname) cmd.volume(sele, mapname) m = menu.vol_color(cmd, sele) # self._eval_first(m) m = menu.volume_hide(cmd, sele) self._eval_first(m) m = menu.volume_show(cmd, sele) self._eval_first(m)
def testVolume(self): ''' cmd.volume cmd.volume_color cmd.volume_ramp_new ''' self._sample_data() cmd.volume('vol', 'map', '2fofc') ramp = cmd.volume_color('vol') self.assertTrue(len(ramp) > 5) self.assertAlmostEqual(ramp[5], 1.0, delta=0.01) cmd.volume_ramp_new('named', [ 2.0, 'blue', .1, 3.0, 'yellow', .2]) cmd.volume_color('vol', 'named') ramp = cmd.volume_color('vol') self.assertEqual(len(ramp), 10) self.assertArrayEqual(ramp, [2., 0., 0., 1., .1, 3., 1., 1., 0., .2], delta=0.01)
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 testVolumePanel(self): self._sample_data() cmd.volume('vol', 'map') cmd.volume_panel('vol')
def load_grid(fname, prefix='aa', ramp='jet'): cmd.volume_ramp_new('ramp_DA', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.77, 0.77, 0.02, 50.00, 1.00, 0.54, 0.54, 0.06, 75.00, 1.00, 0.38, 0.38, 0.18, 90.00, 0.93, 0.00, 0.00, 0.60, 100.00, 0.70, 0.00, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_DG', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 0.77, 0.77, 1.00, 0.02, 50.00, 0.54, 0.54, 1.00, 0.06, 75.00, 0.38, 0.38, 1.00, 0.18, 90.00, 0.00, 0.00, 0.93, 0.60, 100.00, 0.00, 0.00, 0.70, 1.00, ]) cmd.volume_ramp_new('ramp_DC', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 0.64, 1.00, 0.61, 0.02, 50.00, 0.48, 1.00, 0.47, 0.06, 75.00, 0.26, 1.00, 0.28, 0.18, 90.00, 0.04, 0.85, 0.00, 0.44, 100.00, 0.00, 0.52, 0.06, 1.00, ]) cmd.volume_ramp_new('ramp_DT', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.99, 0.55, 0.02, 50.00, 1.00, 0.98, 0.46, 0.06, 75.00, 1.00, 0.99, 0.37, 0.19, 90.00, 0.92, 0.92, 0.00, 0.39, 100.00, 0.76, 0.73, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_P', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.95, 0.93, 0.02, 50.00, 1.00, 0.85, 0.69, 0.06, 75.00, 1.00, 0.78, 0.55, 0.19, 90.00, 1.00, 0.66, 0.30, 0.39, 100.00, 0.97, 0.50, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_jet', [ 0.00, 0.00, 0.00, 1.00, 0.00, 25.00, 0.06, 0.93, 1.00, 0.05, 50.00, 0.49, 0.51, 1.00, 0.15, 75.00, 1.00, 1.00, 0.00, 0.23, 90.00, 0.80, 0.18, 1.00, 0.48, 100.00, 0.98, 0.01, 1.00, 1.00, ]) cmd.volume_ramp_new('ramp_delta', [ -1.0, 1.00, 0.00, 0.00, 0.00, -0.4, 1.00, 1.00, 0.00, 1.0, -0.2, 1.00, 0.00, 0.00, 0.00, 0.2, 0.00, 0.00, 1.00, 0.00, 0.4, 0.00, 1.00, 1.00, 1.0, 1.0, 0.00, 0.00, 1.00, 0.00 ]) F = h5py.File(fname, 'r') # load step along every axis # step = np.array([1.0, 1.0, 1.0]) step = F['step'][()] # load origin of grid # origin = np.array([0.0, 0.0, 0.0]) origin = F['origin'][()] NUCS = set(F.keys()) protected = set(['origin', 'step', 'atypes']) NUCS -= protected for i in NUCS: # load data: 3D array data = F[i][()] # Create brick b = Brick.from_numpy(data, step, origin) bname = prefix + '_' + i # load brick into pymol cmd.load_brick(b, bname) volname = bname + '_volume' # assign ramp to the brick cmd.volume(volname, bname) if ramp == 'nuc': cmd.volume_color(volname, 'ramp_' + i) elif ramp == 'delta': cmd.volume_color(volname, 'ramp_delta') else: cmd.volume_color(volname, 'ramp_jet')
def load_meta_grid(fname, prefix='meta'): F = h5py.File(fname, 'r') step = F['step'][()] origin = F['origin'][()] NUCS = set(F.keys()) protected = set(['origin', 'step', 'atypes']) NUCS -= protected for i in NUCS: data = F[i][()] b = Brick.from_numpy(data, step, origin) bname = prefix + '_' + i cmd.load_brick(b, bname) volname = bname + '_volume' d_min = np.min(data) d_max = np.max(data) v = np.linspace(d_min, d_max, 6) cmd.volume(volname, bname) print('ramp_%s' % i) cmd.volume_ramp_new('ramp_grid', [ v[0], 0.00, 0.00, 1.00, 0.70, v[1], 0.06, 0.93, 1.00, 0.50, v[2], 0.49, 0.51, 1.00, 0.30, v[3], 1.00, 1.00, 0.00, 0.10, v[4], 0.80, 0.18, 1.00, 0.05, v[5], 0.98, 0.01, 1.00, 0.00, ]) cmd.volume_color(volname, 'ramp_grid')
def load_sites(fname, prefix='sites', ramp='jet', top=42): cmd.volume_ramp_new('ramp_DA', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.77, 0.77, 0.02, 50.00, 1.00, 0.54, 0.54, 0.06, 75.00, 1.00, 0.38, 0.38, 0.18, 90.00, 0.93, 0.00, 0.00, 0.60, 100.00, 0.70, 0.00, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_DG', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 0.77, 0.77, 1.00, 0.02, 50.00, 0.54, 0.54, 1.00, 0.06, 75.00, 0.38, 0.38, 1.00, 0.18, 90.00, 0.00, 0.00, 0.93, 0.60, 100.00, 0.00, 0.00, 0.70, 1.00, ]) cmd.volume_ramp_new('ramp_DC', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 0.64, 1.00, 0.61, 0.02, 50.00, 0.48, 1.00, 0.47, 0.06, 75.00, 0.26, 1.00, 0.28, 0.18, 90.00, 0.04, 0.85, 0.00, 0.44, 100.00, 0.00, 0.52, 0.06, 1.00, ]) cmd.volume_ramp_new('ramp_DT', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.99, 0.55, 0.02, 50.00, 1.00, 0.98, 0.46, 0.06, 75.00, 1.00, 0.99, 0.37, 0.19, 90.00, 0.92, 0.92, 0.00, 0.39, 100.00, 0.76, 0.73, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_P', [ 0.00, 1.00, 1.00, 1.00, 0.00, 25.00, 1.00, 0.95, 0.93, 0.02, 50.00, 1.00, 0.85, 0.69, 0.06, 75.00, 1.00, 0.78, 0.55, 0.19, 90.00, 1.00, 0.66, 0.30, 0.39, 100.00, 0.97, 0.50, 0.00, 1.00, ]) cmd.volume_ramp_new('ramp_jet', [ 0.00, 0.00, 0.00, 1.00, 0.00, 25.00, 0.06, 0.93, 1.00, 0.05, 50.00, 0.49, 0.51, 1.00, 0.15, 75.00, 1.00, 1.00, 0.00, 0.23, 90.00, 0.80, 0.18, 1.00, 0.48, 100.00, 0.98, 0.01, 1.00, 1.00, ]) cmd.volume_ramp_new('ramp_delta', [ -1.0, 1.00, 0.00, 0.00, 0.00, -0.4, 1.00, 1.00, 0.00, 1.0, -0.2, 1.00, 0.00, 0.00, 0.00, 0.2, 0.00, 0.00, 1.00, 0.00, 0.4, 0.00, 1.00, 1.00, 1.0, 1.0, 0.00, 0.00, 1.00, 0.00 ]) F = h5py.File(fname, 'r') NUCS = natsort.natsorted(F.keys()) if int(top) < 1: print('top should be greater than 1') return top_ = min(int(top), len(NUCS)) NUCS_ = NUCS[:top_] for i in NUCS_: data = F[i]['data'][()] origin = F[i]['origin'][()] step = F[i]['step'][()] b = Brick.from_numpy(data, step, origin) bname = prefix + '_' + i cmd.load_brick(b, bname) volname = bname + '_volume' cmd.volume(volname, bname) cmd.volume_color(volname, 'ramp_' + ramp)