Coverage for ase/collections/create.py: 15.91%

44 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1import os 

2 

3import ase.db 

4from ase import Atoms 

5from ase.build import niggli_reduce 

6from ase.io import read 

7 

8 

9def dcdft(): 

10 """Create delta-codes-DFT collection. 

11 

12 Data from: https://github.com/molmod/DeltaCodesDFT 

13 """ 

14 os.environ['USER'] = 'ase' 

15 con = ase.db.connect('dcdft.json') 

16 with open('history/exp.txt') as fd: 

17 lines = fd.readlines() 

18 experiment = {} 

19 for line in lines[2:-1]: 

20 words = line.split() 

21 print(words) 

22 experiment[words[0]] = [float(word) for word in words[1:]] 

23 with open('WIEN2k.txt') as fd: 

24 lines = fd.readlines() 

25 for line in lines[2:73]: 

26 words = line.split() 

27 symbol = words.pop(0) 

28 vol, B, Bp = (float(x) for x in words) 

29 filename = f'primCIFs/{symbol}.cif' 

30 atoms = read(filename) 

31 if symbol in ['Li', 'Na']: 

32 niggli_reduce(atoms) 

33 M = { 

34 'Fe': 2.3, 

35 'Co': 1.2, 

36 'Ni': 0.6, 

37 'Cr': 1.5, 

38 'O': 1.5, 

39 'Mn': 2.0, 

40 }.get(symbol) 

41 if M is not None: 

42 magmoms = [M] * len(atoms) 

43 if symbol in ['Cr', 'O', 'Mn']: 

44 magmoms[len(atoms) // 2 :] = [-M] * (len(atoms) // 2) 

45 atoms.set_initial_magnetic_moments(magmoms) 

46 

47 exp = experiment.get(symbol, []) 

48 extra = dict(zip(['exp_volume', 'exp_B', 'exp_Bp'], exp)) 

49 con.write( 

50 atoms, 

51 name=symbol, 

52 wien2k_B=B, 

53 wien2k_Bp=Bp, 

54 wien2k_volume=vol, 

55 **extra, 

56 ) 

57 

58 

59def g2(): 

60 from ase.data.g2 import data 

61 

62 os.environ['USER'] = 'ase' 

63 con = ase.db.connect('g2.json') 

64 for name, d in data.items(): 

65 kwargs = {} 

66 if d['magmoms']: 

67 kwargs['magmoms'] = d['magmoms'] 

68 atoms = Atoms(d['symbols'], d['positions'], **kwargs) 

69 con.write(atoms, name=name)