Commit 2620b776 authored by Marco Govoni's avatar Marco Govoni
Browse files

Removed run from groundState.py

parent 8b11e184
......@@ -262,89 +262,3 @@ class GroundState() :
.. note:: You can use this method to add either upf or xml pseudopotentials. However it is forbidded to mix them.
"""
self.geom.addSpecies(symbol,url)
#
def run(self,session,executable=None,inputFile=None,outputFile=None,number_of_cores=2) :
"""runs the executable using rest api remotely..
:param session: object of instance Connection
:type symbol: Session
:param executable: name of executable
:type executable: string
:param executable: name of input file
:type executable: string
:param executable: name of output file
:type executable: string
:param executable: number of cores to run in
:type executable: int
:Example:
>>> session = Session("emailId")
>>> gs.run( session, "pw" )
>>> gs.run( session, "wstat" )
>>> gs.run( session, "pw", "pw.in", "pw.out", 3 )
"""
from westpy import Connection
assert( isinstance(session,Connection))
download_urls = []
output_dict = {}
if executable and ("pw" in str(executable).lower() or "wstat" in str(executable).lower() or "wfreq" in str(executable).lower()) :
if inputFile is None:
inputFile = str(executable)+".in"
if outputFile is None:
outputFile = str(executable)+".out"
for key in self.geom.species.keys() :
download_urls.append(self.geom.species[key]["url"])
try:
resturl = "http://imedevel.uchicago.edu:8000/runWestCode"
output = self.__runExecutable(executable,resturl,inputFile,session.getOutput(),download_urls,str(number_of_cores))
output_json = json.loads(output)
if "Error" in output_json:
print("Execution failed with the following error \n",output_json['Error'])
return None
elif "JOB DONE." not in str(output_json['output']).strip():
print("MPI execution failed with the following error: \n"+str(output))
return None
output_data = str(output_json['output']).strip()
if "pw" in executable:
output_dict = json.loads(output_json['output_dict'])
else:
output_dict = output_json['output_dict']
with open(outputFile, "w") as file :
file.write(str(output_data))
except Exception as e:
print("Session Expired! Invalid Request sent, Please recreate session and recheck your input. \n"+ e)
return None
else:
raise ValueError("Invalid Executable")
print("Generated ",outputFile)
return output_dict
def __runExecutable(self,executable,resturl,input_file,session_values,download_urls,number_of_cores) :
"""runs the executable using rest api remotely.
"""
try:
file_content = ""
with open(input_file,'r') as f :
for line in f :
file_content = file_content + line + "\\n"
except FileNotFoundError:
error = "Could not find "+ input_file + ". \n Generate input file "+ input_file+" and try again."
print(error)
return None
body = {'urls':download_urls,'file':file_content,'cmd_timeout':'600','script_type':str(executable),'no_of_cores':number_of_cores}
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes
headers = {'Content-Type':'application/json; charset=utf-8','emailId':session_values['emailId'],'token':session_values['token']}
response = ""
try:
response = requests.post(resturl, data = jsondataasbytes, headers=headers, timeout=None)
return response.text
except Exception as e:
print('The West Rest API response to longer than usual, Please try again later',e)
return None
return None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment