Beispiel #1
0
def test():
    from pele.systems import LJCluster
    natoms = 13
    system = LJCluster(natoms)
    
    db = system.create_database()
    
    # get some minima
    bh = system.get_basinhopping(database=db, outstream=None)
    bh.run(100)
    
    manager = ConnectManager(db, clust_min=2)
    
    for i in range(4):
        min1, min2 = manager.get_connect_job(strategy="random")
        print "connecting", min1._id, min2._id
        connect = system.get_double_ended_connect(min1, min2, db, verbosity=0)
        connect.connect()
    
    print "\n\ntesting untrap"
    for i in range(10):
        min1, min2 = manager.get_connect_job(strategy="untrap")
        print min1._id, min2._id
    
    print "\n\ntesting combine"
    for i in range(5):
        min1, min2 = manager.get_connect_job(strategy="combine")
        print min1._id, min2._id
    
    print "\n\ntesting gmin"
    for i in range(5):
        min1, min2 = manager.get_connect_job(strategy="gmin")
        print min1._id, min2._id
 def test1(self):
     natoms = 13
     system = LJCluster(natoms)
     ts1 = RDWrap()
     ts2 = RDWrap()
     
     ts = BlockMoves()
     n1 = 3
     n2 = 5
     ts.addBlock(n1, ts1)
     ts.addBlock(n2, ts2)
     
     bh = system.get_basinhopping(takestep=ts)
     bh.run(n1)
     self.assertEqual(ts1.count, n1) 
     self.assertEqual(ts2.count, 0) 
     
     bh.run(n2)
     self.assertEqual(ts1.count, n1) 
     self.assertEqual(ts2.count, n2)
     
     bh.run(n1 + n2)
     self.assertEqual(ts1.count, 2*n1) 
     self.assertEqual(ts2.count, 2*n2)
     
     bh.run(5*(n1 + n2) - 1)
     self.assertEqual(ts1.count, 7*n1) 
     self.assertEqual(ts2.count, 7*n2 - 1)
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(description="do nested sampling on a Lennard Jones cluster")
    parser.add_argument("natoms", type=int, help="number of atoms")
    parser.add_argument("db", type=str, help="location of the database")
    parser.add_argument("--normalmodes", type=str, help="store the full normalmodes as well")
    args = parser.parse_args()
    
    

    system = LJCluster(args.natoms,)

    if False:
        # build the database    
        database = system.create_database(args.db, createdb=True)
        bh = system.get_basinhopping(database)
        bh.run(1000)
        
    
    else:
        database = system.create_database(args.db, createdb=False)

    assert database.number_of_minima() > 0
    
    print "computing the vibrational free energy and the point group order"
    get_thermodynamic_information(system, database)
    print "computing the normal modes"
    get_all_normalmodes(system, database)
Beispiel #4
0
    def test1(self):
        natoms = 13
        system = LJCluster(natoms)
        ts1 = RDWrap()
        ts2 = RDWrap()

        ts = BlockMoves()
        n1 = 3
        n2 = 5
        ts.addBlock(n1, ts1)
        ts.addBlock(n2, ts2)

        bh = system.get_basinhopping(takestep=ts)
        bh.run(n1)
        self.assertEqual(ts1.count, n1)
        self.assertEqual(ts2.count, 0)

        bh.run(n2)
        self.assertEqual(ts1.count, n1)
        self.assertEqual(ts2.count, n2)

        bh.run(n1 + n2)
        self.assertEqual(ts1.count, 2 * n1)
        self.assertEqual(ts2.count, 2 * n2)

        bh.run(5 * (n1 + n2) - 1)
        self.assertEqual(ts1.count, 7 * n1)
        self.assertEqual(ts2.count, 7 * n2 - 1)
Beispiel #5
0
    def test1(self):
        # lj cluster with 4 atoms has only one minimum
        natoms = 4
        system = LJCluster(natoms)

        ts1 = RDWrap()
        reseed = RDWrap()
        maxnoimprove = 20
        ts = Reseeding(ts1, reseed, maxnoimprove=maxnoimprove)

        bh = system.get_basinhopping(takestep=ts)
        bh.run(1)  # find the global minimum
        bh.run(maxnoimprove - 1)

        self.assertEqual(reseed.count, 0)
        self.assertEqual(ts1.count, maxnoimprove)

        bh.run(1)
        self.assertEqual(reseed.count, 1)
        self.assertEqual(ts1.count, maxnoimprove)

        bh.run(maxnoimprove - 1)
        self.assertEqual(reseed.count, 1)
        self.assertEqual(ts1.count, 2 * maxnoimprove - 1)

        bh.run(1)
        self.assertEqual(reseed.count, 2)
        self.assertEqual(ts1.count, 2 * maxnoimprove - 1)
 def test1(self):
     # lj cluster with 4 atoms has only one minimum
     natoms = 4
     system = LJCluster(natoms)
     
     ts1 = RDWrap()
     reseed = RDWrap()
     maxnoimprove = 20
     ts = Reseeding(ts1, reseed, maxnoimprove=maxnoimprove)
     
     bh = system.get_basinhopping(takestep=ts)
     bh.run(1) # find the global minimum
     bh.run(maxnoimprove - 1)
     
     self.assertEqual(reseed.count, 0)
     self.assertEqual(ts1.count, maxnoimprove)
     
     bh.run(1)
     self.assertEqual(reseed.count, 1)
     self.assertEqual(ts1.count, maxnoimprove)
     
     bh.run(maxnoimprove-1)
     self.assertEqual(reseed.count, 1)
     self.assertEqual(ts1.count, 2*maxnoimprove-1)
     
     bh.run(1)
     self.assertEqual(reseed.count, 2)
     self.assertEqual(ts1.count, 2*maxnoimprove-1)
