Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
 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