Exemple #1
0
class TestAAMindist(unittest.TestCase):
    def setUp(self):
        #GMIN.initialize()
#        self.pot = GMINPotential(GMIN)
        self.nrigid = 10
        self.water = create_water()
        self.topology = RBTopology()
        self.topology.add_sites([deepcopy(self.water) for i in xrange(self.nrigid)])    

#    def test_zeroev(self):
#        x = self.pot.getCoords()
#        zev = self.topology.zeroEV(x)
#        
#        eps = 1e-5
#        for dx in zev:    
#            print "ev test", (self.pot.getEnergy(x) - self.pot.getEnergy(x + eps*dx))/eps  
#        
#        dx = np.random.random(x.shape)
#        dx/=np.linalg.norm(dx)
#        print "ev test", (self.pot.getEnergy(x) - self.pot.getEnergy(x + eps*dx))/eps
        
    def test_distance(self):  
        for i in xrange(100):
            coords1 = np.random.random(6*self.nrigid)*4
            coords2 = np.random.random(6*self.nrigid)*4
            
            coords1[:3*self.nrigid]=0
            coords2[:3*self.nrigid]=0
            
            measure1 = am.MeasureAngleAxisCluster(self.topology)
            measure2 = am.MeasureRigidBodyCluster(self.topology)
            
            #print 
            self.assertAlmostEqual(measure1.get_dist(coords1, coords2),
                                   measure2.get_dist(coords1, coords2))
Exemple #2
0
    def setup_aatopology(self):
        GMIN.initialize()
        pot = GMINPotential(GMIN)
        coords = pot.getCoords()
        nrigid = coords.size / 6

        print "I have %d PAP molecules in the system" % nrigid
        print "The initial energy is", pot.getEnergy(coords)

        water = create_pap()

        system = RBTopology()
        system.add_sites([deepcopy(water) for i in xrange(nrigid)])
        self.potential = pot
        self.nrigid = nrigid

        self.render_scale = 0.1
        self.atom_types = system.get_atomtypes()

        self.draw_bonds = []
        for i in xrange(nrigid):
            self.draw_bonds.append((3 * i, 3 * i + 1))
            self.draw_bonds.append((3 * i, 3 * i + 2))

        return system
Exemple #3
0
 def setUp(self):
     self.nrigid = 10
     self.topology = RBTopology()
     self.topology.add_sites(
         [create_tetrahedron() for _ in range(self.nrigid)])
     self.topology.finalize_setup()
     self.measure = MeasureAngleAxisCluster(self.topology)
Exemple #4
0
class TestAAMeasure(unittest.TestCase):
    def setUp(self):
        self.nrigid = 10
        self.topology = RBTopology()
        self.topology.add_sites(
            [create_tetrahedron() for _ in range(self.nrigid)])
        self.topology.finalize_setup()
        self.measure = MeasureAngleAxisCluster(self.topology)

    def test_cpp_align(self):
        x1 = np.array([random_aa() for _ in range(2 * self.nrigid)]).ravel()
        x2 = np.array([random_aa() for _ in range(2 * self.nrigid)]).ravel()

        x1_cpp = x1.copy()
        x2_cpp = x2.copy()
        x1_python = x1.copy()
        x2_python = x2.copy()

        ret = self.measure._align_pythonic(x1_python, x2_python)
        self.assertIsNone(ret)
        ret = self.measure.align(x1_cpp, x2_cpp)
        self.assertIsNone(ret)

        assert_arrays_almost_equal(self, x1_python, x1)
        assert_arrays_almost_equal(self, x1_cpp, x1)

        # assert that the center of mass coordinates didn't change
        assert_arrays_almost_equal(self, x2_python[:3 * self.nrigid],
                                   x2[:3 * self.nrigid])
        assert_arrays_almost_equal(self, x2_cpp[:3 * self.nrigid],
                                   x2[:3 * self.nrigid])

        # assert that x2 actually changed
        max_change = np.max(np.abs(x2_cpp - x2))
        self.assertGreater(max_change, 1e-3)

        assert_arrays_almost_equal(self, x2_python, x2_cpp)

    def test_align_bad_input(self):
        x1 = np.array([random_aa() for _ in range(2 * self.nrigid)]).ravel()
        x2 = list(x1)

        with self.assertRaises(TypeError):
            self.measure.align(x1, x2)

    def test_symmetries(self):
        tet = create_tetrahedron()
        print(tet.symmetries)
        self.assertEqual(len(tet.symmetries), 12)

    def test_align_exact(self):
        x1 = np.array([random_aa() for _ in range(2 * self.nrigid)]).ravel()
        x2 = x1.copy()
        tet = create_tetrahedron()
        mx = tet.symmetries[2].copy()
        p = x2[-3:].copy()
        x2[-3:] = rotations.rotate_aa(rotations.mx2aa(mx), p)

        self.measure._align_pythonic(x1, x2)
        assert_arrays_almost_equal(self, x1, x2)
