Curie-Web/app/dock-manual.py

109 lines
4.1 KiB
Python
Raw Normal View History

2020-07-06 14:27:35 +01:00
import mysql.connector as con
from misc.common import get3DModel, CopyContentOfFolder, RemoveAllFilesMatching
from misc.email import email
import os
import sys
2020-09-27 09:40:20 +01:00
from misc.config import iniConfig
2020-09-11 14:07:16 +01:00
mycon = con.connect(host=iniConfig['DATABASE']['HOST'],user=iniConfig['DATABASE']['USER'],password=iniConfig['DATABASE']['PASSWORD'],port=iniConfig['DATABASE']['PORT'],database=iniConfig['DATABASE']['NAME'])
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
receptor_name = "protein.pdbqt"
ligand_name = "ligand.pdbqt"
description = "Curie Web Task"
#print(records[0])
r = records[0]
jobID = r[0]
toEmail = r[1]
toaddr = toEmail
2020-07-06 14:27:35 +01:00
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]
else:
description = "not specified"
2020-07-06 14:27:35 +01:00
cd = os.getcwd()
f = os.path.join(cd,"static/uploads")
reportDirectory = os.path.join(f,"reports")
2020-09-22 08:58:48 +01:00
scripts = os.path.join(cd,"scripts")
2020-09-02 12:55:51 +01:00
modelDirectory = os.path.join(f,"3DModels")
2020-07-06 14:27:35 +01:00
import tempfile
2020-09-22 08:58:48 +01:00
from shutil import make_archive, copyfile,copy
2020-07-06 14:27:35 +01:00
with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory)
os.chdir(directory)
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-09-22 08:58:48 +01:00
# Legacy Docker Curie-Cli Run
#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))
CopyContentOfFolder(scripts,directory)
os.system("./main.sh -r %s -l %s -c config.txt -dpi" % (receptor_name,ligand_name))
RemoveAllFilesMatching(directory,".py")
RemoveAllFilesMatching(directory,".sh")
2020-07-06 14:27:35 +01:00
z = "Curie_Web_Result_"+str(jobID)
zi = os.path.join(f,z)
make_archive(zi, 'zip', directory)
try:
copyfile("report.pdf",os.path.join(reportDirectory,(str(jobID)+".pdf")))
2020-09-27 09:40:20 +01:00
except FileNotFoundError:
reason = "Could not generate the report, this could be because of a failed docking job. Please check the ZIP archive for the configuration and converted PDBQTs and try submitting manually. "
email(toaddr,jobID,date,description,zipArchive=zi,reason=reason)
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
mycon.commit()
sys.exit(0)
2020-10-17 11:12:10 +01:00
"""
res = get3DModel(receptor_name,ligand_name.replace(".pdbqt","_out.pdbqt"))
if res == None:
reason = "Could not generate the 3D models."
email(toaddr,jobID,date,description,zipArchive=zi)
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
mycon.commit()
sys.exit(0)
2020-09-02 12:55:51 +01:00
os.system("collada2gltf -i model.dae -o model.gltf")
try:
copyfile("model.gltf",os.path.join(modelDirectory,(str(jobID)+".gltf")))
2020-09-27 09:40:20 +01:00
except FileNotFoundError:
print("Does not have Collada2GLTF Installed")
email(toaddr,jobID,date,description,zipArchive=zi)
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
mycon.commit()
exit(0)
2020-09-02 12:55:51 +01:00
arch = os.popen("uname -m").read()
2020-09-22 08:58:48 +01:00
print("Generating 3D Model")
2020-09-02 12:55:51 +01:00
if "x86" in arch:
2020-09-27 16:43:31 +01:00
os.system("docker run --rm -v $(pwd):/usr/app leon/usd-from-gltf:latest model.gltf model.usdz")
2020-09-02 12:55:51 +01:00
elif "aarch64" in arch:
2020-09-27 16:43:31 +01:00
os.system("docker run --rm -v $(pwd):/usr/app navanchauhan/usd-from-gltf:latest model.gltf model.usdz")
2020-09-02 12:55:51 +01:00
try:
copyfile("model.usdz",os.path.join(modelDirectory,(str(jobID)+".usdz")))
2020-09-27 09:40:20 +01:00
except FileNotFoundError:
2020-09-02 12:55:51 +01:00
print("Could not generate USDZ file")
2020-10-17 11:12:10 +01:00
"""
email(toaddr,jobID,date,description,zipArchive=zi)
2020-07-06 14:27:35 +01:00
mycursor.execute('UPDATE curieweb set done=1 where id="%s"' % (jobID))
2020-07-21 09:03:43 +01:00
mycon.commit()