def mouseReleaseEvent(self, event):
     button = event.button()
     self.setCursor(Qt.arrowCursor)
     if button == Qt.LeftButton:
         try:
             dx = event.x() - self.click1x
             dy = event.y() - self.click1y
         except AttributeError:
             return
         if dx != 0 or dy != 0:
             normal = Vector(self.axis)
             move = Vector(-dx*self.plane[:,0]+dy*self.plane[:,1])
             axis = normal.cross(move) / \
                    N.minimum.reduce(N.fabs(self.plotbox_size))
             rot = Rotation(axis.normal(), axis.length())
             self.axis = rot(normal).array
             self.plane[:,0] = rot(Vector(self.plane[:,0])).array
             self.plane[:,1] = rot(Vector(self.plane[:,1])).array
     elif button == Qt.MidButton:
         try:
             dx = event.x() - self.click2x
             dy = event.y() - self.click2y
         except AttributeError:
             return
         if dx != 0 or dy != 0:
             self.translate = self.translate + N.array([dx, dy])
     else:
         try:
             dy = event.y() - self.click3y
         except AttributeError:
             return
         if dy != 0:
             ratio = -dy/self.plotbox_size[1]
             self.scale = self.scale * (1.+ratio)
     self.update()
Ejemplo n.º 2
0
    def releasehandler1(self, event):
	self.configure(cursor='top_left_arrow')
	self.update_idletasks()
        try:
            dx = event.x - self.click1x
            dy = event.y - self.click1y
        except AttributeError:
            return
        if dx != 0 or dy != 0:
            normal = Vector(self.axis)
            move = Vector(-dx*self.plane[:,0]+dy*self.plane[:,1])
            axis = normal.cross(move) / \
                   Numeric.minimum.reduce(Numeric.fabs(self.plotbox_size))
            rot = Rotation(axis.normal(), axis.length())
            self.axis = rot(normal).array
            self.plane[:,0] = rot(Vector(self.plane[:,0])).array
            self.plane[:,1] = rot(Vector(self.plane[:,1])).array
            self.clear(1)
            self.redraw()
Ejemplo n.º 3
0
import numpy as np
from Scientific.Geometry import Vector
A = Vector([1,1,1])   #Scientfic
a = np.array([1,1,1]) #numpy
B = Vector([0.0,1.0,0.0])
print '|A| = ',A.length()        #Scientific Python way
print '|a| = ',np.sum(a**2)**0.5 #numpy way
print '|a| = ',np.linalg.norm(a) #numpy way 2
print 'ScientificPython angle = ',A.angle(B) #in radians
print 'numpy angle =            ',np.arccos(np.dot(a/np.linalg.norm(a),B/np.linalg.norm(B)))
#cross products
print 'Scientific A .cross. B = ',A.cross(B)
print 'numpy A .cross. B      = ',np.cross(A,B) #you can use Vectors in numpy
Ejemplo n.º 4
0
    def calc(self, atomIndexes, trajectory):
        """Calculates the contribution for one group.
        
        @param bondIndex: the index of the group in |self.group| list.
        @type bondIndex: integer.
        
        @param trajectory: the trajectory.
        @type trajectory: MMTK.Trajectory.Trajectory object
        """

        atoms = [None] * 2

        for at in trajectory.universe.atomList():
            if at.index in atomIndexes:
                atoms[atomIndexes.index(at.index)] = at

        # The atoms forming the bond.
        at1, at2 = atoms

        at1Traj = trajectory.readParticleTrajectory(at1,
                                                    first=self.first,
                                                    last=self.last,
                                                    skip=self.skip)
        at2Traj = trajectory.readParticleTrajectory(at2,
                                                    first=self.first,
                                                    last=self.last,
                                                    skip=self.skip)

        costheta = N.zeros((self.nFrames, ), typecode=N.Float)
        sinphi = N.zeros((self.nFrames, ), typecode=N.Float)
        cosphi = N.zeros((self.nFrames, ), typecode=N.Float)
        sintheta = N.zeros((self.nFrames, ), typecode=N.Float)

        for comp in range(self.nFrames):

            pVect = Vector(
                trajectory.universe.distanceVector(at1Traj[comp],
                                                   at2Traj[comp]))
            pVect = pVect.normal()

            costheta[comp] = pVect * self.referenceDirection
            sintheta[comp] = pVect.cross(self.referenceDirection).length()
            cosphi[comp] = (pVect[0] / sintheta[comp])
            sinphi[comp] = (pVect[1] / sintheta[comp])

        tr2 = 3.0 * costheta**2 - 1.
        cos2phi = 2.0 * cosphi**2 - 1.
        sin2phi = 2.0 * sinphi * cosphi
        cossintheta = costheta * sintheta
        sintheta_sq = sintheta**2

        # calcul de <P2(cos(theta))> en termes de somme de fonctions de correlation
        # d'harmoniques spheriques (theoreme d'addition des harmoniques spheriques).
        P2 = (0.25*correlation(tr2) + 3.00*correlation(cosphi*cossintheta) + \
              3.00*correlation(sinphi*cossintheta) + 0.75*correlation(cos2phi*sintheta_sq) + \
              0.75*correlation(sin2phi*sintheta_sq))

        # calcul du parametre d'ordre S^2 (limite pour t->infini de <P2(cos(theta))>).
        S2 = (0.75 * (N.sum(cos2phi*sintheta_sq)**2 + N.sum(sin2phi*sintheta_sq)**2) + \
              3.00 * (N.sum(cosphi*cossintheta)**2 + N.sum(sinphi*cossintheta)**2) +
              0.25 * N.sum(tr2)**2) / self.nFrames**2

        return atomIndexes, (P2, S2)