Coverage for /builds/ase/ase/ase/io/dacapo.py: 20.00%

35 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

3import numpy as np 

4 

5from ase.atom import Atom 

6from ase.atoms import Atoms 

7from ase.calculators.singlepoint import SinglePointCalculator 

8from ase.utils import reader 

9 

10 

11@reader 

12def read_dacapo_text(fd): 

13 lines = fd.readlines() 

14 i = lines.index(' Structure: A1 A2 A3\n') 

15 cell = np.array([[float(w) for w in line.split()[2:5]] 

16 for line in lines[i + 1:i + 4]]).transpose() 

17 i = lines.index(' Structure: >> Ionic positions/velocities ' + 

18 'in cartesian coordinates <<\n') 

19 atoms = [] 

20 for line in lines[i + 4:]: 

21 words = line.split() 

22 if len(words) != 9: 

23 break 

24 Z, x, y, z = words[2:6] 

25 atoms.append(Atom(int(Z), [float(x), float(y), float(z)])) 

26 

27 atoms = Atoms(atoms, cell=cell.tolist()) 

28 

29 try: 

30 i = lines.index( 

31 ' DFT: CPU time Total energy\n') 

32 except ValueError: 

33 pass 

34 else: 

35 column = lines[i + 3].split().index('selfcons') - 1 

36 try: 

37 i2 = lines.index(' ANALYSIS PART OF CODE\n', i) 

38 except ValueError: 

39 pass 

40 else: 

41 while i2 > i: 

42 if lines[i2].startswith(' DFT:'): 

43 break 

44 i2 -= 1 

45 energy = float(lines[i2].split()[column]) 

46 atoms.calc = SinglePointCalculator(atoms, energy=energy) 

47 

48 return atoms