Exemple #5
0
    def setup_aatopology(self):
        GMIN.initialize()
        pot = GMINPotential(GMIN)
        coords = pot.getCoords()        
        nrigid = old_div(coords.size, 6)

        print("I have %d water molecules in the system"%nrigid)
        print("The initial energy is", pot.getEnergy(coords))

        water = create_base()
        
        system = RBTopology()
        system.add_sites([deepcopy(water) for i in range(nrigid)])
        self.potential = pot
        self.nrigid = nrigid
        
        self.render_scale = 0.15
        self.atom_types = system.get_atomtypes()
        
        self.draw_bonds = []
        for i in range(nrigid-1):
            self.draw_bonds.append((2*i, 2*i+1))
            self.draw_bonds.append((2*i, 2*i+2))
    
        return system
Exemple #6
0
    def setup_aatopology(self):
        GMIN.initialize()
        pot = GMINPotential(GMIN)
        coords = pot.getCoords()        
        nrigid = coords.size / 6

        print "I have %d water molecules in the system"%nrigid
        print "The initial energy is", pot.getEnergy(coords)

        water = tip4p.water()
        
        system = RBTopology()
        system.add_sites([deepcopy(water) for i in xrange(nrigid)])
        self.potential = pot
        self.nrigid = nrigid
        
        self.render_scale = 0.3
        self.atom_types = system.get_atomtypes()
        
        self.draw_bonds = []
        for i in xrange(nrigid):
            self.draw_bonds.append((3*i, 3*i+1))
            self.draw_bonds.append((3*i, 3*i+2))
    
        return system
Exemple #7
0
    def setUp(self):
        #GMIN.initialize()
#        self.pot = GMINPotential(GMIN)
        self.nrigid = 10
        self.water = create_water()
        self.topology = RBTopology()
        self.topology.add_sites([deepcopy(self.water) for _ in xrange(self.nrigid)])
        self.topology.finalize_setup()
Exemple #8
0
class TestAAMeasure(unittest.TestCase):
    def setUp(self):
        self.nrigid = 10
        self.topology = RBTopology()
        self.topology.add_sites([create_tetrahedron() for _ in range(self.nrigid)])
        self.topology.finalize_setup()
        self.measure = MeasureAngleAxisCluster(self.topology)
    
    def test_cpp_align(self):
        x1 = np.array([random_aa() for _ in range(2*self.nrigid)]).ravel()
        x2 = np.array([random_aa() for _ in range(2*self.nrigid)]).ravel()
        
        x1_cpp = x1.copy()
        x2_cpp = x2.copy()
        x1_python = x1.copy()
        x2_python = x2.copy()
        
        ret = self.measure._align_pythonic(x1_python, x2_python)
        self.assertIsNone(ret)
        ret = self.measure.align(x1_cpp, x2_cpp)
        self.assertIsNone(ret)
        
        assert_arrays_almost_equal(self, x1_python, x1)
        assert_arrays_almost_equal(self, x1_cpp, x1)
        
        # assert that the center of mass coordinates didn't change
        assert_arrays_almost_equal(self, x2_python[:3*self.nrigid], x2[:3*self.nrigid])
        assert_arrays_almost_equal(self, x2_cpp[:3*self.nrigid], x2[:3*self.nrigid])
        
        # assert that x2 actually changed
        max_change = np.max(np.abs(x2_cpp - x2))
        self.assertGreater(max_change, 1e-3)

        assert_arrays_almost_equal(self, x2_python, x2_cpp)

    def test_align_bad_input(self):
        x1 = np.array([random_aa() for _ in range(2*self.nrigid)]).ravel()
        x2 = list(x1)
        
        with self.assertRaises(TypeError):
            self.measure.align(x1, x2)

    def test_symmetries(self):
        tet = create_tetrahedron()
        print(tet.symmetries)
        self.assertEqual(len(tet.symmetries), 12)


    def test_align_exact(self):
        x1 = np.array([random_aa() for _ in range(2*self.nrigid)]).ravel()
        x2 = x1.copy()
        tet = create_tetrahedron()
        mx = tet.symmetries[2].copy() 
        p = x2[-3:].copy()
        x2[-3:] = rotations.rotate_aa(rotations.mx2aa(mx), p)
        
        self.measure._align_pythonic(x1, x2)
        assert_arrays_almost_equal(self, x1, x2)
