Example #1
0
    def setUp(self):
        nmin = 10
        natoms = 13

        sys = LJCluster(natoms)

        pot = sys.get_potential()
        mindist = sys.get_mindist()

        db = create_random_database(nmin=nmin,
                                    natoms=natoms,
                                    nts=old_div(nmin, 2))
        min1, min2 = list(db.minima())[:2]

        self.db = db
        self.natoms = natoms
        self.connect = DoubleEndedConnect(min1,
                                          min2,
                                          pot,
                                          mindist,
                                          db,
                                          merge_minima=True,
                                          max_dist_merge=1e100)
        #        for ts in db.transition_states():
        #            self.add_ts(ts.energy, ts.coords,
        #                        ts.minimum1.energy, ts.minimum1.coords,
        #                        ts.minimum2.energy, ts.minimum2.coords)
        for m in db.minima():
            self.connect.dist_graph.addMinimum(m)
Example #2
0
    def setUp1(self, verbose=False, **kwargs):
        np.random.seed(0)
        natoms = 18
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()
        x = self.system.get_random_configuration()
        ret = lbfgs_py(x, self.pot, tol=10)
        self.x = ret.coords

        self.kwargs = kwargs
        self.verbose = verbose

        self.M = 4
        if self.verbose: iprint = 1
        else: iprint = -1
        self.myo = MYLBFGS(self.x,
                           self.pot,
                           iprint=iprint,
                           debug=True,
                           M=self.M)
        self.o = LBFGS(self.x,
                       self.pot,
                       iprint=iprint,
                       debug=True,
                       M=self.M,
                       **self.kwargs)
Example #3
0
 def setUp(self, **kwargs):
     from pele.optimize.tests.test_nfev import _PotWrapper
     natoms = 18
     self.system = LJCluster(natoms)
     self.x = self.system.get_random_minimized_configuration(
         tol=100.).coords
     self.pot = _PotWrapper(self.system.get_potential())
Example #4
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)
Example #5
0
 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)
Example #6
0
def test():  # pragma: no cover
    from pele.systems import LJCluster

    natoms = 30
    system = LJCluster(natoms)
    pot = system.get_potential()
    coords = system.get_random_configuration()

    xmin = system.get_random_minimized_configuration()[0]
    e, g, h = pot.getEnergyGradientHessian(xmin)
    evals = get_eigvals(h)
    print(evals)

    quencher = system.get_minimizer(tol=10.)
    coords = quencher(coords)[0]
    e, g, h = pot.getEnergyGradientHessian(coords)
    w1, v1 = get_smallest_eig(h)
    print(w1)
    w, v = get_smallest_eig_arpack(h)
    print(w)
    w2, v2 = get_smallest_eig_sparse(h)
    print(w2, w2 / w1)
    w3, v3 = get_smallest_eig_nohess(coords, system)
    print(w3, w3 / w1)
    # plot_hist(h)
    # exit()

    if False:
        n = 10
        while n < 500:
            size_scaling_smallest_eig(int(n))
            n *= 1.2
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
0
 def setUp(self):
     natoms = 18
     self.system = LJCluster(natoms)
     self.pot = self.system.get_potential()
     self.evec = vec_random_ndim(3 * natoms)
     self.evec /= np.linalg.norm(self.evec)
     self.x = self.system.get_random_configuration()
Example #11
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
Example #12
0
    def prepare_system(self, frozen_atoms=None):
        if not frozen_atoms: frozen_atoms = [0, 2, 4]
        self.natoms = 13

        fsys = LJCluster(self.natoms)

        self.reference_coords = fsys.get_random_configuration()

        self.system = LJClusterFrozen(self.natoms, frozen_atoms, self.reference_coords)
Example #13
0
    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)
Example #14
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)
Example #15
0
    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)
Example #16
0
def test():  # pragma: no cover
    from pele.gui import run_gui

    natoms = 13

    fsys = LJCluster(natoms)
    reference_coords = fsys.get_random_configuration()
    frozen_atoms = [0, 2, 3, 4]
    system = LJClusterFrozen(natoms, frozen_atoms, reference_coords)

    run_gui(system)
Example #17
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)
Example #18
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
Example #19
0
    def setUp1(self, **kwargs):
        natoms = 18
        #        s = LJCluster(natoms)
        #        nfrozen = 6
        #        reference_coords = s.get_random_configuration()
        #        self.system = LJClusterFrozen(13, range(nfrozen), reference_coords)
        self.system = LJCluster(natoms)
        self.x = self.system.get_random_minimized_configuration(
            tol=100.).coords
        self.pot = self.system.get_potential()

        self.finder = FindLowestEigenVector(self.x.copy(), self.pot, **kwargs)
