aboutsummaryrefslogtreecommitdiff
path: root/app/misc
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2020-09-27 01:11:23 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2020-09-27 01:11:23 +0530
commit019c38039873cd60df915b8026bd8abd50e648b5 (patch)
tree53d7ae4bf1752acf336dd75d07df324c1075a886 /app/misc
parent12bcd3b48a1279cac3624b8d55c2286a6677a9de (diff)
removed common functions and added to misc
Diffstat (limited to 'app/misc')
-rw-r--r--app/misc/__init__.py0
-rw-r--r--app/misc/common.py33
-rw-r--r--app/misc/email.py48
3 files changed, 81 insertions, 0 deletions
diff --git a/app/misc/__init__.py b/app/misc/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/misc/__init__.py
diff --git a/app/misc/common.py b/app/misc/common.py
new file mode 100644
index 0000000..1463c73
--- /dev/null
+++ b/app/misc/common.py
@@ -0,0 +1,33 @@
+import os
+import glob
+from shutil import copy
+
+def CopyContentOfFolder(sauce,destination):
+ src_files = os.listdir(sauce)
+ for file_name in src_files:
+ full_file_name = os.path.join(sauce, file_name)
+ if os.path.isfile(full_file_name):
+ copy(full_file_name, destination)
+
+def RemoveAllFilesMatching(directory,pattern):
+ print(directory+"/*"+pattern)
+ FileList = glob.glob(directory+"/*"+pattern)
+ for FilePath in FileList:
+ try:
+ os.remove(FilePath)
+ except:
+ print("Error in removing misc file")
+
+def get3DModel(protein,ligand):
+ try:
+ import pymol2
+ except ImportError:
+ print("🤭 PyMOL 2 has not been installed correctly")
+ return None
+ session = pymol2.PyMOL()
+ session.start()
+ cmd = session.cmd
+ cmd.load(protein,"target")
+ cmd.load(ligand,"ligand")
+ cmd.save("model.dae")
+ session.stop() \ No newline at end of file
diff --git a/app/misc/email.py b/app/misc/email.py
new file mode 100644
index 0000000..d2967bb
--- /dev/null
+++ b/app/misc/email.py
@@ -0,0 +1,48 @@
+import smtplib
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from email.mime.base import MIMEBase
+from email import encoders
+
+import configparser
+iniConfig = configparser.ConfigParser()
+iniConfig.read('config.ini')
+
+try:
+ iniConfig['DATABASE']
+except KeyError:
+ iniConfig.read("../config.ini")
+
+
+def email(toaddr,jobID,date,description,zipArchive=None,complete=True,reason=None):
+ fromaddr = iniConfig['SMTP']['EMAIL']
+
+ msg = MIMEMultipart()
+ msg['From'] = fromaddr
+ msg['To'] = toaddr
+ msg['Subject'] = "Curie Web Results for Job ID " + str(jobID)
+ if complete:
+ 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)
+ else:
+ body = "Task unsuccessful :( \n Job was submitted on {} with the description {}".format(date, description)
+
+ if reason != None:
+ body = reason + str(body)
+
+ msg.attach(MIMEText(body, 'plain'))
+ if zipArchive != None:
+ filename = "Curie_Web_Results_Job_ID_" + str(jobID) + ".zip"
+ p = MIMEBase('application', 'octet-stream')
+ with open((str(zipArchive) + ".zip"), "rb") as attachment:
+ p.set_payload((attachment).read())
+ encoders.encode_base64(p)
+ p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
+ msg.attach(p)
+
+ s = smtplib.SMTP(iniConfig['SMTP']['SERVER'], iniConfig['SMTP']['PORT'])
+ s.starttls()
+ s.login(fromaddr, iniConfig['SMTP']['PASSWORD'])
+ text = msg.as_string()
+
+ s.sendmail(fromaddr, toaddr, text)
+ s.quit()