Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
class TestNormalModes(unittest.TestCase):
    def setUp(self):
        import pele.rates.tests.__init__ as f
        dirname = os.path.dirname(f.__file__)
        dbfname = os.path.join(dirname, "lj15.sqlite")
        if not os.path.exists(dbfname):
            raise IOError("database file %s does not exist" % dbfname)
        self.system = LJCluster(15)
        self.db = self.system.create_database(dbfname, createdb=False)
    
    def check(self, fvib_expected, coords, nzero, nnegative, metric=None): 
        pot = self.system.get_potential()
        hess = pot.getHessian(coords)
        freqs, modes = normalmodes(hess, metric=metric)
#         print v
        n, fvib = logproduct_freq2(freqs, nzero=nzero, nnegative=nnegative)
        self.assertAlmostEqual(fvib, fvib_expected, 4)
        self.assertEqual(n, len(coords) - nzero - nnegative)

    def test_minimum(self):
        m = self.db.minima()[0]
        self.check(m.fvib, m.coords, 6, 0)
    
    def test_transition_state(self):
        ts = self.db.transition_states()[0]
        self.check(ts.fvib, ts.coords, 6, 1)
        
    def test_metric_tensor(self):
        m = self.db.minima()[0]
        mt = np.eye(m.coords.size)
        self.check(m.fvib, m.coords, 6, 0, metric=mt)


    def test_get_thermo_info(self):
        newdb = self.system.create_database()
        new2old = dict()
        for ts in self.db.transition_states()[:5]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newts = newdb.addTransitionState(ts.energy, ts.coords, m1, m2)
            new2old[m1] = ts.minimum1
            new2old[m2] = ts.minimum2
            new2old[newts] = ts
        
        get_thermodynamic_information(self.system, newdb, nproc=2)
        
        for new in newdb.minima() + newdb.transition_states():
            old = new2old[new]
            self.assertAlmostEqual(new.energy, old.energy, 4)
            self.assertAlmostEqual(new.fvib, old.fvib, 4)
            self.assertEqual(new.pgorder, old.pgorder)
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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 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
Esempio n. 10
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
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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_()) 
Esempio n. 15
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_()) 
Esempio n. 16
0
class TestGraphRatesLJ(unittest.TestCase):
    def setUp(self):
        current_dir = os.path.dirname(__file__)
        dbfname = os.path.join(current_dir,
                               "lj15.{}.sqlite".format(sys.version_info.major))
        print(dbfname)
        self.system = LJCluster(15)
        self.system.params.structural_quench_params.tol = 1e-6
        self.db = self.system.create_database(dbfname, createdb=False)


#        create_random_database(self.system, self.db, 10, 20)
#        get_thermodynamic_information(self.system, self.db, nproc=2)

    def do_check_rates(self, A, B):
        rcalc = RateCalculation(self.db.transition_states(), A, B)
        rcalc.compute_rates()
        rAB = rcalc.get_rate_AB()
        rBA = rcalc.get_rate_BA()

        rla = RatesLinalg(self.db.transition_states(), A, B)
        rAB_la = rla.compute_rates()

        self.assertAlmostEqual(rAB, rAB_la, 7)

    def do_check_committors(self, A, B):
        rcalc = RateCalculation(self.db.transition_states(), A, B)
        rcalc.compute_rates_and_committors()
        committors = rcalc.get_committors()

        rla = RatesLinalg(self.db.transition_states(), A, B)
        cla = rla.compute_committors()

        for m, qla in cla.items():
            self.assertAlmostEqual(committors[m], qla, 7)

    def test(self):
        A = [self.db.minima()[0]]
        B = [self.db.minima()[-1]]
        self.do_check_rates(A, B)
        self.do_check_committors(A, B)

    def test2(self):
        A = self.db.minima()[:2]
        B = self.db.minima()[2:4]
        self.do_check_rates(A, B)
        self.do_check_committors(A, B)
Esempio n. 17
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
class TestGraphRatesLJ(unittest.TestCase):
    def setUp(self):
        current_dir = os.path.dirname(__file__)
        dbfname = os.path.join(current_dir, "lj15.sqlite")
        print dbfname
        self.system = LJCluster(15)
        self.system.params.structural_quench_params.tol = 1e-6
        self.db = self.system.create_database(dbfname, createdb=False)
        
