Пример #1
0
    def test_val_0D_1(self):
        """Values without PBC"""

        masses = np.array([1., 2., 1.])

        ric = RIC()
        ric.add_eckart(trans=[True] * 3, rots=[False] * 3)
        ric.setup(masses)

        for coords, ref in [([[0, 0, 0], [0, 0, 0], [0, 0, 0]], [0, 0, 0]),
                            ([[-1, -1, -1], [0, 0, 0], [1, 1, 1]], [0, 0, 0]),
                            ([[-2, 0, 0], [2, 0, 0], [-2, 0, 0]], [0, 0, 0])]:

            ric.construct_b_matrix(None, np.array(coords, dtype=np.float64))
            res = ric.get_val_eckarts()
            self.assertListEqual(list(res), list(ref))
Пример #2
0
    def test_7(self):

        masses = np.array(range(1, 2), dtype=np.float64)

        ric = RIC()
        ric.add_eckart(rots=[False, 0, 'a'])
        ric.setup(masses)

        self.assertListEqual(list(ric._ric.ric_def_eckart_rots), [3])
        self.assertListEqual(list(ric._ric.ric_ibr_eckart_rots), [4])

        self.assertEqual(ric.num_ric, 4)
        self.assertEqual(ric.num_stretch, 0)
        self.assertEqual(ric.num_in_bend, 0)
        self.assertEqual(ric.num_out_bend, 0)
        self.assertEqual(ric.num_lin_bend, 0)
        self.assertEqual(ric.num_torsion, 0)
        self.assertEqual(ric.num_eckart, 4)
Пример #3
0
    def test_2(self):
        """Multiple repeated calls"""

        ric = RIC()
        ric.add_stretch([1, 2])
        ric.add_stretch([2, 3])
        ric.add_stretch([3, 4])
        ric.add_in_bend([1, 2, 3])
        ric.add_in_bend([2, 3, 4])
        ric.add_torsion([1, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0])
        ric.add_eckart()
        ric.setup(self.masses)

        bmat = ric.construct_b_matrix(None, self.coords)
        b1 = np.copy(bmat)
        bmat = ric.construct_b_matrix(None, self.coords)
        b2 = np.copy(bmat)
        self.assertEqual(np.max(np.abs(b1 - b2)), 0)

        bmat_inv, rank = ric.invert_b_matrix()
        i1 = np.copy(bmat_inv)
        bmat = ric.construct_b_matrix(None, self.coords)
        b3 = np.copy(bmat)
        bmat_inv, rank = ric.invert_b_matrix()
        i2 = np.copy(bmat_inv)
        self.assertEqual(np.max(np.abs(b1 - b3)), 0)
        self.assertEqual(np.max(np.abs(i1 - i2)), 0)

        hess = ric.project_hessian(self.hess)
        h1 = np.copy(hess)
        bmat = ric.construct_b_matrix(None, self.coords)
        b4 = np.copy(bmat)
        bmat_inv, rank = ric.invert_b_matrix()
        i3 = np.copy(bmat_inv)
        hess = ric.project_hessian(self.hess)
        h2 = np.copy(hess)
        hess = ric.get_ric_hessian()
        h3 = np.copy(hess)
        self.assertEqual(np.max(np.abs(b1 - b4)), 0)
        self.assertEqual(np.max(np.abs(i1 - i3)), 0)
        self.assertEqual(np.max(np.abs(h1 - h2)), 0)
        self.assertEqual(np.max(np.abs(h1 - h3)), 0)
Пример #4
0
    def test_1(self):

        ric = RIC()
        ric.add_stretch([1, 2])
        ric.add_eckart()
        ric.setup(self.masses)

        bmat = ric.construct_b_matrix(self.hmat, self.coords)

        self.assertEqual(
            ric.get_val_stretches()[0],
            np.sqrt(np.sum((self.coords[0, :] - self.coords[1, :])**2)))

        bmat_inv, rank = ric.invert_b_matrix()
        bmat_inv_ = nl.pinv(bmat)
        self.assertLess(np.max(np.abs(bmat_inv - bmat_inv_)), 1.e-14)

        hess = ric.project_hessian(self.hess)
        hess_ = np.dot(bmat_inv.T, np.dot(self.hess, bmat_inv))
        self.assertLess(np.max(np.abs(hess - hess_)), 1.e-14)
