示例#1
0
文件: aatopology.py 项目: jdf43/pele
 def zeroEV(self, x):
     zev = []
     ca = self.coords_adapter(x)
     cv = self.coords_adapter(np.zeros(x.shape))
         
     translate_rigid = zeroev.zeroEV_translation(ca.posRigid)
     
     for v in translate_rigid:
         cv.posRigid[:] = v
         zev.append(cv.coords.copy())
         
     #rotate_r = zeroev.zeroEV_rotation(ca.posRigid)
     #rotate_aa = 
     transform = TransformAngleAxisCluster(self)
     d = 1e-5
     dx = x.copy()
     transform.rotate(dx, rotations.aa2mx(np.array([d, 0, 0])))
     self.align_path([x, dx])
     dx -= x
     dx /= np.linalg.norm(dx)
     
     dy = x.copy()
     transform.rotate(dy, rotations.aa2mx(np.array([0, d, 0])))
     self.align_path([x, dy])
     dy -= x
     dy /= np.linalg.norm(dy)
     
     dz = x.copy()
     transform.rotate(dz, rotations.aa2mx(np.array([0, 0, d])))
     self.align_path([x, dz])
     dz -= x
     dz /= np.linalg.norm(dz)
     
     #print "Zero eigenvectors", zev         
     return zev + [dx, dy, dz]
示例#2
0
    def _zeroEV_python(self, x):
        """return a list of zero eigenvectors
        
        This does both translational and rotational eigenvectors
        """
        zev = []
        ca = self.coords_adapter(x)
        cv = self.coords_adapter(np.zeros(x.shape))

        # get the zero eigenvectors corresponding to translation
        translate_rigid = zeroev.zeroEV_translation(ca.posRigid)

        for v in translate_rigid:
            cv.posRigid[:] = v
            zev.append(cv.coords.copy())

        # get the zero eigenvectors corresponding to rotation
        #rotate_r = zeroev.zeroEV_rotation(ca.posRigid)
        #rotate_aa = 
        transform = TransformAngleAxisCluster(self)
        d = 1e-5
        dx = x.copy()
        transform.rotate(dx, rotations.aa2mx(np.array([d, 0, 0])))
        self.align_path([x, dx])
        dx -= x
        dx /= np.linalg.norm(dx)

        dy = x.copy()
        transform.rotate(dy, rotations.aa2mx(np.array([0, d, 0])))
        self.align_path([x, dy])
        dy -= x
        dy /= np.linalg.norm(dy)

        dz = x.copy()
        transform.rotate(dz, rotations.aa2mx(np.array([0, 0, d])))
        self.align_path([x, dz])
        dz -= x
        dz /= np.linalg.norm(dz)

        #print "Zero eigenvectors", zev         
        return zev + [dx, dy, dz]
