Пример #1
0
    def setUp(self):
        from pygmin.landscape import DoubleEndedConnect
        from pygmin.landscape._graph import create_random_database
        from pygmin.systems import LJCluster
        #        from pygmin.mindist import minPermDistStochastic, MinDistWrapper
        #        from pygmin.potentials import LJ

        nmin = 10
        natoms = 13

        sys = LJCluster(natoms)

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

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

        connect = DoubleEndedConnect(min1,
                                     min2,
                                     pot,
                                     mindist,
                                     db,
                                     use_all_min=True,
                                     merge_minima=True,
                                     max_dist_merge=1e100)

        self.connect = connect
        self.db = db
        self.natoms = natoms
Пример #2
0
def test():
    from pygmin.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
Пример #3
0
def test():
    from pygmin.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
Пример #4
0
    def setUp(self):
        from pygmin.landscape import DoubleEndedConnect
        from pygmin.landscape._graph import create_random_database
        from pygmin.systems import LJCluster
#        from pygmin.mindist import minPermDistStochastic, MinDistWrapper
#        from pygmin.potentials import LJ
        
        nmin = 10
        natoms=13
        
        sys = LJCluster(natoms)
        
        pot = sys.get_potential()
        mindist = sys.get_mindist()
        
        db = create_random_database(nmin=nmin, natoms=natoms, nts=nmin/2)
        min1, min2 = list(db.minima())[:2] 
        
        
        connect = DoubleEndedConnect(min1, min2, pot, mindist, db, use_all_min=True, 
                                     merge_minima=True, max_dist_merge=1e100)

        self.connect = connect
        self.db = db
        self.natoms = natoms
def guessts(coords1, coords2, pot):
    from pygmin.optimize import lbfgs_py as quench
    #    from pygmin.mindist.minpermdist_stochastic import minPermDistStochastic as mindist
    from pygmin.transition_states import NEB
    from pygmin.systems import LJCluster
    ret1 = quench(coords1, pot.getEnergyGradient)
    ret2 = quench(coords2, pot.getEnergyGradient)
    coords1 = ret1[0]
    coords2 = ret2[0]
    natoms = len(coords1) / 3
    system = LJCluster(natoms)
    mindist = system.get_mindist()
    dist, coords1, coords2 = mindist(coords1, coords2)
    print "dist", dist
    print "energy coords1", pot.getEnergy(coords1)
    print "energy coords2", pot.getEnergy(coords2)
    from pygmin.transition_states import InterpolatedPath
    neb = NEB(InterpolatedPath(coords1, coords2, 20), pot)
    #neb.optimize(quenchParams={"iprint" : 1})
    neb.optimize(iprint=-30, nsteps=100)
    neb.MakeAllMaximaClimbing()
    #neb.optimize(quenchParams={"iprint": 30, "nsteps":100})
    for i in xrange(len(neb.energies)):
        if (neb.isclimbing[i]):
            coords = neb.coords[i, :]
    return pot, coords, neb.coords[0, :], neb.coords[-1, :]
Пример #6
0
def guessts(coords1, coords2, pot):
    from pygmin.optimize import lbfgs_py as quench
#    from pygmin.mindist.minpermdist_stochastic import minPermDistStochastic as mindist
    from pygmin.transition_states import NEB
    from pygmin.systems import LJCluster
    ret1 = quench(coords1, pot.getEnergyGradient)
    ret2 = quench(coords2, pot.getEnergyGradient)
    coords1 = ret1[0]
    coords2 = ret2[0]
    natoms = len(coords1)/3
    system = LJCluster(natoms)
    mindist = system.get_mindist()
    dist, coords1, coords2 = mindist(coords1, coords2) 
    print "dist", dist
    print "energy coords1", pot.getEnergy(coords1)
    print "energy coords2", pot.getEnergy(coords2)
    from pygmin.transition_states import InterpolatedPath
    neb = NEB(InterpolatedPath(coords1, coords2, 20), pot)
    #neb.optimize(quenchParams={"iprint" : 1})
    neb.optimize(iprint=-30, nsteps=100)
    neb.MakeAllMaximaClimbing()
    #neb.optimize(quenchParams={"iprint": 30, "nsteps":100})
    for i in xrange(len(neb.energies)):
        if(neb.isclimbing[i]):
            coords = neb.coords[i,:]
    return pot, coords, neb.coords[0,:], neb.coords[-1,:]
