#A* ------------------------------------------------------------------- #B* This file contains source code for the PyMOL computer program #C* Copyright (c) Schrodinger, LLC. #D* ------------------------------------------------------------------- #E* It is unlawful to modify or remove this copyright notice. #F* ------------------------------------------------------------------- #G* Please see the accompanying LICENSE file for further information. #H* ------------------------------------------------------------------- #I* Additional authors of this source file include: #-* #-* #-* #Z* ------------------------------------------------------------------- from chempy import cpv #import popen2 import os from pymol import cmd from .cmd import DEFAULT_ERROR, DEFAULT_SUCCESS, _raising POINTS = 0.0 LINES = 1.0 LINE_LOOP = 2.0 LINE_STRIP = 3.0 TRIANGLES = 4.0 TRIANGLE_STRIP = 5.0 TRIANGLE_FAN = 6.0 #QUADS = 7.0 #QUAD_STRIP = 8.0 #POLYGON = 9.0 STOP = 0.0 NULL = 1.0 BEGIN = 2.0 END = 3.0 VERTEX = 4.0 NORMAL = 5.0 COLOR = 6.0 SPHERE = 7.0 TRIANGLE = 8.0 CYLINDER = 9.0 LINEWIDTH = 10.0 WIDTHSCALE = 11.0 ENABLE = 12.0 DISABLE = 13.0 SAUSAGE = 14.0 CUSTOM_CYLINDER = 15.0 DOTWIDTH = 16.0 ALPHA_TRIANGLE = 17.0 ELLIPSOID = 18.0 #SHAPE_VERTEX = 16.0 #SHAPE_COLOR = 17.0 #SHAPE_NORMAL = 18.0 FONT = 19.0 FONT_SCALE = 20.0 FONT_VERTEX = 21.0 FONT_AXES = 22.0 CHAR = 23.0 ALPHA = 25.0 QUADRIC = 26.0 # NOTE: Only works with ellipsoids and disks CONE = 27.0 PICK_COLOR = 31.0 # 0x1F [PICK_COLOR, index, bond/cPickable_t] BEZIER = 66.0 # 0x42 LIGHTING = float(0x0B50) # enum cPickable_t: cPickableAtom = -1.0 cPickableLabel = -2.0 cPickableGadget = -3.0 cPickableNoPick = -4.0 cPickableThrough = -5.0 def molauto(name="mols", sele="(all)", marg="-nice", _self=cmd): _self.save("molauto.pdb",sele) print("molauto %s -nocentre molauto.pdb | molscript -r > molauto.r3d"%marg) os.system("molauto %s -nocentre molauto.pdb | molscript -r > molauto.r3d"%marg) f = open("molauto.r3d") rr = RenderReader(f) f.close() _self.load_cgo(rr.obj,name) def measure_text(font,text, axes=[[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]): w = 0 x = axes[0] for char in text: if char in font: w = w + font[char][0]*x[0] return w def wire_text(cgo,font,pos,text, axes = [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]): # modifies pos x = axes[0] y = axes[1] for char in text: if char in font: fc = font[char] stroke = 0 w = fc[0] f = fc[1] c = 0 l = len(f)-2 while c0.999: clrity=0.999 self.obj.extend([ALPHA, 1.0-clrity]) opts1 = int(s[6]) opts4 = int(s[9]) for x in range(opts4): f.readline(); def mat_reset(self,f): self.append_last() self.obj.extend([ALPHA, 1.0]) def reset(self,f): pass def __init__(self,input): # Author: Warren DeLano # Modifications: Robert Campbell self.app_fn = None self.l_vert = None self.t_colr = None self.c_colr = None self.l_radi = None self.l_norm = None self.o_vert = None self.tri_flag = 0 self.cc = 0 self.obj = [] for a in range(20): input.readline() dispatch = [ None, self.tri, self.sphere, self.cyl, None, self.cyl, None, self.tri_normal, self.mat_prop, self.reset, None, None, None, None, self.quadric, ] ld = len(dispatch) while 1: l = input.readline() if not l: break if l[0] != '#': v = l.split() n=int(v[0]) if(n 1: alphaunit = 255. # detect if normals need to be calculated if surfacenormals and prop[-1] == 'nx': surfacenormals = False records.append(rec) vertices = table['vertex'] obj = [] enum_quad = [0, 1, 2, 2, 3, 0] def colorfromelem(elem): if 'red' in elem: obj.append(COLOR) obj.append(elem['red'] / 255.0) obj.append(elem['green'] / 255.0) obj.append(elem['blue'] / 255.0) if 'alpha' in elem: obj.append(ALPHA) obj.append(elem['alpha'] / alphaunit) 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 if surfacenormals and 'face' in table: compute_surface_normals() for ptype, op in [ ('face', TRIANGLES), ('edge', LINES), ('range_grid', POINTS), ]: if ptype in table: obj.append(BEGIN) obj.append(op) for face in table[ptype]: colorfromelem(face) if 'vertex_index' in face: indices = face['vertex_index'] elif 'vertex_indices' in face: indices = face['vertex_indices'] else: indices = [face['vertex1'], face['vertex2']] N = len(indices) for i in (enum_quad if N == 4 else range(N)): vertex = vertices[indices[i]] colorfromelem(vertex) if 'nx' in vertex: obj.append(NORMAL) obj.append(vertex['nx']) obj.append(vertex['ny']) obj.append(vertex['nz']) obj.append(VERTEX) obj.append(vertex['x']) obj.append(vertex['y']) obj.append(vertex['z']) obj.append(END) obj.append(STOP) return obj