Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import numpy as np
3from ase.calculators.singlepoint import SinglePointCalculator
4from ase.atom import Atom
5from ase.atoms import Atoms
6from ase.utils import reader
9@reader
10def read_dacapo_text(fd):
11 lines = fd.readlines()
12 i = lines.index(' Structure: A1 A2 A3\n')
13 cell = np.array([[float(w) for w in line.split()[2:5]]
14 for line in lines[i + 1:i + 4]]).transpose()
15 i = lines.index(' Structure: >> Ionic positions/velocities ' +
16 'in cartesian coordinates <<\n')
17 atoms = []
18 for line in lines[i + 4:]:
19 words = line.split()
20 if len(words) != 9:
21 break
22 Z, x, y, z = words[2:6]
23 atoms.append(Atom(int(Z), [float(x), float(y), float(z)]))
25 atoms = Atoms(atoms, cell=cell.tolist())
27 try:
28 i = lines.index(
29 ' DFT: CPU time Total energy\n')
30 except ValueError:
31 pass
32 else:
33 column = lines[i + 3].split().index('selfcons') - 1
34 try:
35 i2 = lines.index(' ANALYSIS PART OF CODE\n', i)
36 except ValueError:
37 pass
38 else:
39 while i2 > i:
40 if lines[i2].startswith(' DFT:'):
41 break
42 i2 -= 1
43 energy = float(lines[i2].split()[column])
44 atoms.calc = SinglePointCalculator(atoms, energy=energy)
46 return atoms