示例#1
0
文件: test_otp.py 项目: cjforman/pele
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(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(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 izip(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 izip(x1, self.x0):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in izip(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 izip(zev, czev):
            for v1, v2 in izip(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 = self.system.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 izip(grad, gtrue):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in izip(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)
示例#2
0
文件: test_otp.py 项目: cjforman/pele
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(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(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 izip(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 izip(x1, self.x0):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in izip(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 izip(zev, czev):
            for v1, v2 in izip(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 = self.system.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 izip(grad, gtrue):
            self.assertAlmostEqual(v1, v2, 5)
        for v1, v2 in izip(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)