Exemple #9
0
    def setup_aatopology(self):
        water_sites, ref = water(self.xyzfile)
        rbsystem = RBTopology()
        rbsystem.add_sites(water_sites)
        rbsystem.finalize_setup()
        #print len(rbsystem.sites), len(rbsystem.indices)
        print "I have %d water molecules in the system" % len(rbsystem.sites)
        rbcoords = rbsystem.coords_adapter(np.zeros(len(rbsystem.sites)*6))
        for site, com in zip(rbsystem.sites, rbcoords.posRigid):
            com[:] = ref.coords[site.atom_indices[0]] - site.atom_positions[0]
        pot = LJ(eps=0.1550, sig=3.1536)
        # get the flattened coordinate array
        print "The initial energy is", pot.getEnergy(ref.coords.flatten())
        rbpot = rigidbody.RBPotentialWrapper(rbsystem, pot) 
        print "rbpot.getEnergy(rbcoords.coords)", rbpot.getEnergy(rbcoords.coords)
        e, g = rbpot.getEnergyGradient(rbcoords.coords)
        g_n = rbpot.NumericalDerivative(rbcoords.coords, eps=1e-4)
        cg = rbsystem.coords_adapter(g-g_n)

        # coords = rbpot.getCoords()
        # nrigid = rbcoords.size / 6
        # print "nrigid", nrigid
        self.potential = rbpot
        self.nrigid = len(rbsystem.sites)
        self.render_scale = 0.3
        self.atom_types = rbsystem.get_atomtypes()
Exemple #10
0
 def setup_aatopology(self):
     """this sets up the topology for the whole rigid body system"""
     topology = RBTopology()
     topology.add_sites([self.make_otp() for i in xrange(self.nrigid)])
     
     self.render_scale = 0.2
     self.atom_types = topology.get_atomtypes()
     
     self.draw_bonds = []
     for i in xrange(self.nrigid):
         self.draw_bonds.append((3*i, 3*i+1))
         self.draw_bonds.append((3*i, 3*i+2))
 
     return topology
 def make_atom_indices_cpp_topology(self, atom_indices=None):
     sites = [make_otp() for _ in xrange(self.nrigid)]
     if atom_indices is None:
         atom_indices = np.array(range(self.nrigid*3), dtype=int)
         np.random.shuffle(atom_indices)
     i = 0
     for site in sites:
         site.atom_indices = atom_indices[i:i+site.get_natoms()].copy()
         i += site.get_natoms()
     
     topology = RBTopology()
     topology.add_sites(sites)
     topology.finalize_setup(use_cpp=False)
     return topology, atom_indices
Exemple #12
0
 def setUp(self):
     nrigid = 3
     self.topology = RBTopology()
     self.topology.add_sites([self.make_otp() for i in xrange(nrigid)])
     
     cartesian_potential = LJ()
     self.pot = RBPotentialWrapper(self.topology, cartesian_potential)
     
     self.x0 = [2.550757898788, 2.591553038507, 3.696836364193, 
             2.623281513163, 3.415794212648, 3.310786279789, 
             1.791383852327, 2.264321752809, 4.306217333671, 
             0.761945654023, -0.805817782109, 1.166981882601, 
             0.442065301864, -2.747066418223, -1.784325262714, 
             -1.520905562598, 0.403670860200, -0.729768985400, ]
     self.x0 = np.array(self.x0)
     self.e0 = -17.3387670023
     assert nrigid * 6 == self.x0.size
     
     self.x0atomistic = [ 3.064051819556, 2.474533745459, 3.646107658946,
                         2.412011983074, 2.941152759499, 4.243695098053, 
                         2.176209893734, 2.358972610563, 3.200706335581, 
                         2.786627589565, 3.211876105193, 2.850924310983, 
                         1.962626909252, 3.436918873216, 3.370903763850,
                         3.120590040673, 3.598587659535, 3.710530764535, 
                         1.697360211099, 2.317229950712, 4.823998989452, 
                         2.283487958310, 1.840698306602, 4.168734267290, 
                         1.393303387573, 2.635037001113, 3.925918744272, ]
     self.nrigid = nrigid
