Пример #1
0
def compareTransformed(coords1, coords2, x1, x2, M):
    # the lattice matrix
    ml1 = lattice.lowerTriangular(coords1.lattice)
    ml2 = lattice.lowerTriangular(coords2.lattice)
    
    # the inerse lattice matrix
    iml2 = vec3.invert3x3(ml2)
    for i in xrange(coords1.nrigid):
        ptest = coords1.rotRigid[i]
        ptrans = rotations.mx2aa(rotations.np.dot(M, rotations.aa2mx(ptest)))
        for d in [np.zeros(3),[0.,1.,0.],[0.,1.,0.],[0.,0.,1.]]:
            xtest = coords1.posRigid[i] + np.array(d) - x1
            xtrans = np.dot(iml2, np.dot(M, np.dot(ml1, xtest)))
     
            match = False
            for j in xrange(coords1.nrigid):
                dx = coords2.posRigid[j] - xtrans - x2
                dx = dx - np.floor(dx)
                dx[dx>0.8]-=1.0
                dp = rotations.mx2aa(np.dot(vec3.invert3x3(rotations.aa2mx(ptrans)),rotations.aa2mx(coords2.rotRigid[j])))
                match = np.linalg.norm(np.dot(ml2, dx)) < tol_shift \
                    and np.linalg.norm(dp) < tol_rot
                if(match):
                    break
            if(not match):
                return False
    return True
Пример #2
0
 def Align(self, coords1, coords2):
     from pygmin.mindist import rmsfit,aamindist
     potential = GMINPotential(GMIN)
     
     ca1 = CoordsAdapter(nrigid=coords1.size/6, coords = coords1)
     ca2 = CoordsAdapter(nrigid=coords2.size/6, coords = coords2)
     rot = rmsfit.findrotation_kabsch(ca2.posRigid, ca1.posRigid)
     ca2.posRigid[:] = np.dot(rot,ca2.posRigid.transpose()).transpose()
     for p in ca2.rotRigid:
         p[:] = rotations.mx2aa((np.dot(rot, rotations.aa2mx(p))))
         
     print "before"
     print potential.getEnergy(coords1), potential.getEnergy(coords2)
     print ca2.rotRigid - ca1.rotRigid
     for p1,p2 in zip(ca1.rotRigid, ca2.rotRigid):
         p1[:],p2[:] = aamindist.aadistance(p1, p2)
     print "after"
     print potential.getEnergy(coords1), potential.getEnergy(coords2)
     print ca2.rotRigid - ca1.rotRigid
     path = InterpolatedPath(coords1, coords2, 40)
     print potential.getEnergy(path[0])
     print "Interpolated energies"
     for x in InterpolatedPath(coords1, coords2, 40):
         print potential.getEnergy(x)
     print "done"
     return coords1, coords2
Пример #3
0
def compareStructures(coords1, coords2):    
    for refmol1 in xrange(coords1.nrigid):
        for refmol2 in xrange(refmol1, coords1.nrigid):
            x1 = coords1.posRigid[refmol1]
            x2 = coords2.posRigid[refmol2]
            pref1 = coords1.rotRigid[refmol1]
            pref2 = coords2.rotRigid[refmol2]
            #print "pref",pref1,pref2
            M = vec3.invert3x3(rotations.aa2mx(pref1))
            M = np.dot(rotations.aa2mx(pref2), M)
            # print x1,x2
            ptest = pref1
            ptrans = rotations.mx2aa(rotations.np.dot(M, rotations.aa2mx(ptest)))
            #print "---------------- start try",refmol1,refmol2
            match1 = compareTransformed(coords1, coords2, x1, x2, M)
            match2 = compareTransformed(coords2, coords1, x2, x1, vec3.invert3x3(M))
            if(match1 and match2):
                #print "Structures match"
                return True
    #import dmagmin_ as GMIN
    #GMIN.writeCIF("1.cif", coords1.coords)
    #GMIN.writeCIF("2.cif", coords2.coords)
    #import pickle
    #pickle.dump(coords1, open("1.dat", "w"))
    #pickle.dump(coords2, open("2.dat", "w"))
    #exit()
    return False