Пример #7
0
class TestMinimizers(unittest.TestCase):
    def setUp(self):
        from pygmin.systems import LJCluster
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()

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

        ret = lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.x = ret.coords.copy()
        self.E = ret.energy

    def check_attributes(self, res):
        self.assertTrue(hasattr(res, "energy"))
        self.assertTrue(hasattr(res, "coords"))
        self.assertTrue(hasattr(res, "nsteps"))
        self.assertTrue(hasattr(res, "nfev"))
        self.assertTrue(hasattr(res, "rms"))
        self.assertTrue(hasattr(res, "grad"))
        self.assertTrue(hasattr(res, "success"))

    def test_lbfgs_py(self):
        res = lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)

    def test_mylbfgs(self):
        res = mylbfgs(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)

    def test_fire(self):
        res = fire(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)

    def test_lbfgs_scipy(self):
        res = lbfgs_scipy(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)

    def test_bfgs_scipy(self):
        res = bfgs_scipy(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
Пример #8
0
class TestMinimizers(unittest.TestCase):
    def setUp(self):
        from pygmin.systems import LJCluster
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()
        
        # get a partially minimized structure
        x0 = self.system.get_random_configuration()
        ret = lbfgs_py(x0, self.pot, tol=1e-1)
        self.x0 = ret.coords.copy()
        self.E0 = ret.energy
        
        ret = lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.x = ret.coords.copy()
        self.E = ret.energy
    
    def check_attributes(self, res):
        self.assertTrue(hasattr(res, "energy"))
        self.assertTrue(hasattr(res, "coords"))
        self.assertTrue(hasattr(res, "nsteps"))
        self.assertTrue(hasattr(res, "nfev"))
        self.assertTrue(hasattr(res, "rms"))
        self.assertTrue(hasattr(res, "grad"))
        self.assertTrue(hasattr(res, "success"))
    
    def test_lbfgs_py(self):
        res = lbfgs_py(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
        
    def test_mylbfgs(self):
        res = mylbfgs(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
    
    def test_fire(self):
        res = fire(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
    
    def test_lbfgs_scipy(self):
        res = lbfgs_scipy(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
    
    def test_bfgs_scipy(self):
        res = bfgs_scipy(self.x0, self.pot, tol=1e-7)
        self.assertTrue(res.success)
        self.assertAlmostEqual(self.E, res.energy, 4)
        self.check_attributes(res)
Пример #9
0
def getPairLJ(natoms=38):
    from pygmin.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
Пример #10
0
def getPairLJ(natoms=38):
    from pygmin.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
Пример #11
0
def test(Connect=DoubleEndedConnect, natoms=16):
#    from pygmin.landscape import Graph
#    from pygmin.storage.database import Database
    from pygmin.systems import LJCluster
    #get min1
    system = LJCluster(natoms)
    pot, database = getSetOfMinLJ(system)
#    from pygmin.potentials.lj import LJ
#    pot = LJ()
#    saveit = Database(db="test.db")
    minima = database.minima()
    min1 = minima[0]
    min2 = minima[1]
    print min1.energy, min2.energy
    
    
    mindist = system.get_mindist()
    
    if False:
        #test to see if min1 and min2 are already connected
        connected = graph.areConnected(min1, min2)
        print "at start are minima connected?", connected
        return
 
    connect = Connect(min1, min2, pot, mindist, database)
    connect.connect()
    
    graph = connect.graph
    if False:
        print graph
        for node in graph.graph.nodes():
            print node._id, node.energy
    for ts in graph.storage.transition_states():
        print ts.minimum1._id,ts.minimum2._id, "E", ts.minimum1.energy, ts.minimum2.energy, ts.energy
        
    ret = graph.getPath(min1, min2)
    if ret is None:
        print "no path found"
        return
    distances, path = ret
    with open("path.out", "w") as fout:
        for i in range(len(path)-1):
            m1 = path[i]
            m2 = path[i+1]
            n1 = m1._id
            m2 = m2._id
#            ts = graph._getTS(n1, n2)
#            print "path", n1, "->", n2, m1.E, "/->", ts.E, "\->", m2.E
            fout.write("%f\n" % m1.energy)
            fout.write("%f\n" % ts.energy)
        m2 = path[-1]
        n2 = m2._id
        fout.write("%f\n" % m2.energy)
Пример #12
0
def test(Connect=DoubleEndedConnect, natoms=16):
    #    from pygmin.landscape import TSGraph
    #    from pygmin.storage.database import Database
    from pygmin.systems import LJCluster
    #get min1
    system = LJCluster(natoms)
    pot, database = getSetOfMinLJ(system)
    #    from pygmin.potentials.lj import LJ
    #    pot = LJ()
    #    saveit = Database(db="test.db")
    minima = database.minima()
    min1 = minima[0]
    min2 = minima[1]
    print min1.energy, min2.energy

    mindist = system.get_mindist()

    if False:
        #test to see if min1 and min2 are already connected
        connected = graph.areConnected(min1, min2)
        print "at start are minima connected?", connected
        return

    connect = Connect(min1, min2, pot, mindist, database)
    connect.connect()

    graph = connect.graph
    if False:
        print graph
        for node in graph.graph.nodes():
            print node._id, node.energy
    for ts in graph.storage.transition_states():
        print ts.minimum1._id, ts.minimum2._id, "E", ts.minimum1.energy, ts.minimum2.energy, ts.energy

    ret = graph.getPath(min1, min2)
    if ret is None:
        print "no path found"
        return
    distances, path = ret
    with open("path.out", "w") as fout:
        for i in range(len(path) - 1):
            m1 = path[i]
            m2 = path[i + 1]
            n1 = m1._id
            m2 = m2._id
            #            ts = graph._getTS(n1, n2)
            #            print "path", n1, "->", n2, m1.E, "/->", ts.E, "\->", m2.E
            fout.write("%f\n" % m1.energy)
            fout.write("%f\n" % ts.energy)
        m2 = path[-1]
        n2 = m2._id
        fout.write("%f\n" % m2.energy)
Пример #13
0
def size_scaling_smallest_eig(natoms):
    from pygmin.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()
Пример #14
0
    def setUp(self):
        from pygmin.systems import LJCluster
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()

        # get a partially minimized structure
        x0 = self.system.get_random_configuration()
        ret = lbfgs_py(x0, self.pot.getEnergyGradient, tol=1.e-1)
        self.x0 = ret[0]
        self.E0 = ret[1]

        ret = lbfgs_py(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.x = ret[0]
        self.E = ret[1]
Пример #15
0
def spawnlj(**kwargs):
    from pygmin.systems import LJCluster
    from pygmin.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)
Пример #16
0
def spawnlj(**kwargs):
    from pygmin.systems import LJCluster
    from pygmin.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)
Пример #17
0
def size_scaling_smallest_eig(natoms):
    from pygmin.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()
Пример #18
0
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
Пример #19
0
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
Пример #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)
Пример #21
0
    def setUp(self):
        from pygmin.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)
Пример #22
0
 def setUp(self):
     from pygmin.systems import LJCluster
     natoms = 31
     self.system = LJCluster(natoms)
     self.pot = self.system.get_potential()
     
     # get a partially minimized structure
     x0 = self.system.get_random_configuration()
     ret = lbfgs_py(x0, self.pot.getEnergyGradient, tol=1.e-1)
     self.x0 = ret[0]
     self.E0 = ret[1]
     
     ret = lbfgs_py(self.x0, self.pot.getEnergyGradient, tol=1e-7)
     self.x = ret[0]
     self.E = ret[1]
Пример #23
0
class TestMinimizers(unittest.TestCase):
    def setUp(self):
        from pygmin.systems import LJCluster
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()

        # get a partially minimized structure
        x0 = self.system.get_random_configuration()
        ret = lbfgs_py(x0, self.pot.getEnergyGradient, tol=1.e-1)
        self.x0 = ret[0]
        self.E0 = ret[1]

        ret = lbfgs_py(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.x = ret[0]
        self.E = ret[1]

    def test_lbfgs_py(self):
        res = lbfgs_py(self.x0, self.pot.getEnergyGradient)
        self.assertAlmostEqual(self.E, res[1], 4)

    def test_mylbfgs(self):
        res = mylbfgs(self.x0, self.pot.getEnergyGradient)
        self.assertAlmostEqual(self.E, res[1], 4)

    def test_fire(self):
        res = fire(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)

    def test_lbfgs_scipy(self):
        res = lbfgs_scipy(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)

    def test_bfgs_scipy(self):
        res = bfgs(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)
Пример #24
0
class TestMinimizers(unittest.TestCase):
    def setUp(self):
        from pygmin.systems import LJCluster
        natoms = 31
        self.system = LJCluster(natoms)
        self.pot = self.system.get_potential()
        
        # get a partially minimized structure
        x0 = self.system.get_random_configuration()
        ret = lbfgs_py(x0, self.pot.getEnergyGradient, tol=1.e-1)
        self.x0 = ret[0]
        self.E0 = ret[1]
        
        ret = lbfgs_py(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.x = ret[0]
        self.E = ret[1]
    
    def test_lbfgs_py(self):
        res = lbfgs_py(self.x0, self.pot.getEnergyGradient)
        self.assertAlmostEqual(self.E, res[1], 4)
        
    def test_mylbfgs(self):
        res = mylbfgs(self.x0, self.pot.getEnergyGradient)
        self.assertAlmostEqual(self.E, res[1], 4)
    
    def test_fire(self):
        res = fire(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)
    
    def test_lbfgs_scipy(self):
        res = lbfgs_scipy(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)
    
    def test_bfgs_scipy(self):
        res = bfgs(self.x0, self.pot.getEnergyGradient, tol=1e-7)
        self.assertAlmostEqual(self.E, res[1], 4)
Пример #25
0
import scipy
import numpy as np
from pygmin.systems import LJCluster
from pygmin.mindist import ExactMatchAtomicCluster
from pygmin.mindist import PointGroupOrderCluster
from pygmin.thermodynamics import normalmode_frequencies, logproduct_freq2

beta = 1.
system = LJCluster(13)

db = system.create_database()
pot = system.get_potential()

bh = system.get_basinhopping(database=db)
bh.run(50)

min1 = db.minima()[0]
coords = min1.coords
print
print "Done with basinghopping, performing frequency analysis"
print
#min1 = db.transition_states()[0]

# determine point group order of system
determine_pgorder = PointGroupOrderCluster(system.get_compare_exact())
pgorder = determine_pgorder(min1.coords)
# free energy from symmetry
Fpg = np.log(pgorder) / beta

# get the hession
e, g, hess = pot.getEnergyGradientHessian(min1.coords)
Пример #26
0
from random import choice
from pygmin.systems import LJCluster
from pygmin.storage import Minimum
from pygmin.concurrent import RandomConnectServer

server_name = "ljconnect_example"
hostname="localhost"
port=11567

print "setting up LJ38 with database lj38.sqlite"
system = LJCluster(38)
db = system.create_database("lj38.sqlite")

if db.session.query(Minimum).count() < 10:
    print "The database is empty, run basinhopping to get some minima"
    bh = system.get_basinhopping(database=db)
    bh.run(100)

print "Working on %d minima"%db.session.query(Minimum).count()

print "Running basinhopping to generate initial database"
        
print "Creating new connect manager"
connect_manager=RandomConnectServer(system, db, server_name=server_name,
                                     host=hostname, port=port)

connect_manager.run()
Пример #27
0
This example will be based on a cluster of 38 Lennard-Jones atoms.
We will load two sets of coordinates from a file, minimize them, and try to find
a connected set of minima and transition states betweeen them.

For more information about how to change parameters, see the documentation
for the system class, the parameter tree and DoubleEndedConnect.

See the class LJCluster for what the default parameters are for this system
"""
import numpy as np

from pygmin.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]
Пример #28
0
from pygmin.systems import LJCluster
import numpy as np
import scipy.sparse
import scikits.sparse.cholmod as cholmod
import time
import pygmin.transition_states as ts
from pygmin.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)
Пример #29
0
def create_system():
    natoms = 38
    system = LJCluster(natoms)
    return system
Пример #30
0
        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()

def plot_hist(hess):
    import pylab as pl
    pl.hist(np.log10(np.abs(hess.reshape(-1))))
    pl.show()

if __name__ == "__main__":
    from pygmin.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
Пример #31
0
"""
examples of how to do various things using the system class.  I will use
the Lennard-Jones system as an example
"""
import logging

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


# initialize the system class
natoms = 13
system = LJCluster(natoms)

# make a random configuration
coords = system.get_random_configuration()

# compute the energy of that configuration
potential = system.get_potential()
energy = potential.getEnergy(coords)
print "the energy of the random configuration is", energy

# minimize that configuration
quencher = system.get_minimizer()
ret = quencher(coords)
newcoords = ret[0]
newenergy = ret[1]
print "after quenching, the energy is", newenergy

# create a database to store the minimum in
db = system.create_database()
Пример #32
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 pygmin.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_()) 
Пример #33
0
#    wnd.do_NEB(min1.coords, min2.coords)
    wnd.attach_to_NEB(neb)
    neb.optimize()
    
if __name__ == "__main__":
    from pygmin.systems import LJCluster
    from pygmin.storage import Database
    import pylab as pl
    app = QApplication(sys.argv)
    
    def process_events():
        app.processEvents()
    
    #setup system
    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 = Database()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)
    
    #setup neb dialog
    pl.ion()
#    pl.show()
    dlg = NEBDialog()
    wnd = dlg.nebwgt   
    dlg.show()
    wnd.process_events.connect(process_events)
Пример #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 pygmin.systems import LJCluster
from pygmin.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 ""
Пример #35
0
This example will be based on a cluster of 38 Lennard-Jones atoms.
We will load two sets of coordinates from a file, minimize them, and try to find
a connected set of minima and transition states betweeen them.

For more information about how to change parameters, see the documentation
for the system class, the parameter tree and DoubleEndedConnect.

See the class LJCluster for what the default parameters are for this system
"""
import numpy as np

from pygmin.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]
Пример #36
0
"""
example for how to use double ended connect to connect the minima in an existing database

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 pygmin.systems import LJCluster
from pygmin.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
Пример #37
0
    wnd.set_nebrunner(runner)


if __name__ == "__main__":
    from pygmin.systems import LJCluster
    from nebdlg import getNEB
    from OpenGL.GLUT import glutInit

    app = QApplication(sys.argv)

    def process_events():
        app.processEvents()

    #setup system
    natoms = 13
    system = LJCluster(natoms)
    system.params.double_ended_connect.local_connect_params.NEBparams.iter_density = 10.
    system.params.double_ended_connect.local_connect_params.NEBparams.image_density = 3.
    #    system.params.double_ended_connect.local_connect_params.NEBparams.adaptive_nimages = 5.
    system.params.double_ended_connect.local_connect_params.NEBparams.reinterpolate = 400
    system.params.double_ended_connect.local_connect_params.NEBparams.max_images = 40
    x1, e1 = system.get_random_minimized_configuration()[:2]
    x2, e2 = system.get_random_minimized_configuration()[:2]
    db = Database()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)

    #setup neb dialog
    wnd = ConnectExplorerDialog(system, app)
    wnd.show()
Пример #38
0
def start():
    wnd.start()
    print >> sys.stderr, "started decrunner"


if __name__ == "__main__":
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pygmin.systems import LJCluster
    pl.ion()
    natoms = 113
    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()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)

    wnd = ConnectViewer(system, db, min1=min1, min2=min2, app=app)
    #    decrunner = DECRunner(system, db, min1, min2, outstream=wnd.textEdit_writer)
    glutInit()
    wnd.show()
    from PyQt4.QtCore import QTimer
    QTimer.singleShot(10, start)

    sys.exit(app.exec_())
Пример #39
0
        open a dialog box to change the parameters
        """
        if checked is None:
            return
        if not hasattr(self, "_paramsdlg"):
            self._paramsdlg = DlgParams(self._params, parent=self)
        self._paramsdlg.show()            
    
        
if __name__ == "__main__":
    from OpenGL.GLUT import glutInit
    import sys
    glutInit()
    app = QtGui.QApplication(sys.argv)
    from pygmin.systems import LJCluster
    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]
    db = system.create_database()
    match = system.get_compare_exact()
    min1 = db.addMinimum(e1, x1)
    
    com = match.measure.get_com(x1)
    match.transform.translate(x1, -com)
    wnd = NormalmodeBrowser(app=app, system=system)
    wnd.set_coords(x1)
    
    wnd.show()
    sys.exit(app.exec_())     
Пример #40
0
from pygmin.systems import LJCluster
import numpy as np
import scipy.sparse
import scikits.sparse.cholmod as cholmod
import time
import pygmin.transition_states as ts
from pygmin.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)
Пример #41
0
def start():
    wnd.start()
    print >> sys.stderr, "started decrunner"


if __name__ == "__main__":
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pygmin.systems import LJCluster
    pl.ion()
    natoms = 113
    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()
    min1 = db.addMinimum(e1, x1)
    min2 = db.addMinimum(e2, x2)
    
    
    wnd = ConnectViewer(system, db, min1=min1, min2=min2, app=app)
#    decrunner = DECRunner(system, db, min1, min2, outstream=wnd.textEdit_writer)
    glutInit()
    wnd.show()
    from PyQt4.QtCore import QTimer
    QTimer.singleShot(10, start)
Пример #42
0
import scipy
import numpy as np
from pygmin.systems import LJCluster
from pygmin.mindist import ExactMatchAtomicCluster
from pygmin.mindist import PointGroupOrderCluster
from pygmin.thermodynamics import normalmode_frequencies, logproduct_freq2
    
beta = 1.
system = LJCluster(13)

db = system.create_database()
pot = system.get_potential()

bh = system.get_basinhopping(database=db)
bh.run(50)


min1 = db.minima()[0]
coords = min1.coords
print
print "Done with basinghopping, performing frequency analysis"
print
#min1 = db.transition_states()[0]


# determine point group order of system
determine_pgorder = PointGroupOrderCluster(system.get_compare_exact())
pgorder = determine_pgorder(min1.coords)
# free energy from symmetry
Fpg = np.log(pgorder)/beta
Пример #43
0
    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)

db = system.create_database()

# create takestep routine manually
potential = system.get_potential()
step = TakeStepMonteCarlo(potential)

bh = system.get_basinhopping(database=db, takestep=step)
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima(
)[0].energy
print ""
Пример #44
0
        self.widget.show_graph()

def start():
    wnd.start()


if __name__ == "__main__":
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pygmin.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]
Пример #45
0
"""
Example 2: reading coords from file
"""
import numpy as np

