PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/ase/db/db.py

https://gitlab.com/vote539/ase
Python | 49 lines | 37 code | 11 blank | 1 comment | 4 complexity | 6579a75b218150f853e763eb4af25820 MD5 | raw file
 1# creates: ase-db.txt, ase-db-long.txt
 2import ase.db
 3c = ase.db.connect('abc.db', append=False)
 4
 5from ase import Atoms
 6from ase.calculators.emt import EMT
 7h2 = Atoms('H2', [(0, 0, 0), (0, 0, 0.7)])
 8h2.calc = EMT()
 9h2.get_forces()
10
11c.write(h2, relaxed=False)
12
13from ase.optimize import BFGS
14BFGS(h2).run(fmax=0.01)
15c.write(h2, relaxed=True, data={'abc': [1, 2, 3]})
16
17for d in c.select('molecule'):
18    print(d.forces[0, 2], d.relaxed)
19
20h = Atoms('H')
21h.calc = EMT()
22h.get_potential_energy()
23c.write(h)
24
25import subprocess
26with open('ase-db.txt', 'w') as fd:
27    fd.write('$ ase-db abc.db\n')
28    output = subprocess.check_output(['ase-db', 'abc.db'])
29    fd.write(output)
30with open('ase-db-long.txt', 'w') as fd:
31    fd.write('$ ase-db abc.db relaxed=1 -l\n')
32    output = subprocess.check_output(['ase-db', 'abc.db', 'relaxed=1', '-l'])
33    fd.write(output)
34
35row = c.get(relaxed=1, calculator='emt')
36for key in row:
37    print('{0:22}: {1}'.format(key, row[key]))
38
39print(row.data.abc)
40
41e2 = row.energy
42e1 = c.get(H=1).energy
43ae = 2 * e1 - e2
44print(ae)
45
46id = c.get(relaxed=1).id
47c.update(id, atomization_energy=ae)
48
49del c[c.get(relaxed=0).id]