Exemple #13
0
    def setUp(self):
        #GMIN.initialize()
#        self.pot = GMINPotential(GMIN)
        self.nrigid = 10
        self.water = create_water()
        self.topology = RBTopology()
        self.topology.add_sites([deepcopy(self.water) for i in xrange(self.nrigid)])    
Exemple #14
0
    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([make_otp() for i in range(nrigid)])
        self.topology.finalize_setup()

        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)

        self.x0 = _x03
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size

        self.x0atomistic = _x03_atomistic
        self.nrigid = nrigid
Exemple #15
0
 def setup_aatopology(self):
     self.write_coords_data()
     GMIN.initialize()        
     self.pot = GMINPotential(GMIN)
     coords = self.pot.getCoords()
     self.nrigid = coords.size/6
     assert(self.nrigid == self.nmol)
     #self.nrigid = self.nmol
     otp = self.make_otp()
     topology = RBTopology()
     topology.add_sites([deepcopy(otp) for i in xrange(self.nrigid)])
     
     self.render_scale = 0.2
     self.atom_types = topology.get_atomtypes()
     
     self.draw_bonds = []
     for i in xrange(self.nrigid):
         self.draw_bonds.append((3*i, 3*i+1))
         self.draw_bonds.append((3*i, 3*i+2))
 
     self.params.double_ended_connect.local_connect_params.tsSearchParams.iprint = 10
     return topology
Exemple #16
0
class TestAAMindist(unittest.TestCase):
    def setUp(self):
        #GMIN.initialize()
        #        self.pot = GMINPotential(GMIN)
        self.nrigid = 10
        self.water = create_water()
        self.topology = RBTopology()
        self.topology.add_sites(
            [deepcopy(self.water) for _ in range(self.nrigid)])
        self.topology.finalize_setup()


#    def test_zeroev(self):
#        x = self.pot.getCoords()
#        zev = self.topology.zeroEV(x)
#
#        eps = 1e-5
#        for dx in zev:
#            print "ev test", (self.pot.getEnergy(x) - self.pot.getEnergy(x + eps*dx))/eps
#
#        dx = np.random.random(x.shape)
#        dx/=np.linalg.norm(dx)
#        print "ev test", (self.pot.getEnergy(x) - self.pot.getEnergy(x + eps*dx))/eps

    def test_distance(self):
        for i in range(100):
            coords1 = np.random.random(6 * self.nrigid) * 4
            coords2 = np.random.random(6 * self.nrigid) * 4

            coords1[:3 * self.nrigid] = 0
            coords2[:3 * self.nrigid] = 0

            measure1 = am.MeasureAngleAxisCluster(self.topology)
            measure2 = am.MeasureRigidBodyCluster(self.topology)

            #print
            self.assertAlmostEqual(measure1.get_dist(coords1, coords2),
                                   measure2.get_dist(coords1, coords2))
Exemple #17
0
class TestAATransform(unittest.TestCase):
    def setUp(self):
        self.nrigid = 10
        self.topology = RBTopology()
        self.topology.add_sites([create_water() for _ in range(self.nrigid)])
        self.topology.finalize_setup()
        self.transform = TransformAngleAxisCluster(self.topology)

    def test_cpp_rotate(self):
        x0 = np.array([random_aa() for _ in range(2 * self.nrigid)]).ravel()
        aa = random_aa()
        mx = aa2mx(aa)

        x0_rotated = x0.copy()
        self.transform.rotate(x0_rotated, mx)

        x0_rotated_python = x0.copy()
        self.transform._rotate_python(x0_rotated_python, mx)

        assert_arrays_almost_equal(self, x0_rotated, x0_rotated_python)

        mx_reverse = aa2mx(-aa)
        self.transform.rotate(x0_rotated, mx_reverse)
        assert_arrays_almost_equal(self, x0, x0_rotated)
Exemple #18
0
class TestAATransform(unittest.TestCase):
    def setUp(self):
        self.nrigid = 10
        self.topology = RBTopology()
        self.topology.add_sites([create_water() for _ in range(self.nrigid)])
        self.topology.finalize_setup()
        self.transform = TransformAngleAxisCluster(self.topology)
    
    def test_cpp_rotate(self):
        x0 = np.array([random_aa() for _ in range(2*self.nrigid)]).ravel()
        aa = random_aa()
        mx = aa2mx(aa)
        
        x0_rotated = x0.copy()
        self.transform.rotate(x0_rotated, mx)
        
        x0_rotated_python = x0.copy()
        self.transform._rotate_python(x0_rotated_python, mx)
        
        assert_arrays_almost_equal(self, x0_rotated, x0_rotated_python)
        
        mx_reverse = aa2mx(-aa)
        self.transform.rotate(x0_rotated, mx_reverse)
        assert_arrays_almost_equal(self, x0, x0_rotated)
Exemple #19
0
 def setUp(self):
     nrigid = 3
     self.topology = RBTopology()
     self.topology.add_sites([make_otp() for i in range(nrigid)])
     self.topology.finalize_setup()
     
     cartesian_potential = LJ()
     self.pot = RBPotentialWrapper(self.topology, cartesian_potential)
     
     self.x0 = _x03
     self.x0 = np.array(self.x0)
     self.e0 = -17.3387670023
     assert nrigid * 6 == self.x0.size
     
     self.x0atomistic = _x03_atomistic
     self.nrigid = nrigid
Exemple #20
0
 def setup_aatopology(self):
     """this sets up the topology for the whole rigid body system"""
     topology = RBTopology()
     topology.add_sites([self.make_otp() for _ in xrange(self.nrigid)])
     
     self.render_scale = 0.2
     self.atom_types = topology.get_atomtypes()
     
     self.draw_bonds = []
     for i in xrange(self.nrigid):
         self.draw_bonds.append((3*i, 3*i+1))
         self.draw_bonds.append((3*i, 3*i+2))
     
     topology.finalize_setup()
 
     return topology
Exemple #21
0
    def make_atom_indices_cpp_topology(self, atom_indices=None):
        sites = [make_otp() for _ in xrange(self.nrigid)]
        if atom_indices is None:
            atom_indices = np.array(range(self.nrigid * 3), dtype=int)
            np.random.shuffle(atom_indices)
        i = 0
        for site in sites:
            site.atom_indices = atom_indices[i:i + site.get_natoms()].copy()
            i += site.get_natoms()

        topology = RBTopology()
        topology.add_sites(sites)
        topology.finalize_setup(use_cpp=False)
        return topology, atom_indices
Exemple #22
0
    def setup_aatopology(self):
        """this sets up the topology for the whole rigid body system"""
        topology = RBTopology()
        topology.add_sites([make_triangular_plate() for i in xrange(self.nrigid)])
        
        self.render_scale = 0.2
        self.atom_types = topology.get_atomtypes()
        
        self.draw_bonds = []
#         for i in xrange(self.nrigid):
#             self.draw_bonds.append((3*i, 3*i+1))
#             self.draw_bonds.append((3*i, 3*i+2))
        
        topology.finalize_setup()
    
        return topology
Exemple #23
0
class TestOTPExplicit(unittest.TestCase):
    def make_otp(self):
        """this constructs a single OTP molecule"""
        otp = RigidFragment()
        otp.add_atom("O", np.array([0.0, -2. / 3 * np.sin(7. * pi / 24.),
                                    0.0]), 1.)
        otp.add_atom(
            "O",
            np.array([cos(7. * pi / 24.), 1. / 3. * sin(7. * pi / 24.), 0.0]),
            1.)
        otp.add_atom(
            "O",
            np.array([-cos(7. * pi / 24.), 1. / 3. * sin(7. * pi / 24), 0.0]),
            1.)
        otp.finalize_setup()
        return otp

    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([self.make_otp() for i in xrange(nrigid)])
        self.topology.finalize_setup()

        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)

        self.x0 = _x03
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size

        self.x0atomistic = _x03_atomistic
        self.nrigid = nrigid

    def test_energy(self):
        e = self.pot.getEnergy(self.x0)
        self.assertAlmostEqual(e, self.e0, delta=1e-4)

    def test_energy_gradient(self):
        e = self.pot.getEnergy(self.x0)
        gnum = self.pot.NumericalDerivative(self.x0)

        e2, g = self.pot.getEnergyGradient(self.x0)
        self.assertAlmostEqual(e, e2, delta=1e-4)

        for i in xrange(g.size):
            self.assertAlmostEqual(g[i], gnum[i], 2)

    def test_to_atomistic(self):
        xatom = self.topology.to_atomistic(self.x0).flatten()
        for i in xrange(xatom.size):
            self.assertAlmostEqual(xatom[i], self.x0atomistic[i], 2)

    def test_site_to_atomistic(self):
        rf = self.make_otp()
        p = np.array([1., 2, 3])
        p /= np.linalg.norm(p)
        com = np.array([4., 5, 6])
        print "otp to atomistic"
        print rf.to_atomistic(com, p)

        print "otp transform grad"
        g = np.array(range(9), dtype=float).reshape([-1, 3])
        print g.reshape(-1)

        print rf.transform_grad(p, g)

    def test_to_atomistic2(self):
        x0 = np.array(range(self.nrigid * 6), dtype=float)
        x2 = x0.reshape([-1, 3])
        for p in x2[self.nrigid:, :]:
            p /= np.linalg.norm(p)
        atomistic = self.topology.to_atomistic(x0).flatten()

        from pele.potentials import LJ
        lj = LJ()
        e, g = lj.getEnergyGradient(atomistic.reshape(-1))
        grb = self.topology.transform_gradient(x0, g)
        rbpot = RBPotentialWrapper(self.topology, lj)
        print rbpot.getEnergy(x0)
