def test_contour_sphere(npts): "Test example using POVRay module" from numpy import arange,array from Pistol.POVRay import Scene,TriangleMesh def sphere(x,y,z): return x*x+y*y+z*z # The goal here was to see whether MC would work when there weren't cubes, # e.g. when yvec = 0.1,1.0,0.0. It doesn't appear to. origin = array([-5.0,-5.0,-5.0]) length = 10 xvec = length*array([1.0,0.0,0.0]) yvec = length*array([0.0,1.0,0.0]) zvec = length*array([0.0,0.0,1.0]) nx=ny=nz=npts triangles = [] for i in range(nx-1): ifrac = i/(nx-1.) ifracp = (i+1.)/(nx-1.) for j in range(ny-1): jfrac = j/(ny-1.) jfracp = (j+1.)/(ny-1.) for k in range(nz-1): kfrac = k/(nz-1.) kfracp = (k+1.)/(nz-1.) x,y,z = origin + ifrac*xvec + jfrac*yvec + kfrac*zvec xp,yp,zp = origin + ifracp*xvec + jfracp*yvec + kfracp*zvec newtris = contour(3.0, (x,y,z),(x,y,zp),(x,yp,zp),(x,yp,z), (xp,y,z),(xp,y,zp),(xp,yp,zp),(xp,yp,z), sphere(x,y,z),sphere(x,y,zp), sphere(x,yp,zp),sphere(x,yp,z), sphere(xp,y,z),sphere(xp,y,zp), sphere(xp,yp,zp),sphere(xp,yp,z)) if newtris: for tri in newtris: triangles.append(tri) pov = Scene('test_sphere') tmesh = TriangleMesh(triangles,(0,0,1)) pov.add(tmesh) pov.write_pov() pov.render() pov.display() return
def write_svg(self,filename,atoms): from Pistol.SVG import Scene,Circle,Line # recompute the name from the filename: this will # have the _0001 on it, if applicable: basename = os.path.basename(filename) name = os.path.splitext(basename)[0] atoms = rotate_2d(atoms,self.camera) if self.iframe == 0: # need to recompute bbox for rotated mol xmin,xmax,ymin,ymax,zmin,zmax = get_bbox(atoms) self.bbox = xmin,xmax,ymin,ymax,zmin,zmax else: xmin,xmax,ymin,ymax,zmin,zmax = self.bbox height,width = 800,800 # in pixels # readjust heigh and width based upon bbox. dx = xmax - xmin dy = ymax - ymin if dx > dy: height = height*dy/dx else: width = width*dy/dx scale = get_2d_scale(xmin,xmax,ymin,ymax,height,width) scene = Scene(name,height,width) for i,j in get_bonds_from_distance(atoms): atnoi,(xi,yi,zi) = atoms[i] atnoj,(xj,yj,zj) = atoms[j] Xi = int(scale*(xi-xmin)) Yi = int(scale*(yi-ymin)) Xj = int(scale*(xj-xmin)) Yj = int(scale*(yj-ymin)) scene.add(Line((Xi,Yi),(Xj,Yj))) for atno,(x,y,z) in atoms: X = int(scale*(x-xmin)) Y = int(scale*(y-ymin)) scene.add(Circle((X,Y),rscale*scale*radius[atno],color[atno])) scene.write_svg(filename) if self.nframes == 1: scene.display() return
def main(outname,pltname): mol_info = read_output_as_dict(outname) plt_info = read_plt(pltname) name = mol_info['name'] scene = Scene(name) #scene.set_camera((0,4,0.5),(0,0,0.5)) scene.set_camera((0,10,0)) atoms = mol_info['structure'] for i,j in get_bonds_from_distance(atoms): atnoi,xyzi = atoms[i] atnoj,xyzj = atoms[j] scene.add(Cylinder(xyzi,xyzj,0.1)) for atno,xyz in atoms: r,g,b = color[atno] sphere = Sphere(xyz,rscale*radius[atno],(r/255.,g/255.,b/255.)) scene.add(sphere) ptris = mcube_contour(plt_info,0.1) ntris = mcube_contour(plt_info,-0.1) # if desired, compute normals at each vertex ptris = smooth_tris(ptris) ntris = smooth_tris(ntris) if ptris: scene.add(TriangleMesh(ptris,(1,0,0))) if ntris: scene.add(TriangleMesh(ntris,(0,0,1))) scene.write_pov() scene.render() scene.display() return
def write_pov(self,filename,atoms): from Pistol.POVRay import Scene,Sphere,Cylinder # recompute the name from the filename: this will # have the _0001 on it, if applicable: basename = os.path.basename(filename) name = os.path.splitext(basename)[0] scene = Scene(name,self.camera,self.light,bgcolor=(1,1,1)) for i,j in get_bonds_from_distance(atoms): atnoi,xyzi = atoms[i] atnoj,xyzj = atoms[j] scene.add(Cylinder(xyzi,xyzj,0.1)) for atno,xyz in atoms: r,g,b = color[atno] sphere = Sphere(xyz,rscale*radius[atno],(r/255.,g/255.,b/255.)) scene.add(sphere) scene.write_pov(filename) scene.render() if self.nframes == 1: scene.display() return