Beispiel #7
0
def bh_with_system_class():
    from pele.systems import LJCluster
    natoms = 17
    system = LJCluster(natoms)
    database = system.create_database('lj17.sqlite')
    bh = system.get_basinhopping(database)
    bh.run(10)
Beispiel #8
0
def main():
    parser = argparse.ArgumentParser(
        description="do nested sampling on a Lennard Jones cluster")
    parser.add_argument("natoms", type=int, help="number of atoms")
    parser.add_argument("db", type=str, help="location of the database")
    parser.add_argument("--normalmodes",
                        type=str,
                        help="store the full normalmodes as well")
    args = parser.parse_args()

    system = LJCluster(args.natoms, )

    if False:
        # build the database
        database = system.create_database(args.db, createdb=True)
        bh = system.get_basinhopping(database)
        bh.run(1000)

    else:
        database = system.create_database(args.db, createdb=False)

    assert database.number_of_minima() > 0

    print "computing the vibrational free energy and the point group order"
    get_thermodynamic_information(system, database)
    print "computing the normal modes"
    get_all_normalmodes(system, database)
Beispiel #9
0
def test():
    from pele.systems import LJCluster
    from pele.landscape import ConnectManager
    system = LJCluster(13)
    
    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    bh.run(200)
    
    manager = ConnectManager(db)
    for i in range(3):
        min1, min2 = manager.get_connect_job()
        connect = system.get_double_ended_connect(min1, min2, db)
        connect.connect()
    
#    get_thermodynamic_information(system, db)
    
    print "getting thermodynamic info", db.number_of_minima()
    get_thermodynamic_information(system, db, nproc=4)
    
    for m in db.minima():
        print m._id, m.pgorder, m.fvib
    
    print "\nnow transition states"
    for ts in db.transition_states():
        print ts._id, ts.pgorder, ts.fvib
Beispiel #10
0
def test():
    from pele.systems import LJCluster
    from pele.landscape import ConnectManager

    system = LJCluster(13)

    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    bh.run(200)

    manager = ConnectManager(db)
    for i in range(3):
        min1, min2 = manager.get_connect_job()
        connect = system.get_double_ended_connect(min1, min2, db)
        connect.connect()

    # get_thermodynamic_information(system, db)

    print "getting thermodynamic info", db.number_of_minima()
    get_thermodynamic_information(system, db, nproc=4)

    for m in db.minima():
        print m.id(), m.pgorder, m.fvib

    print "\nnow transition states"
    for ts in db.transition_states():
        print ts.id(), ts.pgorder, ts.fvib
Beispiel #11
0
 def test1(self):
     system = LJCluster(6)
     ss0 = 1.
     displace = RandomDisplacement(stepsize=ss0)
     ts = AdaptiveStepsize(displace, interval=10)
     bh = system.get_basinhopping(takestep=ts)
     bh.run(9)
     self.assertAlmostEqual(displace.stepsize, ss0, 10)
     bh.run(2)
     self.assertNotAlmostEqual(displace.stepsize, ss0, 1)
Beispiel #12
0
 def test1(self):
     system = LJCluster(6)
     ss0 = 1.
     displace = RandomDisplacement(stepsize=ss0)
     ts = AdaptiveStepsize(displace, interval=10)
     bh = system.get_basinhopping(takestep=ts)
     bh.run(9)
     self.assertAlmostEqual(displace.stepsize, ss0, 10)
     bh.run(2)
     self.assertNotAlmostEqual(displace.stepsize, ss0, 1)
Beispiel #13
0
    def test1(self):
        natoms = 13
        system = LJCluster(natoms)
        ts1 = RDWrap()
        ts2 = RDWrap()

        ts = GroupSteps([ts1, ts2])
        bh = system.get_basinhopping(takestep=ts)
        bh.run(2)
        self.assertEqual(ts1.count, 2)
        self.assertEqual(ts2.count, 2)
def initialize_system():
    
    system = LJCluster(natoms)    
    x0 = np.random.random(natoms*3)#.reshape(natoms,3)
    db = system.create_database()
    step = RandomDisplacement(stepsize=1.0)
    bh = system.get_basinhopping(database=db, 
                                 takestep=step,
                                 coords=x0,temperature = 10.0)
    
    return system, db, bh
 def test1(self):
     natoms = 13
     system = LJCluster(natoms)
     ts1 = RDWrap()
     ts2 = RDWrap()
     
     ts = GroupSteps([ts1, ts2])
     bh = system.get_basinhopping(takestep=ts)
     bh.run(2)
     self.assertEqual(ts1.count, 2) 
     self.assertEqual(ts2.count, 2) 