Пример #5
0
    def test_1(self):

        ric = RIC()
        ric.add_stretch([1, 2])
        ric.add_stretch([2, 3])
        ric.add_stretch([3, 4])
        ric.add_in_bend([1, 2, 3])
        ric.add_in_bend([2, 3, 4])
        ric.add_torsion([1, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0])
        ric.add_eckart()
        ric.setup(self.masses)

        bmat = ric.construct_b_matrix(None, self.coords)

        bmat_inv, rank = ric.invert_b_matrix()
        bmat_inv_ = nl.pinv(bmat)
        self.assertLess(np.max(np.abs(bmat_inv - bmat_inv_)), 7.e-14)

        hess = ric.project_hessian(self.hess)
        hess_ = np.dot(bmat_inv.T, np.dot(self.hess, bmat_inv))
        self.assertLess(np.max(np.abs(hess - hess_)), 3.e-13)
Пример #6
0
  def test_2(self):

    g1, g2 = Group([1,2,3]), Group([5,6,7])

    ric = RIC()
    ric.add_stretch([1,3])
    ric.add_stretch([2,3])
    ric.add_distance([g1,4])
    ric.add_distance([4,g2])
    ric.add_stretch([5,6])
    ric.add_stretch([5,7])
    ric.add_in_bend([1,3,2])
    ric.add_in_bend([1,3,4])
    ric.add_in_bend([2,3,4])
    ric.add_in_bend([4,5,6])
    ric.add_in_bend([4,5,7])
    ric.add_in_bend([6,5,7])
    ric.add_lin_bend([3,4,5], 'yz')
    ric.add_out_bend([3,1,2,4])
    ric.add_out_bend([3,2,4,1])
    ric.add_out_bend([3,4,1,2])
    ric.add_out_bend([5,4,6,7])
    ric.add_out_bend([5,6,7,4])
    ric.add_out_bend([5,7,4,6])
    ric.add_dihedral([1,2], [g1,g2], [6,7])
    ric.add_eckart()
    ric.setup(self.masses)

    bmat = ric.construct_b_matrix(None, self.coords)

    bmat_inv, rank = ric.invert_b_matrix()
    bmat_inv_ = nl.pinv(bmat)
    self.assertEqual(rank, self.coords.size)
    self.assertLess(np.max(np.abs(bmat_inv - bmat_inv_)), 1.e-13)

    hess = ric.project_hessian(self.hess)
    hess_ = np.dot(bmat_inv.T,np.dot(self.hess,bmat_inv))
    self.assertLess(np.max(np.abs(hess - hess_)),1.e-13)
