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_thermodynamics(self): get_thermodynamic_information(self.system, self.db, nproc=None, recalculate=True) self.assertIsNotNone(self.m1.fvib) mt = self.system.get_metric_tensor(self.m1.coords) print("metric tensor") print(mt)
def setUp1(self, nproc=1): self.set_up_system() self.nreplicas = 10 self.stepsize = 0.01 self.nproc = nproc 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) # compute the thermodynamic information get_thermodynamic_information(self.system, self.database) get_all_normalmodes(self.system, self.database) self.minima = list(self.database.minima()) assert self.database.number_of_minima() > 1, "%d minima" % self.database.number_of_minima() self.mc_runner = self.system.get_mc_walker(mciter=200) self.energy_accuracy = 1e-4 self.ns = NestedSamplingSAExact(self.system, self.nreplicas, self.mc_runner, self.minima, self.energy_accuracy, mindist=self.system.get_mindist(), config_tests = self.system.get_config_tests(), stepsize=0.1, nproc=nproc, verbose=True, iprint=100) self.Emax0 = self.ns.replicas[-1].energy self.run_ns(max_iter=1000, Etol=.001)
def create_random_database(system, db, nmin=20, nts=10): if db.number_of_minima() < nmin: bh = system.get_basinhopping(db, outstream=None) bh.run(50) if db.number_of_transition_states() < nts: manager = ConnectManager(db, strategy="gmin") for i in range(nts): try: min1, min2 = manager.get_connect_job("gmin") except Exception as e: if not "couldn't find any random minima pair to connect" in str( e): raise connect = system.get_double_ended_connect(min1, min2, db, verbosity=0) connect.connect() connect = system.get_double_ended_connect(db.minima()[0], db.minima()[-1], db, verbosity=0) connect.connect() get_thermodynamic_information(system, db, nproc=2) return db
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 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) get_thermodynamic_information(self.system, self.db, nproc=None)
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_too_few_zero_modes(self): self.system.get_nzero_modes = lambda : 10 newdb = self.system.create_database() for ts in self.db.transition_states()[:4]: 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) with self.assertRaises(ValueError): get_thermodynamic_information(self.system, newdb, nproc=2, verbose=True)
def test_thermodynamics(self): get_thermodynamic_information(self.system, self.db, nproc=None, recalculate=True) self.assertIsNotNone(self.m1.fvib) mt = self.system.get_metric_tensor(self.m1.coords) print("metric tensor") print(mt)
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 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 test_too_few_zero_modes(self): self.system.get_nzero_modes = lambda: 10 newdb = self.system.create_database() for ts in self.db.transition_states()[:4]: m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords) m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords) newdb.addTransitionState(ts.energy, ts.coords, m1, m2) with self.assertRaises(ValueError): get_thermodynamic_information(self.system, newdb, nproc=2, verbose=True)
def test_too_few_negative_modes(self): newdb = self.system.create_database() tslist = [] for ts in self.db.transition_states()[:2]: m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords) m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords) # add a minima as a transition state newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2) tslist.append(newts) # with self.assertRaises(ValueError): get_thermodynamic_information(self.system, newdb, nproc=2, verbose=False) for ts in tslist: self.assertTrue(ts.invalid)
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_())
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_())
def test_too_few_negative_modes(self): newdb = self.system.create_database() tslist = [] for ts in self.db.transition_states()[:2]: m1 = newdb.addMinimum(ts.minimum1.energy, ts.minimum1.coords) m2 = newdb.addMinimum(ts.minimum2.energy, ts.minimum2.coords) # add a minima as a transition state newts = newdb.addTransitionState(m1.energy, m1.coords, m1, m2) tslist.append(newts) # with self.assertRaises(ValueError): get_thermodynamic_information(self.system, newdb, nproc=2, verbose=False) for ts in tslist: self.assertTrue(ts.invalid)
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)
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)
def build_database(system, nminima, dbfname=None, maxiter=1000): if dbfname is None: db = system.create_database() else: db = system.create_database(dbfname) bh = system.get_basinhopping(db, outstream=None) i = 0 while db.number_of_minima() < nminima: bh.run(1) i += 1 if i >= maxiter: break get_thermodynamic_information(system, db) get_all_normalmodes(system, db) return db
def setUp1(self, nproc=1): self.set_up_system() self.nreplicas = 10# * nproc self.stepsize = 0.01 self.nproc = nproc 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) # compute the thermodynamic information get_thermodynamic_information(self.system, self.database) get_all_normalmodes(self.system, self.database) self.minima = list(self.database.minima()) assert self.database.number_of_minima() > 1, "%d minima" % self.database.number_of_minima() self.mc_runner = self.system.get_mc_walker(mciter=200) self.energy_accuracy = 1e-4 self.hsa_sampler = HSASamplerCluster(self.minima, self.system.k, copy_minima=True, center_minima=True, energy_accuracy=self.energy_accuracy, compare_structures=self.system.get_compare_exact(), mindist=self.system.get_mindist(), minimizer=self.system.get_minimizer(), debug=True) replicas = _utils.create_replicas(self.system, self.nreplicas) potential = self.system.get_potential() potential.get_energy = potential.getEnergy self.ns = NestedSamplingSAExact(replicas, self.mc_runner, self.hsa_sampler, potential, config_tests=self.system.get_config_tests(), nproc=nproc, verbose=True, iprint=1, debug=True) self.Emax0 = self.ns.replicas[-1].energy self.run_ns(max_iter=1000, Etol=.001)
def test_get_thermo_info(self): # note, there is an intermittant error in this test # it causes the system to lock, and has to do with multiprocessing sys.stderr.write("test_get_thermo_info: seed {}\n".format(self.seed)) 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, verbose=True) 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)
def setUp1(self, nproc=1): self.set_up_system() self.nreplicas = 10 self.stepsize = 0.01 self.nproc = nproc 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) # compute the thermodynamic information get_thermodynamic_information(self.system, self.database) get_all_normalmodes(self.system, self.database) self.minima = list(self.database.minima()) assert self.database.number_of_minima( ) > 1, "%d minima" % self.database.number_of_minima() self.mc_runner = self.system.get_mc_walker(mciter=200) self.energy_accuracy = 1e-4 self.ns = NestedSamplingSAExact( self.system, self.nreplicas, self.mc_runner, self.minima, self.energy_accuracy, mindist=self.system.get_mindist(), config_tests=self.system.get_config_tests(), stepsize=0.1, nproc=nproc, verbose=True, iprint=100) self.Emax0 = self.ns.replicas[-1].energy self.run_ns(max_iter=1000, Etol=.001)
def test_get_thermo_info(self): # note, there is an intermittant error in this test # it causes the system to lock, and has to do with multiprocessing sys.stderr.write("test_get_thermo_info: seed {}\n".format(self.seed)) 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, verbose=True) 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)
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() sys.exit(app.exec_())
def test_fvib(self): db = self.make_database() get_thermodynamic_information(self.system, db, nproc=1)
# 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() sys.exit(app.exec_())
def test_fvib(self): db = self.make_database() get_thermodynamic_information(self.system, db, nproc=1)