Пример #4
0
 def align(self, coords1, coords2):
     c1 = self.topology.coords_adapter(coords1)
     c2 = self.topology.coords_adapter(coords2)
     
     # now account for symmetry in water
     for p1, p2, site in zip(c1.rotRigid,c2.rotRigid, self.topology.sites):
         theta_min = 10.
         mx2 = rotations.aa2mx(p2)
         mx1 = rotations.aa2mx(p1).transpose()
         mx =  np.dot(mx1, mx2)
         for rot in site.symmetries:
             mx_diff = np.dot(mx, rot)
             theta = np.linalg.norm(rotations.mx2aa(mx_diff))
                                    
             theta -= int(theta/2./pi)*2.*pi
             if(theta < theta_min): 
                 theta_min = theta
                 rot_best = rot
         p2[:] = rotations.rotate_aa(rotations.mx2aa(rot_best), p2)
Пример #5
0
    def rotate(self, X, mx):
        ca = self.topology.coords_adapter(X)
        if(ca.nrigid > 0):
            ca.posRigid[:] = np.dot(mx, ca.posRigid.transpose()).transpose()
            dp = rotations.mx2aa(mx)
            for p in ca.rotRigid:
                p[:] = rotations.rotate_aa(p, dp)

        if(ca.natoms > 0):
            ca.posAtom[:] = np.dot(mx, ca.posAtom.transpose()).transpose()
Пример #6
0
def align(system, coords1, coords2):
    c1 = system.coords_adapter(coords1)
    c2 = system.coords_adapter(coords2)
    R = findrotation_kabsch(c2.posRigid, c1.posRigid)
    #R = rotations.aa2mx(p)
    for x, p in zip(c2.posRigid, c2.rotRigid):
        x[:] = np.dot(R, x)
        p[:] = rotations.rotate_aa(p, rotations.mx2aa(R))
    
    # now account for symmetry in water
    for p1, p2 in zip(c1.rotRigid,c2.rotRigid):
        theta1 = np.linalg.norm(rotations.rotate_aa(p2,-p1))
        p2n = rotations.rotate_aa(np.array([0., 0., pi]), p2)
        theta2 = np.linalg.norm(rotations.rotate_aa(p2n,-p1))
        theta1 -= int(theta1/2./pi)*2.*pi
        theta2 -= int(theta2/2./pi)*2.*pi
        if(theta2 < theta1): 
            p2[:]=p2n
Пример #7
0
def align(system, coords1, coords2):
    c1 = system.coords_adapter(coords1)
    c2 = system.coords_adapter(coords2)
    R = findrotation_kabsch(c2.posRigid, c1.posRigid)
    #R = rotations.aa2mx(p)
    for x, p in zip(c2.posRigid, c2.rotRigid):
        x[:] = np.dot(R, x)
        p[:] = rotations.rotate_aa(p, rotations.mx2aa(R))

    # now account for symmetry in water
    for p1, p2 in zip(c1.rotRigid, c2.rotRigid):
        theta1 = np.linalg.norm(rotations.rotate_aa(p2, -p1))
        p2n = rotations.rotate_aa(np.array([0., 0., pi]), p2)
        theta2 = np.linalg.norm(rotations.rotate_aa(p2n, -p1))
        theta1 -= int(theta1 / 2. / pi) * 2. * pi
        theta2 -= int(theta2 / 2. / pi) * 2. * pi
        if (theta2 < theta1):
            p2[:] = p2n
Пример #8
0
def map_to_aa(xyz):
    coords = np.zeros(6*13)
    ca = CoordsAdapter(nrigid=13, coords=coords)
    for i in xrange(13):
        ca.posRigid[i] = 0.5*(xyz[2*i] + xyz[2*i+1])    
        a1 = -(xyz[2*i] - xyz[2*i+1])
        
        if(i<12):
            a3 = -(xyz[2*i+1] - xyz[2*i+3])
        else:
            a3 = -(xyz[2*i-1] - xyz[2*i+1])
            
        a2 = -np.cross(a1, a3)
        a3 = np.cross(a1, a2)
        a1/=np.linalg.norm(a1)
        a2/=np.linalg.norm(a2)
        a3/=np.linalg.norm(a3)
 #       print np.dot(a1, a2), np.dot(a1, a3), np.dot(a2, a3)
        mx = np.array([a1, a2, a3]).transpose()
        p = rotations.mx2aa(mx)
        #print mx - rotations.aa2mx(p)
#        print a1-np.dot(rotations.aa2mx(p), np.array([1., 0., 0.]))
        ca.rotRigid[i] = p
    return coords