示例#3
0
class TestRBTopologyOTP(unittest.TestCase):
    def setUp(self):
        np.random.seed(0)
        self.nmol = 3
        self.system = OTPCluster(self.nmol)
        #        pot = self.system.get_potential()
        #        self.db = self.system.create_database()
        #        self.m1 = self.db.addMinimum(pot.getEnergy(_x1), _x1)
        #        self.m2 = self.db.addMinimum(pot.getEnergy(_x2), _x2)

        self.x0 = np.array([
            0, 1, 2, 3, 4, 5, 6, 7, 8, 0.517892, 0.575435, 0.632979, 0.531891,
            0.576215, 0.620539, 0.540562, 0.5766, 0.612637
        ])

        from pele.angleaxis.aamindist import TransformAngleAxisCluster
        self.topology = self.system.aatopology
        self.transform = TransformAngleAxisCluster(self.topology)

        self.p0 = np.array(list(range(1, 4)), dtype=float)
        self.p0 /= np.linalg.norm(self.p0)

    def test_transform_rotate(self):
        print("\ntest rotate")
        x = self.x0.copy()
        p = np.array(list(range(1, 4)), dtype=float)
        p /= np.linalg.norm(p)
        self.transform.rotate(x, rotations.aa2mx(p))

        xnewtrue = np.array([
            0.48757698, 0.61588594, 2.09355038, 2.02484605, 4.76822812,
            4.81289924, 3.56211511, 8.92057031, 7.53224809, 0.71469473,
            1.23875927, 1.36136748, 0.72426504, 1.24674367, 1.34426835,
            0.73015833, 1.25159032, 1.33345003
        ])
        for v1, v2 in zip(x, xnewtrue):
            self.assertAlmostEqual(v1, v2, 5)

    def test_align_path(self):
        print("\ntest align_path")
        x1 = self.x0.copy()
        x2 = self.x0 + 5

        self.topology.align_path([x1, x2])

        x2true = np.array([
            5., 6., 7., 8., 9., 10., 11., 12., 13., 1.92786071, 1.94796529,
            1.96807021, 1.93320298, 1.94869267, 1.96418236, 1.93645608,
            1.94905155, 1.96164668
        ])

        for v1, v2 in zip(x1, self.x0):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in zip(x2, x2true):
            self.assertAlmostEqual(v1, v2, 5)

    def test_cpp_zero_ev(self):
        print("\ntest zeroEV cpp")
        x = self.x0.copy()
        zev = self.topology._zeroEV_python(x)
        czev = self.topology.cpp_topology.get_zero_modes(x)
        self.assertEqual(len(czev), 6)
        for ev, cev in zip(zev, czev):
            for v1, v2 in zip(ev, cev):
                self.assertAlmostEqual(v1, v2, 5)

    def test_site_distance_squared(self):
        print("\ntest site distance squared")
        c0 = np.zeros(3)
        c1 = np.ones(3)
        p0 = self.p0.copy()
        p1 = p0 + 1
        site = make_otp()
        d2 = site.distance_squared(c0, p0, c1, p1)
        d2p = _sitedist(c1 - c0, p0, p1, site.S, site.W, site.cog)
        self.assertAlmostEqual(d2, 10.9548367929, 5)

    def test_distance_squared(self):
        print("\ntest distance squared")
        x1 = self.x0.copy()
        x2 = self.x0 + 1.1
        d2 = self.topology.distance_squared(x1, x2)
        d3 = self.topology._distance_squared_python(x1, x2)
        self.assertAlmostEqual(d2, 38.9401810973, 5)
        self.assertAlmostEqual(d2, d3, 5)

    def test_distance_squared_grad(self):
        print("\ntest distance squared grad")
        x1 = self.x0.copy()
        x2 = self.x0 + 1.1
        grad = self.topology.distance_squared_grad(x1, x2)
        g2 = self.topology._distance_squared_grad_python(x1, x2)

        gtrue = np.array([
            -6.6, -6.6, -6.6, -6.6, -6.6, -6.6, -6.6, -6.6, -6.6, -1.21579025,
            -0.07013805, -1.2988823, -1.21331786, -0.06984532, -1.28945301,
            -1.2116105, -0.06975828, -1.28362943
        ])
        for v1, v2 in zip(grad, gtrue):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in zip(grad, g2):
            self.assertAlmostEqual(v1, v2, 5)

    def test_measure_align(self):
        print("\ntest measure align")
        x1 = self.x0.copy()
        x2 = self.x0 + 5.1
        x2[-1] = x1[-1] + .1
        x20 = x2.copy()
        measure = MeasureRigidBodyCluster(self.topology)
        measure.align(x1, x2)
示例#4
0
class TestRBTopologyOTP(unittest.TestCase):
    def setUp(self):
        np.random.seed(0)
        self.nmol = 3
        self.system = OTPCluster(self.nmol)