Beispiel #16
0
def initialize_system():

    system = LJCluster(natoms)
    x0 = np.random.random(natoms * 3)  #.reshape(natoms,3)
    db = system.create_database()
    step = RandomDisplacement(stepsize=1.0)
    bh = system.get_basinhopping(database=db,
                                 takestep=step,
                                 coords=x0,
                                 temperature=10.0)

    return system, db, bh
Beispiel #17
0
class TestBasinhopping(unittest.TestCase):
    def setUp(self):
        natoms = 6
        self.system = LJCluster(natoms)
        self.e1 = -12.7120622568
        self.e2 = -12.302927529580728
    
    def assertEnergy(self, e):
        self.assertTrue( abs(e-self.e1) < 1e-4 or abs(e-self.e2) < 1e-4)
    
    def test_create_basinhopping(self):
        bh = self.system.get_basinhopping(outstream=None)
        bh.run(3)
        self.assertEnergy(bh.result.energy)
        self.assertEnergy(bh.markovE)

    def test_takestep(self):
        takestep = self.system.get_takestep(stepsize=1.)
        bh = self.system.get_basinhopping(outstream=None, takestep=takestep)
        bh.run(3)
        self.assertEnergy(bh.result.energy)
        self.assertEnergy(bh.markovE)
Beispiel #18
0
def testlj6(): # pragma: no cover
    from pele.systems import LJCluster
    from pele.thermodynamics import get_thermodynamic_information
    system = LJCluster(6)
    db = system.create_database()
    bh = system.get_basinhopping(db)
    bh.setPrinting(ostream=None)
    bh.run(10)
    
    get_thermodynamic_information(system, db)

    for m in db.minima():
        print(m.energy, m.pgorder)
Beispiel #19
0
def testlj6(): # pragma: no cover
    from pele.systems import LJCluster
    from pele.thermodynamics import get_thermodynamic_information
    system = LJCluster(6)
    db = system.create_database()
    bh = system.get_basinhopping(db)
    bh.setPrinting(ostream=None)
    bh.run(10)
    
    get_thermodynamic_information(system, db)

    for m in db.minima():
        print(m.energy, m.pgorder)
Beispiel #20
0
class TestBasinhopping(unittest.TestCase):
    def setUp(self):
        natoms = 6
        self.system = LJCluster(natoms)
        self.e1 = -12.7120622568
        self.e2 = -12.302927529580728

    def assertEnergy(self, e):
        self.assertTrue(abs(e - self.e1) < 1e-4 or abs(e - self.e2) < 1e-4)

    def test_create_basinhopping(self):
        bh = self.system.get_basinhopping(outstream=None)
        bh.run(3)
        self.assertEnergy(bh.result.energy)
        self.assertEnergy(bh.markovE)

    def test_takestep(self):
        takestep = self.system.get_takestep(stepsize=1.)
        bh = self.system.get_basinhopping(outstream=None, takestep=takestep)
        bh.run(3)
        self.assertEnergy(bh.result.energy)
        self.assertEnergy(bh.markovE)
Beispiel #21
0
class TestLJClusterSystem(unittest.TestCase):
    def setUp(self):
        self.natoms = 13
        self.system = LJCluster(self.natoms)

    def test_database_property(self):
        db = self.system.create_database()
        p = db.get_property("natoms")
        self.assertIsNotNone(p)
        self.assertEqual(p.value(), 13)

    def test_basinhopping_max_n_minima(self):
        db = self.system.create_database()
        bh = self.system.get_basinhopping(database=db, max_n_minima=2)
        bh.run(10)
        self.assertEqual(db.number_of_minima(), 2)

    def test_basinhopping_max_n_minima_params(self):
        db = self.system.create_database()
        self.system.params.basinhopping.max_n_minima = 2
        bh = self.system.get_basinhopping(database=db)
        bh.run(10)
        self.assertEqual(db.number_of_minima(), 2)
Beispiel #22
0
def test():
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pele.systems import LJCluster
    pl.ion()
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 5.
    dbname = "lj%dtest.db" % (natoms,)
    db = system.create_database(dbname)
    
    #get some minima
    if False:
        bh = system.get_basinhopping(database=db)
        bh.run(10)
        minima = db.minima()
    else:
        x1, e1 = system.get_random_minimized_configuration()[:2]
        x2, e2 = system.get_random_minimized_configuration()[:2]
        min1 = db.addMinimum(e1, x1)
        min2 = db.addMinimum(e2, x2)
        minima = [min1, min2]

    
    # connect some of the minima
    nmax = min(3, len(minima))
    m1 = minima[0]
    for m2 in minima[1:nmax]:
        connect = system.get_double_ended_connect(m1, m2, db)
        connect.connect()
    
        
    if True:
        from pele.thermodynamics import get_thermodynamic_information
        get_thermodynamic_information(system, db, nproc=4)
    
    wnd = GraphViewDialog(db, app=app)