#        create_random_database(self.system, self.db, 10, 20)
#        get_thermodynamic_information(self.system, self.db, nproc=2)
    
    def do_check_rates(self, A, B):
        rcalc = RateCalculation(self.db.transition_states(), A, B)
        rcalc.compute_rates()
        rAB = rcalc.get_rate_AB()
        rBA = rcalc.get_rate_BA()
        
        rla = RatesLinalg(self.db.transition_states(), A, B)
        rAB_la = rla.compute_rates()
        
        self.assertAlmostEqual(rAB, rAB_la, 7)
        
    def do_check_committors(self, A, B):
        rcalc = RateCalculation(self.db.transition_states(), A, B)
        rcalc.compute_rates_and_committors()
        committors = rcalc.get_committors()
        
        rla = RatesLinalg(self.db.transition_states(), A, B)
        cla = rla.compute_committors()
        
        for m, qla in cla.iteritems():
            self.assertAlmostEqual(committors[m], qla, 7)
        
    def test(self):
        A = [self.db.minima()[0]]
        B = [self.db.minima()[-1]]
        self.do_check_rates(A, B)
        self.do_check_committors(A, B)

    def test2(self):
        A = self.db.minima()[:2]
        B = self.db.minima()[2:4]
        self.do_check_rates(A, B)
        self.do_check_committors(A, B)
Esempio n. 19
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)
Esempio n. 20
0
    def test1(self):
        d = os.path.dirname(__file__)
        dbfname = os.path.join(d, "lj75_very_small_pathsample.{}.sqlite".format(sys.version_info.major))

        from pele.systems import LJCluster
        natoms = 75
        system = LJCluster(natoms)
        db = system.create_database(dbfname, createdb=False)

        permlist = [list(range(natoms))]
        
        ts_min = list(db.minima()) + list(db.transition_states())
        
        for m in ts_min:
            match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True)
            calculator = PointGroupOrderCluster(match)
            pgorder = calculator(m.coords)
            self.assertEqual(pgorder, m.pgorder)
Esempio n. 21
0
def spawnlj(**kwargs):
    from pele.systems import LJCluster
    from pele.config import config
    import os
    natoms = 13
    sys = LJCluster(natoms)
    db = sys.create_database()
    x1, E1 = sys.get_random_minimized_configuration()[:2]
    x2, E2 = sys.get_random_minimized_configuration()[:2]
    m1 = db.addMinimum(E1, x1)
    m2 = db.addMinimum(E2, x2)
    
    optim = "/home/js850/git/OPTIM/source/build/OPTIM"
    optim = config.get("exec", "OPTIM")
    optim = os.path.expandvars(os.path.expanduser(optim))
    spawner = SpawnOPTIM_LJ(x1, x2, sys, OPTIM=optim, **kwargs)
    spawner.run()
    spawner.load_results(db)
Esempio n. 22
0
    def test1(self):
        d = os.path.dirname(__file__)
        dbfname = os.path.join(d, "lj75_very_small_pathsample.sqlite")

        from pele.systems import LJCluster
        natoms = 75
        system = LJCluster(natoms)
        db = system.create_database(dbfname, createdb=False)

        permlist = [range(natoms)]

        ts_min = list(db.minima()) + list(db.transition_states())

        for m in ts_min:
            match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True)
            calculator = PointGroupOrderCluster(match)
            pgorder = calculator(m.coords)
            self.assertEqual(pgorder, m.pgorder)
Esempio n. 23
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_())
Esempio n. 24
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
Esempio n. 25
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_()) 
Esempio n. 26
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 = [list(range(natoms))]
        match = ExactMatchAtomicCluster(permlist=permlist, can_invert=True)
        calculator = PointGroupOrderCluster(match)
        pgorder = calculator(m.coords)
#        print pgorder
        
        self.assertEqual(pgorder, 120)
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
Esempio n. 28
0
def spawnlj(**kwargs):
    from pele.systems import LJCluster
    from pele.config import config
    import os

    natoms = 13
    sys = LJCluster(natoms)
    db = sys.create_database()
    x1, E1 = sys.get_random_minimized_configuration()[:2]
    x2, E2 = sys.get_random_minimized_configuration()[:2]
    m1 = db.addMinimum(E1, x1)
    m2 = db.addMinimum(E2, x2)

    optim = "/home/js850/git/OPTIM/source/build/OPTIM"
    optim = config.get("exec", "OPTIM")
    optim = os.path.expandvars(os.path.expanduser(optim))
    spawner = SpawnOPTIM_LJ(x1, x2, sys, OPTIM=optim, **kwargs)
    spawner.run()
    spawner.load_results(db)
