Coverage for ase/io/dacapo.py: 20.00%
35 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1import numpy as np
3from ase.atom import Atom
4from ase.atoms import Atoms
5from ase.calculators.singlepoint import SinglePointCalculator
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(
14 [[float(w) for w in line.split()[2:5]] for line in lines[i + 1 : i + 4]]
15 ).transpose()
16 i = lines.index(
17 ' Structure: >> Ionic positions/velocities '
18 + 'in cartesian coordinates <<\n'
19 )
20 atoms = []
21 for line in lines[i + 4 :]:
22 words = line.split()
23 if len(words) != 9:
24 break
25 Z, x, y, z = words[2:6]
26 atoms.append(Atom(int(Z), [float(x), float(y), float(z)]))
28 atoms = Atoms(atoms, cell=cell.tolist())
30 try:
31 i = lines.index(
32 ' DFT: CPU time Total energy\n'
33 )
34 except ValueError:
35 pass
36 else:
37 column = lines[i + 3].split().index('selfcons') - 1
38 try:
39 i2 = lines.index(' ANALYSIS PART OF CODE\n', i)
40 except ValueError:
41 pass
42 else:
43 while i2 > i:
44 if lines[i2].startswith(' DFT:'):
45 break
46 i2 -= 1
47 energy = float(lines[i2].split()[column])
48 atoms.calc = SinglePointCalculator(atoms, energy=energy)
50 return atoms