from pygmin.systems import LJCluster

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

coords = np.loadtxt('coords')
coords = coords.reshape(-1)

db = system.create_database()
bh = system.get_basinhopping(database=db)
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima()[0].energy
print ""
Пример #46
0
#    print "times", n, t1-t0, t2-t1, w1, w
    print "times", n, time1, time2, time3, time4
    sys.stdout.flush()


def plot_hist(hess):
    import pylab as pl
    pl.hist(np.log10(np.abs(hess.reshape(-1))))
    pl.show()


if __name__ == "__main__":
    from pygmin.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
Пример #47
0
        else:
            faccept = float(ndiff_accept) / ndiff
        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 pygmin.takestep import displace
    from pygmin.systems import LJCluster
    #from pygmin.takestep import adaptive
    
    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)
        
Пример #48
0
"""
examples of how to do various things using the system class.  I will use
the Lennard-Jones system as an example
"""
import logging

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

# initialize the system class
natoms = 13
system = LJCluster(natoms)

# make a random configuration
coords = system.get_random_configuration()

# compute the energy of that configuration
potential = system.get_potential()
energy = potential.getEnergy(coords)
print "the energy of the random configuration is", energy

# minimize that configuration
quencher = system.get_minimizer()
ret = quencher(coords)
newcoords = ret[0]
newenergy = ret[1]
print "after quenching, the energy is", newenergy