Exemple #24
0
class TestOTPExplicit(unittest.TestCase):
    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([make_otp() for i in range(nrigid)])
        self.topology.finalize_setup()

        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)

        self.x0 = _x03
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size

        self.x0atomistic = _x03_atomistic
        self.nrigid = nrigid

    def test_energy(self):
        e = self.pot.getEnergy(self.x0)
        self.assertAlmostEqual(e, self.e0, delta=1e-4)

    def test_energy_gradient(self):
        e = self.pot.getEnergy(self.x0)
        gnum = self.pot.NumericalDerivative(self.x0)

        e2, g = self.pot.getEnergyGradient(self.x0)
        self.assertAlmostEqual(e, e2, delta=1e-4)

        for i in range(g.size):
            self.assertAlmostEqual(g[i], gnum[i], 2)

    def test_to_atomistic(self):
        xatom = self.topology.to_atomistic(self.x0).flatten()
        for i in range(xatom.size):
            self.assertAlmostEqual(xatom[i], self.x0atomistic[i], 2)

    def test_site_to_atomistic(self):
        rf = make_otp()
        p = np.array([1., 2, 3])
        p /= np.linalg.norm(p)
        com = np.array([4., 5, 6])
        print("otp to atomistic")
        print(rf.to_atomistic(com, p))

        print("otp transform grad")
        g = np.array(list(range(9)), dtype=float).reshape([-1, 3])
        print(g.reshape(-1))

        print(rf.transform_grad(p, g))

    def test_to_atomistic2(self):
        x0 = np.array(list(range(self.nrigid * 6)), dtype=float)
        x2 = x0.reshape([-1, 3])
        for p in x2[self.nrigid:, :]:
            p /= np.linalg.norm(p)
        atomistic = self.topology.to_atomistic(x0).flatten()

        from pele.potentials import LJ
        lj = LJ()
        e, g = lj.getEnergyGradient(atomistic.reshape(-1))
        grb = self.topology.transform_gradient(x0, g)
        rbpot = RBPotentialWrapper(self.topology, lj)
        print(rbpot.getEnergy(x0))
Exemple #25
0
class TestOTPExplicit(unittest.TestCase):
    
    def make_otp(self):
        """this constructs a single OTP molecule"""
        otp = RigidFragment()
        otp.add_atom("O", np.array([0.0, -2./3 * np.sin( 7.*pi/24.), 0.0]), 1.)
        otp.add_atom("O", np.array([cos( 7.*pi/24.),  1./3. * sin( 7.* pi/24.), 0.0]), 1.)
        otp.add_atom("O", np.array([-cos( 7.* pi/24.),  1./3. * sin( 7.*pi/24), 0.0]), 1.)
        otp.finalize_setup()
        return otp

    
    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([self.make_otp() for i in xrange(nrigid)])
        self.topology.finalize_setup()
        
        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)
        
        self.x0 = _x03
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size
        
        self.x0atomistic = _x03_atomistic
        self.nrigid = nrigid
    
    def test_energy(self):
        e = self.pot.getEnergy(self.x0)
        self.assertAlmostEqual(e, self.e0, delta=1e-4)

    def test_energy_gradient(self):
        e = self.pot.getEnergy(self.x0)
        gnum = self.pot.NumericalDerivative(self.x0)
         
        e2, g = self.pot.getEnergyGradient(self.x0)
        self.assertAlmostEqual(e, e2, delta=1e-4)
         
        for i in xrange(g.size):
            self.assertAlmostEqual(g[i], gnum[i], 2)
    
    def test_to_atomistic(self):
        xatom = self.topology.to_atomistic(self.x0).flatten()
        for i in xrange(xatom.size):
            self.assertAlmostEqual(xatom[i], self.x0atomistic[i], 2)
    
    def test_site_to_atomistic(self):
        rf = self.make_otp()
        p = np.array([1., 2, 3])
        p /= np.linalg.norm(p)
        com = np.array([4., 5, 6])
        print "otp to atomistic"
        print rf.to_atomistic(com, p)
        

        print "otp transform grad"
        g = np.array(range(9), dtype=float).reshape([-1,3])
        print g.reshape(-1)
        
        print rf.transform_grad(p, g)
    
    def test_to_atomistic2(self):
        x0 = np.array(range(self.nrigid * 6), dtype=float)
        x2 = x0.reshape([-1,3])
        for p in x2[self.nrigid:,:]:
            p /= np.linalg.norm(p)
        atomistic = self.topology.to_atomistic(x0).flatten()
        
        from pele.potentials import LJ
        lj = LJ()
        e, g = lj.getEnergyGradient(atomistic.reshape(-1))
        grb = self.topology.transform_gradient(x0, g)
        rbpot = RBPotentialWrapper(self.topology, lj)
        print rbpot.getEnergy(x0)
