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


Python Database.number_of_minima方法代码示例

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


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

示例1: benchmark_number_of_minima

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

示例2: test1

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

示例3: enumerate

# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import number_of_minima [as 别名]
        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)
print len(A), "A minima"
print len(B), "B minima"
开发者ID:js850,项目名称:kmc_rates,代码行数:32,代码来源:bench_optim_lj.py

示例4: TestDB

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


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