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 runtest(X, pot, natoms = 100, iprint=-1): tol = 1e-5 Xinit = np.copy(X) e, g = pot.getEnergyGradient(X) print "energy", e lbfgs = LBFGS(X, pot, maxstep = 0.1, tol=tol, iprint=iprint, nsteps=10000) printevent = PrintEvent( "debugout.xyz") lbfgs.attachEvent(printevent) ret = lbfgs.run() print "done", ret print "now do the same with scipy lbfgs" from pygmin.optimize import lbfgs_scipy as quench ret = quench(Xinit, pot, tol = tol) print ret 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 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"
from pygmin.potentials.lj import LJ from pygmin.optimize import lbfgs_py from pygmin.landscape import DoubleEndedConnect, smoothPath from pygmin.mindist import MinPermDistAtomicCluster from pygmin.transition_states import orthogopt from pygmin.storage import Database, Minimum from pygmin.printing import printAtomsXYZ np.random.seed(0) #set up the potential pot = LJ() #import the starting and ending points and quench them, coords1 = np.genfromtxt("coords.A") coords2 = np.genfromtxt("coords.B") res1 = lbfgs_py(coords1.reshape(-1), pot) res2 = lbfgs_py(coords2.reshape(-1), pot) coords1 = res1.coords coords2 = res2.coords E1 = res1.energy E2 = res2.energy natoms = len(coords1)/3 #add the minima to a database dbfile = "database.sqlite" database = Database(dbfile) database.addMinimum(E1, coords1) database.addMinimum(E2, coords2) min1 = database.minima()[0] min2 = database.minima()[1]
# finalize the rigid body setup for rb in rb_sites: rb.finalize_setup() # define a new rigid body system rbsystem = rigidbody.RBSystem() rbsystem.add_sites(rb_sites) print len(rbsystem.sites), len(rbsystem.indices) rbcoords = rbsystem.coords_adapter(np.zeros(len(rbsystem.sites)*6)) for site, com in zip(rbsystem.sites, rbcoords.posRigid): com[:] = ref.coords[site.indices[0]] - site.atom_positions[0] # for simplicity just use a lj potential here pot = LJ(sigma=2.) # get the flattened coordinate array print pot.getEnergy(ref.coords.flatten()) rbpot = rigidbody.RBPotentialWrapper(rbsystem, pot) print rbpot.getEnergy(rbcoords.coords) e, g = rbpot.getEnergyGradient(rbcoords.coords) g_n = rbpot.NumericalDerivative(rbcoords.coords, eps=1e-4) cg = rbsystem.coords_adapter(g-g_n) print cg.posRigid print cg.rotRigid ret = lbfgs_py(rbcoords.coords, rbpot.getEnergyGradient) print ret[1] xyz.write_xyz(open("quenched.xyz", "w"), rbsystem.to_atomistic(ret[0]), atomtypes=ref.atomtypes)
# finalize the rigid body setup for rb in rb_sites: rb.finalize_setup() # define a new rigid body system rbsystem = rigidbody.RBSystem() rbsystem.add_sites(rb_sites) print len(rbsystem.sites), len(rbsystem.indices) rbcoords = rbsystem.coords_adapter(np.zeros(len(rbsystem.sites)*6)) for site, com in zip(rbsystem.sites, rbcoords.posRigid): com[:] = ref.coords[site.indices[0]] - site.atom_positions[0] # for simplicity just use a lj potential here pot = LJ(sigma=2.) # get the flattened coordinate array print pot.getEnergy(ref.coords.flatten()) rbpot = rigidbody.RBPotentialWrapper(rbsystem, pot) print rbpot.getEnergy(rbcoords.coords) e, g = rbpot.getEnergyGradient(rbcoords.coords) g_n = rbpot.NumericalDerivative(rbcoords.coords, eps=1e-4) cg = rbsystem.coords_adapter(g-g_n) print cg.posRigid print cg.rotRigid ret = lbfgs_py(rbcoords.coords, rbpot) print ret.energy xyz.write_xyz(open("quenched.xyz", "w"), rbsystem.to_atomistic(ret.coords), atomtypes=ref.atomtypes)
from pygmin.potentials.lj import LJ from pygmin.optimize import lbfgs_py from pygmin.landscape import DoubleEndedConnect, smoothPath from pygmin.mindist import minPermDistStochastic, MinDistWrapper from pygmin.transition_states import orthogopt from pygmin.storage import Database, Minimum from pygmin.printing import printAtomsXYZ np.random.seed(0) #set up the potential pot = LJ() #import the starting and ending points and quench them, coords1 = np.genfromtxt("coords.A") coords2 = np.genfromtxt("coords.B") res1 = lbfgs_py(coords1.reshape(-1), pot.getEnergyGradient) res2 = lbfgs_py(coords2.reshape(-1), pot.getEnergyGradient) coords1 = res1[0] coords2 = res2[0] E1 = res1[1] E2 = res2[1] natoms = len(coords1)/3 #add the minima to a database dbfile = "database.sqlite" database = Database(dbfile) database.addMinimum(E1, coords1) database.addMinimum(E2, coords2) min1 = database.minima()[0] min2 = database.minima()[1]
""" an example for finding the minimum distance and best alignment between two lennard jones clusters """ import numpy as np from pygmin.potentials.lj import LJ from pygmin.optimize import lbfgs_py from pygmin.mindist import minPermDistStochastic pot = LJ() natoms = 40 #get two random quenched structures to compare coords1 = np.random.rand(natoms*3)*natoms**(1./3)*1.5 coords2 = np.random.rand(natoms*3)*natoms**(1./3)*1.5 ret1 = lbfgs_py(coords1, pot.getEnergyGradient) ret2 = lbfgs_py(coords2, pot.getEnergyGradient) coords1 = ret1[0] coords2 = ret2[0] #all the atoms are permutable permlist = [range(natoms)] dist, newcoords1, newcoords2 = minPermDistStochastic(coords1, coords2, niter=100, permlist=permlist, verbose=False) print "" print "dist =", dist
""" an example for finding the minimum distance and best alignment between two lennard jones clusters """ import numpy as np from pygmin.potentials.lj import LJ from pygmin.optimize import lbfgs_py from pygmin.mindist import MinPermDistAtomicCluster pot = LJ() natoms = 40 #get two random quenched structures to compare coords1 = np.random.rand(natoms * 3) * natoms**(1. / 3) * 1.5 coords2 = np.random.rand(natoms * 3) * natoms**(1. / 3) * 1.5 ret1 = lbfgs_py(coords1, pot) ret2 = lbfgs_py(coords2, pot) coords1 = ret1.coords coords2 = ret2.coords #all the atoms are permutable permlist = [range(natoms)] mindist = MinPermDistAtomicCluster(niter=100, permlist=permlist, verbose=False) dist, newcoords1, newcoords2 = mindist(coords1, coords2) print "" print "dist =", dist
# finalize the rigid body setup for rb in rb_sites: rb.finalize_setup() # define a new rigid body system rbsystem = rigidbody.RBSystem() rbsystem.add_sites(rb_sites) print len(rbsystem.sites), len(rbsystem.indices) rbcoords = rbsystem.coords_adapter(np.zeros(len(rbsystem.sites) * 6)) for site, com in zip(rbsystem.sites, rbcoords.posRigid): com[:] = ref.coords[site.indices[0]] - site.atom_positions[0] # for simplicity just use a lj potential here pot = LJ(sigma=2.0) # get the flattened coordinate array print pot.getEnergy(ref.coords.flatten()) rbpot = rigidbody.RBPotentialWrapper(rbsystem, pot) print rbpot.getEnergy(rbcoords.coords) e, g = rbpot.getEnergyGradient(rbcoords.coords) g_n = rbpot.NumericalDerivative(rbcoords.coords, eps=1e-4) cg = rbsystem.coords_adapter(g - g_n) print cg.posRigid print cg.rotRigid ret = lbfgs_py(rbcoords.coords, rbpot) print ret.energy xyz.write_xyz(open("quenched.xyz", "w"), rbsystem.to_atomistic(ret.coords), atomtypes=ref.atomtypes)
""" an example for finding the minimum distance and best alignment between two lennard jones clusters """ import numpy as np from pygmin.potentials.lj import LJ from pygmin.optimize import lbfgs_py from pygmin.mindist import MinPermDistAtomicCluster pot = LJ() natoms = 40 #get two random quenched structures to compare coords1 = np.random.rand(natoms*3)*natoms**(1./3)*1.5 coords2 = np.random.rand(natoms*3)*natoms**(1./3)*1.5 ret1 = lbfgs_py(coords1, pot) ret2 = lbfgs_py(coords2, pot) coords1 = ret1.coords coords2 = ret2.coords #all the atoms are permutable permlist = [range(natoms)] mindist = MinPermDistAtomicCluster(niter=100, permlist=permlist, verbose=False) dist, newcoords1, newcoords2 = mindist(coords1, coords2) print "" print "dist =", dist