def AxesMod1 ( COM=[0,0,0], U=None, length=10.0, exfac=10.0, rad=1.0, alignTo = None, axes=None ) : import _surface toaxes = axes if toaxes == None : toaxes = _surface.SurfaceModel() chimera.openModels.add([toaxes], sameAs = alignTo) toaxes.name = "Axes" #axes = AddAxes ( rad, Extents[0]*f, Extents[1]*f, Extents[2]*f, 1.0, mol ) pos = chimera.Vector(0,0,0) #mol = AddArrow2 ( pos, chimera.Vector(1,0,0), lX, (cF,0,0,1), rad, mol ) #mol = AddArrow2 ( pos, chimera.Vector(0,1,0), lY, (0,cF,0,1), rad, mol ) naxes = AddArrow3 ( pos, chimera.Vector(0,0,1), length, (0,0,1,1), rad, _surface.SurfaceModel() ) if U != None : S = numpy.array([ [ 1.0, 0.0, 0.0, 0 ], [ 0.0, 1.0, 0.0, 0 ], [ 0.0, 0.0, 2.0, 0 ] ] ) P = numpy.array([ [ 1.0, 0.0, 0.0, 0 ], [ 0.0, 1.0, 0.0, 0 ], [ 0.0, 0.0, 1.0, -length ] ] ) R = numpy.array([ [ U[0,0], U[0,1], U[0,2], 0.0 ], [ U[1,0], U[1,1], U[1,2], 0.0 ], [ U[2,0], U[2,1], U[2,2], 0.0 ] ] ) T = numpy.array([ [ 1.0, 0.0, 0.0, COM[0] ], [ 0.0, 1.0, 0.0, COM[1] ], [ 0.0, 0.0, 1.0, COM[2] ] ] ) import Matrix M = Matrix.multiply_matrices ( T, R ) M = Matrix.multiply_matrices ( M, P ) M = Matrix.multiply_matrices ( M, S ) import _contour for p in naxes.surfacePieces : v, t = numpy.copy(p.geometry[0]), numpy.copy(p.geometry[1]) _contour.affine_transform_vertices( v, M ) toaxes.addPiece ( v,t,p.color ) return toaxes
def outline_box(origin, axes, rgb, surface_model): a0, a1, a2 = axes from numpy import array, add c000 = array(origin) c100 = add(c000, a0) c010 = add(c000, a1) c001 = add(c000, a2) c110 = add(c100, a1) c101 = add(c100, a2) c011 = add(c010, a2) c111 = add(a0, c011) vlist = (c000, c001, c010, c011, c100, c101, c110, c111) qlist = ((0, 4, 5), (5, 1, 0), (0, 2, 6), (6, 4, 0), (0, 1, 3), (3, 2, 0), (7, 3, 1), (1, 5, 7), (7, 6, 2), (2, 3, 7), (7, 5, 4), (4, 6, 7)) b = 8 + 2 + 1 # Bit mask, 8 = show triangle, edges are bits 4,2,1 hide_diagonals = (b, b, b, b, b, b, b, b, b, b, b, b) if surface_model: # Replace the geometry of the first piece. p = surface_model.surfacePieces[0] p.geometry = vlist, qlist p.triangleAndEdgeMask = hide_diagonals else: import _surface surface_model = _surface.SurfaceModel() rgba = tuple(rgb) + (1, ) piece = surface_model.addPiece(vlist, qlist, rgba) piece.displayStyle = piece.Mesh piece.useLighting = False piece.triangleAndEdgeMask = hide_diagonals piece.outline_box = True return surface_model
def show_cb(self, event=None, model_id=None): radius = self.radius.value(self.default_radius) sphere_factor = self.sphere_factor.value(0) surface_style = self.surface_style.get() orientation = self.orientation_name() subdivision_levels = self.subdivision_levels(radius) if self.surface_model == None: import _surface sm = _surface.SurfaceModel() sm.name = 'Icosahedron' self.surface_model = sm import chimera chimera.addModelClosedCallback(sm, self.surface_closed_cb) self.surface_piece = None from Icosahedron import make_icosahedron_surface p = make_icosahedron_surface(radius, orientation, subdivision_levels, sphere_factor, surface_style, self.color.rgba, self.surface_model) if self.surface_piece: self.surface_model.removePiece(self.surface_piece) else: from chimera import openModels as om if model_id is None: id = subid = om.Default else: id, subid = model_id om.add([self.surface_model], baseId=id, subid=subid) self.surface_piece = p
def BoxArrowMesh (w, h, l, al, color, xf, mol) : if mol == None : import _surface mol = _surface.SurfaceModel() chimera.openModels.add ( [mol] ) # , sameAs = alignTo) mol.name = "Box" v = numpy.zeros ( [14,3] ) # print "BoxMesh:", div at = 0 w = w / 2.0 h = h / 2.0 l = l / 2.0 if xf == None : xf = chimera.Xform() v[0] = xf.apply ( chimera.Point ( -w,-h,-l ) ) v[1] = xf.apply ( chimera.Point ( w,-h,-l ) ) v[2] = xf.apply ( chimera.Point ( w,h,-l ) ) v[3] = xf.apply ( chimera.Point ( -w,h,-l ) ) v[4] = xf.apply ( chimera.Point ( -w,-h,l-al ) ) v[5] = xf.apply ( chimera.Point ( w,-h,l-al ) ) v[6] = xf.apply ( chimera.Point ( w,h,l-al ) ) v[7] = xf.apply ( chimera.Point ( -w,h,l-al ) ) vi = [] vi.extend( Quad2Tri ( [0,3,2,1] ) ) vi.extend( Quad2Tri ( [1,5,6,2] ) ) vi.extend( Quad2Tri ( [2,6,7,3] ) ) vi.extend( Quad2Tri ( [0,4,5,1] ) ) vi.extend( Quad2Tri ( [0,4,7,3] ) ) vi.extend( Quad2Tri ( [5,4,7,6] ) ) v[8] = xf.apply ( chimera.Point ( -w,-h-al/2.0,l-al ) ) v[9] = xf.apply ( chimera.Point ( w,-h-al/2.0,l-al ) ) v[10] = xf.apply ( chimera.Point ( w,h+al/2.0,l-al ) ) v[11] = xf.apply ( chimera.Point ( -w,h+al/2.0,l-al ) ) v[12] = xf.apply ( chimera.Point ( -w,0,l ) ) v[13] = xf.apply ( chimera.Point ( w,0,l ) ) vi.extend( Quad2Tri ( [8,11,10,9] ) ) vi.extend( Quad2Tri ( [8,9,13,12] ) ) vi.extend( Quad2Tri ( [11,12,13,10] ) ) vi.extend( [(8,12,11)] ) vi.extend( [(9,10,13)] ) sph = mol.addPiece ( v, vi, color ) return sph
def surface_model(surface, xf, name): if surface is None: import _surface s = _surface.SurfaceModel() s.name = name from chimera import openModels as om om.add([s]) s.openState.xform = xf return s return surface
def AxesModOffset ( COM=[0,0,0], U=None, Extents=[30,30,30], rad=1.0, f=1.0, alignTo = None ) : import _surface mol = _surface.SurfaceModel() chimera.openModels.add([mol], sameAs = alignTo) pos = chimera.Vector(0,0,0) axes = AddArrow2 ( pos, chimera.Vector(0,1,0), lY, (cF,.3,.3,1), rad, mol ) axes.name = "Riboarrow" if U != None : R = numpy.array([ [ U[0,0], U[0,1], U[0,2], 0.0 ], [ U[1,0], U[1,1], U[1,2], 0.0 ], [ U[2,0], U[2,1], U[2,2], 0.0 ] ] ) T = numpy.array([ [ 1.0, 0.0, 0.0, COM[0] ], [ 0.0, 1.0, 0.0, COM[1] ], [ 0.0, 0.0, 1.0, COM[2] ] ] ) Ti = numpy.array([ [ 1.0, 0.0, 0.0, Extents[0]*0.7 ], [ 0.0, 1.0, 0.0, -Extents[1]/2.0 ], [ 0.0, 0.0, 1.0, -Extents[0]*0.7 ] ] ) import Matrix M = Matrix.multiply_matrices ( R, Ti ) M = Matrix.multiply_matrices ( T, M ) ps = [] for p in axes.surfacePieces : v, t = numpy.copy(p.geometry[0]), numpy.copy(p.geometry[1]) ps.append ( [v,t,p.color] ) axes.removePiece ( p ) import _contour for p in ps : _contour.affine_transform_vertices( p[0], M ) axes.addPiece ( p[0], p[1], p[2] ) from random import random as rand clr = ( rand()*.7, rand()*.7, rand()*.7, 1.0 ) # for p in axes.surfacePieces : p.color = clr #for g in axes.surfacePieces : # g.initial_v = numpy.copy ( g.geometry[0] ) return axes
def test(): from numpy import array, float32, int32 varray = array(((0, 0, 0), (5.1, 0, 0), (5.1, 8.5, 0)), float32) narray = array(((0, 0, 1), (0, 0, 1), (0, 0, 1)), float32) tarray = array(((0, 1, 2), ), int32) elength = 1 va, ta = subdivided_geometry(varray, tarray, narray, elength) import _surface s = _surface.SurfaceModel() color = (1, 1, 1, 1) p = s.addPiece(va, ta, color) p.displayStyle = p.Mesh from chimera import openModels as om om.add([s])
def create_surface(va, ta, color, v, model_id): import _surface s = _surface.SurfaceModel() s.name = '%s field lines' % v.name p = s.addPiece(va, ta, color) p.save_in_session = True from chimera import openModels, OpenModels id, subid = ((OpenModels.Default, OpenModels.Default) if model_id is None else model_id) openModels.add([s], baseId=id, subid=subid) s.openState.xform = v.openState.xform return p
def AddArrow2 ( pos, v, d, clr=(0,1,1,1), rad=0.2, mol=None ) : if mol == None : import _surface mol = _surface.SurfaceModel() chimera.openModels.add ( [mol] ) # , sameAs = alignTo) mol.name = "Box" xf = AlignXf ( pos, v ) mol = CylinderMesh2 (rad, rad, d-(rad*2), 40, clr, xf, mol ) xf = AlignXf ( pos+(v*(d-(rad*3))), v ) mol = CylinderMesh2 (rad*2, 0.01, rad*2, 40, clr, xf, mol ) return mol
def show_icosahedron(radius=1, orientation='222', subdivision_levels=0, sphere_factor=0, style='mesh', color_rgba=(.7, .7, .7, 1)): import _surface surface_model = _surface.SurfaceModel() p = make_icosahedron_surface(radius, orientation, subdivision_levels, sphere_factor, style, color_rgba, surface_model) import chimera chimera.openModels.add([surface_model]) return p
def ellipsoid_surface(center, axes, lengths, color=(.7, .7, .7, 1)): from Icosahedron import icosahedron_triangulation varray, tarray = icosahedron_triangulation(subdivision_levels=3, sphere_factor=1.0) #print(varray) from numpy import dot, multiply es = dot(varray, axes) print("This is my ES: ", es) ee = multiply(es, lengths) ev = dot(ee, axes.transpose()) ev += center import _surface sm = _surface.SurfaceModel() sm.addPiece(ev, tarray, color) return sm
def cube_surface_model(size, mesh=0): import _surface s = _surface.SurfaceModel() (vertices, vertex_indices) = cube_triangles(size) rgba = (.5, .5, .5, 1) p = s.addPiece(vertices, vertex_indices, rgba) if mesh: style = p.Mesh else: style = p.Solid p.displayStyle = style p.useLighting = True p.twoSidedLighting = True p.smoothLines = False return s
def MeshFromVertsTris (verts, tris, color=None, m=None) : if m == None : m = _surface.SurfaceModel() com = Vector (0,0,0) rad = Vector (0,0,0) numv = 0 print " - mesh from %d verts, %d tris" % (len(verts), len(tris)) if color == None : color = (0.6039, 0.8431, 0.898, 1.0) patch = m.addPiece( verts, tris, color ) #sph.set_display_style(sph.Mesh) #sph.set_vertex_colors( vcolors ) return m
def tube_surface_piece(ptlist, pcolors, radius, circle_subdivisions, surface_model=None, model_id=None): nz = len(ptlist) nc = circle_subdivisions height = 0 from Shape.shapecmd import cylinder_geometry varray, tarray = cylinder_geometry(radius, height, nz, nc, caps=True) tflist = extrusion_transforms(ptlist) # Transform circles. from _contour import affine_transform_vertices for i in range(nz): affine_transform_vertices(varray[nc * i:nc * (i + 1), :], tflist[i]) # Transform cap center points affine_transform_vertices(varray[-2:-1, :], tflist[0]) affine_transform_vertices(varray[-1:, :], tflist[-1]) # Vertex colors. from numpy import empty, float32 carray = empty((nz * nc + 2, 4), float32) for i in range(nz): carray[nc * i:nc * (i + 1), :] = pcolors[i] carray[-2, :] = pcolors[0] carray[-1, :] = pcolors[-1] if surface_model is None: import _surface surface_model = _surface.SurfaceModel() from chimera import openModels as om if model_id is None: model_id = (om.Default, om.Default) om.add([surface_model], baseId=model_id[0], subid=model_id[1]) p = surface_model.addPiece(varray, tarray, (1, 1, 1, 1)) p.vertexColors = carray if radius == 0: p.displayStyle = p.Mesh p.useLighting = False return p
def ReadMesh2 (fname, m) : if m == None : m = _surface.SurfaceModel() com = Vector (0,0,0) rad = Vector (0,0,0) numv = 0 aV = [] fp = open ( fname, 'r' ) l1 = fp.readline() numV, numT = l1.split () numV = int ( numV ) numT = int ( numT ) print "%d verts, %d tris" % (numV, numT) verts = numpy.ones ( [numV, 3] ) tris = numpy.ones ( [numT, 3], numpy.int ) for vi in range ( numV ) : line = fp.readline() c = line.split(' ') if len(c) == 3 : verts[vi] = c for ti in range ( numT ) : line = fp.readline() n = line.split(' ') tris[ti] = n fp.close() color = (0.6039, 0.8431, 0.898, 1.0) patch = m.addPiece( verts, tris, color ) #sph.set_display_style(sph.Mesh) #sph.set_vertex_colors( vcolors ) return m
def ToggleDisp(self): smod = self.GetMod("Icosahedron Faces") if smod == None: self.status("Did not find Icos2") return import _surface nmod = _surface.SurfaceModel() nmod.name = smod.name nmod.icosVerts0 = smod.icosVerts0 nmod.icosVerts = smod.icosVerts nmod.icosTris = smod.icosTris nmod.nvecs = smod.nvecs nmod.sps = [] for spi, sp in enumerate(smod.sps): v, t = sp.geometry #print " sp %d - %d verts, %d tris" % (spi, len(v), len(t) ) if len(v) > 0 and len(t) > 0: ns = nmod.addPiece(v, t, sp.color) nmod.sps.append(ns) ns.N = sp.N ns.ind = spi if hasattr(sp, 'verts0'): ns.verts0 = sp.verts0 if sp.displayStyle == sp.Mesh: ns.displayStyle = sp.Solid else: ns.displayStyle = sp.Mesh chimera.openModels.close([smod]) #chimera.openModels.add([nmod], sameAs = smod) chimera.openModels.add([nmod]) smod = nmod self.status("Toggle Display %s - %d surfaces" % (smod.name, len(smod.surfacePieces)))
def imod_models(chunk_list, name, mesh, contours): mlist = [] surf_model = None for c in chunk_list: if c['id'] == 'IMOD': xyz_scale = c['xscale'], c['yscale'], c['zscale'] pixel_size = c['pixsize'] print 'IMOD pixel size =', pixel_size, ' scale', xyz_scale elif c['id'] == 'OBJT': alpha = 1.0 - 0.01 * c['trans'] object_rgba = (c['red'], c['green'], c['blue'], alpha) obj_name = c['name'] radius = c['pdrawsize'] * pixel_size fill = c['flags'] & (1 << 8) lines = not (c['flags'] & (1 << 11)) only_points = (not lines and not fill) link = not only_points open_contours = c['flags'] & (1 << 3) mset = None elif c['id'] == 'MESH': if mesh: if surf_model == None: import _surface surf_model = _surface.SurfaceModel() surf_model.name = name + ' mesh' mlist.append(surf_model) create_mesh(c, pixel_size, xyz_scale, object_rgba, surf_model, obj_name) elif c['id'] == 'CONT': if contours: if mset == None: from VolumePath import Marker_Set mname = '%s %s contours' % (name, obj_name) mset = Marker_Set(mname) # Marker set already added to openModels so don't return # it in mlist. create_contour(c, pixel_size, xyz_scale, radius, object_rgba, link, open_contours, mset) return mlist
def transform_schematic(xform, center, from_rgba, to_rgba): corners = transform_square(xform, center) if corners is None: return None # No rotation. import _surface sm = _surface.SurfaceModel() varray = corners tarray = ((0, 1, 2), (0, 2, 3), (0, 1, 5), (0, 5, 4), (1, 2, 6), (1, 6, 5), (2, 3, 7), (2, 7, 6), (3, 0, 4), (3, 4, 7), (4, 5, 6), (4, 6, 7)) g1 = sm.addPiece(varray, tarray, from_rgba) from Matrix import xform_matrix, apply_matrix tf = xform_matrix(xform) corners2 = [apply_matrix(tf, p) for p in corners] varray2 = corners2 g2 = sm.addPiece(varray2, tarray, to_rgba) return sm
def PlaneMesh ( w, h, d, color, xf, mol ) : if mol == None : import _surface mol = _surface.SurfaceModel() chimera.openModels.add ( [mol] ) # , sameAs = alignTo) mol.name = "Box" atX = -w/2 atY = -h/2 if xf == None : xf = chimera.Xform() numx = int ( max ( numpy.ceil ( w / d ), 2 ) ) numy = int ( max ( numpy.ceil ( h / d ), 2 ) ) dx = w / float(numx-1) dy = h / float(numx-1) print " - plane - w %.2f, h %.2f, %d/%d" % (w, h, numx, numy) v = numpy.zeros ( [numx*numy,3] ) vi = [] for j in range ( numy ) : for i in range ( numx ) : v[j*numx+i] = xf.apply ( chimera.Point ( atX + dx*i, atY + dy*j, 0 ) ) #vs.append ( p.data() ) if i > 0 and j > 0 : p1 = j*numx+i p2 = j*numx+i-1 p3 = (j-1)*numx+i-1 p4 = (j-1)*numx+i vi.extend( Quad2Tri ( [p1,p2,p3,p4] ) ) sph = mol.addPiece ( v, vi, color ) return sph
def make_icosahedron_surface(radius=1, orientation='222', subdivision_levels=0, sphere_factor=0, style='mesh', color_rgba=(.7, .7, .7, 1), surface_model=None): varray, tarray, iradii = \ icosahedron_triangulation(radius, subdivision_levels, sphere_factor, orientation, return_radii = True) if surface_model == None: import _surface surface_model = _surface.SurfaceModel() import chimera chimera.openModels.add([surface_model]) p = surface_model.addPiece(varray, tarray, color_rgba) if style == 'mesh': p.displayStyle = p.Mesh p.icosahedral_radii = iradii return p
def showAniso(self, targets, color=None, scale=1.0, smoothing=1, showEllipsoid=True, ellipsoidTransparency=None, axisColor=None, axisFactor=None, axisThickness=0.01, ellipseColor=None, ellipseFactor=None, ellipseThickness=0.02): """targets can be an iterable of atoms or molecules color of None means match the atom color. showing outer ellipsoid controlled with 'showEllipsoid' if 'ellipsoidTransparency' is not None, then the color's transparency is set to that fraction. 'axisFactor' is a multiplicative factor of how long the displayed axes lengths are versus the ellipsoid axes. If 'axisFactor' is None then no axes are displayed. 'ellipseFactor' is similar to 'axisFactor', but for the major ellipses. """ molMap = self._makeMolMap(targets) self.removeAniso(molMap) noneShowing = not self._surfMap newlyShown = 0 for m, atoms in molMap.items(): if not m.display: continue surfMap = self._surfMap.setdefault(m, {}) if surfMap: model = surfMap["model"] else: import _surface model = _surface.SurfaceModel() surfMap["model"] = model openModels.add([model], sameAs=m, hidden=True) for a in atoms: if not a.display or a.hide: continue if not hasattr(a, "anisoU"): continue noneColor = a.color if noneColor is None: noneColor = a.molecule.color if showEllipsoid: if color is None: _ellipsoidColor = noneColor else: _ellipsoidColor = color else: _ellipsoidColor = None if axisFactor is None: _axisColor = None elif axisColor is None: _axisColor = noneColor else: _axisColor = axisColor if ellipseFactor is None: _ellipseColor = None elif ellipseColor is None: _ellipseColor = noneColor else: _ellipseColor = ellipseColor surfMap[a] = self._makePieces(model, a, (_ellipsoidColor, _axisColor, _ellipseColor), ellipsoidTransparency, scale, smoothing, axisFactor, ellipseFactor, axisThickness, ellipseThickness) newlyShown += 1 # can't look up 'molecule' in deleted atoms, # so remember it... self._atomMolLookup[a] = a.molecule if noneShowing and self._surfMap: self._handlerID = triggers.addHandler('Atom', self._atomCB, None) return newlyShown
def Icos2(self): imod = self.GetMod("Icosahedron") axmods = [] for m in chimera.openModels.list(): if m.name == "Icosahedron Faces": axmods.append(m) if len(axmods) > 0: chimera.openModels.close(axmods) if imod == None: self.umsg("No Icosahedron model found - please follow step 2.") return if len(imod.surfacePieces) <> 1: self.umsg("Please set 'Subdivision factor' to 1") return print len(imod.surfacePieces[0].geometry[1]), " tris" print len(imod.surfacePieces[0].geometry[0]), " verts" if len(imod.surfacePieces[0].geometry[1]) <> 20: self.umsg("Please set 'Subdivision factor' to 1") return self.umsg("Building Icos2") import _surface surf_mod = _surface.SurfaceModel() surf_mod.name = "Icosahedron Faces" chimera.openModels.add([surf_mod], sameAs=imod) import axes reload(axes) self.icos_vecs = [] from numpy import arccos, pi for p in imod.surfacePieces: v, t = p.geometry[0], p.geometry[1] #print len(v), len(t) #for pt in v : # print " - pt: ", pt surf_mod.icosVerts0 = numpy.copy(v) surf_mod.icosVerts = numpy.copy(v) surf_mod.icosTris = numpy.copy(t) surf_mod.nvecs = numpy.zeros((len(t), 3)) surf_mod.sps = [] for ti, tri in enumerate(t): #print " - tri: ", tri, p1 = v[tri[0]] p2 = v[tri[1]] p3 = v[tri[2]] mp = (p1 + p2 + p3) / 3.0 pv = chimera.Vector(mp[0], mp[1], mp[2]) r = pv.length pv.normalize() #print mp #self.icos_vecs.append ( pv ) mp = mp / r #cyl = axes.AddCylinderSolid ( chimera.Vector(0,0,0), pv, r, (.6,.4,.4,1), 10.0, surf_mod ) #cyl.name = "Icosahedron_Axes" sp = axes.TriangleMeshDiv(p1, p2, p3, 50.0, None, None, surf_mod) #sp = surf_mod.surfacePieces [ len(surf_mod.surfacePieces)-1 ] sp.N = numpy.array(pv, numpy.float32) #surf_mod.nvecs.append ( mp ) surf_mod.nvecs[ti] = mp surf_mod.sps.append(sp) sp.ind = ti #p1v = chimera.Vector ( p1[0], p1[1], p1[2] ); p1v.normalize () #p2v = chimera.Vector ( p2[0], p2[1], p2[2] ); p2v.normalize () #p3v = chimera.Vector ( p3[0], p3[1], p3[2] ); p3v.normalize () #a1 = arccos ( p1v * pv ) * 180.0 / pi #a2 = arccos ( p2v * pv ) * 180.0 / pi #a3 = arccos ( p3v * pv ) * 180.0 / pi #a12 = arccos ( p1v * p2v ) * 180.0 / pi #print a1, a2, a3, a12 #if ti >= 0 : # break p1 = surf_mod.icosVerts0[surf_mod.icosTris[0][0]] r0 = numpy.sqrt(numpy.sum(p1 * p1)) self.umsg("Made Icos2 from %d sps in %s -> %d sps, rad %.1f" % (len( imod.surfacePieces), imod.name, len(surf_mod.surfacePieces), r0)) self.rad.set(r0)
def Icos(self): imod = None axmod = None for m in chimera.openModels.list(): if m.name == "Icosahedron": imod = m if m.name == "Icosahedron_Axes": axmod = m if axmod == None: pass else: chimera.openModels.close([axmod]) if imod == None: self.umsg("No Icosahedron model found - please follow step 2.") return if len(imod.surfacePieces) <> 1: self.umsg("Please set 'Subdivision factor' to 1") return print len(imod.surfacePieces[0].geometry[1]), " tris" print len(imod.surfacePieces[0].geometry[0]), " verts" if len(imod.surfacePieces[0].geometry[1]) <> 20: self.umsg("Please set 'Subdivision factor' to 1") return self.umsg("Building axes...") import _surface surf_mod = _surface.SurfaceModel() chimera.openModels.add([surf_mod], sameAs=imod) import axes reload(axes) self.icos_vecs = [] from numpy import arccos, pi for p in imod.surfacePieces: v, t = p.geometry[0], p.geometry[1] #print len(v), len(t) #for pt in v : # print " - pt: ", pt for tri in t: #print " - tri: ", tri, p1 = v[tri[0]] p2 = v[tri[1]] p3 = v[tri[2]] mp = (p1 + p2 + p3) / 3.0 pv = chimera.Vector(mp[0], mp[1], mp[2]) r = pv.length pv.normalize() #print mp self.icos_vecs.append(pv) cyl = axes.AddCylinderSolid(chimera.Vector(0, 0, 0), pv, r, (.6, .4, .4, 1), 10.0, surf_mod) cyl.name = "Icosahedron_Axes" p1v = chimera.Vector(p1[0], p1[1], p1[2]) p1v.normalize() p2v = chimera.Vector(p2[0], p2[1], p2[2]) p2v.normalize() p3v = chimera.Vector(p3[0], p3[1], p3[2]) p3v.normalize() a1 = arccos(p1v * pv) * 180.0 / pi a2 = arccos(p2v * pv) * 180.0 / pi a3 = arccos(p3v * pv) * 180.0 / pi a12 = arccos(p1v * p2v) * 180.0 / pi # print a1, a2, a3, a12 minAng = 1e9 pv1 = self.icos_vecs[0] for pv2 in self.icos_vecs[1:]: dp = pv1 * pv2 ang = arccos(dp) #print ang * 180.0 / pi self.umsg("Axes built.")