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

35 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1import numpy as np 

2 

3from ase.atom import Atom 

4from ase.atoms import Atoms 

5from ase.calculators.singlepoint import SinglePointCalculator 

6from ase.utils import reader 

7 

8 

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)])) 

24 

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

26 

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) 

45 

46 return atoms