# 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
Пример #49
0
        return [range(self.ntypeA), range(self.ntypeA, self.natoms)]
    
if __name__ == '__main__':
    unittest.main()
        
if __name__ == "__main__":
    from pygmin.systems import LJCluster
    natoms = 20
    rho = .5
    boxl = (float(natoms) / rho)**(1./3)
    boxlengths = np.ones(3) * boxl
    
    permlist = [range(natoms)]
    measure = MeasurePeriodic(boxlengths, permlist)
    
    system = LJCluster(natoms)

    x1 = system.get_random_configuration()
    x2 = x1.copy()
    x2 = randomly_permute(x2, permlist)
    
    exact_match = ExactMatchPeriodic(measure)
    em = exact_match.are_exact(x1, x2)
    print em
    
    unittest.main()
    
    
    
    
    
Пример #50
0

def start():
    wnd.start()


if __name__ == "__main__":
    from OpenGL.GLUT import glutInit
    import sys
    import pylab as pl

    app = QtGui.QApplication(sys.argv)
    from pygmin.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]
Пример #51
0
        #########################################################################
        return self.acceptstep, self.trial_coords, self.trial_energy

    def printStep(self):
        if self.stepnum % self.printfrq == 0:
            if self.outstream != None:
                self.outstream.write("Qu   " + str(self.stepnum) + " E= " +
                                     str(self.trial_energy) +
                                     " quench_steps= " + str(self.funcalls) +
                                     " RMS= " + str(self.rms) + " Markov E= " +
                                     str(self.markovE_old) + " accepted= " +
                                     str(self.acceptstep) + "\n")

    def __getstate__(self):
        ddict = self.__dict__.copy()
        del ddict["outstream"]
        del ddict["potential"]
        return ddict  #.items()

    def __setstate__(self, dct):
        self.__dict__.update(dct)
        self.outstream = sys.stdout