Exemple #26
0
 def setUp(self):
     self.nrigid = 10
     self.topology = RBTopology()
     self.topology.add_sites([create_water() for _ in range(self.nrigid)])
     self.topology.finalize_setup()
     self.transform = TransformAngleAxisCluster(self.topology)
Exemple #27
0
 def setUp(self):
     self.nrigid = 10
     self.topology = RBTopology()
     self.topology.add_sites([create_tetrahedron() for _ in range(self.nrigid)])
     self.topology.finalize_setup()
     self.measure = MeasureAngleAxisCluster(self.topology)
Exemple #28
0
class TestOTP(unittest.TestCase):
    
    def make_otp(self):
        """this constructs a single OTP molecule"""
        otp = RigidFragment()
        otp.add_atom("O", np.array([0.0, -2./3 * np.sin( 7.*pi/24.), 0.0]), 1.)
        otp.add_atom("O", np.array([cos( 7.*pi/24.),  1./3. * sin( 7.* pi/24.), 0.0]), 1.)
        otp.add_atom("O", np.array([-cos( 7.* pi/24.),  1./3. * sin( 7.*pi/24), 0.0]), 1.)
        otp.finalize_setup()
        print "otp"
        print otp.atom_positions
        return otp

    
    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([self.make_otp() for i in xrange(nrigid)])
        
        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)
        
        self.x0 = [2.550757898788, 2.591553038507, 3.696836364193, 
                2.623281513163, 3.415794212648, 3.310786279789, 
                1.791383852327, 2.264321752809, 4.306217333671, 
                0.761945654023, -0.805817782109, 1.166981882601, 
                0.442065301864, -2.747066418223, -1.784325262714, 
                -1.520905562598, 0.403670860200, -0.729768985400, ]
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size
        
        self.x0atomistic = [ 3.064051819556, 2.474533745459, 3.646107658946,
                            2.412011983074, 2.941152759499, 4.243695098053, 
                            2.176209893734, 2.358972610563, 3.200706335581, 
                            2.786627589565, 3.211876105193, 2.850924310983, 
                            1.962626909252, 3.436918873216, 3.370903763850,
                            3.120590040673, 3.598587659535, 3.710530764535, 
                            1.697360211099, 2.317229950712, 4.823998989452, 
                            2.283487958310, 1.840698306602, 4.168734267290, 
                            1.393303387573, 2.635037001113, 3.925918744272, ]
        self.nrigid = nrigid
    
    def test_energy(self):
        e = self.pot.getEnergy(self.x0)
        self.assertAlmostEqual(e, self.e0, delta=1e-4)

    def test_energy_gradient(self):
        e = self.pot.getEnergy(self.x0)
        gnum = self.pot.NumericalDerivative(self.x0)
         
        e2, g = self.pot.getEnergyGradient(self.x0)
        self.assertAlmostEqual(e, e2, delta=1e-4)
         
        for i in xrange(g.size):
            self.assertAlmostEqual(g[i], gnum[i], 2)
    
    def test_to_atomistic(self):
        xatom = self.topology.to_atomistic(self.x0).flatten()
        for i in xrange(xatom.size):
            self.assertAlmostEqual(xatom[i], self.x0atomistic[i], 2)
    
    def test_site_to_atomistic(self):
        rf = self.make_otp()
        p = np.array([1., 2, 3])
        p /= np.linalg.norm(p)
        com = np.array([4., 5, 6])
        print "otp to atomistic"
        print rf.to_atomistic(com, p)
        

        print "otp transform grad"
        g = np.array(range(9), dtype=float).reshape([-1,3])
        print g.reshape(-1)
        
        print rf.transform_grad(p, g)
    
    def test_to_atomistic2(self):
        x0 = np.array(range(self.nrigid * 6), dtype=float);
        x2 = x0.reshape([-1,3])
        for p in x2[self.nrigid:,:]:
            p /= np.linalg.norm(p);
        print x0
        print "range to atomistic"
        print x0
        atomistic = self.topology.to_atomistic(x0).flatten()
        print atomistic
        print atomistic.size
        print atomistic[14]
        print atomistic[23]
        
        from pele.potentials import LJ
        lj = LJ()
        e, g = lj.getEnergyGradient(atomistic.reshape(-1))
        grb = self.topology.transform_gradient(x0, g);
        print "transformed gradient"
        print grb
        
        print "rbpotential"
        rbpot = RBPotentialWrapper(self.topology, lj);
        print rbpot.getEnergy(x0);