#    decrunner = DECRunner(system, db, min1, min2, outstream=wnd.textEdit_writer)
    glutInit()
    wnd.show()
    from PyQt4.QtCore import QTimer
    def start():
        wnd.start()

    QTimer.singleShot(10, start)
    sys.exit(app.exec_()) 
Beispiel #23
0
def test():
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pele.systems import LJCluster
    pl.ion()
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 5.
    dbname = "lj%dtest.db" % (natoms,)
    db = system.create_database(dbname)
    
    #get some minima
    if False:
        bh = system.get_basinhopping(database=db)
        bh.run(10)
        minima = db.minima()
    else:
        x1, e1 = system.get_random_minimized_configuration()[:2]
        x2, e2 = system.get_random_minimized_configuration()[:2]
        min1 = db.addMinimum(e1, x1)
        min2 = db.addMinimum(e2, x2)
        minima = [min1, min2]

    
    # connect some of the minima
    nmax = min(3, len(minima))
    m1 = minima[0]
    for m2 in minima[1:nmax]:
        connect = system.get_double_ended_connect(m1, m2, db)
        connect.connect()
    
        
    if True:
        from pele.thermodynamics import get_thermodynamic_information
        get_thermodynamic_information(system, db, nproc=4)
    
    wnd = GraphViewDialog(db, app=app)
#    decrunner = DECRunner(system, db, min1, min2, outstream=wnd.textEdit_writer)
    glutInit()
    wnd.show()
    from PyQt4.QtCore import QTimer
    def start():
        wnd.start()

    QTimer.singleShot(10, start)
    sys.exit(app.exec_()) 
Beispiel #24
0
def get_x0():
    from pele.systems import LJCluster
    natoms = 31
    system = LJCluster(natoms)
    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    while db.number_of_minima() < 2:
        bh.run(1)
    
    mindist = system.get_mindist()
    m1, m2 = db.minima()[:4]
    d, x1, x2 = mindist(m1.coords, m2.coords)
    
    x0 = (x1 + x2) / 2
    evec0 = x2 - x1
    
    return system, x0, evec0
Beispiel #25
0
    def test1(self):
        from pele.systems import LJCluster
        natoms = 13
        system = LJCluster(natoms)
        db = system.create_database()
        bh = system.get_basinhopping(db)
        bh.setPrinting(ostream=None)
        while db.minima()[0].energy > -44.3:
            bh.run(10)

        m = db.minima()[0]
        permlist = [range(natoms)]
        match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True)
        calculator = PointGroupOrderCluster(match)
        pgorder = calculator(m.coords)
        #        print pgorder

        self.assertEqual(pgorder, 120)
    def test1(self):
        from pele.systems import LJCluster
        natoms = 13
        system = LJCluster(natoms)
        db = system.create_database()
        bh = system.get_basinhopping(db)
        bh.setPrinting(ostream=None)
        while db.minima()[0].energy > -44.3:
            bh.run(10)

        m = db.minima()[0]
        permlist = [list(range(natoms))]
        match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True)
        calculator = PointGroupOrderCluster(match)
        pgorder = calculator(m.coords)
#        print pgorder
        
        self.assertEqual(pgorder, 120)
Beispiel #27
0
def test():
    import sys
    from pele.systems import LJCluster
    app = QtGui.QApplication(sys.argv)
    system = LJCluster(13)

    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    bh.run(200)

    obj = HeatCapacityViewer(system, db)
    obj.show()

    def test_start():
        obj.rebuild_cv_plot()

    QtCore.QTimer.singleShot(10, test_start)
    sys.exit(app.exec_())
Beispiel #28
0
def test():
    import sys
    from pele.systems import LJCluster
    app = QtGui.QApplication(sys.argv)
    system = LJCluster(13)
    
    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    bh.run(200)

    obj = HeatCapacityViewer(system, db)
    obj.show()

    def test_start():
        obj.rebuild_cv_plot()
    
    QtCore.QTimer.singleShot(10, test_start)
    sys.exit(app.exec_()) 
Beispiel #29
0
def get_x0():  # pragma: no cover
    from pele.systems import LJCluster

    natoms = 31
    system = LJCluster(natoms)
    db = system.create_database()
    bh = system.get_basinhopping(db, outstream=None)
    while db.number_of_minima() < 2:
        bh.run(1)

    mindist = system.get_mindist()
    m1, m2 = db.minima()[:4]
    d, x1, x2 = mindist(m1.coords, m2.coords)

    x0 = (x1 + x2) / 2
    evec0 = x2 - x1

    return system, x0, evec0
def get_database(natoms=13, nconn=5):
    """create a database for a lennard jones system
    
    fill it with minima from a basinhopping run, then connect
    some of those minima using DoubleEndedConnect
    """
    ljsys = LJCluster(natoms)
    db = ljsys.create_database()
    bh = ljsys.get_basinhopping(database=db, outstream=None)
    while (len(db.minima()) < nconn + 1):
        bh.run(100)

    minima = list(db.minima())
    m1 = minima[0]
    for m2 in minima[1:nconn + 1]:
        connect = ljsys.get_double_ended_connect(m1, m2, db)
        connect.connect()

    return db
