def benchmark_number_of_minima(): import time, sys import numpy as np db = Database("test.large.db") if True: istart = np.random.randint(0, sys.maxint) for i in range(istart,istart+10000): e = float(i) db.addMinimum(e, [e], commit=False) db.session.commit() else: i=1 t1 = time.clock() print(db.number_of_minima()) print("time", t1 - time.clock()); t1 = time.clock() print(db.number_of_minima()) print("time", t1 - time.clock()); t1 = time.clock() print(db.number_of_minima()) print("time", t1 - time.clock()); t1 = time.clock() e = float(i+1) db.addMinimum(e, [e], commit=False) t1 = time.clock() print(db.number_of_minima()) print("time", t1 - time.clock()); t1 = time.clock() print(len(db.minima())) print("time", t1 - time.clock()); t1 = time.clock()
def create_random_database(nmin=20, nts=None, natoms=2): """ create a database for test purposes """ from pele.storage import Database import numpy as np if nts is None: nts = nmin db = Database() # generate random structures minlist = [] for i in range(nmin): coords = np.random.uniform(-1, 1, natoms * 3) e = float(i) # make up a fake energy minlist.append(db.addMinimum(e, coords)) # add random transition states for i in range(nts): j1, j2 = 1, 1 while j1 == j2: j1, j2 = np.random.randint(0, nmin, 2) m1, m2 = minlist[j1], minlist[j2] coords = np.random.uniform(-1, 1, natoms * 3) e = float(j1 + j2) db.addTransitionState(e, coords, m1, m2) return db
def get_database_params(dbname): db = Database(dbname, createdb=False) interactions = db.get_property("interactions").value() db_nspins = db.get_property("nspins").value() db_p = db.get_property("p").value() params = (db_nspins, db_p, interactions) return db, params
def _get_database_params(dbname): db = Database(dbname, createdb=False) interactions = db.get_property("interactions").value() db_nspins = db.get_property("nspins").value() db_p = db.get_property("p").value() params = (db_nspins, db_p, interactions) return db, params
def test1(self): current_dir = os.path.dirname(__file__) db = Database() converter = OptimDBConverter(db, mindata=os.path.join(current_dir, "min.data"), tsdata=os.path.join(current_dir, "ts.data"), pointsmin=os.path.join(current_dir, "points.min"), pointsts=os.path.join(current_dir, "points.ts"), endianness="<") converter.convert() self.assertEqual(db.number_of_minima(), 2) self.assertEqual(db.number_of_transition_states(), 1) ts = db.transition_states()[0] self.assertAlmostEqual(ts.coords[0], 1.548324, 5) self.assertAlmostEqual(ts.coords[2], 0.18178001, 5) self.assertAlmostEqual(ts.coords[-1], -0.50953229, 5) self.assertEqual((180,), ts.coords.shape) m = db.minima()[0] print(repr(m.coords)) self.assertAlmostEqual(m.coords[0], 1.53700142, 5) self.assertAlmostEqual(m.coords[2], 0.87783657, 5) self.assertAlmostEqual(m.coords[-1], -0.50953229, 5) self.assertEqual((180,), m.coords.shape)
def setUp(self): from pele.utils.optim_compatibility import OptimDBConverter from pele.storage import Database ndof = 10 # wrong, but who cares. self.db = Database() current_dir = os.path.dirname(__file__) converter = OptimDBConverter(self.db, ndof=ndof, mindata=current_dir+"/collagen.min.data", tsdata=current_dir+"/collagen.ts.data", assert_coords=False) converter.convert_no_coords()
def get_database_params(dbname, nspins, p): db = Database(dbname, createdb=False) interactions = db.get_property("interactions").value() db_nspins = db.get_property("nspins").value() db_p = db.get_property("p").value() # check that parameters match assert db_nspins == nspins assert db_p == p return db, interactions
def run_gui_db(dbname="xy_10x10.sqlite"): from pele.gui import run_gui from pele.storage import Database try: db = Database(dbname, createdb=False) phases = db.get_property("phases").value() except IOError: phases = None system = XYModlelSystem(dim=[10, 10], phi_disorder=np.pi, phases=phases) run_gui(system, db=dbname)
def test(): # pragma: no cover from pele.storage import Database coords1, coords2, pot, mindist, E1, E2 = getPairLJ() db = Database() min1 = db.addMinimum(E1, coords1) min2 = db.addMinimum(E2, coords2) local_connect = LocalConnect(pot, mindist) local_connect.connect(min1, min2)
def run_gui_db(dbname="xy_10x10.sqlite"): from pele.gui import run_gui from pele.storage import Database try: db = Database(dbname, createdb=False) phases = db.get_property("phases").value() except IOError: phases=None system = XYModlelSystem(dim=[10,10], phi_disorder=np.pi, phases=phases) run_gui(system, db=dbname)
def test(): from pele.storage import Database coords1, coords2, pot, mindist, E1, E2 = getPairLJ() db = Database() min1 = db.addMinimum(E1, coords1) min2 = db.addMinimum(E2, coords2) local_connect = LocalConnect(pot, mindist) local_connect.connect(min1, min2)
def run_gui_db(dbname="pspin_spherical_p3_N20.sqlite"): from pele.gui import run_gui try: db = Database(dbname, createdb=False) interactions = db.get_property("interactions").value() nspins = db.get_property("nspins").value() p = db.get_property("p").value() except IOError: interactions=None system = MeanFieldPSpinSphericalSystem(nspins, p=p, interactions=interactions) run_gui(system, db=dbname)
def setUp(self): self.db = Database() self.nminima = 10 for i in range(self.nminima): e = float(i) self.db.addMinimum(e, [e]) self.nts = 3 self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[1], eigenval=0., eigenvec=[0.]) self.db.addTransitionState(0., [0.], self.db.minima()[1], self.db.minima()[2], eigenval=0., eigenvec=[0.]) self.db.addTransitionState(0., [0.], self.db.minima()[0], self.db.minima()[2], eigenval=0., eigenvec=[0.])
def create_soft_sphere_system_from_db(dbname): from pele.storage import Database db = Database(dbname, createdb=False) radii = db.get_property("radii").value() boxvec = db.get_property("boxvec").value() power = db.get_property("power").value() print(radii) system = SoftSphereSystem(radii, boxvec, power=power) db = system.create_database(dbname, createdb=False) return system, db
def create_soft_sphere_system_from_db(dbname): from pele.storage import Database db = Database(dbname, createdb=False) radii = db.get_property("radii").value() boxvec = db.get_property("boxvec").value() power = db.get_property("power").value() print radii system = SoftSphereSystem(radii, boxvec, power=power) db = system.create_database(dbname, createdb=False) return system, db
def create_system(L, dbname): print("testing whether", dbname, "exists") try: # if the database already exists get the phases db = Database(dbname, createdb=False) print(dbname, "exists. getting phases") phases = db.get_property("phases").value() dim = db.get_property("dim").value() assert dim[0] == L except IOError: print(dbname, "doesn't exist, generating random phases") phases=None dim=[L,L] system = XYModlelSystem(dim=dim, phi_disorder=np.pi, phases=phases) return system
def plot_disconnectivity_graph(path_to_data_dir, input_param): path_to_db = os.path.join(path_to_data_dir,'pele_database.db') re_calc = input_param["re_calc"] if (not os.path.exists(path_to_db)) or (re_calc is True): if re_calc is True and os.path.exists(path_to_db): os.remove(path_to_db) db = Database(db=path_to_db, accuracy=0.001, createdb=True) list_event_str = get_list_of_final_filtered_events_str(path_to_data_dir) for event_state in list_event_str: print "event_state:", event_state single_event_adder(event_state, path_to_data_dir,db) else: db = Database(db=path_to_db, accuracy=0.001, createdb=True) make_graph(path_to_data_dir,db) print ("done adding all final selected events into pele database and plotting their disconnectivity graph!")
def run_gui_db(dbname="regression_logit_mnist.sqlite", scale=2.5, device='cpu'): from pele.gui import run_gui try: db = Database(dbname, createdb=False) x_train_data=db.get_property("x_train_data").value(), y_train_data=db.get_property("y_train_data").value(), hnodes=db.get_property("hnodes").value(), reg=db.get_property("reg").value(), except IOError: pass hnodes, reg = hnodes[0], reg[0] x_train_data, y_train_data = np.array(np.array(x_train_data)[0,:,:]), np.array(np.array(y_train_data)[0,:,:]) print np.array(x_train_data).shape, np.array(y_train_data).shape # system = Mlp3System(x_train_data, y_train_data, hnodes, reg=reg, device=device) system = Elu2NNSystem(x_train_data, y_train_data, hnodes, reg=reg, scale=scale, device=device) run_gui(system, db=dbname)
def create_neb(self, coords1, coords2): """setup the NEB object""" system = self.system throwaway_db = Database() min1 = throwaway_db.addMinimum(0., coords1) min2 = throwaway_db.addMinimum(1., coords2) # use the functions in DoubleEndedConnect to set up the NEB in the proper way double_ended = system.get_double_ended_connect(min1, min2, throwaway_db, fresh_connect=True) local_connect = double_ended._getLocalConnectObject() self.local_connect = local_connect return local_connect.create_neb(system.get_potential(), coords1, coords2, **local_connect.NEBparams)
def create_neb(self, coords1, coords2): """setup the NEB object""" system = self.system throwaway_db = Database() min1 = throwaway_db.addMinimum(0., coords1) min2 = throwaway_db.addMinimum(1., coords2) #use the functions in DoubleEndedConnect to set up the NEB in the proper way double_ended = system.get_double_ended_connect(min1, min2, throwaway_db, fresh_connect=True) local_connect = double_ended._getLocalConnectObject() self.local_connect = local_connect return local_connect.create_neb(system.get_potential(), coords1, coords2, **local_connect.NEBparams)
def main(): parser = argparse.ArgumentParser(description=""" convert an OPTIM database to a pele sqlite database. Four files are needed. Normally they are called: points.min : the coordinates of the minima in binary format min.data : additional information about the minima (like the energy) points.ts : the coordinates of the transition states min.ts : additional information about transition states (like which minima they connect) Other file names can optionally be passed. Some fortran compilers use non-standard endianness to save the binary data. If your coordinates are garbage, try changing the endianness. """, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('--ndof', help='Number of total degrees of freedom (e.g. 3*number of atoms). This is simply the length of a coordinates vector.', type=int, default=None) parser.add_argument('--parentDB', help = 'Name of parent pinned database from which the system properties will be copied. Choose a small one!') parser.add_argument('--Database','-d', help = 'Name of database to write into', type = str, default="optimdb.sqlite") parser.add_argument('--Mindata','-m', help = 'Name of min.data file', type = str, default="min.data") parser.add_argument('--Tsdata','-t', help = 'Name of ts.data file', type = str, default="ts.data") parser.add_argument('--Pointsmin','-p', help = 'Name of points.min file', type = str, default="points.min") parser.add_argument('--Pointsts','-q', help = 'Name of points.ts file', type = str, default="points.ts") parser.add_argument('--endianness', help = 'set the endianness of the binary data. Can be "<" for little-endian or ">" for big-endian', type = str, default="=") parser.add_argument('--nopoints', help = 'Load the metadata for minima and transition states without reading the coordinates (usually to save storage space)', action = 'store_true') args = parser.parse_args() system, basedb, x0 = create_frozenblj_system_from_db(args.parentDB) db = Database(args.Database) props = basedb.properties(as_dict=True) for key, prop in props.iteritems(): db.add_property(key, prop) cv = OptimDBConverter(database=db, ndof=args.ndof, mindata=args.Mindata, tsdata=args.Tsdata, pointsmin=args.Pointsmin, pointsts=args.Pointsts, endianness=args.endianness, coords_converter=system.coords_converter.get_reduced_coords) cv.setAccuracy() if args.nopoints: cv.convert_no_coords() else: cv.convert() cv.db.session.commit()
def getNEB(coords1, coords2, system): """setup the NEB object""" throwaway_db = Database() min1 = throwaway_db.addMinimum(0., coords1) min2 = throwaway_db.addMinimum(1., coords2) #use the functions in DoubleEndedConnect to set up the NEB in the proper way double_ended = system.get_double_ended_connect(min1, min2, throwaway_db, fresh_connect=True) local_connect = double_ended._getLocalConnectObject() neb = local_connect._getNEB(system.get_potential(), coords1, coords2, verbose=True, **local_connect.NEBparams) return neb
def bh_no_system_class(): import numpy as np from pele.potentials import LJ natoms = 17 potential = LJ() x0 = np.random.uniform(-1, 1, 3*natoms) from pele.takestep import RandomDisplacement, AdaptiveStepsizeTemperature displace = RandomDisplacement() adaptive_displacement = AdaptiveStepsizeTemperature(displace) from pele.storage import Database database = Database("lj17.sqlite") from pele.basinhopping import BasinHopping bh = BasinHopping(x0, potential, adaptive_displacement, storage=database.minimum_adder) bh.run(10) for m in database.minima(): print m.energy
def test2(self): from pele.storage import Database from pele.systems import LJCluster np.random.seed(0) natoms = 13 system = LJCluster(natoms) pot = system.get_potential() mindist = system.get_mindist(niter=1) db = Database() db.addMinimum(pot.getEnergy(_x1), _x1) db.addMinimum(pot.getEnergy(_x2), _x2) m1, m2 = db.minima() connect = DoubleEndedConnect(m1, m2, pot, mindist, db, verbosity=10) connect.connect() self.assertTrue(connect.success()) path = connect.returnPath()
def test_nocoords(self): current_dir = os.path.dirname(__file__) db = Database() converter = OptimDBConverter( db, mindata=os.path.join(current_dir, "min.data"), tsdata=os.path.join(current_dir, "ts.data"), pointsmin="poo", pointsts="poo", assert_coords=False, endianness="<") converter.convert()
def test1(self): current_dir = os.path.dirname(__file__) db = Database() converter = OptimDBConverter( db, mindata=os.path.join(current_dir, "min.data"), tsdata=os.path.join(current_dir, "ts.data"), pointsmin=os.path.join(current_dir, "points.min"), pointsts=os.path.join(current_dir, "points.ts"), endianness="<") converter.convert() self.assertEqual(db.number_of_minima(), 2) self.assertEqual(db.number_of_transition_states(), 1) ts = db.transition_states()[0] self.assertAlmostEqual(ts.coords[0], 1.548324, 5) self.assertAlmostEqual(ts.coords[2], 0.18178001, 5) self.assertAlmostEqual(ts.coords[-1], -0.50953229, 5) self.assertEqual((180, ), ts.coords.shape) m = db.minima()[0] print repr(m.coords) self.assertAlmostEqual(m.coords[0], 1.53700142, 5) self.assertAlmostEqual(m.coords[2], 0.87783657, 5) self.assertAlmostEqual(m.coords[-1], -0.50953229, 5) self.assertEqual((180, ), m.coords.shape)
class TestOptimCollagen(unittest.TestCase): """test a known value for a large database""" def setUp(self): from pele.utils.optim_compatibility import OptimDBConverter from pele.storage import Database ndof = 10 # wrong, but who cares. self.db = Database() current_dir = os.path.dirname(__file__) converter = OptimDBConverter(self.db, ndof=ndof, mindata=current_dir+"/collagen.min.data", tsdata=current_dir+"/collagen.ts.data", assert_coords=False) converter.convert_no_coords() def test1(self): m1 = self.db.getMinimum(1) m2 = self.db.getMinimum(2) m3 = self.db.getMinimum(3) m4 = self.db.getMinimum(4) rcalc = RateCalculation(self.db.transition_states(), [m1], [m2], T=0.592) rcalc.compute_rates() self.assertAlmostEqual(rcalc.get_rate_AB(), 7106337458., delta=1e4) self.assertAlmostEqual(rcalc.get_rate_BA(), 1955395816., delta=1e4) rcalc = RateCalculation(self.db.transition_states(), [m1,m3], [m2, m4], T=0.592) rcalc.compute_rates() self.assertAlmostEqual(rcalc.get_rate_AB(), 8638736600., delta=1e4) self.assertAlmostEqual(rcalc.get_rate_BA(), 3499625167., delta=1e4) rla = RatesLinalg(self.db.transition_states(), [m1], [m2], T=0.592) rAB = rla.compute_rates() self.assertAlmostEqual(rAB, 7106337458., delta=1e4) rla = RatesLinalg(self.db.transition_states(), [m1, m3], [m2, m4], T=0.592) rAB = rla.compute_rates() self.assertAlmostEqual(rAB, 8638736600., delta=1e4)
def create_database(self, *args, **kwargs): """return a new database object See Also -------- pele.storage """ kwargs = dict_copy_update(self.params["database"], kwargs) # note this syntax is quite ugly, but we would like to be able to # create a new database by passing the filename as the first arg, # not as a kwarg. if len(args) > 1: raise ValueError( "create_database can only take one non-keyword argument") if len(args) == 1: if "db" not in kwargs: kwargs["db"] = args[0] try: overwrite_properties = kwargs.pop("overwrite_properties") except KeyError: overwrite_properties = True # get a routine to compare the minima as exact try: if not "compareMinima" in kwargs: try: compare_minima = self.get_compare_minima() kwargs["compareMinima"] = compare_minima except NotImplementedError: pass except NotImplementedError: # compareMinima is optional pass db = Database(**kwargs) db.add_properties(self.get_system_properties(), overwrite=overwrite_properties) return db
def test_nocoords_Fails(self): current_dir = os.path.dirname(__file__) db = Database() converter = OptimDBConverter( db, mindata=os.path.join(current_dir, "min.data"), tsdata=os.path.join(current_dir, "ts.data"), pointsmin="poo", pointsts="poo", assert_coords=True, endianness="<") with self.assertRaises(IOError): converter.convert()
def test2(self): from pele.utils.tests.test_disconnectivity_graph import create_random_database db = create_random_database(nmin=20, nts=15) delete = False mdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".min.data") tsdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".ts.data") pm = tempfile.NamedTemporaryFile(delete=delete) pts = tempfile.NamedTemporaryFile(delete=delete) print mdata.name, tsdata.name writer = WritePathsampleDB(db, mindata=mdata.name, tsdata=tsdata.name, pointsmin=pm.name, pointsts=pts.name, endianness="<") writer.write_db() newdb = Database() reader = OptimDBConverter(newdb, mindata=mdata.name, tsdata=tsdata.name, pointsmin=pm.name, pointsts=pts.name, endianness="<") reader.convert() for m1, m2 in izip(db.minima(), newdb.minima()): self.assertAlmostEqual(m1.energy, m2.energy) _base_test.assert_arrays_almost_equal(self, m1.coords, m2.coords) for ts1, ts2 in izip(db.transition_states(), newdb.transition_states()): self.assertAlmostEqual(ts1.energy, ts2.energy) _base_test.assert_arrays_almost_equal(self, ts1.coords, ts2.coords) self.assertAlmostEqual(ts1.minimum1.energy, ts2.minimum1.energy) self.assertAlmostEqual(ts1.minimum2.energy, ts2.minimum2.energy)
def create_database(self, *args, **kwargs): """return a new database object See Also -------- pele.storage """ kwargs = dict_copy_update(self.params["database"], kwargs) # note this syntax is quite ugly, but we would like to be able to # create a new database by passing the filename as the first arg, # not as a kwarg. if len(args) > 1: raise ValueError("create_database can only take one non-keyword argument") if len(args) == 1: if "db" not in kwargs: kwargs["db"] = args[0] try: overwrite_properties = kwargs.pop("overwrite_properties") except KeyError: overwrite_properties = True # get a routine to compare the minima as exact try: if not "compareMinima" in kwargs: try: compare_minima = self.get_compare_minima() kwargs["compareMinima"] = compare_minima except NotImplementedError: pass except NotImplementedError: # compareMinima is optional pass db = Database(**kwargs) db.add_properties(self.get_system_properties(), overwrite=overwrite_properties) return db
def test2(self): from pele.utils.tests.test_disconnectivity_graph import create_random_database db = create_random_database(nmin=20, nts=15) delete=False mdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".min.data") tsdata = tempfile.NamedTemporaryFile(delete=delete, suffix=".ts.data") pm = tempfile.NamedTemporaryFile(delete=delete) pts = tempfile.NamedTemporaryFile(delete=delete) print(mdata.name, tsdata.name) writer = WritePathsampleDB(db, mindata=mdata.name, tsdata=tsdata.name, pointsmin=pm.name, pointsts=pts.name, endianness="<") writer.write_db() newdb = Database() reader = OptimDBConverter(newdb, mindata=mdata.name, tsdata=tsdata.name, pointsmin=pm.name, pointsts=pts.name, endianness="<") reader.convert() for m1, m2 in zip(db.minima(), newdb.minima()): self.assertAlmostEqual(m1.energy, m2.energy) _base_test.assert_arrays_almost_equal(self, m1.coords, m2.coords) for ts1, ts2 in zip(db.transition_states(), newdb.transition_states()): self.assertAlmostEqual(ts1.energy, ts2.energy) _base_test.assert_arrays_almost_equal(self, ts1.coords, ts2.coords) self.assertAlmostEqual(ts1.minimum1.energy, ts2.minimum1.energy) self.assertAlmostEqual(ts1.minimum2.energy, ts2.minimum2.energy)
def get_database_params(dbname): db = Database(dbname, createdb=False) x_train_data = db.get_property("x_train_data").value() y_train_data = db.get_property("y_train_data").value() hnodes = db.get_property("hnodes").value() hnodes2 = db.get_property("hnodes2").value() reg = db.get_property("reg").value() params = (x_train_data, y_train_data, hnodes, hnodes2, reg) return db, params
def create_random_database(nmin=20, nts=20): db = Database() for i in range(nmin): energy = np.random.uniform(-1., 10.) x = [energy] db.addMinimum(energy, x) manager = ConnectManager(db, verbosity=0) for i in range(old_div(nts, 2)): m1, m2 = manager.get_connect_job("gmin") energy = max([m1.energy, m2.energy]) + np.random.uniform(1, 10) x = [energy] db.addTransitionState(energy, x, m1, m2) for i in range(old_div(nts, 2)): m1, m2 = manager.get_connect_job("random") energy = max([m1.energy, m2.energy]) + np.random.uniform(1, 5) x = [energy] db.addTransitionState(energy, x, m1, m2) return db
def test1(self): current_dir = os.path.dirname(__file__) db = Database() converter = OptimDBConverter( db, mindata=os.path.join(current_dir, "min.data"), tsdata=os.path.join(current_dir, "ts.data"), pointsmin=os.path.join(current_dir, "points.min"), pointsts=os.path.join(current_dir, "points.ts"), endianness="<") converter.convert() mdata = tempfile.NamedTemporaryFile(delete=True) tsdata = tempfile.NamedTemporaryFile(delete=True) pm = tempfile.NamedTemporaryFile(delete=True) pts = tempfile.NamedTemporaryFile(delete=True) print mdata.name, tsdata.name writer = WritePathsampleDB(db, mindata=mdata.name, tsdata=tsdata.name, pointsmin=pm.name, pointsts=pts.name, endianness="<") writer.write_db() d1 = np.genfromtxt(os.path.join(current_dir, "min.data"))[:, :3] d2 = np.genfromtxt(mdata.name)[:, :3] _base_test.assert_arrays_almost_equal(self, d1, d2) d1 = np.genfromtxt(os.path.join(current_dir, "ts.data")).reshape(-1, 8)[:, :5] d2 = np.genfromtxt(tsdata.name).reshape(-1, 8)[:, :5] print d1, d2 _base_test.assert_arrays_almost_equal(self, d1, d2) self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.min")), sha1_of_file(pm.name)) self.assertEqual(sha1_of_file(os.path.join(current_dir, "points.ts")), sha1_of_file(pts.name))
def create_random_database(nmin=20, nts=20): db = Database() for i in xrange(nmin): energy = np.random.uniform(-1., 10.) x = [energy] db.addMinimum(energy, x) manager = ConnectManager(db, verbosity=0) for i in xrange(nts/2): m1, m2 = manager.get_connect_job("gmin") energy = max([m1.energy, m2.energy]) + np.random.uniform(1,10) x = [energy] db.addTransitionState(energy, x, m1, m2) for i in xrange(nts/2): m1, m2 = manager.get_connect_job("random") energy = max([m1.energy, m2.energy]) + np.random.uniform(1,5) x = [energy] db.addTransitionState(energy, x, m1, m2) return db
def create_frozenblj_system_from_db(dbname): from pele.storage import Database db = Database(dbname, createdb=False) natoms = db.get_property("natoms").value() boxvec = db.get_property("boxvec").value() ntypeA = db.get_property("ntypeA").value() initial_coords = db.get_property("initial_coords").value() frozen = db.get_property("frozen_atoms").value() system = BLJBulkFrozen(natoms, boxvec, initial_coords, frozen, ntypeA=ntypeA) # The next line is a nasty hack to avoid an odd error. # When we call create_database on an exisiting database, it compares all the system properties # against the ones that are saved in the database. It then commits any changes to the database, # but that step seems to fail when trying to overwrite a sequence object (in this case the kwargs # dictionary) with another sequence. Instead, I overwrite with a None-type object first. Then in # the next command we are overwriting a None-type with a dictionary, which doesn't cause an error. db.add_property("potential_kwargs",{}) db = system.create_database(dbname, createdb=False, overwrite_properties=True) return system, db, initial_coords
run_gui(system, db=dbname) if __name__ == "__main__": p = 5 N = 20 #run_gui(N, p) #event_after_step = lambda energy, coords, acceptstep : normalize_spins(coords) #event_after_step=[event_after_step] if False: system = MeanFieldPSpinSphericalSystem(N, p=p) db = system.create_database("pspin_spherical_p{}_N{}.sqlite".format(p,N)) bh = system.get_basinhopping(database=db, outstream=None) bh.run(100) if True: run_gui_db(dbname="pspin_spherical_p{}_N{}.sqlite".format(p,N)) if False: compare_minima = lambda m1, m2 : compare_exact(m1.coords, m2.coords, rel_tol=1e-7, debug=False) db = Database("pspin_spherical_p{}_N{}.sqlite".format(p,N)) minima = db.minima() minima.sort(key=lambda m: m.energy) #for m in minima: # print m.energy, m.coords print minima[0].energy, minima[0].coords print minima[1].energy, minima[1].coords print compare_minima(minima[0],minima[1])
# why this is. This step is already often the bottleneck of the d-graph # calculation. minima = db.session.query(Minimum).filter(Minimum.energy <= Emax) g.add_nodes_from(minima) # if we order by energy first and add the transition states with the largest # the we will take the smallest energy transition state in the case of duplicates ts = db.session.query(TransitionState).filter(TransitionState.energy <= Emax)\ .order_by(-TransitionState.energy) for t in ts: g.add_edge(t.minimum1, t.minimum2, ts=t) return g if __name__ == "__main__": db = Database("lj31.db", createdb=False) if len(db.minima()) < 2: raise Exception("database has no minima") if True: from pele.systems import LJCluster from pele.thermodynamics import get_thermodynamic_information system = LJCluster(31) get_thermodynamic_information(system, db, nproc=10) app = QApplication(sys.argv) md = DGraphDialog(db) md.show() md.rebuild_disconnectivity_graph()
parser.add_argument("-o", metavar="output", type=str, help="output file name. The heat capacity will be written to output and output.pdf", default="Cv") parser.add_argument("--Tmin", type=float, help="Minimum temperature for the calculation.", default=0.02) parser.add_argument("--Tmax", type=float, help="Minimum temperature for the calculation.", default=1.0) parser.add_argument("--Tcount", type=int, help="Number of temperature points for the calculation.", default=300) parser.add_argument("--OPTIM", action="store_true", help="read data from a min.data file instead." "fname should be the filename of the min.data file") args = parser.parse_args() print args.fname print args k = args.k # get the list of minima if args.OPTIM: # fname is a min.data file db = Database() converter = OptimDBConverter(db, mindata=args.fname) converter.convert_no_coords() minima = db.minima() else: dbfname = args.fname db = Database(dbfname, createdb=False) minima = [m for m in db.minima() if m.fvib is not None and m.pgorder is not None] if len(minima) == 0: print "There are not minima with the necessary thermodynamic information in the database. Have you computed the normal mode"\ " frequencies and point group order for all the minima? See pele.thermodynamics "\ " for more information" exit(1) print "computing heat capacity from", len(minima), "minima" Tmin = args.Tmin
#p#ath = [ x for x in IntterpolatedPath(db.minima[19], )] #path = [ x for x in InterpolatedPath(path[0].copy(), path[-1].copy(), 34) ] traj = open("traj.xyz", "w") #for x in path: # #export_xyz(traj, x) # #ret = quench.mylbfgs(x, pot.getEnergyGradient) # #print i,pot.getEnergy(x), ret[1] # # # export_xyz(traj, ret[0]) for x in path: export_xyz(traj, x) import pickle pickle.dump(path, open("interpolate.pickle", "w")) exit() db=Database(db="oxdna.sqlite") path[0]=db.minima()[19].coords path[-1]=db.minima()[0].coords e1 = [] e2 = [] e1.append(pot.getEnergy(path[0])) e2.append(pot.getEnergy(path[0])) #for i in xrange(1): for i in xrange(len(path) - 1): e1.append(pot.getEnergy(path[i + 1])) c1 = CoordsAdapter(nrigid=13, coords=path[i]) c2 = CoordsAdapter(nrigid=13, coords=path[i + 1]) com1 = np.sum(c1.posRigid, axis=0) / float(13)
print gnum[60:65] import numpy as np print 'Num vs Analytic Gradient =' print np.max(np.abs(gnum-g)), np.max(np.abs(gnum)) print np.max(np.abs(gnum-g)) / np.max(np.abs(gnum)) # --- Test AMBERSystem class from pele.amber.amberSystem import AMBERSystem # create new amber system sysAmb = AMBERSystem('../aladipep/coords.prmtop', '../aladipep/coords.inpcrd') # load existing database from pele.storage import Database dbcurr = Database(db="../aladipep/aladipep.db") # ------ Test potential print 'testing potential in ambSystem' sysAmb.test_potential("../aladipep/coords.pdb") # ------ BH print 'testing BH' nsteps = 1 sysAmb.test_BH(dbcurr, nsteps) for minimum in dbcurr.minima(): print minimum._id, minimum.energy # -- test connect dbcurr = Database(db="aladipep.db")
for m2 in minima[1:nconn + 1]: connect = ljsys.get_double_ended_connect(m1, m2, db) connect.connect() return db def make_graph(database): # make a graph from the database graph = database2graph(database) # turn the graph into a disconnectivity graph dg = DisconnectivityGraph(graph, nlevels=5, center_gmin=False, order_by_energy=True) dg.calculate() print "number of minima:", dg.tree_graph.number_of_leaves() dg.plot() dg.show() if __name__ == "__main__": if True: db = get_database() else: db = Database("lj38.sqlite") make_graph(db)
class TestConnectManager(unittest.TestCase): def setUp(self): self.db = Database() self.nminima = 10 for i in range(self.nminima): e = float(i) self.db.addMinimum(e, [e]) def connect_min(self, m1, m2): e = np.random.uniform(0,100) self.db.addTransitionState(e, [e], m1, m2) def test_gmin(self): manager = ConnectManager(self.db, strategy="gmin") m0 = self.db.minima()[0] for i in range(5): m1, m2 = manager.get_connect_job() self.assertEqual(m1, m0) self.connect_min(m1, m2) def test_random(self): manager = ConnectManager(self.db, strategy="random") for i in range(5): m1, m2 = manager.get_connect_job() self.connect_min(m1, m2) def test_combine(self): minima = self.db.minima() i = 5 for m1, m2 in zip(minima[:i-1], minima[1:i]): self.connect_min(m1, m2) for m1, m2 in zip(minima[i:], minima[i+1:]): self.connect_min(m1, m2) # at this point the minima should be in two disconnected groups g = database2graph(self.db) self.assertEqual(len(list(nx.connected_components(g))), 2) manager = ConnectManager(self.db, strategy="combine") m1, m2 = manager.get_connect_job() self.connect_min(m1, m2) # they should all be connected now g = database2graph(self.db) self.assertEqual(len(list(nx.connected_components(g))), 1) def test_untrap(self): # first connect them all randomly manager = ConnectManager(self.db, strategy="random") while True: try: m1, m2 = manager.get_connect_job() except manager.NoMoreConnectionsError: break self.connect_min(m1, m2) for i in range(5): try: m1, m2 = manager.get_connect_job(strategy="untrap") except manager.NoMoreConnectionsError: break self.connect_min(m1, m2)
def setUp(self): self.db = Database() self.nminima = 10 for i in range(self.nminima): e = float(i) self.db.addMinimum(e, [e])
"""load data from min.A or min.B""" with open(fname) as fin: ids = [] for i, line in enumerate(fin): if i == 0: nminima = int(line.split()[0]) else: sline = line.split() ids += map(int, sline) assert nminima == len(ids) print len(ids), "minima read from file:", fname return [db.getMinimum(mid) for mid in ids] db = Database() direc = "lj38/20000.minima" direc = "." if db.number_of_minima() == 0: converter = OptimDBConverter(db, mindata=direc+"/min.data", tsdata=direc+"/ts.data") converter.pointsmin_data = None converter.pointsts_data = None converter.ReadMinDataFast() converter.ReadTSdataFast() A = read_minA(direc+"/min.A", db) B = read_minA(direc+"/min.B", db)
self.local_connect_explorer.show() self.local_connect_explorer.set_nebrunner(self.nebrunner) def start(): wnd.new_neb(x1, x2) if __name__ == "__main__": import sys import pylab as pl from OpenGL.GLUT import glutInit glutInit() 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. 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) wnd = NEBExplorer(app=app, system=system) wnd.show() from PyQt4.QtCore import QTimer QTimer.singleShot(10, start) sys.exit(app.exec_())
""" fout.write(odatastr) fout.write("\n") # ============================ MAIN ================================ if __name__ == "__main__": # create new amber system sysAmb = AMBERSystem('../../examples/amber/aladipep/coords.prmtop', '../../examples/amber/aladipep/coords.inpcrd') # load existing database from pele.storage import Database dbcurr = Database(db="../../examples/amber/aladipep/aladipep.db") coords = sysAmb.get_random_configuration() # aa = sysAmb.get_metric_tensor(coords) # ------- TEST gui from pele.gui import run as gr gr.run_gui(sysAmb) # ------ Test potential sysAmb.test_potential("../../examples/amber/aladipep/coords.pdb") # ------ BH nsteps = 100 sysAmb.test_BH(dbcurr, nsteps)
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() glutInit() #initilize the NEB and run it. #we have to do it through QTimer because the gui has to #be intitialized first... I don't really understand it from PyQt4.QtCore import QTimer QTimer.singleShot(10, start)
if __name__ == "__main__": p = 5 N = 20 #run_gui(N, p) #event_after_step = lambda energy, coords, acceptstep : normalize_spins(coords) #event_after_step=[event_after_step] if False: system = MeanFieldPSpinSphericalSystem(N, p=p) db = system.create_database("pspin_spherical_p{}_N{}.sqlite".format( p, N)) bh = system.get_basinhopping(database=db, outstream=None) bh.run(100) if True: run_gui_db(dbname="pspin_spherical_p{}_N{}.sqlite".format(p, N)) if False: compare_minima = lambda m1, m2: compare_exact( m1.coords, m2.coords, rel_tol=1e-7, debug=False) db = Database("pspin_spherical_p{}_N{}.sqlite".format(p, N)) minima = db.minima() minima.sort(key=lambda m: m.energy) #for m in minima: # print m.energy, m.coords print(minima[0].energy, minima[0].coords) print(minima[1].energy, minima[1].coords) print(compare_minima(minima[0], minima[1]))