Esempio n. 29
0
class TestHeatCapacity(unittest.TestCase):
    def setUp(self):
        import pele.rates.tests.__init__ as f
        dirname = os.path.dirname(f.__file__)
        dbfname = os.path.join(dirname, "lj15.sqlite")
        if not os.path.exists(dbfname):
            raise IOError("database file %s does not exist" % dbfname)
        self.system = LJCluster(15)
        self.db = self.system.create_database(dbfname, createdb=False)
        get_thermodynamic_information(self.system, self.db, nproc=None)
    
    def test_cv(self):
        kT = np.array([.1, 1.])
        k = self.system.get_ndof()
        minima = self.db.minima()[:10]
        cvdata = minima_to_cv(minima, kT, k)
        self.assertAlmostEqual(cvdata.U[0], -50.37139067, places=5)
        self.assertAlmostEqual(cvdata.U[1], -31.26584667, places=5)
        self.assertAlmostEqual(cvdata.Cv[0], 39.1151649, places=5)
        self.assertAlmostEqual(cvdata.Cv[1], 39.20781194, places=5)
Esempio n. 30
0
class TestHeatCapacity(unittest.TestCase):
    def setUp(self):
        import pele.rates.tests.__init__ as f

        dirname = os.path.dirname(f.__file__)
        dbfname = os.path.join(dirname, "lj15.{}.sqlite".format(sys.version_info.major))
        if not os.path.exists(dbfname):
            raise IOError("database file %s does not exist" % dbfname)
        self.system = LJCluster(15)
        self.db = self.system.create_database(dbfname, createdb=False)
        get_thermodynamic_information(self.system, self.db, nproc=None)

    def test_cv(self):
        kT = np.array([.1, 1.])
        k = self.system.get_ndof()
        minima = self.db.minima()[:10]
        cvdata = minima_to_cv(minima, kT, k)
        self.assertAlmostEqual(cvdata.U[0], -50.37139067, places=5)
        self.assertAlmostEqual(cvdata.U[1], -31.26584667, places=5)
        self.assertAlmostEqual(cvdata.Cv[0], 39.1151649, places=5)
        self.assertAlmostEqual(cvdata.Cv[1], 39.20781194, places=5)
Esempio n. 31
0
def main(system_name="lj75", n_minimizations=20000):
    if system_name == "lj75":
        system = LJCluster(75)
    elif system_name == "blj100":
        system = BLJCluster(100, epsAB=1., epsBB=1., sigBB=1.3, sigAB=2.3/2)
    elif system_name == "blj30":
        system = BLJCluster(30, epsAB=1., epsBB=1., sigBB=1.3, sigAB=2.3/2)
    else:
        raise ValueError()
    db = system.create_database()
    
    
    tdb = BHTrajDatabase("bh_traj_new.sqlite")
    
    if False:
        minE_list = pickle.load(open(picklef, "rb"))
        for minE in minE_list:
            tdb.add_trajectory(system_name, minE)
    
    if False:
        for traj in tdb.get_trajectories(system_name):
            print traj.trajectory_length, traj.minimum_energy_found
        return
    
    minE, etraj = do_bh_run(system, db, n_minimizations=n_minimizations)
    tdb.add_trajectory(system_name, minE, etraj)

    print "minimum energies found"
    for traj in tdb.get_trajectories(system_name):
        print traj.trajectory_length, traj.minimum_energy_found
    
    colors = ["black", "red", "blue", "green", "red", "cyan", "magenta"]
    for i, traj in enumerate(tdb.get_trajectories(system_name)):
        c = colors[i%len(colors)]
        
        plt.plot(traj.minimum_energy_trajectory, color=c)
        plt.plot(traj.energy_trajectory, ':', color=c)
    plt.show()
Esempio n. 32
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)
Esempio n. 33
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)
Esempio n. 34
0
        db.session.add(nm)
        db.session.commit()