Beispiel #31
0
class TestBuildDatabase(unittest.TestCase):
    def setUp(self):
        self.natoms = 6
        self.system = LJCluster(self.natoms)
        
        # create a database
        self.database = self.system.create_database()
        
        # add some minima to the database
        bh = self.system.get_basinhopping(self.database, outstream=None)
        while self.database.number_of_minima() < 2:
            bh.run(1)
        
        get_thermodynamic_information(self.system, self.database)
        

    def test(self):
        self.assertGreaterEqual(self.database.number_of_minima(), 2)
        for m in self.database.minima():
            self.assertIsNotNone(m.energy)
            self.assertIsNotNone(m.pgorder)
            self.assertIsNotNone(m.fvib)
        # test that the lowest minimum has the right vibrational free energy
        self.assertAlmostEqual(self.database.minima()[0].fvib, 56.085, 2)
        if faccept > self.target_new_min_accept_prob:
            driver.acceptTest.temperature *= self.Tfactor
        else:
            driver.acceptTest.temperature /= self.Tfactor
        if self.verbose:
            print("    temperature is now %.4g ratio %.4g target %.4g" % (driver.acceptTest.temperature,
                                                                          faccept, self.target_new_min_accept_prob))


if __name__ == "__main__":
    import numpy as np
    from pele.takestep import displace
    from pele.systems import LJCluster

    natoms = 38
    sys = LJCluster(natoms=38)


    # random initial coordinates
    coords = sys.get_random_configuration()

    takeStep = displace.RandomDisplacement(stepsize=0.4)
    tsAdaptive = AdaptiveStepsizeTemperature(takeStep, interval=300, verbose=True)

    db = sys.create_database()
    opt = sys.get_basinhopping(database=db, takestep=tsAdaptive, coords=coords)
    opt.printfrq = 50
    opt.run(5000)
        

Beispiel #33
0
class TestBuildDatabase(unittest.TestCase):
    def setUp(self):
        self.natoms = 6
        self.system = LJCluster(self.natoms)

        # create a database
        self.database = self.system.create_database()

        # add some minima to the database
        bh = self.system.get_basinhopping(self.database, outstream=None)
        while self.database.number_of_minima() < 2:
            bh.run(1)

        get_thermodynamic_information(self.system, self.database)
        get_all_normalmodes(self.system, self.database)

        self.ndof = self.natoms * 3 - 6
        self.sampler = SASampler(self.database.minima(), self.ndof)

#    def test(self):
#        for m in self.database.minima():
#            print m.energy
#        print self.sampler.compute_weights(-11.7)
#        for i in range(10):
#            m = self.sampler.sample_minimum(-11)
#            print m._id

    def test1(self):
        Emax = -11.7
        minima, weights = self.sampler.compute_weights(0.)
        minima, weights = self.sampler.compute_weights(Emax)
        self.assertAlmostEqual(weights[0], 0.81256984, 3)
        self.assertAlmostEqual(weights[1], 1., 7)

    def test2(self):
        Emax = -11.7
        minima, weights = self.sampler.compute_weights(Emax)
        minima, weights = self.sampler.compute_weights(Emax)
        self.assertAlmostEqual(weights[0], 0.81256984, 3)
        self.assertAlmostEqual(weights[1], 1., 7)

    def test3(self):
        m = self.sampler.sample_minimum(-11.7)
        self.assertIn(m, self.database.minima())

    def test4(self):
        """check that the HSA energy is computed correctly"""
        pot = self.system.get_potential()
        for m in self.database.minima():
            x = m.coords.copy()
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            ecompare = (ehsa - ecalc) / (ecalc - m.energy)
            print ehsa - m.energy, ecalc - m.energy, m.energy, ecompare
            self.assertAlmostEqual(ecompare, 0., 1)

    def test_rotation(self):
        """assert that the HSA energy is *not* invariant under rotation"""
        pot = self.system.get_potential()
        aa = rotations.random_aa()
        rmat = rotations.aa2mx(aa)
        from pele.mindist import TransformAtomicCluster
        tform = TransformAtomicCluster(can_invert=True)
        for m in self.database.minima():
            x = m.coords.copy()
            # randomly move the atoms by a small amount
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            # now rotate by a random matrix
            xnew = x.copy()
            tform.rotate(xnew, rmat)
            ehsa2 = self.sampler.compute_energy(xnew, m, x0=m.coords)
            ecalc2 = pot.getEnergy(xnew)
            self.assertAlmostEqual(ecalc, ecalc2, 5)
            self.assertNotAlmostEqual(ehsa1, ehsa2, 1)