Пример #7
0
    def test_8(self):

        masses = np.array(range(1, 10), dtype=np.float64)

        ric = RIC()
        ric.add_stretch([2, 3])
        ric.add_in_bend([3, 4, 5])
        ric.add_out_bend([4, 5, 6, 7])
        ric.add_lin_bend([5, 6, 7], 'xy')
        ric.add_torsion([1, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8])
        ric.add_torsion([3, 4, 0, 0, 0, 5, 6, 7, 8, 9, 0, 0])
        ric.add_eckart(rots=[True, False, True])
        ric.setup(masses)

        self.assertTrue(np.all(ric._ric.atomic_masses == masses))
        self.assertListEqual(list(ric._ric.cart_coords.shape), [3, 9])
        self.assertListEqual(list(ric._ric.cart_hessian.shape), [3 * 9, 3 * 9])
        self.assertListEqual(list(ric._ric.ric_ibr_stretches), [1])
        self.assertListEqual(list(ric._ric.ric_ibr_in_bends), [2])
        self.assertListEqual(list(ric._ric.ric_ibr_out_bends), [3])
        self.assertListEqual(list(ric._ric.ric_ibr_lin_bends), [4, 5])
        self.assertListEqual(list(ric._ric.ric_ibr_torsions), [6, 7])
        self.assertListEqual(list(ric._ric.ric_ibr_eckart_trans), [8, 9, 10])
        self.assertListEqual(list(ric._ric.ric_ibr_eckart_rots), [11, 12])
        self.assertListEqual(list(ric._ric.bmat.shape), [3 * 9, 12])
        self.assertEqual(ric._ric.ric_val_stretches.size, 1)
        self.assertEqual(ric._ric.ric_val_in_bends.size, 1)
        self.assertEqual(ric._ric.ric_val_out_bends.size, 1)
        self.assertEqual(ric._ric.ric_val_lin_bends.size, 2)
        self.assertListEqual(list(ric._ric.ric_hessian.shape), [12, 12])

        self.assertEqual(ric.num_ric, 12)
        self.assertEqual(ric.num_stretch, 1)
        self.assertEqual(ric.num_in_bend, 1)
        self.assertEqual(ric.num_out_bend, 1)
        self.assertEqual(ric.num_lin_bend, 2)
        self.assertEqual(ric.num_torsion, 2)
        self.assertEqual(ric.num_eckart, 5)
Пример #8
0
    def test_grad_0D_1(self):

        masses = np.array([1., 2., 1.])

        ric = RIC()
        ric.add_eckart(trans=[True] * 3, rots=[False] * 3)
        ric.setup(masses)

        def func(x):
            ric.construct_b_matrix(None, np.reshape(x, (3, 3)))
            return np.copy(ric.get_val_eckarts())

        jac = nd.Jacobian(func, step_nom=[0.01] * 9)

        for coords in [[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
                       [[-1, -1, -1], [0, 0, 0], [1, 1, 1]],
                       [[-2, 0, 0], [2, 0, 0], [-2, 0, 0]]]:
            coords = np.array(coords, dtype=np.float64)
            ref = jac(coords.flatten())
            res = ric.construct_b_matrix(None, coords)
            #print ref
            #print res
            self.assertLess(np.max(np.abs(ref - res)), 1.e-12)
Пример #9
0
  def test_1(self):

    ric = RIC()
    ric.add_stretch([1,3])
    ric.add_stretch([2,3])
    ric.add_stretch([3,4])
    ric.add_stretch([4,5])
    ric.add_stretch([5,6])
    ric.add_stretch([5,7])
    ric.add_in_bend([1,3,2])
    ric.add_in_bend([1,3,4])
    ric.add_in_bend([2,3,4])
    ric.add_in_bend([4,5,6])
    ric.add_in_bend([4,5,7])
    ric.add_in_bend([6,5,7])
    ric.add_lin_bend([3,4,5], 'yz')
    ric.add_out_bend([3,1,2,4])
    ric.add_out_bend([3,2,4,1])
    ric.add_out_bend([3,4,1,2])
    ric.add_out_bend([5,4,6,7])
    ric.add_out_bend([5,6,7,4])
    ric.add_out_bend([5,7,4,6])
    ric.add_torsion([1,2,0,0,0,3,5,6,7,0,0,0])
    ric.add_eckart()
    ric.setup(self.masses)

    bmat = ric.construct_b_matrix(None, self.coords)

    bmat_inv, rank = ric.invert_b_matrix()
    bmat_inv_ = nl.pinv(bmat)
    self.assertEqual(rank, self.coords.size)
    self.assertLess(np.max(np.abs(bmat_inv - bmat_inv_)), 7.e-14)

    hess = ric.project_hessian(self.hess)
    hess_ = np.dot(bmat_inv.T,np.dot(self.hess,bmat_inv))
    self.assertLess(np.max(np.abs(hess - hess_)),3.e-13)