Exemple #29
0
 def setUp(self):
     self.nrigid = 10
     self.topology = RBTopology()
     self.topology.add_sites([create_water() for _ in range(self.nrigid)])
     self.topology.finalize_setup()
     self.transform = TransformAngleAxisCluster(self.topology)
 def make_normal_cpp_topology(self):
     sites = [make_otp() for _ in xrange(self.nrigid)]
     normal_topology = RBTopology()
     normal_topology.add_sites(sites)
     normal_topology.finalize_setup()
     return normal_topology
Exemple #31
0
class TestOTPExplicit(unittest.TestCase):
    
    def setUp(self):
        nrigid = 3
        self.topology = RBTopology()
        self.topology.add_sites([make_otp() for i in range(nrigid)])
        self.topology.finalize_setup()
        
        cartesian_potential = LJ()
        self.pot = RBPotentialWrapper(self.topology, cartesian_potential)
        
        self.x0 = _x03
        self.x0 = np.array(self.x0)
        self.e0 = -17.3387670023
        assert nrigid * 6 == self.x0.size
        
        self.x0atomistic = _x03_atomistic
        self.nrigid = nrigid
    
    def test_energy(self):
        e = self.pot.getEnergy(self.x0)
        self.assertAlmostEqual(e, self.e0, delta=1e-4)

    def test_energy_gradient(self):
        e = self.pot.getEnergy(self.x0)
        gnum = self.pot.NumericalDerivative(self.x0)
         
        e2, g = self.pot.getEnergyGradient(self.x0)
        self.assertAlmostEqual(e, e2, delta=1e-4)
         
        for i in range(g.size):
            self.assertAlmostEqual(g[i], gnum[i], 2)
    
    def test_to_atomistic(self):
        xatom = self.topology.to_atomistic(self.x0).flatten()
        for i in range(xatom.size):
            self.assertAlmostEqual(xatom[i], self.x0atomistic[i], 2)
    
    def test_site_to_atomistic(self):
        rf = make_otp()
        p = np.array([1., 2, 3])
        p /= np.linalg.norm(p)
        com = np.array([4., 5, 6])
        print("otp to atomistic")
        print(rf.to_atomistic(com, p))
        

        print("otp transform grad")
        g = np.array(list(range(9)), dtype=float).reshape([-1,3])
        print(g.reshape(-1))
        
        print(rf.transform_grad(p, g))
    
    def test_to_atomistic2(self):
        x0 = np.array(list(range(self.nrigid * 6)), dtype=float)
        x2 = x0.reshape([-1,3])
        for p in x2[self.nrigid:,:]:
            p /= np.linalg.norm(p)
        atomistic = self.topology.to_atomistic(x0).flatten()
        
        from pele.potentials import LJ
        lj = LJ()
        e, g = lj.getEnergyGradient(atomistic.reshape(-1))
        grb = self.topology.transform_gradient(x0, g)
        rbpot = RBPotentialWrapper(self.topology, lj)
        print(rbpot.getEnergy(x0))
Exemple #32
0
 def make_normal_cpp_topology(self):
     sites = [make_otp() for _ in xrange(self.nrigid)]
     normal_topology = RBTopology()
     normal_topology.add_sites(sites)
     normal_topology.finalize_setup()
     return normal_topology