-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCasmEnergies.py
59 lines (48 loc) · 1.93 KB
/
getCasmEnergies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
import os
import sys
import numpy as np
#use absolute paths. searchDir should be the training data directory
searchDir = sys.argv[1]
output = sys.argv[2]
ratio_N_Zr = []
energies = []
trainingNames = []
numberNs = []
numberZrs = []
for subdir, dirs, files in os.walk(searchDir):
if subdir.split('/')[-1] == 'run.final':
name = subdir.split('/')[-5] + '__' + subdir.split('/')[-4]
for carFile in files:
#get the number of atoms in the unit cell, and the number of each type
if carFile == 'POSCAR':
with open(subdir +'/' + carFile) as poscar:
for i, line in enumerate(poscar):
if i == 6:
atoms = np.array(line.split()).astype(int)
numberOfAtoms = sum(atoms)
if len(atoms) > 1:
numberN = atoms[0]
numberZr = atoms[1]
elif len(atoms) == 1:
numberN = 0
numberZr = atoms[0]
#get energy of the static run
if carFile == 'vasp.out':
with open(subdir + '/' + carFile) as vaspOut:
for line in vaspOut:
if len(line.split()) > 4:
if line.split()[3] == 'E0=':
e0 = float(line.split()[4])
trainingNames.append(name)
energies.append(e0)
numberNs.append(numberN)
numberZrs.append(numberZr)
ratio_N_Zr.append(numberN/numberZr)
data = np.zeros((len(trainingNames),4))
data[:,0] = ratio_N_Zr
data[:,1] = energies
#data[:,2] = trainingNames
data[:,2] = numberNs
data[:,3] = numberZrs
np.savetxt(output, data,header='N/Zr_rato energies trainingNames number_of_Nitrogen number_of_Zirconium')