def random_ellipsoid(box, size, min_axis): # return a random ellipsoid record of the form: # [ ELLIPSOID, x_pos, y_pos, z_pos, size, x0, y0, z0, x1, y1, z2, x2, y2, z2 ] # where the xyz vectors are orthogonal and of length 1.0 or less. box = box - size tmp0 = cpv.random_vector() tmp1 = cpv.random_vector() tmp2 = cpv.cross_product(tmp1, tmp0) tmp3 = cpv.cross_product(tmp1, tmp2) tmp4 = cpv.cross_product(tmp2, tmp3) tmp2 = cpv.normalize(tmp2) tmp3 = cpv.normalize(tmp3) tmp4 = cpv.normalize(tmp4) primary = cpv.scale(tmp2, random()) secondary = cpv.scale(tmp3,random()) tertiary = cpv.scale(tmp4,random()) factor = 1.0 / max( cpv.length(primary), cpv.length(secondary), cpv.length(tertiary)) primary = cpv.scale(primary, factor) secodary = cpv.scale(secondary, factor) tertiary = cpv.scale(tertiary, factor) return [ ELLIPSOID, size + random() * box, size + random() * box, size + random() * box, max(random() * size, min_axis), ] + primary + secondary + tertiary
def planeFromPoints(point1, point2, point3, facetSize): v1 = cpv.normalize(cpv.sub(point2, point1)) v2 = cpv.normalize(cpv.sub(point3, point1)) normal = cpv.cross_product(v1, v2) v2 = cpv.cross_product(normal, v1) x = cpv.scale(v1, facetSize) y = cpv.scale(v2, facetSize) center = point2 corner1 = cpv.add(cpv.add(center, x), y) corner2 = cpv.sub(cpv.add(center, x), y) corner3 = cpv.sub(cpv.sub(center, x), y) corner4 = cpv.add(cpv.sub(center, x), y) return plane(corner1, corner2, corner3, corner4, normal)
def planeFromPoints(p1, p2, p3, vm1=None, vm2=None, center=True, settings={}): v1 = cpv.sub(p1, p2) v2 = cpv.sub(p3, p2) normal = cpv.cross_product(v1, v2) if 'translate' in settings: vtran = cpv.scale(cpv.normalize(normal), settings['translate']) p1_t = cpv.sub(p1, vtran) p2_t = cpv.sub(p2, vtran) p3_t = cpv.sub(p3, vtran) print("New coordinates are:") print_info("New", p1_t, p2_t, p3_t) print("New coordinates are for normalized plane:") v1_t = cpv.normalize(cpv.sub(p1_t, p2_t)) v2_t = cpv.normalize(cpv.sub(p3_t, p2_t)) normal_t = cpv.normalize(cpv.cross_product(v1_t, v2_t)) v2_t = cpv.normalize(cpv.cross_product(normal_t, v1_t)) p1_t2 = cpv.add(v1_t, p2_t) p3_t2 = cpv.add(v2_t, p2_t) print_info("Newnormal", p1_t2, p2_t, p3_t2) if vm1 != None: v1 = cpv.scale(cpv.normalize(v1), vm1) if vm2 != None: v2 = cpv.scale(cpv.normalize(v2), vm2) centrum = p2 if center: corner1 = cpv.add(cpv.add(centrum, v1), v2) corner2 = cpv.sub(cpv.add(centrum, v1), v2) corner3 = cpv.sub(cpv.sub(centrum, v1), v2) corner4 = cpv.add(cpv.sub(centrum, v1), v2) else: corner1 = cpv.add(cpv.add(centrum, v1), v2) corner2 = cpv.add(centrum, v1) corner3 = centrum corner4 = cpv.add(centrum, v2) return plane(corner1, corner2, corner3, corner4, normal, settings)
def _cgo_quad(pos, normal, radius): '''Return a CGO list specifying a quad.''' v1 = cpv.normalize(_perp_vec(normal)) v2 = cpv.cross_product(normal, v1) v1 = cpv.scale(v1, radius) v2 = cpv.scale(v2, radius) obj = [cgo.BEGIN, cgo.TRIANGLE_STRIP, cgo.NORMAL] obj.extend(normal) obj.append(cgo.VERTEX) obj.extend(cpv.add(pos, v1)) obj.append(cgo.VERTEX) obj.extend(cpv.add(pos, v2)) obj.append(cgo.VERTEX) obj.extend(cpv.sub(pos, v2)) obj.append(cgo.VERTEX) obj.extend(cpv.sub(pos, v1)) obj.append(cgo.END) return obj
def _cgo_quad(pos, normal, radius): '''Return a CGO list specifying a quad.''' v1 = cpv.normalize(_perp_vec(normal)) v2 = cpv.cross_product(normal, v1) v1 = cpv.scale(v1, radius) v2 = cpv.scale(v2, radius) obj = [ cgo.BEGIN, cgo.TRIANGLE_STRIP, cgo.NORMAL] obj.extend(normal) obj.append(cgo.VERTEX) obj.extend(cpv.add(pos, v1)) obj.append(cgo.VERTEX) obj.extend(cpv.add(pos, v2)) obj.append(cgo.VERTEX) obj.extend(cpv.sub(pos, v2)) obj.append(cgo.VERTEX) obj.extend(cpv.sub(pos, v1)) obj.append(cgo.END) return obj
def append_tri(self): if self.l_vert: d0 = cpv.sub(self.l_vert[0],self.l_vert[1]) d1 = cpv.sub(self.l_vert[0],self.l_vert[2]) n0 = cpv.cross_product(d0,d1) n0 = cpv.normalize_failsafe(n0) if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 indices = [0, 1, 2] if not self.l_norm: # TODO could simplify this if ray tracing would support # object-level two_sided_lighting. Duplicating the # face with an offset is a hack and produces visible # lines on edges. n1 = [-n0[0],-n0[1],-n0[2]] ns = cpv.scale(n0,0.002) indices = [0, 1, 2, 4, 3, 5] l_vert_offsetted = [cpv.add(v, ns) for v in self.l_vert] l_vert_offsetted.extend(cpv.sub(v, ns) for v in self.l_vert) self.l_vert = l_vert_offsetted self.l_norm = [n0, n0, n0, n1, n1, n1] elif cpv.dot_product(self.l_norm[0], n0) < 0: indices = [0, 2, 1] for i in indices: self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[i % 3]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[i]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[i]) self.l_vert=None self.t_colr=None self.l_norm=None
def append_tri(self): if self.l_vert: d0 = cpv.sub(self.l_vert[0],self.l_vert[1]) d1 = cpv.sub(self.l_vert[0],self.l_vert[2]) n0 = cpv.cross_product(d0,d1) n0 = cpv.normalize_failsafe(n0) if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 indices = [0, 1, 2] if not self.l_norm: # TODO could simplify this if ray tracing would support # object-level two_sided_lighting. Duplicating the # face with an offset is a hack and produces visible # lines on edges. n1 = [-n0[0],-n0[1],-n0[2]] ns = cpv.scale(n0,0.002) indices = [0, 1, 2, 4, 3, 5] l_vert_offsetted = [cpv.add(v, ns) for v in self.l_vert] l_vert_offsetted.extend(cpv.sub(v, ns) for v in self.l_vert) self.l_vert = l_vert_offsetted self.l_norm = [n0, n0, n0, n1, n1, n1] elif cpv.dot_product(self.l_norm[0], n0) < 0: indices = [0, 2, 1] for i in indices: self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[i % 3]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[i]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[i]) self.l_vert=None self.t_colr=None self.l_norm=None
def compute_surface_normals(): ''' Compute average normals from all adjacent triangles on each vertex ''' from functools import reduce # don't use cpv.normalize which has an RSMALL4 limit normalize = lambda v: cpv.scale(v, 1. / cpv.length(v)) for face in table['face']: if 'vertex_index' in face: indices = face['vertex_index'] elif 'vertex_indices' in face: indices = face['vertex_indices'] else: return f_vert = [vertices[i] for i in indices] f_xyz = [(v['x'], v['y'], v['z']) for v in f_vert] try: normal = normalize(cpv.cross_product( cpv.sub(f_xyz[1], f_xyz[0]), cpv.sub(f_xyz[2], f_xyz[1]))) except ZeroDivisionError: continue for v in f_vert: v.setdefault('normals', []).append(normal) for v in vertices: try: v['nx'], v['ny'], v['nz'] = normalize( reduce(cpv.add, v.pop('normals'))) except (KeyError, ZeroDivisionError): continue
def compute_surface_normals(): ''' Compute average normals from all adjacent triangles on each vertex ''' from functools import reduce # don't use cpv.normalize which has an RSMALL4 limit normalize = lambda v: cpv.scale(v, 1. / cpv.length(v)) for face in table['face']: if 'vertex_index' in face: indices = face['vertex_index'] elif 'vertex_indices' in face: indices = face['vertex_indices'] else: return f_vert = [vertices[i] for i in indices] f_xyz = [(v['x'], v['y'], v['z']) for v in f_vert] try: normal = normalize(cpv.cross_product( cpv.sub(f_xyz[1], f_xyz[0]), cpv.sub(f_xyz[2], f_xyz[1]))) except ZeroDivisionError: continue for v in f_vert: v.setdefault('normals', []).append(normal) for v in vertices: try: v['nx'], v['ny'], v['nz'] = normalize( reduce(cpv.add, v.pop('normals'))) except (KeyError, ZeroDivisionError): continue
def torus(center=(0., 0., 0.), normal=(0., 0., 1.), radius=1., color='', cradius=.25, samples=20, csamples=20): ''' Generate and return a torus CGO with given center, normal and ring radius. ''' from math import cos, sin, pi if color and isinstance(color, str): color = list(cmd.get_color_tuple(color)) obj = [] axis = cpv.cross_product(normal, (0., 0., 1.)) angle = -cpv.get_angle(normal, (0., 0., 1.)) matrix = cpv.rotation_matrix(angle, cpv.normalize(axis)) obj_vertex = lambda x, y, z: obj.extend([VERTEX] + cpv.add(center, cpv.transform(matrix, [x, y, z]))) obj_normal = lambda x, y, z: obj.extend([NORMAL] + cpv.transform(matrix, [x, y, z])) r = radius cr = cradius rr = 1.5 * cr dv = 2 * pi / csamples dw = 2 * pi / samples v = 0.0 w = 0.0 while w < 2 * pi: v = 0.0 c_w = cos(w) s_w = sin(w) c_wdw = cos(w + dw) s_wdw = sin(w + dw) obj.append(BEGIN) obj.append(TRIANGLE_STRIP) if color: obj.append(COLOR) obj.extend(color) while v < 2 * pi + dv: c_v = cos(v) s_v = sin(v) c_vdv = cos(v + dv) s_vdv = sin(v + dv) obj_normal( (r + rr * c_v) * c_w - (r + cr * c_v) * c_w, (r + rr * c_v) * s_w - (r + cr * c_v) * s_w, (rr * s_v - cr * s_v)) obj_vertex( (r + cr * c_v) * c_w, (r + cr * c_v) * s_w, cr * s_v) obj_normal( (r + rr * c_vdv) * c_wdw - (r + cr * c_vdv) * c_wdw, (r + rr * c_vdv) * s_wdw - (r + cr * c_vdv) * s_wdw, rr * s_vdv - cr * s_vdv) obj_vertex( (r + cr * c_vdv) * c_wdw, (r + cr * c_vdv) * s_wdw, cr * s_vdv) v += dv obj.append(END) w += dw return obj
def planeFromPoints(point1, point2, point3, facetSize): corner1 = point1 corner2 = point2 corner3 = point3 normal = cpv.cross_product(corner1, corner2) return triangle(corner1, corner2, corner3, normal)
def torus(center=(0., 0., 0.), normal=(0., 0., 1.), radius=1., color='', cradius=.25, samples=20, csamples=20, _self=cmd): ''' Generate and return a torus CGO with given center, normal and ring radius. ''' from math import cos, sin, pi if color and isinstance(color, str): color = list(_self.get_color_tuple(color)) obj = [] axis = cpv.cross_product(normal, (0., 0., 1.)) angle = -cpv.get_angle(normal, (0., 0., 1.)) matrix = cpv.rotation_matrix(angle, cpv.normalize(axis)) obj_vertex = lambda x, y, z: obj.extend([VERTEX] + cpv.add(center, cpv.transform(matrix, [x, y, z]))) obj_normal = lambda x, y, z: obj.extend([NORMAL] + cpv.transform(matrix, [x, y, z])) r = radius cr = cradius rr = 1.5 * cr dv = 2 * pi / csamples dw = 2 * pi / samples v = 0.0 w = 0.0 while w < 2 * pi: v = 0.0 c_w = cos(w) s_w = sin(w) c_wdw = cos(w + dw) s_wdw = sin(w + dw) obj.append(BEGIN) obj.append(TRIANGLE_STRIP) if color: obj.append(COLOR) obj.extend(color) while v < 2 * pi + dv: c_v = cos(v) s_v = sin(v) c_vdv = cos(v + dv) s_vdv = sin(v + dv) obj_normal( (r + rr * c_v) * c_w - (r + cr * c_v) * c_w, (r + rr * c_v) * s_w - (r + cr * c_v) * s_w, (rr * s_v - cr * s_v)) obj_vertex( (r + cr * c_v) * c_w, (r + cr * c_v) * s_w, cr * s_v) obj_normal( (r + rr * c_vdv) * c_wdw - (r + cr * c_vdv) * c_wdw, (r + rr * c_vdv) * s_wdw - (r + cr * c_vdv) * s_wdw, rr * s_vdv - cr * s_vdv) obj_vertex( (r + cr * c_vdv) * c_wdw, (r + cr * c_vdv) * s_wdw, cr * s_vdv) v += dv obj.append(END) w += dw return obj
def append_tri(self): if self.l_vert and not self.l_norm: d0 = cpv.sub(self.l_vert[0], self.l_vert[1]) d1 = cpv.sub(self.l_vert[0], self.l_vert[2]) n0 = cpv.cross_product(d0, d1) n0 = cpv.normalize_failsafe(n0) n1 = [-n0[0], -n0[1], -n0[2]] ns = cpv.scale(n0, 0.002) if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[0], ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[1], ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[2], ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[0], ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[1], ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[2], ns)) elif self.l_vert and self.t_colr and self.l_norm: if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[0]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[0]) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[1]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[1]) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[2]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[2]) self.l_vert = None self.t_colr = None self.l_norm = None
def append_tri(self): if self.l_vert and not self.l_norm: d0 = cpv.sub(self.l_vert[0],self.l_vert[1]) d1 = cpv.sub(self.l_vert[0],self.l_vert[2]) n0 = cpv.cross_product(d0,d1) n0 = cpv.normalize_failsafe(n0) n1 = [-n0[0],-n0[1],-n0[2]] ns = cpv.scale(n0,0.002) if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[0],ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[1],ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(n0) self.obj.append(VERTEX) self.obj.extend(cpv.add(self.l_vert[2],ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[0],ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[1],ns)) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(n1) self.obj.append(VERTEX) self.obj.extend(cpv.sub(self.l_vert[2],ns)) elif self.l_vert and self.t_colr and self.l_norm: if not self.tri_flag: self.obj.append(BEGIN) self.obj.append(TRIANGLES) self.tri_flag = 1 self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[0]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[0]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[0]) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[1]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[1]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[1]) self.obj.append(COLOR) # assuming unicolor self.obj.extend(self.t_colr[2]) self.obj.append(NORMAL) self.obj.extend(self.l_norm[2]) self.obj.append(VERTEX) self.obj.extend(self.l_vert[2]) self.l_vert=None self.t_colr=None self.l_norm=None
def read_moestr(contents, object, state=0, finish=1, discrete=1, quiet=1, zoom=-1, _self=cmd): moestr = contents name = object import sys if sys.version_info[0] > 2 and isinstance(moestr, bytes): moestr = moestr.decode() cmd = _self mr = MOEReader() mr.appendFromStr(moestr) split_chains = cmd.get_setting_int("moe_separate_chains") cmd.group(name) if hasattr(mr, 'system'): have_valences = 0 chain_count = 0 cmd.set_color("_aseg0", [1.0, 1.0, 1.0]) aseg_color = cmd.get_color_index("_aseg0") aseg_flag = 0 aseg_rep = {} model = Indexed() molecule = mr.system['molecule'] if 'atoms' in molecule: n_atom = molecule['atoms'] model.atom = [Atom() for x in range(n_atom)] residues = {} chains = {} for columns, data in molecule['attr']: for row in data: cur_atom = None for key, value in zip(columns, row): key = key[0] if key == 'ID': ID = value else: aProp = _atom_prop_map.get(key, None) if aProp != None: setattr(model.atom[ID - 1], aProp, value) else: xyz = _atom_coord_map.get(key, None) if xyz != None: coord = list(model.atom[ID - 1].coord) coord[xyz] = value model.atom[ID - 1].coord = coord elif key in _atom_vis_map: atom = model.atom[ID - 1] if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible if key == 'aBondLook': if value == 'cylinder': atom.visible = 0x00000001 | visible elif value == 'line': atom.visible = 0x00000080 | visible elif value == 'none': atom.visible = -129 & Visible # 0xFFFFFF7F elif key == 'aNucleusLook': if value == 'sphere': atom.visible = 0x00000002 | visible elif value == 'small-sphere': # need to set sphere_scale=0.2 for these atoms atom.visible = 0x00000002 | visible atom.sphere_scale = 0.2 elif value == 'point': # nonbonded atom.visible = 0x00000800 | visible elif value == 'none': atom.visible = -2067 & visible # 0xFFFFF7ED elif key == 'aHidden': atom.visible = 0 atom.hidden = 1 if hasattr( atom, 'hidden' ): # be sure that hidden atoms aren't shown atom.visible = 0 elif key in _atom_color_map: if key == 'aRGB': model.atom[ID - 1].trgb = value elif key == 'aColorBy': model.atom[ID - 1].aColorBy = value elif key in _atom_label_map: atom = model.atom[ID - 1] if hasattr(atom, 'label_dict'): atom.label_dict[key] = None else: atom.label_dict = {key: None} elif key in _residue_prop_map: resi_dict = residues.get(ID, {}) resi_dict[key] = value residues[ID] = resi_dict elif key in _chain_prop_map: chain_dict = chains.get(ID, {}) if ID not in chains: chain_count = chain_count + 1 chain_dict['count'] = chain_count chain_dict[key] = value chains[ID] = chain_dict chn_keys = list(chains.keys()) chn_keys.sort() res_keys = list(residues.keys()) res_keys.sort() # map chain properties onto residues chn_resi = 0 ch_colors = copy.deepcopy(_ch_colors) unique_chain_names = {} for chn_idx in chn_keys: chain_dict = chains[chn_idx] cName = make_valid_name(chain_dict.get('cName', '')) segi = cName[0:4] chain = cName[-1:] if not len(cName): if 'count' in chain_dict: cName = "chain_" + str(chain_dict['count']) else: cName = str(chn_idx) if cName not in unique_chain_names: unique_chain_names[cName] = cName else: cnt = 2 while (cName + "_" + str(cnt)) in unique_chain_names: cnt = cnt + 1 newCName = cName + "_" + str(cnt) unique_chain_names[newCName] = cName cName = newCName chain_dict['chain_color'] = ch_colors[0] ch_colors = ch_colors[1:] + [ch_colors[0]] cResCount = chain_dict.get('cResidueCount', 0) for res_idx in range(chn_resi, chn_resi + cResCount): resi_dict = residues[res_keys[res_idx]] resi_dict['chain'] = chain resi_dict['segi'] = segi resi_dict['cName'] = cName resi_dict['chain_dict'] = chain_dict chn_resi = chn_resi + cResCount # map residue properties onto atoms res_atom = 0 for res_idx in res_keys: resi_dict = residues[res_idx] rRibbonMode = resi_dict.get('rRibbonMode', 'none') rAtomCount = resi_dict['rAtomCount'] rType = resi_dict.get('rType', '') if rAtomCount > 0: for at_idx in range(res_atom, res_atom + rAtomCount): atom = model.atom[at_idx] setattr( atom, 'resi', string.strip( str(resi_dict.get('rUID', '')) + resi_dict.get('rINS', ''))) setattr(atom, 'resn', resi_dict.get('rName', '')) setattr(atom, 'chain', resi_dict.get('chain', '')) setattr(atom, 'segi', resi_dict.get('segi', '')) setattr(atom, 'custom', resi_dict.get('cName', '')) # add labels if hasattr(atom, 'label_dict'): label = '' label_dict = atom.label_dict if 'aLabelElement' in label_dict: label = atom.symbol if 'aLabelRes' in label_dict: if len(label): label = label + "," label = label + atom.resn + "_" + atom.resi if 'aLabelName' in label_dict: if len(label): label = label + "." label = label + atom.name atom.label = label if rType not in ['none', 'heme']: atom.hetatm = 0 # all normal atoms else: atom.flags = 0x02000000 # hetatom or ligand -- ignore when surfacing if rRibbonMode != 'none': if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible rRibbonColorBy = resi_dict['rRibbonColorBy'] repeat = 1 while repeat: repeat = 0 if rRibbonColorBy in ['rgb', 'r:rgb' ]: # handled automatically pass elif rRibbonColorBy == 'chain': chain_dict = resi_dict['chain_dict'] cColorBy = chain_dict['cColorBy'] if cColorBy == 'rgb': cColorBy = 'c:rgb' rRibbonColorBy = cColorBy repeat = 1 rRibbon_color = 0 rRibbon_trgb = 0xFFFFFF # default -- white # now color ribbon if rRibbonColorBy == 'r:rgb': rRibbon_trgb = resi_dict.get('rRGB', 0xFFFFFF) elif rRibbonColorBy == 'rgb': rRibbon_trgb = resi_dict.get( 'rRibbonRGB', 0xFFFFFF) elif rRibbonColorBy == 'c:rgb': chain_dict = resi_dict['chain_dict'] rRibbon_trgb = chain_dict.get('cRGB', 0xFFFFFF) elif rRibbonColorBy == 'r:aseg': rRibbon_trgb = None rRibbon_color = aseg_color aseg_flag = 1 elif rRibbonColorBy == 'tempfactor': pass # TO DO elif rRibbonColorBy == 'c:number': # per chain colors rRibbon_trgb = chain_dict['chain_color'] if rRibbonMode in ['line', 'trace']: atom.visible = 0x00000040 | visible # PyMOL ribbon if rRibbon_trgb != None: atom.ribbon_trgb = rRibbon_trgb else: atom.ribbon_color = rRibbon_color aseg_rep['ribbon'] = 1 else: atom.visible = 0x00000020 | visible # PyMOL cartoon if rRibbon_trgb != None: atom.cartoon_trgb = rRibbon_trgb else: atom.cartoon_color = rRibbon_color aseg_rep['cartoon'] = 1 if hasattr(atom, 'label'): if hasattr(atom, 'visible'): visible = atom.visible else: visible = _default_visible atom.visible = 0x00000028 | visible # labels if not hasattr(atom, 'aColorBy'): atom.aColorBy = 'element' if hasattr(atom, 'aColorBy'): aColorBy = atom.aColorBy repeat = 1 while repeat: repeat = 0 if aColorBy == 'ribbon': aColorBy = resi_dict.get('rRibbonColorBy') if aColorBy == 'rgb': aColorBy = 'rib:rgb' else: repeat = 1 # TO DO still need to handle "cartoon_color", "ribbon_color" elif aColorBy == 'element': if hasattr(atom, 'trgb'): del atom.trgb elif aColorBy in ['rgb', 'a:rgb' ]: # handled automatically pass elif aColorBy == 'residue': rColorBy = resi_dict.get('rColorBy') if rColorBy == 'rgb': rColorBy = 'r:rgb' aColorBy = rColorBy repeat = 1 elif aColorBy == 'chain': chain_dict = resi_dict['chain_dict'] cColorBy = chain_dict['cColorBy'] if cColorBy == 'rgb': cColorBy = 'c:rgb' aColorBy = cColorBy repeat = 1 # now color atom... if aColorBy == 'r:rgb': atom.trgb = resi_dict.get('rRGB', 0xFFFFFF) elif aColorBy == 'rib:rgb': atom.trgb = resi_dict.get('rRibbonRGB', 0xFFFFFF) elif aColorBy == 'c:rgb': chain_dict = resi_dict['chain_dict'] atom.trgb = chain_dict.get('cRGB', 0xFFFFFF) elif aColorBy == 'r:aseg': pass # TO DO elif aColorBy == 'tempfactor': pass # TO DO elif aColorBy == 'c:number': # per chain colors atom.trgb = chain_dict['chain_color'] res_atom = res_atom + rAtomCount bond_list = molecule.get('bond', []) for bond in bond_list: new_bond = Bond() new_bond.index = [bond[0] - 1, bond[1] - 1] if len(bond) > 2: new_bond.order = bond[2] if bond[2] == 2: # work around .MOE bug with triple bonds if model.atom[new_bond.index[0]].hybridization == 'sp': if model.atom[new_bond.index[1]].hybridization == 'sp': new_bond.order = 3 have_valences = 1 model.bond.append(new_bond) if 'ViewOrientationY' in mr.system: vy = mr.system['ViewOrientationY'] vz = mr.system['ViewOrientationZ'] pos = mr.system['ViewLookAt'] scale = mr.system['ViewScale'] vx = cpv.cross_product(vy, vz) m = [cpv.normalize(vx), cpv.normalize(vy), cpv.normalize(vz)] m = cpv.transpose(m) asp_rat = 0.8 # MOE default (versus 0.75 for PyMOL) cmd.set("field_of_view", 25.0) fov = float(cmd.get("field_of_view")) window_height = scale * asp_rat dist = (0.5 * window_height) / math.atan(3.1415 * (0.5 * fov) / 180.0) new_view = tuple(m[0] + m[1] + m[2] + [0.0, 0.0, -dist] + pos + [dist * 0.5, dist * 1.5, 0.0]) cmd.set_view(new_view) zoom = 0 cmd.set("auto_color", 0) cmd.set_color("carbon", [0.5, 0.5, 0.5]) # default MOE grey obj_name = name + ".system" if split_chains < 0: # by default, don't split chains if over 50 objects would be created if len(unique_chain_names) > 50: split_chains = 0 if not split_chains: cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=quiet, zoom=zoom) obj_name_list = [obj_name] else: cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=1, zoom=zoom) obj_name_list = [] system_name = obj_name for chain in unique_chain_names.keys(): obj_name = name + "." + chain obj_name_list.append(obj_name) cmd.select("_moe_ext_tmp", "custom %s" % chain, domain=system_name) cmd.extract(obj_name, "_moe_ext_tmp", quiet=quiet, zoom=0) # cmd.extract(obj_name,system_name+" and text_type %s"%chain,quiet=quiet) cmd.delete("_moe_ext_tmp") if not cmd.count_atoms(system_name): cmd.delete(system_name) else: obj_name_list.append(system_name) cmd.order(name + ".*", sort=1) for obj_name in obj_name_list: cmd.set("stick_radius", 0.1, obj_name) cmd.set("line_width", 2.0, obj_name) cmd.set("label_color", "white", obj_name) cmd.set("nonbonded_size", 0.05, obj_name) # temporary workaround... if have_valences: # if this MOE file has valences, then show em! cmd.set("valence", 1, obj_name) cmd.set("stick_valence_scale", 1.25, obj_name) if aseg_flag: cmd.dss(obj_name) if 'cartoon' in aseg_rep: cmd.set("cartoon_color", "red", obj_name + " and cartoon_color _aseg0 and ss h") cmd.set("cartoon_color", "yellow", obj_name + " and cartoon_color _aseg0 and ss s") cmd.set( "cartoon_color", "cyan", obj_name + " and cartoon_color _aseg0 and not ss h+s") if 'ribbon' in aseg_rep: cmd.set("ribbon_color", "red", obj_name + " and ribbon_color _aseg0 and ss h" ) # need selection op ribbon_color cmd.set("ribbon_color", "yellow", obj_name + " and ribbon_color _aseg0 and ss s") cmd.set( "ribbon_color", "cyan", obj_name + " and ribbon_color _aseg0 and not ss h+s") if 'ViewZFront' in mr.system: moe_front = mr.system['ViewZFront'] moe_width = mr.system['ViewZWidth'] extent = cmd.get_extent( name) # will this work with groups? TO DO: check! dx = (extent[0][0] - extent[1][0]) dy = (extent[0][1] - extent[1][1]) dz = (extent[0][2] - extent[1][2]) half_width = 0.5 * math.sqrt(dx * dx + dy * dy + dz * dz) cmd.clip("atoms", 0.0, name) cur_view = cmd.get_view() center = (cur_view[-3] + cur_view[-2]) * 0.5 # center of clipping slab front = center - half_width back = center + half_width width = half_width * 2 new_view = tuple( list(cur_view[0:15]) + [ front + width * moe_front, front + width * (moe_front + moe_width), 0.0 ]) cmd.set_view(new_view) if 'graphics' in mr.system: cgo_cnt = 1 lab_cnt = 1 unique_cgo_names = {} for graphics in mr.system['graphics']: cgo = [] for gvertex in graphics.get('gvertex', []): vrt = gvertex[0] seg_list = gvertex[1]['seg'] idx = gvertex[1]['idx'] len_idx = len(idx) if not cmd.is_list(seg_list): seg_list = [seg_list] * (len_idx / seg_list) last_seg = None ix_start = 0 for seg in seg_list: if seg != last_seg: if last_seg != None: cgo.append(END) if seg == 3: cgo.extend([BEGIN, TRIANGLES]) elif seg == 2: cgo.extend([BEGIN, LINES]) elif seg == 1: cgo.extend([BEGIN, POINTS]) ix_stop = seg + ix_start if seg == 3: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) elif seg == 2: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) elif seg == 1: for s in idx[ix_start:ix_stop]: v = vrt[s - 1] cgo.extend([ COLOR, (0xFF & (v[0] >> 16)) / 255.0, (0xFF & (v[0] >> 8)) / 255.0, (0xFF & (v[0])) / 255.0 ]) if len(v) > 4: cgo.extend([NORMAL, v[4], v[5], v[6]]) cgo.extend([VERTEX, v[1], v[2], v[3]]) ix_start = ix_stop last_seg = seg if last_seg != None: cgo.append(END) for gtext in graphics.get('gtext', []): lab_name = name + ".label_%02d" % lab_cnt exists = 0 for entry in gtext: exists = 1 cmd.pseudoatom(lab_name, pos=[ float(entry[1]), float(entry[2]), float(entry[3]) ], color="0x%06x" % entry[0], label=entry[4]) if exists: cmd.set('label_color', -1, lab_name) lab_cnt = lab_cnt + 1 # TO DO -- via CGO's? if len(cgo): cgo_name = name + "." + make_valid_name( graphics.get('GTitle', 'graphics')) if cgo_name not in unique_cgo_names: unique_cgo_names[cgo_name] = cgo_name else: cnt = 2 while cgo_name + "_" + str(cnt) in unique_cgo_names: cnt = cnt + 1 new_name = cgo_name + "_" + str(cnt) unique_cgo_names[new_name] = new_name cgo_name = new_name cmd.load_cgo(cgo, cgo_name, state=state, quiet=quiet, zoom=0) cgo_cnt = cgo_cnt + 1 cmd.set("two_sided_lighting", 1) # global setting... cmd.set("cgo_line_width", 2, cgo_name) if 'GTransparency' in graphics: g_trans = graphics['GTransparency'] if len(g_trans) >= 2: if g_trans[0] != 0: cmd.set('cgo_transparency', '%1.6f' % (g_trans[0] / 255.0), cgo_name) cmd.set('transparency_global_sort') if 'meter' in mr.system: meter_name = name + ".meter" exists = 0 for meter_block in mr.system['meter']: if meter_block[0][0:2] == ['type', 'atoms']: for meter in meter_block[1]: (type, atoms) = meter[0:2] arg = tuple([meter_name] + list( map(lambda x, o=name: o + " and id " + str(x - 1), atoms))) getattr(cmd, type)(*arg) exists = 1 if exists: cmd.color("green", meter_name) # print mr.system['meter'] elif hasattr(mr, 'feature'): model = Indexed() cols = mr.feature[0] rows = mr.feature[1] col = {} cnt = 0 for a in cols: col[a] = cnt cnt = cnt + 1 for row in rows: atom = Atom() atom.coord = [row[col['x']], row[col['y']], row[col['z']]] atom.vdw = row[col['r']] atom.custom = row[col['expr']] model.atom.append(atom) obj_name = name + ".feature" cmd.load_model(model, obj_name, state=state, finish=finish, discrete=discrete, quiet=quiet, zoom=zoom) rank = 1 for row in rows: cmd.color("0x%06x" % row[col['color']], obj_name + " & id %d" % (rank - 1)) rank = rank + 1 cmd.show("mesh", obj_name) cmd.set("min_mesh_spacing", 0.55, obj_name) cmd.label(obj_name, "' '+custom") cmd.set("label_color", "yellow", obj_name) else: print(dir(mr))
def bbPlane(selection='(all)', color='gray', transp=0.3, state=-1, name=None, quiet=1): """ DESCRIPTION Draws a plane across the backbone for a selection ARGUMENTS selection = string: protein object or selection {default: (all)} color = string: color name or number {default: white} transp = float: transparency component (0.0--1.0) {default: 0.0} state = integer: object state, 0 for all states {default: 1} NOTES You need to pass in an object or selection with at least two amino acids. The plane spans CA_i, O_i, N-H_(i+1), and CA_(i+1) """ from pymol.cgo import BEGIN, TRIANGLES, COLOR, VERTEX, END from pymol import cgo from chempy import cpv # format input transp = float(transp) state, quiet = int(state), int(quiet) if name is None: name = cmd.get_unused_name("backbonePlane") if state < 0: state = cmd.get_state() elif state == 0: for state in range(1, cmd.count_states(selection) + 1): bbPlane(selection, color, transp, state, name, quiet) return AAs = [] coords = dict() # need hydrogens on peptide nitrogen cmd.h_add('(%s) and n. N' % selection) # get the list of residue ids for obj in cmd.get_object_list(selection): sel = obj + " and (" + selection + ")" for a in cmd.get_model(sel + " and n. CA", state).atom: key = '/%s/%s/%s/%s' % (obj, a.segi, a.chain, a.resi) AAs.append(key) coords[key] = [a.coord, None, None] for a in cmd.get_model(sel + " and n. O", state).atom: key = '/%s/%s/%s/%s' % (obj, a.segi, a.chain, a.resi) if key in coords: coords[key][1] = a.coord for a in cmd.get_model(sel + " and ((n. N extend 1 and e. H) or (r. PRO and n. CD))", state).atom: key = '/%s/%s/%s/%s' % (obj, a.segi, a.chain, a.resi) if key in coords: coords[key][2] = a.coord # need at least two amino acids if len(AAs) <= 1: print("ERROR: Please provide at least two amino acids, the alpha-carbon on the 2nd is needed.") return # prepare the cgo obj = [ BEGIN, TRIANGLES, COLOR, ] obj.extend(cmd.get_color_tuple(color)) for res in range(0, len(AAs) - 1): curIdx, nextIdx = str(AAs[res]), str(AAs[res + 1]) # populate the position array pos = [coords[curIdx][0], coords[curIdx][1], coords[nextIdx][2], coords[nextIdx][0]] # if the data are incomplete for any residues, ignore if None in pos: if not quiet: print(' bbPlane: peptide bond %s -> %s incomplete' % (curIdx, nextIdx)) continue if cpv.distance(pos[0], pos[3]) > 4.0: if not quiet: print(' bbPlane: %s and %s not adjacent' % (curIdx, nextIdx)) continue normal = cpv.normalize(cpv.cross_product( cpv.sub(pos[1], pos[0]), cpv.sub(pos[2], pos[0]))) obj.append(cgo.NORMAL) obj.extend(normal) # need to order vertices to generate correct triangles for plane if cpv.dot_product(cpv.sub(pos[0], pos[1]), cpv.sub(pos[2], pos[3])) < 0: vorder = [0, 1, 2, 2, 3, 0] else: vorder = [0, 1, 2, 3, 2, 1] # fill in the vertex data for the triangles; for i in vorder: obj.append(VERTEX) obj.extend(pos[i]) # finish the CGO obj.append(END) # update the UI cmd.load_cgo(obj, name, state, zoom=0) cmd.set("cgo_transparency", transp, name)
def rebuild(self) -> None: """ Rebuilds torus """ obj = [] axis = cpv.cross_product(self.normal.array(), (0., 0., 1.)) angle = -cpv.get_angle(self.normal.array(), (0., 0., 1.)) matrix = cpv.rotation_matrix(angle, cpv.normalize(axis)) def obj_vertex(x, y, z): return [cgo.VERTEX] + cpv.add(self.center.array(), cpv.transform(matrix, [x, y, z])) def obj_normal(x, y, z): return [cgo.NORMAL] + cpv.transform(matrix, [x, y, z]) r = self.radius cr = self.cradius rr = 1.5 * cr dv = 2 * math.pi / self.csamples dw = 2 * math.pi / self.samples v = 0.0 w = 0.0 while w < 2 * math.pi: v = 0.0 c_w = math.cos(w) s_w = math.sin(w) c_wdw = math.cos(w + dw) s_wdw = math.sin(w + dw) obj.append(cgo.BEGIN) obj.append(cgo.TRIANGLE_STRIP) obj.append(cgo.COLOR) obj.extend(self.color.array()) while v < 2 * math.pi + dv: c_v = math.cos(v) s_v = math.sin(v) c_vdv = math.cos(v + dv) s_vdv = math.sin(v + dv) obj.extend( obj_normal((r + rr * c_v) * c_w - (r + cr * c_v) * c_w, (r + rr * c_v) * s_w - (r + cr * c_v) * s_w, (rr * s_v - cr * s_v))) obj.extend( obj_vertex((r + cr * c_v) * c_w, (r + cr * c_v) * s_w, cr * s_v)) obj.extend( obj_normal( (r + rr * c_vdv) * c_wdw - (r + cr * c_vdv) * c_wdw, (r + rr * c_vdv) * s_wdw - (r + cr * c_vdv) * s_wdw, rr * s_vdv - cr * s_vdv)) obj.extend( obj_vertex((r + cr * c_vdv) * c_wdw, (r + cr * c_vdv) * s_wdw, cr * s_vdv)) v += dv obj.append(cgo.END) w += dw self._data = obj
[[0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], 0], [[-1.0, 0.0, 0.0], [0.0, -1.0, 0.0], 0], [[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], 0], [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], 1], [[0.0, 1.0, 0.0], [-1.0, 0.0, 0.0], 1], [[-1.0, 0.0, 0.0], [0.0, -1.0, 0.0], 1], [[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], 1], ]: hand = basis[2] if hand: if z1 == 0.0: (x, y) = basis[0:2] else: (y, x) = basis[0:2] normal = normalize(cross_product(x, y)) else: if z1 == 0.0: (y, x) = basis[0:2] else: (x, y) = basis[0:2] normal = normalize(cross_product(y, x)) obj.extend([BEGIN, TRIANGLE_STRIP] + [COLOR, 1.0, 1.0, 1.0] + [NORMAL] + normal) for i in range(sampling + 1): x1 = edge y1 = edge * i / sampling vlen = sqrt(x1 * x1 + y1 * y1) x0 = radius * x1 / vlen
def update_box(self): if self.points_name in self.cmd.get_names(): model = self.cmd.get_model(self.points_name) self.coord = ( model.atom[0].coord, model.atom[1].coord, model.atom[2].coord, model.atom[3].coord, ) p = self.coord[0] d10 = sub(self.coord[1], p) d20 = sub(self.coord[2], p) d30 = sub(self.coord[3], p) x10_20 = cross_product(d10,d20) if self.mode != 'quad': if dot_product(d30,x10_20)<0.0: p = model.atom[1].coord d10 = sub(self.coord[0], p) d20 = sub(self.coord[2], p) d30 = sub(self.coord[3], p) n10_20 = normalize(x10_20) n10 = normalize(d10) d100 = d10 d010 = remove_component(d20, n10) if self.mode != 'quad': d001 = project(d30, n10_20) else: d001 = n10_20 n100 = normalize(d100) n010 = normalize(d010) n001 = normalize(d001) f100 = reverse(n100) f010 = reverse(n010) f001 = reverse(n001) if self.mode == 'quad': p000 = p p100 = add(p, remove_component(d10,n001)) p010 = add(p, remove_component(d20,n001)) p001 = add(p, remove_component(d30,n001)) else: p000 = p p100 = add(p,d100) p010 = add(p,d010) p001 = add(p,d001) p110 = add(p100, d010) p011 = add(p010, d001) p101 = add(p100, d001) p111 = add(p110, d001) obj = [] if self.mode == 'box': # standard box obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(f001) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p110) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n001) obj.append(VERTEX); obj.extend(p001) obj.append(VERTEX); obj.extend(p101) obj.append(VERTEX); obj.extend(p011) obj.append(VERTEX); obj.extend(p111) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(f010) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p001) obj.append(VERTEX); obj.extend(p101) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n010) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p011) obj.append(VERTEX); obj.extend(p110) obj.append(VERTEX); obj.extend(p111) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(f100) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p001) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p011) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n100) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p110) obj.append(VERTEX); obj.extend(p101) obj.append(VERTEX); obj.extend(p111) obj.append(END) model.atom[0].coord = p000 model.atom[1].coord = p100 model.atom[2].coord = add(p010, scale(d100,0.5)) model.atom[3].coord = add(add(p001, scale(d010,0.5)),d100) elif self.mode=='walls': obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n001) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p110) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n010) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p001) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p101) obj.append(END) obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n100) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p001) obj.append(VERTEX); obj.extend(p011) obj.append(END) model.atom[0].coord = p000 model.atom[1].coord = p100 model.atom[2].coord = p010 model.atom[3].coord = p001 elif self.mode=='plane': obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n001) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p110) obj.append(END) model.atom[0].coord = p000 model.atom[1].coord = p100 model.atom[2].coord = p010 model.atom[3].coord = add(add(p001, scale(d010,0.5)),scale(d100,0.5)) elif self.mode=='quad': obj.extend([ BEGIN, TRIANGLE_STRIP ]) obj.append(NORMAL); obj.extend(n001) obj.append(VERTEX); obj.extend(p000) obj.append(VERTEX); obj.extend(p100) obj.append(VERTEX); obj.extend(p010) obj.append(VERTEX); obj.extend(p001) obj.append(END) model.atom[0].coord = p000 model.atom[1].coord = p100 model.atom[2].coord = p010 model.atom[3].coord = p001 self.cmd.load_model(model, '_tmp', zoom=0) self.cmd.update(self.points_name,"_tmp") self.cmd.delete("_tmp") # then we load it into PyMOL self.cmd.delete(self.cgo_name) self.cmd.load_cgo(obj,self.cgo_name,zoom=0) self.cmd.order(self.cgo_name+" "+self.points_name,sort=1,location='bottom') self.cmd.set("nonbonded_size",math.sqrt(dot_product(d10,d10))/10,self.points_name)
obj = [] for basis in [ [ [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], 0], [ [ 0.0, 1.0, 0.0], [ -1.0, 0.0, 0.0], 0], [ [-1.0, 0.0, 0.0], [ 0.0, -1.0, 0.0], 0], [ [ 0.0, -1.0, 0.0], [ 1.0, 0.0, 0.0], 0], [ [ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], 1], [ [ 0.0, 1.0, 0.0], [ -1.0, 0.0, 0.0], 1], [ [-1.0, 0.0, 0.0], [ 0.0, -1.0, 0.0], 1], [ [ 0.0, -1.0, 0.0], [ 1.0, 0.0, 0.0], 1] ]: hand = basis[2] if hand: (x,y) = basis[0:2] normal = normalize(cross_product(x,y)) else: (y,x) = basis[0:2] normal = normalize(cross_product(y,x)) obj.extend( [BEGIN, TRIANGLE_STRIP] + [COLOR, 1.0, 1.0, 1.0] + [NORMAL] + normal ) for i in range(sampling+1): x1 = edge y1 = edge*i/sampling vlen = sqrt(x1*x1+y1*y1) x0 = radius*x1/vlen y0 = radius*y1/vlen v0 = add( scale(x, x0 ), scale(y,y0) )