def lbfgs_py(coords, pot, **kwargs): if not hasattr(pot, "getEnergyGradient"): # for compatibility with old quenchers. # assume pot is a getEnergyGradient function pot = _getEnergyGradientWrapper(pot) lbfgs = LBFGS(coords, pot, **kwargs) return lbfgs.run()
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"
def _lbfgs_py(coords, pot, **kwargs): lbfgs = LBFGS(coords, pot, **kwargs) ret = lbfgs.run() coords = ret.coords e = ret.energy rms = ret.rms funcalls = ret.nfev return coords, e, rms, funcalls, ret
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"