Пример #9
0
def map_to_aa(xyz):
    coords = np.zeros(6 * 13)
    ca = CoordsAdapter(nrigid=13, coords=coords)
    for i in xrange(13):
        ca.posRigid[i] = 0.5 * (xyz[2 * i] + xyz[2 * i + 1])
        a1 = -(xyz[2 * i] - xyz[2 * i + 1])

        if (i < 12):
            a3 = -(xyz[2 * i + 1] - xyz[2 * i + 3])
        else:
            a3 = -(xyz[2 * i - 1] - xyz[2 * i + 1])

        a2 = -np.cross(a1, a3)
        a3 = np.cross(a1, a2)
        a1 /= np.linalg.norm(a1)
        a2 /= np.linalg.norm(a2)
        a3 /= np.linalg.norm(a3)
        #       print np.dot(a1, a2), np.dot(a1, a3), np.dot(a2, a3)
        mx = np.array([a1, a2, a3]).transpose()
        p = rotations.mx2aa(mx)
        #print mx - rotations.aa2mx(p)
        #        print a1-np.dot(rotations.aa2mx(p), np.array([1., 0., 0.]))
        ca.rotRigid[i] = p
    return coords
Пример #10
0
e2.append(pot.getEnergy(path[0]))

for i in xrange(1):
    for i in xrange(len(path)-1):
        e1.append(pot.getEnergy(path[i+1]))
        c1 = CoordsAdapter(nrigid=13, coords = path[i])
        c2 = CoordsAdapter(nrigid=13, coords = path[i+1])
        com1 = np.sum(c1.posRigid,axis=0) / float(13)
        com2 = np.sum(c1.posRigid,axis=0) / float(13)
        c1.posRigid-=com1    
        c2.posRigid-=com2    
        mx = findrotation_kabsch(c2.posRigid, c1.posRigid)
        #print mx
        c2.posRigid[:] = np.dot(mx, c2.posRigid.transpose()).transpose()
        for p in c2.rotRigid:
            p[:] = rotations.rotate_aa(p, rotations.mx2aa(mx))
        e2.append(pot.getEnergy(path[i+1]))
    
        for p1,p2 in zip(c1.rotRigid, c2.rotRigid):
            n2 = p2/np.linalg.norm(p2)*2.*pi
            
            while True:
                p2n = p2+n2
                if(np.linalg.norm(p2n - p1) > np.linalg.norm(p2 - p1)):
                    break
                p2[:]=p2n
                
            while True:
                p2n = p2-n2
                if(np.linalg.norm(p2n - p1) > np.linalg.norm(p2 - p1)):
                    break
Пример #11
0
 def invert(self, X):
     ca = self.topology.coords_adapter(X)
     ca.posRigid[:] = - ca.posRigid 
     for p, site in zip(ca.rotRigid, self.topology.sites):
         p[:] = rotations.rotate_aa(rotations.mx2aa(site.inversion), p)
Пример #12
0
e2.append(pot.getEnergy(path[0]))

for i in xrange(1):
    for i in xrange(len(path) - 1):
        e1.append(pot.getEnergy(path[i + 1]))
        c1 = CoordsAdapter(nrigid=13, coords=path[i])
        c2 = CoordsAdapter(nrigid=13, coords=path[i + 1])
        com1 = np.sum(c1.posRigid, axis=0) / float(13)
        com2 = np.sum(c1.posRigid, axis=0) / float(13)
        c1.posRigid -= com1
        c2.posRigid -= com2
        mx = findrotation_kabsch(c2.posRigid, c1.posRigid)
        #print mx
        c2.posRigid[:] = np.dot(mx, c2.posRigid.transpose()).transpose()
        for p in c2.rotRigid:
            p[:] = rotations.rotate_aa(p, rotations.mx2aa(mx))
        e2.append(pot.getEnergy(path[i + 1]))

        for p1, p2 in zip(c1.rotRigid, c2.rotRigid):
            n2 = p2 / np.linalg.norm(p2) * 2. * pi

            while True:
                p2n = p2 + n2
                if (np.linalg.norm(p2n - p1) > np.linalg.norm(p2 - p1)):
                    break
                p2[:] = p2n

            while True:
                p2n = p2 - n2
                if (np.linalg.norm(p2n - p1) > np.linalg.norm(p2 - p1)):
                    break