-
Notifications
You must be signed in to change notification settings - Fork 2
/
gather.py
137 lines (120 loc) · 3.9 KB
/
gather.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import h5py
import numpy as np
from scipy import stats
import pyqmc.obdm
import itertools
import pandas as pd
import glob
def separate_variables_in_fname(spl):
method=spl[0]
startingwf=spl[1]
i=1
if "hci" in startingwf:
i+=1
orbitals=spl[i+1]
statenumber=spl[i+2]
nconfig=spl[i+3]
if "dmc" in method:
method+=spl[i+4]
return method,startingwf,orbitals,statenumber,nconfig
def extract_from_fname(fname):
fname=fname.replace('.chk','')
spl=fname.split('/')
if '_' in spl[3]:
spl_2=spl[3].split('_')
method,startingwf,orbitals,statenumber,nconfig=separate_variables_in_fname(spl_2)
if (startingwf=="mf"):
startingwf=spl[1]
else:
startingwf=spl[1]
orbitals,nconfig="/","/"
statenumber=0
method=spl[3]
if (method=="mf"):
method=spl[1]
return {"bond_length": spl[0][3:],
"basis":spl[2],
"startingwf":startingwf,
"method":method,
"orbitals":orbitals,
"statenumber":statenumber,
"determinant_cutoff":0,
"nconfig":nconfig
}
def avg(data):
mean=np.mean(data,axis=0)
error=np.std(data,axis=0)/np.sqrt(len(data)-1)
return mean,error
def calculate_entropy(dm):
if len(dm.shape) == 2:
dm = np.asarray([dm/2.0,dm/2.0])
u,v = np.linalg.eig(dm)
#print(u)
u = u[u>0]
return -np.sum(np.log(u)*u).real
def normalize_rdm(rdm1_value,rdm1_norm,warmup):
rdm1, rdm1_err=avg(rdm1_value[warmup:,...])
rdm1_norm, rdm1_norm_err = avg(rdm1_norm[warmup:,...])
rdm1=pyqmc.obdm.normalize_obdm(rdm1,rdm1_norm)
rdm1_err=pyqmc.obdm.normalize_obdm(rdm1_err,rdm1_norm)
return rdm1,rdm1_err
def read_vmc(fname):
with h5py.File(fname,'r') as f:
#print(list(f.keys()))
warmup=2
energy=f['energytotal'][warmup:,...]
e_tot,error=avg(energy)
rdm1_up,rdm1_up_err=normalize_rdm(f['rdm1_upvalue'],f['rdm1_upnorm'],warmup)
rdm1_down,rdm1_down_err=normalize_rdm(f['rdm1_downvalue'],f['rdm1_downnorm'],warmup)
rdm1=np.array([rdm1_up,rdm1_down])
entropy=calculate_entropy(rdm1)
return e_tot,error,entropy
def read_dmc(fname):
return read_vmc(fname)
def read(fname):
with h5py.File(fname,'r') as f:
e_tot,error,entropy=0.0,0.0,0.0
method=extract_from_fname(fname)["method"]
if 'cc' in method:
e_tot=f['ccsd']['energy'][()]
elif 'vmc' in method:
e_tot,error,entropy=read_vmc(fname)
elif 'dmc' in method:
e_tot,error,entropy=read_dmc(fname)
elif 'hf' in method:
e_tot = f['scf']['e_tot'][()]
elif 'fci' in method:
e_tot=np.array(f['e_tot'][()])[0] #state0,1,2,3,
elif 'hci' in method:
e_tot=np.array(f['ci']['energy'])[0] #state0,1,2,3
return e_tot,error,entropy
def create(fname):
e_tot,error,entropy = read(fname)
record = extract_from_fname(fname)
record.update({
"energy":e_tot,
"error":error,
"entropy":entropy
})
return record
if __name__=="__main__":
fname=[]
fqmc=[]
fhci=[]
for name in glob.glob('**/*.chk',recursive=True):
method=extract_from_fname(name)["method"]
startingwf=extract_from_fname(name)["startingwf"]
if 'opt' in method:
continue
if ('hci' in method or 'hci' in startingwf):
fhci.append(name)
if ('vmc' in method or 'dmc' in method):
fqmc.append(name)
fname.append(name)
df=pd.DataFrame([create(name) for name in fname])
df.to_csv("h2_data.csv", index=False)
df1=pd.DataFrame([create(name) for name in fqmc])
df1 = df1[(df1.basis=='vtz')]
df1.to_csv("h2_qmc.csv", index=False)
#df2=pd.DataFrame([create(name) for name in fhci])
#df2.to_csv("hci.csv", index=False)