#    def test_rotation_2(self):
#        """assert that the HSA energy *is* invariant under rotation *if* the initial coords are also rotated"""
#        pot = self.system.get_potential()
#        aa = rotations.random_aa()
#        rmat = rotations.aa2mx(aa)
#        from pele.mindist import TransformAtomicCluster
#        tform = TransformAtomicCluster(can_invert=True)
#        for m in self.database.minima():
#            x = m.coords.copy()
#            # randomly move the atoms by a small amount
#            x += np.random.uniform(-1e-3, 1e-3, x.shape)
#            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
#            ecalc = pot.getEnergy(x)
#            # now rotate by a random matrix
#            xnew = x.copy()
#            tform.rotate(xnew, rmat)
#            xmnew = m.coords.copy()
#            tform.rotate(xmnew, rmat)
#            ehsa2 = self.sampler.compute_energy(xnew, m, x0=xmnew)
#            ecalc2 = pot.getEnergy(xnew)
#            self.assertAlmostEqual(ecalc, ecalc2, 5)
#            self.assertAlmostEqual(ehsa1, ehsa2, 3)

    def test_permutation(self):
        """assert that the HSA energy is not invariant under permutation"""
        pot = self.system.get_potential()
        perm = range(self.natoms)
        np.random.shuffle(perm)
        from pele.mindist import TransformAtomicCluster
        tform = TransformAtomicCluster(can_invert=True)
        for m in self.database.minima():
            x = m.coords.copy()
            # randomly move the atoms by a small amount
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            # now rotate by a random matrix
            xnew = x.copy()
            xnew = tform.permute(xnew, perm)
            ehsa2 = self.sampler.compute_energy(xnew, m, x0=m.coords)
            ecalc2 = pot.getEnergy(xnew)
            self.assertAlmostEqual(ecalc, ecalc2, 5)
            self.assertNotAlmostEqual(ehsa1, ehsa2, 1)
Beispiel #34
0
"""
Example 4: modify the parameters of the adaptive stepsize
note that the system class uses adaptive stepsize by default, 
so the previous examples also use adaptive stepsize
"""
from __future__ import print_function
from pele.systems import LJCluster
from pele.takestep import RandomDisplacement, AdaptiveStepsizeTemperature

natoms = 12
niter = 100
system = LJCluster(natoms)

db = system.create_database()

# create takestep routine manually
step = RandomDisplacement(stepsize=0.3)
# wrap it in the class which will adaptively improve the stepsize
wrapped_step = AdaptiveStepsizeTemperature(step, interval=30)

bh = system.get_basinhopping(database=db, takestep=wrapped_step)
bh.run(niter)
print("the lowest energy found after", niter, " basinhopping steps is", db.minima()[0].energy)
print("")
Beispiel #35
0
        self.mcstep = RandomDisplacement(stepsize=stepsize)
    
    def takeStep(self, coords, **kwargs):
        #make a new monte carlo class
        mc = MonteCarlo(coords, self.potential, self.mcstep, 
                        temperature = self.T, outstream=None)
        mc.run( self.nsteps )
        coords[:] = mc.coords[:]
    
    def updateStep(self, acc, **kwargs):
        pass


natoms = 12
niter = 100
system = LJCluster(natoms)

# define a custom takestep routine
potential = system.get_potential()
reseed = TakeStepMonteCarlo(potential, T=100, nsteps=1000)
takestep = system.get_takestep()
stepGroup = Reseeding(takestep, reseed, maxnoimprove=20)

db = system.create_database()
bh = system.get_basinhopping(database=db, takestep=stepGroup)
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima()[0].energy
print ""


# create a database to store the minimum in
db = system.create_database()
# note: this creates a database in memory, if you want to save the results
# you would use
# db = system.create_database("lj.sqlite")
minimum1 = db.addMinimum(newenergy, newcoords)

# get a second random minimized configuration and add it to the database
ret = system.get_random_minimized_configuration()
print "a second minimum has energy", ret[1]
e2, coords2 = ret[1], ret[0]
minimum2 = db.addMinimum(e2, coords2)

# do a basinhopping run to find the global minimum and build up the database of minima
bh = system.get_basinhopping(database=db, outstream=None)
niter = 20
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima()[0].energy

# print the energies of all the minima found
print "the minima in the database have energies"
for minimum in db.minima():
    print "  ", minimum.energy

# find the minimum distance (a.k.a. mindist) between the two lowest minima
m1, m2 = db.minima()[:2]
mindist = system.get_mindist()
dist, coords1, coords2 = mindist(m1.coords, m2.coords)
print "the minimum distance between the two lowest minima is", dist
Beispiel #37
0
import numpy as np
from pele.systems import LJCluster
from pele.utils.xyz import write_xyz

natoms=38
system = LJCluster(natoms)
db = system.create_database()
bh = system.get_basinhopping(db)
bh.run(1000)

m1, m2 = db.minima()[:2]

if False:
    mindist = system.get_mindist()
    d, x1, x2 = mindist(m1.coords, m2.coords)
else:
    x1, x2 = m1.coords, m2.coords


