-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_initial_sg_wyck.py
110 lines (82 loc) · 3.31 KB
/
get_initial_sg_wyck.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from Pool.mpi_pool import MPIPool
import sys,argparse
import numpy as np
from libs.input_structure import input2crystal
from libs.io import Frame_Dataset_h5
from tqdm import tqdm
import h5py
from glob import glob
from time import ctime
import spglib as spg
import pandas as pd
def get_initial_sg_wyck(fn):
frame_reader = Frame_Dataset_h5(fn,mode='r',swmr_mode=False,disable_pbar=True)
frame_names = frame_reader.names
frame_reader.open(mode='r')
data_init = {'Space Group': [], 'Wyckoff Position': [], 'tag': [], 'fn': [], 'frame_name': []}
for frame_name in frame_names:
inp = {}
for k, v in frame_reader.f[frame_name]['inputs'].iteritems():
inp[k] = v.value
inp.pop('symprec')
inp.pop('isotropic_external_pressure')
cc, _, _ = input2crystal(**inp)
sym_data = spg.get_symmetry_dataset(cc)
sg = sym_data['number']
wyck = np.unique(sym_data['wyckoffs'])
# if len(wyck) > 1:
# print(fn, frame_reader, wyck)
tag = '{}:{}'.format(sg, wyck[0])
data_init['fn'].append(fn)
data_init['frame_name'].append(frame_name)
data_init['tag'].append(tag)
data_init['Space Group'].append(sg)
data_init['Wyckoff Position'].append(wyck[0])
frame_reader.close()
return data_init
def get_initial_sg_wyck_generation(fn):
frame_reader = Frame_Dataset_h5(fn,mode='r',swmr_mode=False,disable_pbar=True)
frame_names = frame_reader.names
frame_reader.open(mode='r')
data_init = {'Space Group': [], 'Wyckoff Position': [], 'tag': [], 'fn': [], 'frame_name': []}
for frame_name in frame_names:
inp = {}
for k, v in frame_reader.f[frame_name]['inputs'].iteritems():
inp[k] = v.value
inp.pop('symprec')
inp.pop('isotropic_external_pressure')
cc, sg, wyck = input2crystal(**inp)
wyck = wyck[0]
tag = '{}:{}'.format(sg, wyck)
data_init['fn'].append(fn)
data_init['frame_name'].append(frame_name)
data_init['tag'].append(tag)
data_init['Space Group'].append(sg)
data_init['Wyckoff Position'].append(wyck)
frame_reader.close()
return data_init
if __name__ == '__main__':
pool = MPIPool()
if not pool.is_master():
pool.wait()
# pool.wait(callbacks=[fout.close,executor.shutdown])
sys.exit(0)
dataPath = '/home/musil/workspace/qmat/structures/'
fns = glob(dataPath + 'relaxed_structures_step1_*.h5')
print len(fns)
inputs = [fn for fn in fns]
# Ns = map(add_Nequivalent,inputs)
# res = pool.map(get_initial_sg_wyck,inputs)
# fout = '/home/musil/workspace/qmat/sg_wyck_tag_step0_spg.pck'
res = pool.map(get_initial_sg_wyck_generation, inputs)
fout = '/home/musil/workspace/qmat/sg_wyck_tag_step0_sel.pck'
data_inits = {'Space Group': [], 'Wyckoff Position': [], 'tag': [], 'fn': [], 'frame_name': []}
for data_init in res:
data_inits['fn'].extend(data_init['fn'])
data_inits['frame_name'].extend(data_init['frame_name'])
data_inits['tag'].extend(data_init['tag'])
data_inits['Space Group'].extend(data_init['Space Group'])
data_inits['Wyckoff Position'].extend(data_init['Wyckoff Position'])
df = pd.DataFrame.from_dict(data_inits)
df.to_pickle(fout)
pool.close()