Ejemplo n.º 1
0
# Get orientation of the Body_Point
Orientation_Body_Point = GL.Globals['Body_Point'].getOrientation()

# Get orientation of the Body
Orientation_Body = GL.Globals['Body'].getOrientation()

# Adjust z
GL.Globals['z'] = (GL.Globals['Body_Point'].getPosition()[2] -
                   GL.Globals['z_0']) * GL.Globals['Blender_Factor_Position']

# Adjust phi_x
if Orientation_Body[2][1] > 0:
    phi_x_Body = (M.pi / 180.0) * MU.AngleBetweenVecs(
        MU.Vector(Orientation_Body[0][1], Orientation_Body[1][1],
                  Orientation_Body[2][1]),
        MU.Vector(Orientation_Body_Point[0][1], Orientation_Body_Point[1][1],
                  Orientation_Body_Point[2][1]))
else:
    phi_x_Body = -(M.pi / 180.0) * MU.AngleBetweenVecs(
        MU.Vector(Orientation_Body[0][1], Orientation_Body[1][1],
                  Orientation_Body[2][1]),
        MU.Vector(Orientation_Body_Point[0][1], Orientation_Body_Point[1][1],
                  Orientation_Body_Point[2][1]))
GL.Globals['phi_x'] = phi_x_Body * GL.Globals['Blender_Factor_Angle']

# Adjust phi_y
if Orientation_Body[2][0] > 0:
    phi_y_Body = -(M.pi / 180.0) * MU.AngleBetweenVecs(
        MU.Vector(Orientation_Body[0][0], Orientation_Body[1][0],
                  Orientation_Body[2][0]),
Ejemplo n.º 2
0
    def animatedensity(self, filenamelist, renderingpath, isovalue):
        context = self.scene.getRenderingContext()
        context.extensions = True
        context.renderPath = renderingpath
        #context.imageType=Render.JPEG
        context.sFrame = 1
        context.eFrame = 1
        context.sizeX = width
        context.sizeY = height

        cubeobject = cube(filenamelist[0])
        cubeobject.readCube()
        atoms = []
        ipokeytypeloc = Object.IpoKeyTypes.LOC
        ipokeytyperot = Object.IpoKeyTypes.ROT
        for i in range(len(cubeobject.atomtypes)):
            me = Mesh.Primitives.Icosphere(
                spheresubdivisions,
                atomicradii.get(cubeobject.atomtypes[i], 2.0))
            me.materials = [
                materials.get(cubeobject.atomtypes[i], materials["default"])
            ]
            for face in me.faces:
                face.smooth = True
            obj = self.scene.objects.new(me, 'Atom')
            obj.setLocation(cubeobject.coord[i][0], cubeobject.coord[i][1],
                            cubeobject.coord[i][2])
            atoms.append(obj)

        bonds = []
        for i in range(len(cubeobject.atomtypes)):
            for j in range(i + 1, len(cubeobject.atomtypes)):
                vec1 = Mathutils.Vector(cubeobject.coord[i])
                vec2 = Mathutils.Vector(cubeobject.coord[j])
                vec = vec2 - vec1
                distcovalent = covalentradii.get(
                    cubeobject.atomtypes[i], 2.0) + covalentradii.get(
                        cubeobject.atomtypes[j], 2.0)
                if (vec.length - distcovalent) <= 0.10 * distcovalent:
                    me = Mesh.Primitives.Tube(32, stickradius, vec.length)
                    for face in me.faces:
                        face.smooth = True
                    obj = self.scene.objects.new(me, 'Cylinder')
                    axis = Mathutils.CrossVecs(Vector([0, 0, 1]), vec)
                    angle = Mathutils.AngleBetweenVecs(Vector([0, 0, 1]), vec)
                    rotmat = Mathutils.RotationMatrix(angle, 4, "R", axis)
                    obj.setMatrix(obj.matrix * rotmat)
                    obj.setLocation((vec1 + vec2) * 0.5)
                    bonds.append([i, j, vec, obj, vec.length])
        self.isosurface(cubeobject, isovalue)
        context.render()
        filename = "RENDER/image_0000.jpg"
        context.saveRenderedImage(filename)

        for j in range(1, len(filenamelist)):
            print(("Rendering:", j))
            filename = "RENDER/image_%04d.jpg" % (j)
            for ob in self.scene.objects:
                if "Lobe" in ob.name:
                    self.scene.unlink(ob)
            cubeobject = cube(filenamelist[j])
            cubeobject.readCube()
            for i in range(len(atoms)):
                atoms[i].setLocation(cubeobject.coord[i][0],
                                     cubeobject.coord[i][1],
                                     cubeobject.coord[i][2])
                atoms[i].insertIpoKey(ipokeytypeloc)
            for i in range(len(bonds)):
                vec1 = Mathutils.Vector(cubeobject.coord[bonds[i][0]])
                vec2 = Mathutils.Vector(cubeobject.coord[bonds[i][1]])
                vec = vec2 - vec1
                dist = vec.length
                axis = Mathutils.CrossVecs(bonds[i][2], vec)
                angle = Mathutils.AngleBetweenVecs(bonds[i][2], vec)
                rotmat = Mathutils.RotationMatrix(angle, 4, "R", axis)
                bonds[i][3].setMatrix(bonds[i][3].matrix * rotmat)
                bonds[i][3].setLocation((vec1 + vec2) * 0.5)
                bonds[i][3].setSize(1.0, 1.0, dist / bonds[i][4])
                bonds[i][3].insertIpoKey(ipokeytypeloc)
                bonds[i][3].insertIpoKey(ipokeytyperot)
                bonds[i][2] = vec
                bonds[i][4] = dist
            self.isosurface(cubeobject, isovalue)
            context.render()
            context.saveRenderedImage(filename)