#write_xyz(open("lj6_m1.xyz", "w"), x1)
#write_xyz(open("lj6_m2.xyz", "w"), x2)
np.savetxt("lj{}_m1".format(natoms), x1.reshape(-1,3))
np.savetxt("lj{}_m2".format(natoms), x2.reshape(-1,3))
Beispiel #38
0
from pele.systems import LJCluster
import numpy as np
import scipy.sparse
import scikits.sparse.cholmod as cholmod
import time
import pele.transition_states as ts
from pele.utils.hessian import get_sorted_eig

natoms = 1000
system = LJCluster(natoms)
#system.params.structural_quench_params.debug = True
#system.params.structural_quench_params.iprint = 100
db = system.create_database()
bh = system.get_basinhopping(db)
bh.run(1)

m = db.minima()[0]
coords = m.coords

potential = system.get_potential()
energy, gradient, hessian = potential.getEnergyGradientHessian(coords)

dummy_vec = ts.gramm_schmidt(ts.zeroEV_cluster(coords))

shifted_hess = hessian.copy()

for i in range(6):
    shifted_hess += np.outer(dummy_vec[i], dummy_vec[i])

shifted_eval, shifted_evec = get_sorted_eig(shifted_hess)
Beispiel #39
0
        if faccept > self.target_new_min_accept_prob:
            driver.acceptTest.temperature *= self.Tfactor
        else:
            driver.acceptTest.temperature /= self.Tfactor
        if self.verbose:
            print("    temperature is now %.4g ratio %.4g target %.4g" %
                  (driver.acceptTest.temperature, faccept,
                   self.target_new_min_accept_prob))


if __name__ == "__main__":
    import numpy as np
    from pele.takestep import displace
    from pele.systems import LJCluster

    natoms = 38
    sys = LJCluster(natoms=38)

    # random initial coordinates
    coords = sys.get_random_configuration()

    takeStep = displace.RandomDisplacement(stepsize=0.4)
    tsAdaptive = AdaptiveStepsizeTemperature(takeStep,
                                             interval=300,
                                             verbose=True)

    db = sys.create_database()
    opt = sys.get_basinhopping(database=db, takestep=tsAdaptive, coords=coords)
    opt.printfrq = 50
    opt.run(5000)
import logging

from pele.systems import LJCluster
from pele.utils.disconnectivity_graph import DisconnectivityGraph, database2graph

natoms = 13
system = LJCluster(natoms)

use_existing_database = False
if use_existing_database:
    db = system.create_database("lj13.sqlite", createdb=False)
else:
    # build a small database using basinhopping
    print "building a small database using basinhopping" ""
    db = system.create_database()
    bh = system.get_basinhopping(database=db, outstream=None)
    bh.run(20)

print "starting with a database of", len(db.minima()), "minima"

# turn of status printing for the connect run
# first use the logging module to turn off the status messages
logger = logging.getLogger("pele.connect")
logger.setLevel("WARNING")

# connect all minima to the lowest minimum
print "now connecting all the minima to the lowest energy minimum"
m1 = db.minima()[0]
for m2 in db.minima()[1:]:
    print "    connecting minima with id's", m1._id, m2._id
    connect = system.get_double_ended_connect(m1, m2, db)
Beispiel #41
0
    def takeStep(self, coords, **kwargs):
        # ake a new monte carlo class
        mc = MonteCarlo(coords,
                        self.potential,
                        self.mcstep,
                        temperature=self.T,
                        outstream=None)
        mc.run(self.nsteps)
        coords[:] = mc.coords[:]

    def updateStep(self, acc, **kwargs):
        pass


natoms = 12
niter = 100
system = LJCluster(natoms)

# define a custom takestep routine
potential = system.get_potential()
reseed = TakeStepMonteCarlo(potential, T=100, nsteps=1000)
takestep = system.get_takestep()
stepGroup = Reseeding(takestep, reseed, maxnoimprove=20)

db = system.create_database()
bh = system.get_basinhopping(database=db, takestep=stepGroup)
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima(
)[0].energy
print ""
Beispiel #42
0
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pele.systems import LJCluster
    pl.ion()
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 5.
    dbname = "lj%dtest.db" % (natoms,)
    db = system.create_database(dbname)
    
    # get some minima
    if False:
        bh = system.get_basinhopping(database=db)
        bh.run(10)
        minima = db.minima()
    else:
        x1, e1 = system.get_random_minimized_configuration()[:2]
        x2, e2 = system.get_random_minimized_configuration()[:2]
        min1 = db.addMinimum(e1, x1)
        min2 = db.addMinimum(e2, x2)
        minima = [min1, min2]

    
    # connect some of the minima
    nmax = min(3, len(minima))
    m1 = minima[0]
    for m2 in minima[1:nmax]:
        connect = system.get_double_ended_connect(m1, m2, db)
Beispiel #43
0
class TestBuildDatabase(unittest.TestCase):
    def setUp(self):
        self.natoms = 6
        self.system = LJCluster(self.natoms)
        
        # create a database
        self.database = self.system.create_database()
        
        # add some minima to the database
        bh = self.system.get_basinhopping(self.database, outstream=None)
        while self.database.number_of_minima() < 2:
            bh.run(1)
        
        get_thermodynamic_information(self.system, self.database)
        get_all_normalmodes(self.system, self.database)
        
        self.ndof = self.natoms * 3 - 6
        self.sampler = SASampler(self.database.minima(), self.ndof)

