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

44 statements  

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

1# fmt: off 

2 

3import os 

4 

5import ase.db 

6from ase import Atoms 

7from ase.build import niggli_reduce 

8from ase.io import read 

9 

10 

11def dcdft(): 

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

13 

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

15 """ 

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

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

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

19 lines = fd.readlines() 

20 experiment = {} 

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

22 words = line.split() 

23 print(words) 

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

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

26 lines = fd.readlines() 

27 for line in lines[2:73]: 

28 words = line.split() 

29 symbol = words.pop(0) 

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

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

32 atoms = read(filename) 

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

34 niggli_reduce(atoms) 

35 M = {'Fe': 2.3, 

36 'Co': 1.2, 

37 'Ni': 0.6, 

38 'Cr': 1.5, 

39 'O': 1.5, 

40 'Mn': 2.0}.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(atoms, name=symbol, 

50 wien2k_B=B, wien2k_Bp=Bp, wien2k_volume=vol, 

51 **extra) 

52 

53 

54def g2(): 

55 from ase.data.g2 import data 

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

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

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

59 kwargs = {} 

60 if d['magmoms']: 

61 kwargs['magmoms'] = d['magmoms'] 

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

63 con.write(atoms, name=name)