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

44 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +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 = {'Fe': 2.3, 

34 'Co': 1.2, 

35 'Ni': 0.6, 

36 'Cr': 1.5, 

37 'O': 1.5, 

38 'Mn': 2.0}.get(symbol) 

39 if M is not None: 

40 magmoms = [M] * len(atoms) 

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

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

43 atoms.set_initial_magnetic_moments(magmoms) 

44 

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

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

47 con.write(atoms, name=symbol, 

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

49 **extra) 

50 

51 

52def g2(): 

53 from ase.data.g2 import data 

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

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

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

57 kwargs = {} 

58 if d['magmoms']: 

59 kwargs['magmoms'] = d['magmoms'] 

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

61 con.write(atoms, name=name)