#        # calculate the eigenvalues and eigenvectors of the hessian and attach them to the database
#        eval, evec = get_eig(hess)
#        if len(m.hessian_eigs) == 0:
#            nm = HessianEigs(m, eval, evec)

    db.session.commit()

if __name__ == "__main__":
    from pele.systems import LJCluster
    from pele.utils.hessian import get_sorted_eig
    system = LJCluster(20)
    db = system.create_database()  #"test.sqlite")
    coords, energy = system.get_random_minimized_configuration()[:2]
    print energy
    m = db.addMinimum(energy, coords)

    pot = system.get_potential()
    e, g, hess = pot.getEnergyGradientHessian(coords)
    eval, evec = get_sorted_eig(hess)
    epair = NormalModes(m, eval, evec, nzero=6, nnegative=0)
    db.session.commit()
    print m.normal_modes[0].vectors.shape

    if False:
        print m.normal_modes
        print m.normal_modes[0].freq, eval[0]
        epair = NormalModes(m, eval[1], evec[:, 1])
Esempio n. 35
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 ""
Esempio n. 36
0
from pele.systems import LJCluster

natoms = 38
system = LJCluster(natoms)

# load the coordinates from disk
coords1 = np.genfromtxt("coords.A").flatten()
coords2 = np.genfromtxt("coords.B").flatten()

# minimize them
quencher = system.get_minimizer()
ret1 = quencher(coords1)
ret2 = quencher(coords2)

# make a database and add the minima
db = system.create_database()
coords, E = ret1[:2]
min1 = db.addMinimum(E, coords)
coords, E = ret2[:2]
min2 = db.addMinimum(E, coords)

# do the double ended connect run
connect = system.get_double_ended_connect(min1, min2, db)
connect.connect()
success = connect.success()
if not success:
    print "failed to find connection"
else:
    mints, S, energies = connect.returnPath()
    nts = (len(mints) - 1)/2
    print "found a path with", nts, "transition states"
        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)
        

