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 xrange(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 benchmark_number_of_minima(): import time, sys import numpy as np db = Database("test.large.db") if True: istart = np.random.randint(0, sys.maxsize) for i in range(istart, istart + 10000): e = float(i) db.addMinimum(e, [e], commit=False) db.session.commit() else: i = 1 t1 = time.process_time() print(db.number_of_minima()) print("time", t1 - time.process_time()) t1 = time.process_time() print(db.number_of_minima()) print("time", t1 - time.process_time()) t1 = time.process_time() print(db.number_of_minima()) print("time", t1 - time.process_time()) t1 = time.process_time() e = float(i + 1) db.addMinimum(e, [e], commit=False) t1 = time.process_time() print(db.number_of_minima()) print("time", t1 - time.process_time()) t1 = time.process_time() print(len(db.minima())) print("time", t1 - time.process_time()) t1 = time.process_time()
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 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 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 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 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 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_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 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
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_())
state_listdir.sort() process_names = [ 'proc', 'saddle energy', 'prefactor', 'productID', 'product energy', 'product prefactor', 'barrier', 'rate', 'repeats' ] emphasize = [] specified_min = None for dir in state_listdir: if dir < min_state_n: continue if dir == max_state_n: break print "state:", dir try: rs = db.addMinimum(states_e[dir], [dir]) except: continue if dir == min_state_n: start_state = rs if emphasize_state_start: if dir >= emphasize_state_start and dir <= emphasize_state_end: emphasize.append(rs) if dir == specified_state: specified_min = rs os.chdir(state_main_dir + str(dir)) atoms = read('reactant.con', index=0) Au_seg[get_coord(atoms)].append(rs)
class TestDB(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]) 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 test_add_minimum(self): # add a duplicate minimum and ensure the db doesn't change self.db.addMinimum(0, [0]) self.assertEqual(self.db.number_of_minima(), self.nminima) def test_size(self): self.assertEqual(len(self.db.minima()), self.nminima) def test_energy(self): m = self.db.minima()[0] self.assertEqual(m.energy, 0.) def test_coords(self): m = self.db.minima()[0] self.assertEqual(m.coords, [0.]) def test_sizets(self): self.assertEqual(len(self.db.transition_states()), self.nts) def test_energyts(self): ts = self.db.transition_states()[0] self.assertEqual(ts.energy, 0.) def test_coordsts(self): ts = self.db.transition_states()[0] self.assertEqual(ts.coords, [0.]) def test_remove_minimum(self): m = self.db.minima()[0] self.db.removeMinimum(m) self.assertEqual(len(self.db.minima()), self.nminima - 1) self.assertNotIn(m, self.db.minima()) # m should have 2 minima. both of those should be gone self.assertEqual(len(self.db.transition_states()), self.nts - 2) def test_remove_ts(self): ts = self.db.transition_states()[0] self.db.remove_transition_state(ts) self.assertEqual(self.db.number_of_transition_states(), self.nts - 1) self.assertNotIn(ts, self.db.transition_states()) # m should have 2 minima. both of those should be gone self.assertEqual(self.db.number_of_minima(), self.nminima) def test_getTransitionState(self): m1 = self.db.minima()[0] m2 = self.db.minima()[1] m3 = self.db.minima()[-1] self.assertIsNotNone(self.db.getTransitionState(m1, m2)) self.assertIsNone(self.db.getTransitionState(m1, m3)) def test_getMinimum(self): m = self.db.minima()[0] self.assertEqual(m, self.db.getMinimum(m._id)) def test_minimum_adder(self): ma = self.db.minimum_adder() ma(101., [101.]) self.assertEqual(len(self.db.minima()), self.nminima + 1) def test_minimum_adder_Ecut(self): ma = self.db.minimum_adder(Ecut=0) n0 = self.db.number_of_minima() ma(101., [101.]) self.assertEqual(n0, self.db.number_of_minima()) ma(-101., [-101.]) self.assertEqual(n0 + 1, self.db.number_of_minima()) def test_minimum_adder_commit_interval(self): ma = self.db.minimum_adder(commit_interval=2) # replace db.session.commit with a wrapper that keeps track of how # many times it's been called self.real_commit = self.db.session.commit self.count = 0 def commit_wrapper(): self.count += 1 self.real_commit() self.db.session.commit = commit_wrapper # commit should be called for the first minimum ma(101., [101.]) self.assertEqual(self.count, 1) self.assertEqual(self.nminima + 1, self.db.number_of_minima()) # commit should not be called for the second minimum ma(102., [102.]) self.assertEqual(self.count, 1) self.assertEqual(self.nminima + 2, self.db.number_of_minima()) # yes for the third, no for the 4th ma(103., [103.]) self.assertEqual(self.count, 2) ma(104., [104.]) self.assertEqual(self.count, 2) # commit should be called when minimum adder is deleted del ma self.assertEqual(self.count, 3) self.assertEqual(self.nminima + 4, self.db.number_of_minima()) def test_merge_minima(self): m1 = self.db.minima()[0] m2 = self.db.minima()[1] self.db.mergeMinima(m1, m2) self.assertEqual(len(self.db.minima()), self.nminima - 1) # transition states shouldn't be deleted self.assertEqual(len(self.db.transition_states()), self.nts) def test_number_of_minima(self): self.assertEqual(self.nminima, self.db.number_of_minima()) def test_number_of_transition_states(self): self.assertEqual(self.nts, self.db.number_of_transition_states()) def test_highest_energy_minimum(self): m1 = self.db._highest_energy_minimum() m2 = self.db.minima()[-1] self.assertEqual(m1, m2) def test_maximum_number_of_minima(self): m = self.db.addMinimum(-1., [-1.], max_n_minima=self.nminima) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIn(m, self.db.minima()) def test_maximum_number_of_minima_largestE(self): e = float(self.nminima + 1) m = self.db.addMinimum(e, [e], max_n_minima=self.nminima) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIsNone(m) #ensure the highest energy minimum is still in the database mmax = self.db._highest_energy_minimum() self.assertEqual(mmax.energy, float(self.nminima - 1)) def test_maximum_number_of_minima_minima_adder(self): ma = self.db.minimum_adder(max_n_minima=self.nminima) m = ma(-1., [-1.]) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIn(m, self.db.minima()) def test_getTSfromID(self): ts = self.db.transition_states()[0] ts1 = self.db.getTransitionStateFromID(ts._id) self.assertEqual(ts, ts1) def test_property(self): # add some system properties and ensure they were added correctly self.db.add_property("natoms", 10) p = self.db.get_property("natoms") self.assertEqual(p.value(), 10) self.db.add_property("eps", 2.1) p = self.db.get_property("eps") self.assertEqual(p.value(), 2.1) self.db.add_property("author", "Jake") p = self.db.get_property("author") self.assertEqual(p.value(), "Jake") self.db.add_property("data", [1, 2]) p = self.db.get_property("data") self.assertEqual(p.value(), [1, 2]) # assert that the not set values are None p = self.db.get_property("natoms") self.assertIsNone(p.string_value) self.assertIsNone(p.float_value) self.assertIsNone(p.pickle_value) p = self.db.get_property("noprop") self.assertIsNone(p) props = self.db.properties(as_dict=True) self.assertIsInstance(props, dict) self.assertDictContainsSubset(dict(natoms=10), props) self.assertEqual(len(list(props.items())), 4) props = self.db.properties(as_dict=False) self.assertIn(("natoms", 10), [p.item() for p in props]) self.assertEqual(len(props), 4) def test_property_dtype(self): # add some system properties and ensure they were added correctly self.db.add_property("natoms", 10, dtype="int") p = self.db.get_property("natoms") self.assertEqual(p.value(), 10) self.db.add_property("eps", 2.1, dtype="float") p = self.db.get_property("eps") self.assertEqual(p.value(), 2.1) self.db.add_property("author", "Jake", dtype="string") p = self.db.get_property("author") self.assertEqual(p.value(), "Jake") self.db.add_property("data", [1, 2], dtype="pickle") p = self.db.get_property("data") self.assertEqual(p.value(), [1, 2]) def test_bad_property(self): self.db.add_property("natoms", 10, dtype="string") p = self.db.get_property("natoms") self.assertEqual(p.value(), "10") def test_property_overwrite_false(self): self.db.add_property("natoms", 10) # overwriting with the same value should not raise error self.db.add_property("natoms", 10, overwrite=False) # overwriting with a different value should raise error with self.assertRaises(RuntimeError): self.db.add_property("natoms", 11, overwrite=False) def test_add_properties(self): props = dict(natoms=10, author="jake") self.db.add_properties(props) for name, value in props.items(): p = self.db.get_property(name) self.assertEqual(p.value(), value) def test_load_wrong_schema(self): current_dir = os.path.dirname(__file__) dbname = current_dir + "/lj6_schema1.sqlite" with self.assertRaises(IOError): db = Database(dbname, createdb=False) def test_load_right_schema(self): current_dir = os.path.dirname(__file__) dbname = current_dir + "/lj6_schema2.sqlite" db = Database(dbname, createdb=False) def test_invalid(self): m = self.db.minima()[0] self.assertFalse(m.invalid) m.invalid = True self.db.session.commit() self.assertTrue(m.invalid) # now with a ts m = self.db.transition_states()[0] self.assertFalse(m.invalid) m.invalid = True self.db.session.commit() self.assertTrue(m.invalid) def test_user_data(self): m = self.db.minima()[0] m.user_data = dict(key="value") self.db.session.commit() v = m.user_data["key"] # now with a transition state m = self.db.transition_states()[0] m.user_data = dict(key="value") self.db.session.commit() v = m.user_data["key"]
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)
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)
class TestDB(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]) 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 test_size(self): self.assertEqual(len(self.db.minima()), self.nminima) def test_energy(self): m = self.db.minima()[0] self.assertEqual(m.energy, 0.) def test_coords(self): m = self.db.minima()[0] self.assertEqual(m.coords, [0.]) def test_sizets(self): self.assertEqual(len(self.db.transition_states()), self.nts) def test_energyts(self): ts = self.db.transition_states()[0] self.assertEqual(ts.energy, 0.) def test_coordsts(self): ts = self.db.transition_states()[0] self.assertEqual(ts.coords, [0.]) def test_remove_minimum(self): m = self.db.minima()[0] self.db.removeMinimum(m) self.assertEqual(len(self.db.minima()), self.nminima-1) self.assertNotIn(m, self.db.minima()) # m should have 2 minima. both of those should be gone self.assertEqual(len(self.db.transition_states()), self.nts-2) def test_remove_ts(self): ts = self.db.transition_states()[0] self.db.remove_transition_state(ts) self.assertEqual(self.db.number_of_transition_states(), self.nts-1) self.assertNotIn(ts, self.db.transition_states()) # m should have 2 minima. both of those should be gone self.assertEqual(self.db.number_of_minima(), self.nminima) def test_getTransitionState(self): m1 = self.db.minima()[0] m2 = self.db.minima()[1] m3 = self.db.minima()[-1] self.assertIsNotNone(self.db.getTransitionState(m1, m2)) self.assertIsNone(self.db.getTransitionState(m1, m3)) def test_getMinimum(self): m = self.db.minima()[0] self.assertEqual(m, self.db.getMinimum(m._id)) def test_minimum_adder(self): ma = self.db.minimum_adder() ma(101., [101.]) self.assertEqual(len(self.db.minima()), self.nminima+1) def test_merge_minima(self): m1 = self.db.minima()[0] m2 = self.db.minima()[1] self.db.mergeMinima(m1, m2) self.assertEqual(len(self.db.minima()), self.nminima-1) # transition states shouldn't be deleted self.assertEqual(len(self.db.transition_states()), self.nts) def test_number_of_minima(self): self.assertEqual(self.nminima, self.db.number_of_minima()) def test_number_of_transition_states(self): self.assertEqual(self.nts, self.db.number_of_transition_states()) def test_highest_energy_minimum(self): m1 = self.db._highest_energy_minimum() m2 = self.db.minima()[-1] self.assertEqual(m1, m2) def test_maximum_number_of_minima(self): m = self.db.addMinimum(-1., [-1.], max_n_minima=self.nminima) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIn(m, self.db.minima()) def test_maximum_number_of_minima_largestE(self): e = float(self.nminima + 1) m = self.db.addMinimum(e, [e], max_n_minima=self.nminima) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIsNone(m) #ensure the highest energy minimum is still in the database mmax = self.db._highest_energy_minimum() self.assertEqual(mmax.energy, float(self.nminima-1)) def test_maximum_number_of_minima_minima_adder(self): ma = self.db.minimum_adder(max_n_minima=self.nminima) m = ma(-1., [-1.]) self.assertEqual(self.nminima, self.db.number_of_minima()) self.assertIn(m, self.db.minima()) def test_getTSfromID(self): ts = self.db.transition_states()[0] ts1 = self.db.getTransitionStateFromID(ts._id) self.assertEqual(ts, ts1) def test_property(self): # add some system properties and ensure they were added correctly self.db.add_property("natoms", 10) p = self.db.get_property("natoms") self.assertEqual(p.value(), 10) self.db.add_property("eps", 2.1) p = self.db.get_property("eps") self.assertEqual(p.value(), 2.1) self.db.add_property("author", "Jake") p = self.db.get_property("author") self.assertEqual(p.value(), "Jake") self.db.add_property("data", [1, 2]) p = self.db.get_property("data") self.assertEqual(p.value(), [1, 2]) # assert that the not set values are None p = self.db.get_property("natoms") self.assertIsNone(p.string_value) self.assertIsNone(p.float_value) self.assertIsNone(p.pickle_value) p = self.db.get_property("noprop") self.assertIsNone(p) props = self.db.properties(as_dict=True) self.assertIsInstance(props, dict) self.assertDictContainsSubset(dict(natoms=10), props) self.assertEqual(len(props.items()), 4) props = self.db.properties(as_dict=False) self.assertIn(("natoms", 10), [p.item() for p in props]) self.assertEqual(len(props), 4) def test_property_dtype(self): # add some system properties and ensure they were added correctly self.db.add_property("natoms", 10, dtype="int") p = self.db.get_property("natoms") self.assertEqual(p.value(), 10) self.db.add_property("eps", 2.1, dtype="float") p = self.db.get_property("eps") self.assertEqual(p.value(), 2.1) self.db.add_property("author", "Jake", dtype="string") p = self.db.get_property("author") self.assertEqual(p.value(), "Jake") self.db.add_property("data", [1, 2], dtype="pickle") p = self.db.get_property("data") self.assertEqual(p.value(), [1, 2]) def test_bad_property(self): self.db.add_property("natoms", 10, dtype="string") p = self.db.get_property("natoms") self.assertEqual(p.value(), "10") def test_property_overwrite_false(self): self.db.add_property("natoms", 10) # overwriting with the same value should not raise error self.db.add_property("natoms", 10, overwrite=False) # overwriting with a different value should raise error with self.assertRaises(RuntimeError): self.db.add_property("natoms", 11, overwrite=False) def test_add_properties(self): props = dict(natoms=10, author="jake") self.db.add_properties(props) for name, value in props.iteritems(): p = self.db.get_property(name) self.assertEqual(p.value(), value) def test_load_wrong_schema(self): current_dir = os.path.dirname(__file__) dbname = current_dir + "/lj6_schema1.sqlite" with self.assertRaises(IOError): db = Database(dbname, createdb=False) def test_load_right_schema(self): current_dir = os.path.dirname(__file__) dbname = current_dir + "/lj6_schema2.sqlite" db = Database(dbname, createdb=False) def test_invalid(self): m = self.db.minima()[0] self.assertFalse(m.invalid) m.invalid = True self.db.session.commit() self.assertTrue(m.invalid) # now with a ts m = self.db.transition_states()[0] self.assertFalse(m.invalid) m.invalid = True self.db.session.commit() self.assertTrue(m.invalid) def test_user_data(self): m = self.db.minima()[0] m.user_data = dict(key="value") self.db.session.commit() v = m.user_data["key"] # now with a transition state m = self.db.transition_states()[0] m.user_data = dict(key="value") self.db.session.commit() v = m.user_data["key"]
#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] #set up the structural alignment routine. #we have to deal with global translational, global rotational, #and permutational symmetry. permlist = [range(natoms)] mindist = MinPermDistAtomicCluster(permlist=permlist, niter=10) #The transition state search needs to know what the eigenvector corresponding #to the lowest nonzero eigenvector is. For this we need to know what the
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) sys.exit(app.exec_())
# 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] # set up the structural alignment routine. # we have to deal with global translational, global rotational, # and permutational symmetry. permlist = [range(natoms)] mindist = MinPermDistAtomicCluster(permlist=permlist, niter=10) # The transition state search needs to know what the eigenvector corresponding # to the lowest nonzero eigenvector is. For this we need to know what the