if __name__ == "__main__":
    from pygmin.systems import LJCluster
    natoms = 13
    sys = LJCluster(natoms)
    bh = sys.get_basinhopping()
    bh.run(100)
Пример #52
0
 def setUp(self):
     natoms = 6
     self.system = LJCluster(natoms)
     self.e1 = -12.7120622568
     self.e2 = -12.302927529580728
Пример #53
0
class TestExactMatchPeriodicBLJ(TestExactMatchPeriodicLJ):
    def get_permlist(self):
        self.ntypeA = int(self.natoms * .8)
        return [range(self.ntypeA), range(self.ntypeA, self.natoms)]


if __name__ == '__main__':
    unittest.main()

if __name__ == "__main__":
    from pygmin.systems import LJCluster
    natoms = 20
    rho = .5
    boxl = (float(natoms) / rho)**(1. / 3)
    boxlengths = np.ones(3) * boxl

    permlist = [range(natoms)]
    measure = MeasurePeriodic(boxlengths, permlist)

    system = LJCluster(natoms)

    x1 = system.get_random_configuration()
    x2 = x1.copy()
    x2 = randomly_permute(x2, permlist)

    exact_match = ExactMatchPeriodic(measure)
    em = exact_match.are_exact(x1, x2)
    print em

    unittest.main()
Пример #54
0
        else:
            faccept = float(ndiff_accept) / ndiff
        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 pygmin.takestep import displace
    from pygmin.systems import LJCluster
    #from pygmin.takestep import adaptive
    
    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)
        
Пример #55
0
        self.nsteps = nsteps
        
        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)

db = system.create_database()

# create takestep routine manually
potential = system.get_potential()
step = TakeStepMonteCarlo(potential)

bh = system.get_basinhopping(database=db, takestep=step)
bh.run(niter)
print "the lowest energy found after", niter, " basinhopping steps is", db.minima()[0].energy
print ""
Пример #56
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 pygmin.systems import LJCluster
from pygmin.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 ""