本文整理汇总了Python中pele.storage.Database.addTransitionState方法的典型用法代码示例。如果您正苦于以下问题:Python Database.addTransitionState方法的具体用法?Python Database.addTransitionState怎么用?Python Database.addTransitionState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pele.storage.Database
的用法示例。
在下文中一共展示了Database.addTransitionState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_random_database
# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import addTransitionState [as 别名]
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
示例2: create_random_database
# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import addTransitionState [as 别名]
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
示例3: TestConnectManager
# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import addTransitionState [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)
示例4: TestDB
# 需要导入模块: from pele.storage import Database [as 别名]
# 或者: from pele.storage.Database import addTransitionState [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)
#.........这里部分代码省略.........