forked from lkwagner/autogenv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Variance.py
104 lines (91 loc) · 3.33 KB
/
Variance.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
from __future__ import print_function
####################################################
class VarianceWriter:
def __init__(self,options={}):
self.qmc_type='Variance optimization'
self.sysfiles=['qw_000.sys']
self.slaterfiles=['qw_000.slater']
self.jastfiles=['qw.jast2']
self.basenames=['qw_000']
self.iterations=10
self.macro_iterations=3
self.completed=False
self.set_options(options)
#-----------------------------------------------
def set_options(self, d):
selfdict=self.__dict__
for k in d.keys():
if not k in selfdict.keys():
print("Error:",k,"not a keyword for VarianceWriter")
raise InputError
selfdict[k]=d[k]
#-----------------------------------------------
def is_consistent(self,other):
#In principle we should check for the files, but
#they are often determined *after* the plan has been
#written so it's not currently practical to check them.
skipkeys = ['completed','sysfiles','slaterfiles','jastfiles','basenames']
for otherkey in other.__dict__.keys():
if otherkey not in self.__dict__.keys():
print('other is missing a key.')
return False
for selfkey in self.__dict__.keys():
if selfkey not in other.__dict__.keys():
print('self is missing a key.')
return False
for key in self.__dict__.keys():
if self.__dict__[key]!=other.__dict__[key] and key not in skipkeys:
print("Different keys [{}] = \n{}\n or \n {}"\
.format(key,self.__dict__[key],other.__dict__[key]))
return False
return True
#-----------------------------------------------
def qwalk_input(self):
nfiles=len(self.sysfiles)
assert nfiles==len(self.slaterfiles)
assert nfiles==len(self.jastfiles)
for i in range(nfiles):
sys=self.sysfiles[i]
slater=self.slaterfiles[i]
jast=self.jastfiles[i]
base=self.basenames[i]
with open(base+'.variance','w') as f:
for j in range(self.macro_iterations):
f.write("method { optimize iterations %i }\n"%self.iterations)
f.write("include "+sys+"\n")
f.write("trialfunc { slater-jastrow \n")
f.write("wf1 { include "+slater + "}\n")
f.write("wf2 { include " + jast + "}\n")
f.write("}\n")
infiles=[x+".variance" for x in self.basenames]
outfiles=[x+".o" for x in infiles]
self.completed=True
return infiles,outfiles
####################################################
class VarianceReader:
def __init__(self):
self.output={}
self.completed=False
def read_outputfile(self,outfile):
ret={}
ret['sigma']=[]
with open(outfile) as f:
for line in f:
if 'dispersion' in line:
ret['sigma'].append(float(line.split()[4]))
return ret
#------------------------------------------------
def collect(self,outfiles):
for f in outfiles:
if f not in self.output.keys():
self.output[f]=[]
self.output[f].append(self.read_outputfile(f))
self.completed=True
#------------------------------------------------
def write_summary(self):
print("#### Variance optimization")
for f,out in self.output.items():
nruns=len(out)
print(f,"Number of runs",nruns)
for run in out:
print("dispersion",run['sigma'])