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
class TestFindTransitionState_NFEV(unittest.TestCase): def setUp(self): from pele.optimize.tests.test_nfev import _PotWrapper np.random.seed(0) self.system = LJCluster(18) self.pot = _PotWrapper(self.system.get_potential()) self.x = self.system.get_random_minimized_configuration(tol=10.).coords def do_check(self, **kwargs): self.pot.nfev = 0 opt = FindTransitionState(self.x, self.pot, **kwargs) ret = opt.run() self.assertEqual(ret.nfev, self.pot.nfev) self.assertTrue(ret.success) self.assertGreater(ret.nfev, 0) def test(self): self.do_check() # def test1(self): # self.do_check(invert_gradient=True) def test2(self): self.do_check(lowestEigenvectorQuenchParams=dict(first_order=True) )
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)
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()
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())
class TestFindTransitionState_NFEV(unittest.TestCase): def setUp(self): from pele.optimize.tests.test_nfev import _PotWrapper np.random.seed(0) self.system = LJCluster(18) self.pot = _PotWrapper(self.system.get_potential()) self.x = self.system.get_random_minimized_configuration(tol=10.).coords def do_check(self, **kwargs): self.pot.nfev = 0 opt = FindTransitionState(self.x, self.pot, **kwargs) ret = opt.run() self.assertEqual(ret.nfev, self.pot.nfev) self.assertTrue(ret.success) self.assertGreater(ret.nfev, 0) def test(self): self.do_check() # def test1(self): # self.do_check(invert_gradient=True) def test2(self): self.do_check(lowestEigenvectorQuenchParams=dict(first_order=True))
class TestGeneralizedDimer(unittest.TestCase): def setUp(self): self.system = LJCluster(18) self.pot = self.system.get_potential() def make_dimer(self, x): return GeneralizedDimer(x, self.pot, leig_kwargs=dict(orthogZeroEigs=self.system.get_orthogonalize_to_zero_eigenvectors() ) , ) def test1(self): x = self.system.get_random_configuration() dimer = self.make_dimer(x) res = dimer.run() self.assertTrue(res.success) def test2(self): # get the path of the file directory path = os.path.dirname(os.path.abspath(__file__)) xyz = read_xyz(open(path+"/lj18_ts.xyz", "r")) x = xyz.coords.flatten() dimer = self.make_dimer(x) res = dimer.run() self.assertTrue(res.success) self.assertLess(res.nsteps, 5)
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)
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)
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)
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)
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)
def guessts(coords1, coords2, pot): from pele.optimize import lbfgs_py as quench # from pele.mindist.minpermdist_stochastic import minPermDistStochastic as mindist from pele.transition_states import NEB from pele.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 pele.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,:]
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
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
def setUp(self): # from pele.mindist import minPermDistStochastic, MinDistWrapper # from pele.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] 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)
class TestFindLowestEigenvector(unittest.TestCase): def setUp(self): self.setUp1() 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) def test(self): lval, lvec = analyticalLowestEigenvalue(self.x, self.pot) ret = self.finder.run(100) self.assertLess(np.abs(ret.eigenval - lval) / np.abs(lval), 1e-2) def test2(self): lval, lvec = analyticalLowestEigenvalue(self.x, self.pot) ret = findLowestEigenVector(self.x.copy(), self.pot) self.assertLess(np.abs(ret.eigenval - lval) / np.abs(lval), 1e-2)
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)
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)
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)
def test(): from pele.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
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)
def test(): # pragma: no cover from pele.systems import LJCluster from pele.transition_states import GeneralizedDimer from pele.transition_states import FindTransitionState from pele.utils.xyz import read_xyz system = LJCluster(13) x = system.get_random_configuration() x = read_xyz(open("tests/lj18_ts.xyz", "r")).coords.flatten() dimer = GeneralizedDimer(x.copy(), system.get_potential(), rotational_steps=40, dimer=False, leig_kwargs=dict(iprint=10, maxstep=2., tol=.1, ), translator_kwargs=dict(iprint=1, verbosity=10, ), ) ret = dimer.run() print(ret) print("\n\nnow the same with the old version") searcher = FindTransitionState(x.copy(), system.get_potential(), iprint=1, verbosity=10) # print ret ret = searcher.run() print(ret)
class TestFindLowestEigenvector(unittest.TestCase): def setUp(self): self.setUp1() 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) def test(self): lval, lvec = analyticalLowestEigenvalue(self.x, self.pot) ret = self.finder.run(100) self.assertLess(np.abs(ret.eigenval - lval) / np.abs(lval), 1e-2) def test2(self): lval, lvec = analyticalLowestEigenvalue(self.x, self.pot) ret = findLowestEigenVector(self.x.copy(), self.pot) self.assertLess(np.abs(ret.eigenval - lval) / np.abs(lval), 1e-2)
class TestGeneralizedDimer(unittest.TestCase): def setUp(self): self.system = LJCluster(18) self.pot = self.system.get_potential() def make_dimer(self, x): return GeneralizedDimer( x, self.pot, leig_kwargs=dict(orthogZeroEigs=self.system. get_orthogonalize_to_zero_eigenvectors()), ) def test1(self): x = self.system.get_random_configuration() dimer = self.make_dimer(x) res = dimer.run() self.assertTrue(res.success) def test2(self): # get the path of the file directory path = os.path.dirname(os.path.abspath(__file__)) xyz = read_xyz(open(path + "/lj18_ts.xyz", "r")) x = xyz.coords.flatten() dimer = self.make_dimer(x) res = dimer.run() self.assertTrue(res.success) self.assertLess(res.nsteps, 5)
def prepare_system(self, 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)
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)
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)
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)
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)
def test(): 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)
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)
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)
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
def getPairLJ(natoms=38): 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
def test(Connect=DoubleEndedConnect, natoms=16): # from pele.landscape import TSGraph # from pele.storage.database import Database from pele.systems import LJCluster #get min1 system = LJCluster(natoms) pot, database = getSetOfMinLJ(system) # from pele.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)
class TestEigPot(unittest.TestCase): def setUp(self): self.first_order = False self.setUp1() def setUp1(self): np.random.seed(0) 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_configuration() #ret = self.system.get_random_minimized_configuration(tol=100.) #self.x = ret.coords self.pot = self.system.get_potential() self.eigpot = LowestEigPot(self.x, self.pot, orthogZeroEigs=self.system.get_orthogonalize_to_zero_eigenvectors(), first_order=self.first_order, ) def test_gradient(self): vec = np.random.rand(self.x.size) vec /= np.linalg.norm(vec) e1 = self.eigpot.getEnergy(vec) e, g = self.eigpot.getEnergyGradient(vec) gnum = self.eigpot.NumericalDerivative(vec, eps=1e-6) gnum -= np.dot(gnum, vec) self.assertLess(np.max(np.abs(g-gnum)) / np.max(np.abs(g)), 1e-2) self.assertAlmostEqual(e, e1, delta=e * 1e-4) self.assertAlmostEqual(1., np.dot(g, gnum) / np.linalg.norm(g) / np.linalg.norm(gnum), 3) def test_ts(self): from pele.utils.xyz import read_xyz path = os.path.dirname(os.path.abspath(__file__)) xyz = read_xyz(open(path + "/lj18_ts.xyz", "r")) x = xyz.coords.flatten() vec = np.random.rand(x.size) vec /= np.linalg.norm(vec) self.eigpot = LowestEigPot(x, self.pot, orthogZeroEigs=self.system.get_orthogonalize_to_zero_eigenvectors(), first_order=self.first_order) e1 = self.eigpot.getEnergy(vec) e, g = self.eigpot.getEnergyGradient(vec) gnum = self.eigpot.NumericalDerivative(vec, eps=1e-4) gnum -= np.dot(gnum, vec) self.assertLess(np.max(np.abs(g-gnum)) / np.max(np.abs(g)), 1e-3) self.assertAlmostEqual(e, e1, delta=e * 1e-4) self.assertAlmostEqual(1., np.dot(g, gnum) / np.linalg.norm(g) / np.linalg.norm(gnum), 3)
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
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)
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)
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)
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
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
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, ]
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()
class TestNormalModes(unittest.TestCase): 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) def check(self, fvib_expected, coords, nzero, nnegative, metric=None): pot = self.system.get_potential() hess = pot.getHessian(coords) freqs, modes = normalmodes(hess, metric=metric) # print v n, fvib = logproduct_freq2(freqs, nzero=nzero, nnegative=nnegative) self.assertAlmostEqual(fvib, fvib_expected, 4) self.assertEqual(n, len(coords) - nzero - nnegative) def test_minimum(self): m = self.db.minima()[0] self.check(m.fvib, m.coords, 6, 0) def test_transition_state(self): ts = self.db.transition_states()[0] self.check(ts.fvib, ts.coords, 6, 1) def test_metric_tensor(self): m = self.db.minima()[0] mt = np.eye(m.coords.size) self.check(m.fvib, m.coords, 6, 0, metric=mt) def test_get_thermo_info(self): newdb = self.system.create_database() new2old = dict() for ts in self.db.transition_states()[:5]: m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords) m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords) newts = newdb.addTransitionState(ts.energy, ts.coords, m1, m2) new2old[m1] = ts.minimum1 new2old[m2] = ts.minimum2 new2old[newts] = ts get_thermodynamic_information(self.system, newdb, nproc=2) for new in newdb.minima() + newdb.transition_states(): old = new2old[new] self.assertAlmostEqual(new.energy, old.energy, 4) self.assertAlmostEqual(new.fvib, old.fvib, 4) self.assertEqual(new.pgorder, old.pgorder)
class TestLBFGS_General(unittest.TestCase): def setUp(self): self.system = LJCluster(13) self.x0 = self.system.get_random_minimized_configuration(tol=1).coords self.pot = self.system.get_potential() def test_event(self): self.called = False def event(coords=None, energy=None, rms=None): self.called = True opt = LBFGS(self.x0, self.pot, events=[event]) opt.one_iteration() self.assertTrue(self.called)
class TestTransverseWalker_NFEV(unittest.TestCase): def setUp(self): from pele.optimize.tests.test_nfev import _PotWrapper self.system = LJCluster(18) self.pot = _PotWrapper(self.system.get_potential()) def test(self): x = self.system.get_random_configuration() evec = vec_random_ndim(x.size) evec /= np.linalg.norm(evec) opt = _TransverseWalker(x, self.pot, evec) ret = opt.run(10) self.assertEqual(ret.nfev, self.pot.nfev) self.assertGreater(ret.nfev, 0)
class TestTransverseWalker_NFEV(unittest.TestCase): def setUp(self): from pele.optimize.tests.test_nfev import _PotWrapper self.system = LJCluster(18) self.pot = _PotWrapper(self.system.get_potential()) def test(self): x = self.system.get_random_configuration() evec = vec_random_ndim(x.size) evec /= np.linalg.norm(evec) opt = _DimerTranslator(x, self.pot, evec) ret = opt.run(10) self.assertEqual(ret.nfev, self.pot.nfev) self.assertGreater(ret.nfev, 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_())
class TestLBFGSFortran(unittest.TestCase): def setUp(self): self.system = LJCluster(13) self.x = self.system.get_random_configuration() self.pot = self.system.get_potential() def test(self): minimizer = LBFGS(self.x.copy(), self.pot, fortran=True, debug=True) ret = minimizer.run() m2 = LBFGS(self.x.copy(), self.pot, fortran=False, debug=True) ret2 = m2.run() print "fortran", ret.nfev, ret2.nfev # self.assertEqual(ret.nfev, ret2.nfev) self.assertAlmostEqual(ret.energy, ret2.energy, 5)
class TestFindLowestEigenvector_NFEV(unittest.TestCase): 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()) def test(self): self.pot.nfev = 0 ret = findLowestEigenVector(self.x.copy(), self.pot) self.assertEqual(ret.nfev, self.pot.nfev) self.assertTrue(ret.success) self.assertGreater(ret.nfev, 0)
class TestFindLowestEigenvector_NFEV(unittest.TestCase): 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()) def test(self): self.pot.nfev = 0 ret = findLowestEigenVector(self.x.copy(), self.pot) self.assertEqual(ret.nfev, self.pot.nfev) self.assertTrue(ret.success) self.assertGreater(ret.nfev, 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)
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()
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)