forked from lkwagner/autogenv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manager.py
234 lines (192 loc) · 6.76 KB
/
Manager.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import os
import numpy as np
def resolve_status(runner,reader,outfiles):
#Check if the reader is done
if reader.completed:
return 'done'
#Check if the job is in the queue
# or running. If so, we just return that.
currstat=runner.check_status()
print("Current status:",currstat)
if currstat=='running':
return currstat
#Now we are in a state where either there was an error,
#the job hasn't been run, or we haven't collected the results
for outfile in outfiles:
if not os.path.exists(outfile):
return 'not_started'
#We are in an error state or we haven't collected
#the results.
return "ready_for_analysis"
#######################################################################
class CrystalManager:
""" Internal class managing process of running a DFT job though Crystal.
Has authority over file names associated with this task."""
def __init__(self,writer,crys_runner,crys_reader,prop_runner,prop_reader):
self.writer=writer
self.creader=crys_reader
self.crunner=crys_runner
self.preader=prop_reader
self.prunner=prop_runner
self.crysinpfn='crys.in'
self.crysoutfn='crys.in.o'
self.propinpfn='prop.in'
self.propoutfn='prop.in.o'
self.completed=False
#----------------------------------------
def nextstep(self):
""" Check write status, then if it's running. If not running check if
finished. If not finished, attempt to run. """
# Generate input files.
if not self.writer.completed:
with open(self.crysinpfn,'w') as f:
self.writer.write_crys_input(self.crysinpfn)
with open(self.propinpfn,'w') as f:
self.writer.write_prop_input(self.propinpfn)
#Check on the CRYSTAL run
while True:
status=resolve_status(self.crunner,self.creader,[self.crysoutfn])
print("Crystal status",status)
if status=="running":
return
elif status=="not_started":
self.crunner.run(self.crysinpfn,self.crysoutfn)
elif status=="ready_for_analysis":
#This is where we (eventually) do error correction and resubmits
self.creader.collect(self.crysoutfn)
break
elif status=='done':
break
else:
return
if not self.preader.completed:
self.prunner.run(self.propinpfn,self.propoutfn)
self.preader.collect(self.propoutfn)
print("Crystal properties done: ",self.preader.completed)
if self.creader.completed and self.preader.completed:
self.completed=True
#----------------------------------------
def is_consistent(self,other):
# This documents what needs to be checked.
return self.writer.is_consistent(other.writer)
#----------------------------------------
def to_json(self):
raise NotImplementedError
#----------------------------------------
def write_summary(self):
self.creader.write_summary()
#----------------------------------------
def status(self):
if self.completed:
return 'ok'
else:
return 'not_finished'
#######################################################################
class QWalkfromCrystalManager:
"""Set up a QWalk job from Crystal.
In this we will Convert from a CRYAPI_OUT-ed properties run.
"""
#------------------------------------------------
def __init__(self,convert_runner,convert_checker):
self.runner=convert_runner
self.reader=convert_checker
def is_consistent(self,other):
return self.runner.is_consistent(other.runner)
#------------------------------------------------
def nextstep(self):
if not self.reader.completed:
self.runner.run()
self.reader.collect()
#------------------------------------------------
def write_summary(self):
print("K-points",len(self.reader.out['basenames']))
#----------------------------------------
def status(self):
if self.reader.completed:
return 'ok'
else:
return 'not_finished'
#######################################################################
class QWalkRunManager:
def __init__(self,writer,runner,reader):
self.writer=writer
self.runner=runner
self.reader=reader
self.infiles=[]
self.outfiles=[]
def is_consistent(self,other):
# This documents what needs to be checked.
return self.writer.is_consistent(other.writer)
#------------------------------------------------
def nextstep(self):
if not self.writer.completed:
self.infiles,self.outfiles=self.writer.qwalk_input()
while True:
status=resolve_status(self.runner,self.reader,self.outfiles)
print("%s status: %s"%(self.writer.qmc_type,status))
if status=="running":
return
elif status=="not_started":
stdoutfiles=[x+".stdout" for x in self.infiles]
self.runner.run(self.infiles,stdoutfiles)
elif status=="ready_for_analysis":
#This is where we (eventually) do error correction and resubmits
self.reader.collect(self.outfiles)
break
elif status=='done':
break
else:
return
#------------------------------------------------
def write_summary(self):
self.reader.write_summary()
#------------------------------------------------
def generate_report(self):
return {}
#----------------------------------------
def status(self):
if self.reader.completed:
return 'ok'
else:
return 'not_finished'
#######################################################################
class PySCFManager:
def __init__(self,writer,runner,reader):
self.writer=writer
self.runner=runner
self.reader=reader
self.driverfn='pyscf_driver.py'
self.infiles=[]
self.outfiles=[]
#------------------------------------------------
def is_consistent(self,other):
# This documents what needs to be checked.
return self.writer.is_consistent(other.writer)
#------------------------------------------------
def nextstep(self):
if not self.writer.completed:
self.infiles,self.outfiles,self.chkfiles=self.writer.pyscf_input(self.driverfn)
while True:
status=resolve_status(self.runner,self.reader,self.outfiles)
print("PySCF status",status)
if status=="running":
return
elif status=="not_started":
self.runner.run(self.infiles,self.outfiles)
elif status=="ready_for_analysis":
#This is where we (eventually) do error correction and resubmits
self.reader.collect(self.outfiles,self.chkfiles)
break
elif status=='done':
break
else:
return
#------------------------------------------------
def write_summary(self):
self.reader.write_summary()
#----------------------------------------
def status(self):
if self.reader.completed:
return 'ok'
else:
return 'not_finished'