-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial_toy.py
63 lines (63 loc) · 1.92 KB
/
material_toy.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
60
61
62
63
import os
import json
import csv
import pickle
import sys
rootdir = '/mnt/data/datasets/Material_Raw_Data'
id = []
xrd = []
params = []
energy = []
for subdir, dirs, files in os.walk(rootdir):
#####ID#####
for dir in dirs:
if 'mp' in dir:
id.append(dir)
#####XRD#####
# read file
for file in files:
if file == 'xrd.csv':
with open(os.path.join(subdir, file), newline='') as f:
reader = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
data = list(reader)
# extract xrd (only non-zero rows)
xrd.append([row for row in data if any(row)])
#####PARAMETERS#####
# read file
for file in files:
if file == 'struct.json':
with open(os.path.join(subdir, file)) as f:
data = json.load(f)
# parse file
obj = json.loads(data)
# extract lattice parameters
lattice = obj['lattice']
a = float(lattice['a'])
b = float(lattice['b'])
c = float(lattice['c'])
alpha = float(lattice['alpha'])
beta = float(lattice['beta'])
gamma = float(lattice['gamma'])
# save parameters
params.extend([[a, b, c, alpha, beta, gamma]])
#####ENERGY#####
# read file
for file in files:
if file == 'energy.json':
with open(os.path.join(subdir, file)) as f:
data = json.load(f)
# parse file
obj = json.loads(data)
# extract lattice parameters
coh_eng = float(obj['cohesive_energy_per_atom'])
# save energy
energy.append(coh_eng)
# create files
with open('id.txt', 'wb') as f:
pickle.dump(id, f)
with open('xrd.txt', 'wb') as f:
pickle.dump(xrd, f)
with open('params.txt', 'wb') as f:
pickle.dump(params, f)
with open('energy.txt', 'wb') as f:
pickle.dump(energy, f)