Curie-Web/app/dock_docker.py

101 lines
3.3 KiB
Python
Raw Normal View History

2020-07-06 14:27:35 +01:00
import mysql.connector as con
2020-08-24 11:57:31 +01:00
mycon = con.connect(host='192.168.1.6',user="curieweb",password="curie-web-russian-54",port=3306,database="curie")
2020-07-06 14:27:35 +01:00
mycursor = mycon.cursor()
sql_select_Query = "select * from curieweb where done=0 LIMIT 1"
mycursor.execute(sql_select_Query)
records = mycursor.fetchall()
2020-08-04 18:42:03 +01:00
if records == []:
print("Empty Set 😳")
print("No active task, exitting gracefully")
exit(0)
2020-07-06 14:27:35 +01:00
def email(zipArchive):
2020-07-06 14:27:35 +01:00
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
fromaddr = "navanchauhan@gmail.com"
toaddr = toEmail
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Curie Web Results for Job ID " + str(jobID)
body = "Attached Zip contains the docked files, PLIP report and PyMOL Visualisations. If the ZIP file does not contain these files, please report this issue by replying to this email. Job was submitted on {} with the description {}".format(date, description)
msg.attach(MIMEText(body, 'plain'))
filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
p = MIMEBase('application', 'octet-stream')
2020-07-07 07:57:10 +01:00
with open((str(zipArchive) + ".zip"), "rb") as attachment:
p.set_payload((attachment).read())
2020-07-06 14:27:35 +01:00
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
2020-07-21 09:03:43 +01:00
s.login(fromaddr, 'okrs shoc ahtk idui')
2020-07-06 14:27:35 +01:00
text = msg.as_string()
s.sendmail(fromaddr, toaddr, text)
s.quit()
receptor_name = "protein.pdbqt"
ligand_name = "ligand.pdbqt"
description = "Curie Web Task"
#print(records[0])
r = records[0]
jobID = r[0]
toEmail = r[1]
targetB = r[2]
2020-07-07 08:02:10 +01:00
if r[3] is not None:
receptor_name = str(r[3])
2020-07-07 08:02:10 +01:00
if r[6] is not None:
ligand_name = str(r[6])
2020-07-06 14:27:35 +01:00
ligandB = r[4]
configB = r[7]
date = r[8]
2020-07-07 08:02:10 +01:00
if r[9] is not None:
2020-07-06 14:27:35 +01:00
description = r[9]
import os
cd = os.getcwd()
f = os.path.join(cd,"static/uploads")
reportDirectory = os.path.join(f,"reports")
2020-07-06 14:27:35 +01:00
#t = os.path.join(f,"receptor",target)
#r = os.path.join(f,"ligands",ligand)
#c = os.path.join(f,"configs",config)
print(f)
import tempfile
from shutil import make_archive, copyfile
2020-07-06 14:27:35 +01:00
with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory)
os.chdir(directory)
# copy(t,os.getcwd())
# copy(r,os.getcwd())
# copy(c, os.getcwd())
2020-07-07 07:57:10 +01:00
with open(receptor_name,"wb") as file:
file.write(targetB)
with open(ligand_name,"wb") as file:
file.write(ligandB)
with open("config.txt","wb") as file:
file.write(configB)
2020-07-06 14:27:35 +01:00
os.system("docker run --rm -v ${PWD}:/results -w /results -u $(id -u ${USER}):$(id -g ${USER}) navanchauhan/curie-cli -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name))
#copy("report.pdf",f)
z = "Curie_Web_Result_"+str(jobID)
zi = os.path.join(f,z)
make_archive(zi, 'zip', directory)
#copy(("Curie_Web_Result_"+str(jobID)),f)
copyfile("report.pdf",os.path.join(reportDirectory,(str(jobID)+".pdf")))
2020-07-06 14:27:35 +01:00
email(zi)
#print((str(zi) + ".zip"))
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
2020-07-21 09:03:43 +01:00
mycon.commit()