#        pot = self.system.get_potential()
#        self.db = self.system.create_database()
#        self.m1 = self.db.addMinimum(pot.getEnergy(_x1), _x1)
#        self.m2 = self.db.addMinimum(pot.getEnergy(_x2), _x2)

        self.x0 = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 
                             0.517892, 0.575435, 0.632979, 
                             0.531891, 0.576215, 0.620539, 
                             0.540562, 0.5766, 0.612637 ])
        
        from pele.angleaxis.aamindist import TransformAngleAxisCluster
        self.topology = self.system.aatopology
        self.transform = TransformAngleAxisCluster(self.topology)
        
        self.p0 = np.array(list(range(1,4)), dtype=float)
        self.p0 /= np.linalg.norm(self.p0)

    
    def test_transform_rotate(self):
        print("\ntest rotate")
        x = self.x0.copy()
        p = np.array(list(range(1,4)), dtype=float)
        p /= np.linalg.norm(p)
        self.transform.rotate(x, rotations.aa2mx(p))
        
        xnewtrue = np.array([ 0.48757698,  0.61588594,  2.09355038,  2.02484605,  4.76822812,
                            4.81289924,  3.56211511,  8.92057031,  7.53224809,  0.71469473,
                            1.23875927,  1.36136748,  0.72426504,  1.24674367,  1.34426835,
                            0.73015833,  1.25159032,  1.33345003])
        for v1, v2 in zip(x, xnewtrue):
            self.assertAlmostEqual(v1, v2, 5)
    
    def test_align_path(self):
        print("\ntest align_path")
        x1 = self.x0.copy()
        x2 = self.x0 + 5
        
        self.topology.align_path([x1, x2])
        
        x2true = np.array([  5.        ,   6.        ,   7.        ,   8.        ,
                             9.        ,  10.        ,  11.        ,  12.        ,
                            13.        ,   1.92786071,   1.94796529,   1.96807021,
                             1.93320298,   1.94869267,   1.96418236,   1.93645608,
                             1.94905155,   1.96164668])
        
        for v1, v2 in zip(x1, self.x0):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in zip(x2, x2true):
            self.assertAlmostEqual(v1, v2, 5)
    
    def test_cpp_zero_ev(self):
        print("\ntest zeroEV cpp")
        x = self.x0.copy()
        zev = self.topology._zeroEV_python(x)
        czev = self.topology.cpp_topology.get_zero_modes(x)
        self.assertEqual(len(czev), 6)
        for ev, cev in zip(zev, czev):
            for v1, v2 in zip(ev, cev):
                self.assertAlmostEqual(v1, v2, 5)     
    
    def test_site_distance_squared(self):
        print("\ntest site distance squared")
        c0 = np.zeros(3)
        c1 = np.ones(3)
        p0 = self.p0.copy()
        p1 = p0 + 1
        site = make_otp()
        d2 = site.distance_squared(c0, p0, c1, p1)
        d2p = _sitedist(c1-c0, p0, p1, site.S, site.W, site.cog)
        self.assertAlmostEqual(d2, 10.9548367929, 5)


    def test_distance_squared(self):
        print("\ntest distance squared")
        x1 = self.x0.copy()
        x2 = self.x0 + 1.1
        d2 = self.topology.distance_squared(x1, x2)
        d3 = self.topology._distance_squared_python(x1, x2)
        self.assertAlmostEqual(d2, 38.9401810973, 5)
        self.assertAlmostEqual(d2, d3, 5)
        


    def test_distance_squared_grad(self):
        print("\ntest distance squared grad")
        x1 = self.x0.copy()
        x2 = self.x0 + 1.1
        grad = self.topology.distance_squared_grad(x1, x2)
        g2 = self.topology._distance_squared_grad_python(x1, x2)
        
        gtrue = np.array([-6.6       , -6.6       , -6.6       , -6.6       , -6.6       ,
                       -6.6       , -6.6       , -6.6       , -6.6       , -1.21579025,
                       -0.07013805, -1.2988823 , -1.21331786, -0.06984532, -1.28945301,
                       -1.2116105 , -0.06975828, -1.28362943])
        for v1, v2 in zip(grad, gtrue):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in zip(grad, g2):
            self.assertAlmostEqual(v1, v2, 5)
    
    def test_measure_align(self):
        print("\ntest measure align")
        x1 = self.x0.copy()
        x2 = self.x0 + 5.1
        x2[-1] = x1[-1] + .1
        x20 = x2.copy()
        measure = MeasureRigidBodyCluster(self.topology)
        measure.align(x1, x2)