当前位置: 首页>>代码示例>>Python>>正文


Python Database.minima方法代码示例

本文整理汇总了Python中pele.storage.Database.minima方法的典型用法代码示例。如果您正苦于以下问题:Python Database.minima方法的具体用法?Python Database.minima怎么用?Python Database.minima使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pele.storage.Database的用法示例。


在下文中一共展示了Database.minima方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test1

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
    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)
开发者ID:pele-python,项目名称:pele,代码行数:27,代码来源:test_optim_compatibility.py

示例2: benchmark_number_of_minima

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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()
开发者ID:borislavujo,项目名称:pele,代码行数:31,代码来源:test_database.py

示例3: test2

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
    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()
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:22,代码来源:test_double_ended_connect.py

示例4: bh_no_system_class

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:22,代码来源:example2_global_optimization.py

示例5: test2

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
 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)
开发者ID:pele-python,项目名称:pele,代码行数:40,代码来源:test_optim_compatibility.py

示例6: Database

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
    # 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_()) 
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:33,代码来源:dgraph_dlg.py

示例7: TestConnectManager

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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)
开发者ID:pele-python,项目名称:pele,代码行数:66,代码来源:test_connect_manager.py

示例8: Database

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
    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
    Tmax = args.Tmax
    nT = args.Tcount
    dT = (Tmax-Tmin) / nT
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:33,代码来源:compute_cv.py

示例9: run_gui

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
    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])

开发者ID:Mahdisadjadi,项目名称:pele,代码行数:31,代码来源:pspin_spherical_system.py

示例10: InterpolatedPath

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
#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)
    com2 = np.sum(c1.posRigid, axis=0) / float(13)
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:33,代码来源:path.py

示例11: AMBERSystem

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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")
sysAmb.test_connect(dbcurr) 


#print "---------id, m1_id, m2_id, tsener"
#for ts in dbcurr.transition_states() :
#    print ts._id, ts._minimum1_id, ts._minimum2_id,  ts.energy      
            
# connect to existing db 
#    sysOpenMM.create_database(db=dbcurr)   

开发者ID:Mahdisadjadi,项目名称:pele,代码行数:31,代码来源:testOpenMM_in_PELE.py

示例12: TestDB

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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)
        
#.........这里部分代码省略.........
开发者ID:borislavujo,项目名称:pele,代码行数:103,代码来源:test_database.py

示例13: Database

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
#                        default="otp.db")
    parser.add_argument("k", type=int, help="number of degrees of vibrational freedom")
    parser.add_argument("fname", type=str, help="database file name")
    args = parser.parse_args()
    print args.fname
    k = args.k
    
    dbfname = args.fname
    db = Database(dbfname)

    Tmin = .001
    Tmax = .5
    nT = 300
    dT = (Tmax-Tmin) / nT
    
    T = np.array([Tmin + dT*i for i in range(nT)])
    Z, U, U2, Cv = compute_cv(db.minima(), T, k)
    print Z, Cv
    
    with open("cv_ha", "w") as fout:
        fout.write("#T Cv <E> <E**2>\n")
        for vals in zip(T, Cv, U, U2):
            fout.write("%g %g %g %g\n" % vals)
    
    import pylab as pl
    pl.plot(T, Cv, 'o-')
    pl.xlabel("T")
    pl.ylabel("Cv")
    pl.savefig("cv_ha.pdf")
        
开发者ID:js850,项目名称:sens,代码行数:31,代码来源:harmonic_approx_cv.py

示例14: lbfgs_py

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
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
#eivenvector corresponding to the zero eigenvalues are.  These are related
#to global symmetries.  for this system we have 3 zero eigenvalues for translational
开发者ID:borislavujo,项目名称:pele,代码行数:33,代码来源:connect_no_system_class.py

示例15: Database

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import minima [as 别名]
from pele.utils.disconnectivity_graph import DisconnectivityGraph
from pele.storage import Database
from pele.landscape import TSGraph
import pylab as pl
import numpy as np

kbT = 0.75

db = Database(db="tip4p_8.sqlite", createdb=False)

graph = TSGraph(db)

dg = DisconnectivityGraph(graph.graph, db.minima(), subgraph_size=20)
dg.calculate()
dg.plot()

for m in db.minima():
    if m.pgorder != 2:
        print m.pgorder
    m.free_energy = m.energy + kbT * 0.5*m.fvib + kbT*np.log(m.pgorder)

 
for ts in db.transition_states():
#    if ts.pgorder != 2:
    print ts.pgorder
    #assert ts.pgorder == 2    

    ts.free_energy = ts.energy + kbT * 0.5*ts.fvib + kbT*np.log(ts.pgorder) + kbT*np.log(kbT)
    if ts.free_energy > ts.minimum1.free_energy or ts.free_energy > ts.minimum2.free_energy:        
        print "warning, free energy of transition state lower than minimum"
        print ts.free_energy, ts.minimum1.free_energy, ts.minimum2.free_energy
开发者ID:Mahdisadjadi,项目名称:pele,代码行数:33,代码来源:tip4p_dgraph.py


注:本文中的pele.storage.Database.minima方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。