Exemple #1
0
def runtest(X, pot, natoms = 100, iprint=-1):
    from _lbfgs_py import PrintEvent
    tol = 1e-5
    maxstep = 0.005

    Xinit = np.copy(X)
    e, g = pot.getEnergyGradient(X)
    print "energy", e
    
    lbfgs = LBFGS(X, pot, maxstep = 0.1, nsteps=10000, tol=tol,
                  iprint=iprint, H0=2.)
    printevent = PrintEvent( "debugout.xyz")
    lbfgs.attachEvent(printevent)
    
    ret = lbfgs.run()
    print ret
    
    print ""
    print "now do the same with scipy lbfgs"
    from pygmin.optimize import lbfgs_scipy as quench
    ret = quench(Xinit, pot, tol = tol)
    print ret
    #print ret[1], ret[2], ret[3]    
    
    if False:
        print "now do the same with scipy bfgs"
        from pygmin.optimize import bfgs as oldbfgs
        ret = oldbfgs(Xinit, pot, tol = tol)
        print ret
    
    if False:
        print "now do the same with gradient + linesearch"
        import _bfgs
        gpl = _bfgs.GradientPlusLinesearch(Xinit, pot, maxstep = 0.1)  
        ret = gpl.run(1000, tol = 1e-6)
        print ret
            
    if False:
        print "calling from wrapper function"
        from pygmin.optimize import lbfgs_py
        ret = lbfgs_py(Xinit, pot, tol = tol)
        print ret
        
    if True:
        print ""
        print "now do the same with lbfgs_py"
        from pygmin.optimize import lbfgs_py
        ret = lbfgs_py(Xinit, pot, tol = tol)
        print ret



    try:
        import pygmin.utils.pymolwrapper as pym
        pym.start()
        for n, coords in enumerate(printevent.coordslist):
            coords=coords.reshape(natoms, 3)
            pym.draw_spheres(coords, "A", n)
    except ImportError:
        print "error loading pymol"
Exemple #2
0
def runtest(X, pot, natoms=100, iprint=-1):
    from lbfgs_py import PrintEvent
    tol = 1e-5
    maxstep = 0.005

    Xinit = np.copy(X)
    e, g = pot.getEnergyGradient(X)
    print "energy", e

    lbfgs = LBFGS(X, pot, maxstep=0.1)
    printevent = PrintEvent("debugout.xyz")
    #lbfgs.attachEvent(printevent)

    ret = lbfgs.run(10000, tol=tol, iprint=iprint)
    print "done", ret[1], ret[2], ret[3], ret[5]

    print ""
    print "now do the same with scipy lbfgs"
    from pygmin.optimize import lbfgs_scipy as quench
    ret = quench(Xinit, pot.getEnergyGradient, tol=tol)
    print ret[1], ret[2], ret[3]

    if False:
        print "now do the same with scipy bfgs"
        from pygmin.optimize import bfgs as oldbfgs
        ret = oldbfgs(Xinit, pot.getEnergyGradient, tol=tol)
        print ret[1], ret[2], ret[3]

    if False:
        print "now do the same with gradient + linesearch"
        import bfgs
        gpl = bfgs.GradientPlusLinesearch(Xinit, pot, maxstep=0.1)
        ret = gpl.run(1000, tol=1e-6)
        print ret[1], ret[2], ret[3]

    if True:
        print ""
        print "calling from wrapper function"
        from pygmin.optimize import mylbfgs as quench
        ret = quench(Xinit, pot.getEnergyGradient, tol=tol)
        print ret[1], ret[2], ret[3]

    if True:
        print ""
        print "now do the same with lbfgs_py"
        from pygmin.optimize import lbfgs_py
        ret = lbfgs_py(Xinit, pot.getEnergyGradient, tol=tol)
        print ret[1], ret[2], ret[3]

    if False:
        import pygmin.utils.pymolwrapper as pym
        pym.start()
        for n, coords in enumerate(printevent.coordslist):
            coords = coords.reshape(natoms, 3)
            pym.draw_spheres(coords, "A", n)
Exemple #3
0
def test():
    natoms = 100
    tol = 1e-6
    
    from pygmin.potentials.lj import LJ
    pot = LJ()
    
    X = getInitialCoords(natoms, pot)
    X += np.random.uniform(-1,1,[3*natoms]) * 0.3
    
    #do some steepest descent steps so we don't start with a crazy structure
    #from optimize.quench import _steepest_descent as steepestDescent
    #ret = steepestDescent(X, pot.getEnergyGradient, iprint = 1, dx = 1e-4, nsteps = 100, gtol = 1e-3, maxstep = .5)
    #X = ret[0]
    #print X

    
    Xinit = np.copy(X)
    e, g = pot.getEnergyGradient(X)
    print "energy", e
    
    lbfgs = BFGS(X, pot, maxstep = 0.1)
    
    ret = lbfgs.run(100, tol = tol, iprint=1)
    print "done", ret[1], ret[2], ret[3]
    
    print "now do the same with scipy lbfgs"
    from pygmin.optimize import lbfgs_scipy as quench
    ret = quench(Xinit, pot.getEnergyGradient, tol = tol)
    print ret[1], ret[2], ret[3]    
    
    print "now do the same with scipy bfgs"
    from pygmin.optimize import bfgs as oldbfgs
    ret = oldbfgs(Xinit, pot.getEnergyGradient, tol = tol)
    print ret[1], ret[2], ret[3]    
    
    print "now do the same with old gradient + linesearch"
    gpl = GradientPlusLinesearch(Xinit, pot, maxstep = 0.1)  
    ret = gpl.run(100, tol = 1e-6)
    print ret[1], ret[2], ret[3]    
Exemple #4
0
def test():
    natoms = 100
    tol = 1e-6

    from pygmin.potentials.lj import LJ
    pot = LJ()

    X = getInitialCoords(natoms, pot)
    X += np.random.uniform(-1, 1, [3 * natoms]) * 0.3

    #do some steepest descent steps so we don't start with a crazy structure
    #from optimize.quench import _steepest_descent as steepestDescent
    #ret = steepestDescent(X, pot.getEnergyGradient, iprint = 1, dx = 1e-4, nsteps = 100, gtol = 1e-3, maxstep = .5)
    #X = ret[0]
    #print X

    Xinit = np.copy(X)
    e, g = pot.getEnergyGradient(X)
    print "energy", e

    lbfgs = BFGS(X, pot, maxstep=0.1)

    ret = lbfgs.run(100, tol=tol, iprint=1)
    print "done", ret[1], ret[2], ret[3]

    print "now do the same with scipy lbfgs"
    from pygmin.optimize import lbfgs_scipy as quench
    ret = quench(Xinit, pot.getEnergyGradient, tol=tol)
    print ret[1], ret[2], ret[3]

    print "now do the same with scipy bfgs"
    from pygmin.optimize import bfgs as oldbfgs
    ret = oldbfgs(Xinit, pot.getEnergyGradient, tol=tol)
    print ret[1], ret[2], ret[3]

    print "now do the same with old gradient + linesearch"
    gpl = GradientPlusLinesearch(Xinit, pot, maxstep=0.1)
    ret = gpl.run(100, tol=1e-6)
    print ret[1], ret[2], ret[3]