Example #20
0
 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)
Example #21
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)
Example #22
0
def getPairLJ(natoms=38):  # pragma: no cover
    from pele.systems import LJCluster

    system = LJCluster(natoms)
    ret1 = system.get_random_minimized_configuration()
    ret2 = system.get_random_minimized_configuration()
    coords1, coords2 = ret1[0], ret2[0]
    E1, E2 = ret1[1], ret2[1]

    mindist = system.get_mindist()
    mindist(coords1, coords2)

    return coords1, coords2, system.get_potential(), mindist, E1, E2
Example #23
0
    def setUp(self):
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = _PotWrapper(self.system.get_potential())

        # get a partially minimized structure
        self.x0 = _x0.copy()

        self.minimizers = [
            _quench.lbfgs_py,
            _quench.mylbfgs,
            _quench.lbfgs_scipy,
        ]
Example #24
0
    def setUp(self):
        np.random.seed(0)
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()

        # get a partially minimized structure
        self.x0 = _x0.copy()
        self.E0 = -128.289209867

        ret = _quench.lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.x = ret.coords.copy()
        self.E = ret.energy
Example #25
0
def size_scaling_smallest_eig(natoms):  # pragma: no cover
    from pele.systems import LJCluster
    import time, sys

    system = LJCluster(natoms)
    pot = system.get_potential()
    quencher = system.get_minimizer(tol=10.)

    time1 = 0.
    time2 = 0.
    time3 = 0.
    time4 = 0.
    for i in range(100):
        coords = system.get_random_configuration()
        # print "len(coords)", len(coords)
        coords = quencher(coords)[0]
        e, g, h = pot.getEnergyGradientHessian(coords)

        t0 = time.time()
        w1, v1 = get_smallest_eig(h)
        t1 = time.time()
        w, v = get_smallest_eig_arpack(h)
        t2 = time.time()
        w2, v2 = get_smallest_eig_sparse(h)
        t3 = time.time()
        w3, v3 = get_smallest_eig_nohess(coords, system, tol=1e-3)
        t4 = time.time()

        time1 += t1 - t0
        time2 += t2 - t1
        time3 += t3 - t2
        time4 += t4 - t3

        wdiff = np.abs(w - w1) / np.max(np.abs([w, w1]))
        if wdiff > 5e-3:
            sys.stderr.write(
                "eigenvalues for dense  are different %g %g normalized diff %g\n"
                % (w1, w, wdiff))
        wdiff = np.abs(w - w2) / np.max(np.abs([w, w2]))
        if wdiff > 5e-2:
            sys.stderr.write(
                "eigenvalues for sparse are different %g %g normalized diff %g\n"
                % (w2, w, wdiff))
        wdiff = np.abs(w - w3) / np.max(np.abs([w, w3]))
        if wdiff > 5e-2:
            sys.stderr.write(
                "eigenvalues for nohess are different %g %g normalized diff %g\n"
                % (w3, w, wdiff))
        # print "times", n, t1-t0, t2-t1, w1, w
    print("times", n, time1, time2, time3, time4)
    sys.stdout.flush()
Example #26
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_()) 
Example #27
0
    def setUp(self):
        np.random.seed(0)
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()

        # get a partially minimized structure
        x0 = self.system.get_random_configuration()
        ret = _quench.lbfgs_py(x0, self.pot, tol=1e-1)
        self.x0 = ret.coords.copy()
        self.E0 = ret.energy

        ret = _quench.lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.x = ret.coords.copy()
        self.E = ret.energy
Example #28
0
    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")
        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)
Example #29
0
    def setUp(self):
        np.random.seed(0)
        from pele.systems import LJCluster
        natoms = 10
        self.system = LJCluster(natoms)
        system = self.system
        self.pot = system.get_potential()
        quencher = system.get_minimizer(tol=2.)
        x = system.get_random_configuration()
        ret = quencher(x)
        self.x = ret[0]

        self.xmin = system.get_random_minimized_configuration()[0]

        e, g, self.h = self.pot.getEnergyGradientHessian(self.x)
        e, g, self.hmin = self.pot.getEnergyGradientHessian(self.xmin)
Example #30
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