Esempio n. 38
0
we will use as an example system the Lennard-Jones cluster with a small number of atoms.
Since we don't already have a database, for this example we'll build a small one using
basinhopping"
"""
import numpy as np
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
Esempio n. 39
0
class TestNormalModes(unittest.TestCase):
    def setUp(self):
        import numpy as np
        s = np.random.randint(1000000)
        s = 322846
        self.seed = s
        sys.stderr.write("setUp: seed {}\n".format(self.seed))
        np.random.seed(s)
        import pele.rates.tests.__init__ as f

        dirname = os.path.dirname(f.__file__)
        dbfname = os.path.join(dirname, "lj15.{}.sqlite".format(sys.version_info.major))
        if not os.path.exists(dbfname):
            raise IOError("database file %s does not exist" % dbfname)
        self.system = LJCluster(15)
        self.db = self.system.create_database(dbfname, createdb=False)

    def check(self, fvib_expected, coords, nzero, nnegative, metric=None):
        pot = self.system.get_potential()
        hess = pot.getHessian(coords)
        freqs, modes = normalmodes(hess, metric=metric)
        # print v
        n, fvib = logproduct_freq2(freqs, nzero=nzero, nnegative=nnegative)
        self.assertAlmostEqual(fvib, fvib_expected, 4)
        self.assertEqual(n, len(coords) - nzero - nnegative)

    def test_minimum(self):
        m = self.db.minima()[0]
        self.check(m.fvib, m.coords, 6, 0)

    def test_transition_state(self):
        ts = self.db.transition_states()[0]
        self.check(ts.fvib, ts.coords, 6, 1)

    def test_metric_tensor(self):
        m = self.db.minima()[0]
        mt = np.eye(m.coords.size)
        self.check(m.fvib, m.coords, 6, 0, metric=mt)


    def test_get_thermo_info(self):
        # note, there is an intermittant error in this test
        # it causes the system to lock, and has to do with multiprocessing
        sys.stderr.write("test_get_thermo_info: seed {}\n".format(self.seed))
        newdb = self.system.create_database()
        new2old = dict()
        for ts in self.db.transition_states()[:5]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newts = newdb.addTransitionState(ts.energy, ts.coords, m1, m2)
            new2old[m1] = ts.minimum1
            new2old[m2] = ts.minimum2
            new2old[newts] = ts

        get_thermodynamic_information(self.system, newdb, nproc=2, verbose=True)

        for new in newdb.minima() + newdb.transition_states():
            old = new2old[new]
            self.assertAlmostEqual(new.energy, old.energy, 4)
            self.assertAlmostEqual(new.fvib, old.fvib, 4)
            self.assertEqual(new.pgorder, old.pgorder)

    def test_too_few_zero_modes(self):
        self.system.get_nzero_modes = lambda: 10
        newdb = self.system.create_database()
        for ts in self.db.transition_states()[:4]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newdb.addTransitionState(ts.energy, ts.coords, m1, m2)

        get_thermodynamic_information(self.system, newdb, nproc=2, verbose=True)
        for ts in newdb.transition_states():
            self.assertTrue(ts.invalid)
        for m in newdb.minima():
            self.assertTrue(m.invalid)

    def test_too_few_negative_modes(self):
        newdb = self.system.create_database()
        tslist = []
        for ts in self.db.transition_states()[:2]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            # add a minima as a transition state
            newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2)
            tslist.append(newts)

        # with self.assertRaises(ValueError):
        get_thermodynamic_information(self.system, newdb, nproc=2, verbose=False)
        for ts in tslist:
            self.assertTrue(ts.invalid)

    def test_too_many_negative_modes(self):
        newdb = self.system.create_database()
        mlist = []
        for ts in self.db.transition_states()[:2]:
            # add a transition state as a minimum
            m1 = newdb.addMinimum(ts.energy, ts.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2)
            mlist.append(m1)

        # with self.assertRaises(ValueError):
        get_thermodynamic_information(self.system, newdb, nproc=2, verbose=False)
        for m in mlist:
            self.assertTrue(m.invalid)
Esempio n. 40
0
        self.ui.label.setText(label)
        if with_path:
            coordspath = np.array(self.quench_path)
            self.ui.show3d.setCoordsPath(coordspath, frame=-1)
        else:
            self.ui.show3d.setCoords(self.coords, index=2)
            self.ui.show3d.setCoords(self.quenched, index=1)


if __name__ == "__main__":
    import sys
    import pylab as pl
    from OpenGL.GLUT import glutInit
    glutInit()
    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.
    x1, e1 = system.get_random_minimized_configuration()[:2]
    x2, e2 = system.get_random_minimized_configuration()[:2]
    db = system.create_database(db=":memory:")
    system.database = db
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)

    wnd = TakestepExplorer(app=app, system=system, database=db)
    wnd.show()
    from PyQt4.QtCore import QTimer
    sys.exit(app.exec_())
Esempio n. 41
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)
Esempio n. 42
0
        db.session.add(nm)
        db.session.commit()

#        # calculate the eigenvalues and eigenvectors of the hessian and attach them to the database
#        eval, evec = get_eig(hess)
#        if len(m.hessian_eigs) == 0: 
#            nm = HessianEigs(m, eval, evec)

    db.session.commit()


if __name__ == "__main__":
    from pele.systems import LJCluster
    from pele.utils.hessian import get_sorted_eig
    system = LJCluster(20)
    db = system.create_database()#"test.sqlite")
    coords, energy = system.get_random_minimized_configuration()[:2]
    print energy
    m = db.addMinimum(energy, coords)
    
    pot = system.get_potential()
    e, g, hess = pot.getEnergyGradientHessian(coords)
    eval, evec = get_sorted_eig(hess)
    epair = NormalModes(m, eval, evec, nzero=6, nnegative=0)
    db.session.commit()
    print m.normal_modes[0].vectors.shape
    
    
    if False:
        print m.normal_modes 
        print m.normal_modes[0].freq, eval[0]
Esempio n. 43
0
class TestNormalModes(unittest.TestCase):
    def setUp(self):
        import numpy as np
        s = np.random.randint(1000000)
        s = 322846
        self.seed = s
        sys.stderr.write("setUp: seed {}\n".format(self.seed))
        np.random.seed(s)
        import pele.rates.tests.__init__ as f

        dirname = os.path.dirname(f.__file__)
        dbfname = os.path.join(dirname,
                               "lj15.{}.sqlite".format(sys.version_info.major))
        if not os.path.exists(dbfname):
            raise IOError("database file %s does not exist" % dbfname)
        self.system = LJCluster(15)
        self.db = self.system.create_database(dbfname, createdb=False)

    def check(self, fvib_expected, coords, nzero, nnegative, metric=None):
        pot = self.system.get_potential()
        hess = pot.getHessian(coords)
        freqs, modes = normalmodes(hess, metric=metric)
        # print v
        n, fvib = logproduct_freq2(freqs, nzero=nzero, nnegative=nnegative)
        self.assertAlmostEqual(fvib, fvib_expected, 4)
        self.assertEqual(n, len(coords) - nzero - nnegative)

    def test_minimum(self):
        m = self.db.minima()[0]
        self.check(m.fvib, m.coords, 6, 0)

    def test_transition_state(self):
        ts = self.db.transition_states()[0]
        self.check(ts.fvib, ts.coords, 6, 1)

    def test_metric_tensor(self):
        m = self.db.minima()[0]
        mt = np.eye(m.coords.size)
        self.check(m.fvib, m.coords, 6, 0, metric=mt)

    def test_get_thermo_info(self):
        # note, there is an intermittant error in this test
        # it causes the system to lock, and has to do with multiprocessing
        sys.stderr.write("test_get_thermo_info: seed {}\n".format(self.seed))
        newdb = self.system.create_database()
        new2old = dict()
        for ts in self.db.transition_states()[:5]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newts = newdb.addTransitionState(ts.energy, ts.coords, m1, m2)
            new2old[m1] = ts.minimum1
            new2old[m2] = ts.minimum2
            new2old[newts] = ts

        get_thermodynamic_information(self.system,
                                      newdb,
                                      nproc=2,
                                      verbose=True)

        for new in newdb.minima() + newdb.transition_states():
            old = new2old[new]
            self.assertAlmostEqual(new.energy, old.energy, 4)
            self.assertAlmostEqual(new.fvib, old.fvib, 4)
            self.assertEqual(new.pgorder, old.pgorder)

    def test_too_few_zero_modes(self):
        self.system.get_nzero_modes = lambda: 10
        newdb = self.system.create_database()
        for ts in self.db.transition_states()[:4]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newdb.addTransitionState(ts.energy, ts.coords, m1, m2)

        get_thermodynamic_information(self.system,
                                      newdb,
                                      nproc=2,
                                      verbose=True)
        for ts in newdb.transition_states():
            self.assertTrue(ts.invalid)
        for m in newdb.minima():
            self.assertTrue(m.invalid)

    def test_too_few_negative_modes(self):
        newdb = self.system.create_database()
        tslist = []
        for ts in self.db.transition_states()[:2]:
            m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            # add a minima as a transition state
            newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2)
            tslist.append(newts)

        # with self.assertRaises(ValueError):
        get_thermodynamic_information(self.system,
                                      newdb,
                                      nproc=2,
                                      verbose=False)
        for ts in tslist:
            self.assertTrue(ts.invalid)

    def test_too_many_negative_modes(self):
        newdb = self.system.create_database()
        mlist = []
        for ts in self.db.transition_states()[:2]:
            # add a transition state as a minimum
            m1 = newdb.addMinimum(ts.energy, ts.coords)
            m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords)
            newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2)
            mlist.append(m1)

        # with self.assertRaises(ValueError):
        get_thermodynamic_information(self.system,
                                      newdb,
                                      nproc=2,
                                      verbose=False)
        for m in mlist:
            self.assertTrue(m.invalid)
Esempio n. 44
0
def start():
    wnd.compute_rates()

if __name__ == "__main__":
    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
Esempio n. 45
0
            coordspath = np.array(self.quench_path)
            self.ui.show3d.setCoordsPath(coordspath, frame=-1)
        else:
            self.ui.show3d.setCoords(self.coords, index=2)
            self.ui.show3d.setCoords(self.quenched, index=1)
        

if __name__ == "__main__":
    import sys
    import pylab as pl
    from OpenGL.GLUT import glutInit
    glutInit()
    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.
    x1, e1 = system.get_random_minimized_configuration()[:2]
    x2, e2 = system.get_random_minimized_configuration()[:2]
    db = system.create_database(db=":memory:")
    system.database = db
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)
    
    wnd = TakestepExplorer(app=app, system=system, database = db)
    wnd.show()
    from PyQt4.QtCore import QTimer
    sys.exit(app.exec_()) 

Esempio n. 46
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)
Esempio n. 47
0
Since we don't already have a database, for this example we'll build a small one using
basinhopping"
"""
import numpy as np
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")