#    def test(self):
#        for m in self.database.minima():
#            print m.energy
#        print self.sampler.compute_weights(-11.7)
#        for i in range(10):
#            m = self.sampler.sample_minimum(-11)
#            print m._id

    def compute_weights(self, Emax, k):
        print [m.energy for m in self.database.minima()], Emax
        lweights = [ - np.log(m.pgorder) + 0.5 * k * np.log(Emax - m.energy) - 0.5 * m.fvib
                    for m in self.database.minima() if m.energy < Emax]
        lweights = np.array(lweights)
        if lweights.size <= 1: return lweights
        lwmax = lweights.max()
        lweights -= lwmax
        return np.exp(lweights)

    def test1(self):
        Emax = -11.7
        minima, weights = self.sampler.compute_weights(0.)
        minima, weights = self.sampler.compute_weights(Emax)
        self.assertAlmostEqual(weights[0], 0.81256984, 3)
        self.assertAlmostEqual(weights[1], 1., 7)
        
        new_weights = self.compute_weights(Emax, self.ndof)
        print weights
        print new_weights
        

    def test2(self):
        Emax = -11.7
        minima, weights = self.sampler.compute_weights(Emax)
        minima, weights = self.sampler.compute_weights(Emax)
        self.assertAlmostEqual(weights[0], 0.81256984, 3)
        self.assertAlmostEqual(weights[1], 1., 7)
    
    def test3(self):
        m = self.sampler.sample_minimum(-11.7)
        self.assertIn(m, self.database.minima())
    
    def test4(self):
        """check that the HSA energy is computed correctly"""
        pot = self.system.get_potential()
        for m in self.database.minima():
            x = m.coords.copy()
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            ecompare = (ehsa - ecalc) / (ecalc - m.energy) 
            print ehsa - m.energy, ecalc - m.energy, m.energy, ecompare
            self.assertAlmostEqual(ecompare, 0., 1)
    
    def test_rotation(self):
        """assert that the HSA energy is *not* invariant under rotation"""
        pot = self.system.get_potential()
        aa = rotations.random_aa()
        rmat = rotations.aa2mx(aa)
        from pele.mindist import TransformAtomicCluster
        tform = TransformAtomicCluster(can_invert=True)
        for m in self.database.minima():
            x = m.coords.copy()
            # randomly move the atoms by a small amount
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            # now rotate by a random matrix
            xnew = x.copy()
            tform.rotate(xnew, rmat)
            ehsa2 = self.sampler.compute_energy(xnew, m, x0=m.coords)
            ecalc2 = pot.getEnergy(xnew)
            self.assertAlmostEqual(ecalc, ecalc2, 5)
            self.assertNotAlmostEqual(ehsa1, ehsa2, 1)
    
#    def test_rotation_2(self):
#        """assert that the HSA energy *is* invariant under rotation *if* the initial coords are also rotated"""
#        pot = self.system.get_potential()
#        aa = rotations.random_aa()
#        rmat = rotations.aa2mx(aa)
#        from pele.mindist import TransformAtomicCluster
#        tform = TransformAtomicCluster(can_invert=True)
#        for m in self.database.minima():
#            x = m.coords.copy()
#            # randomly move the atoms by a small amount
#            x += np.random.uniform(-1e-3, 1e-3, x.shape)
#            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
#            ecalc = pot.getEnergy(x)
#            # now rotate by a random matrix
#            xnew = x.copy()
#            tform.rotate(xnew, rmat)
#            xmnew = m.coords.copy()
#            tform.rotate(xmnew, rmat)
#            ehsa2 = self.sampler.compute_energy(xnew, m, x0=xmnew)
#            ecalc2 = pot.getEnergy(xnew)
#            self.assertAlmostEqual(ecalc, ecalc2, 5)
#            self.assertAlmostEqual(ehsa1, ehsa2, 3)
    
    def test_permutation(self):
        """assert that the HSA energy is not invariant under permutation"""
        pot = self.system.get_potential()
        perm = range(self.natoms)
        np.random.shuffle(perm)
        from pele.mindist import TransformAtomicCluster
        tform = TransformAtomicCluster(can_invert=True)
        for m in self.database.minima():
            x = m.coords.copy()
            # randomly move the atoms by a small amount
            x += np.random.uniform(-1e-3, 1e-3, x.shape)
            ehsa1 = self.sampler.compute_energy(x, m, x0=m.coords)
            ecalc = pot.getEnergy(x)
            # now rotate by a random matrix
            xnew = x.copy()
            xnew = tform.permute(xnew, perm)
            ehsa2 = self.sampler.compute_energy(xnew, m, x0=m.coords)
            ecalc2 = pot.getEnergy(xnew)
            self.assertAlmostEqual(ecalc, ecalc2, 5)
            self.assertNotAlmostEqual(ehsa1, ehsa2, 1)