-
Notifications
You must be signed in to change notification settings - Fork 0
/
AD4.py
60 lines (53 loc) · 2.51 KB
/
AD4.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
import flask
import os
import shutil
import logging
import smtplib
import threading
import subprocess
import werkzeug
from flask.ext.restful import reqparse, MethodView
from mail_handler import *
ALLOWED_EXTENSIONS = set(['zip'])
class AD4(MethodView):
def allowed_file(self, filename):
return '.' in filename and filename.rsplit('.', 1)[-1] in ALLOWED_EXTENSIONS
def __init__(self):
self.working_dir = os.getcwd() + '/ad4_files/'
logging.info('AutoDock4 class started! Waiting for user to make requests.')
@login_required
def get(self):
return flask.render_template('ad4.html')
@login_required
def post(self):
threads = clean_threads()
logging.info('User requested to add new data.')
self.archivo = flask.request.files['file']
self.correo = flask.request.form.get('mail')
print type(self.archivo.filename)
if self.archivo and self.allowed_file(self.archivo.filename):
self.nombre = werkzeug.secure_filename(self.archivo.filename)
self.archivo.save(os.path.join(self.working_dir, self.nombre))
logging.info('Data loaded.')
threads.append(threading.Thread(target=self._run_docking))
threads[-1].start()
return flask.render_template('alt1.html')
return flask.render_template('alt2.html')
def _run_docking(self):
logging.info('Change directory and unzip files.')
os.chdir('./ad4_files')
subprocess.call(['unzip',os.path.join(os.getcwd() + '/', self.nombre)])
logging.info('Running autogrid and autodock.')
subprocess.call(['../../AD4/autogrid4','-p','grid.gpf','-l','grid.glg'])
subprocess.call(['../../AD4/autodock4','-p','dock.dpf','-l','dock.dlg'])
all_files = os.listdir(os.getcwd())
if self.nombre in all_files:
all_files.remove(self.nombre)
logging.info('Compressing all files.')
subprocess.call(['zip','temp_out.zip'] + all_files)
send_mail(self.correo, 'Results of AutoDock4 calculation', "Your output files are ready and were attached to this email as a zip file.", [self.nombre,"temp_out.zip"])
send_mail('zronyj@yahoo.com', 'Results of AutoDock4 calculation', "Your output files are ready and were attached to this email as a zip file.", [self.nombre,"temp_out.zip"])
logging.info('Changing directory, deleting files and recreating the folder.')
os.chdir('..')
shutil.rmtree(os.getcwd() + '/ad4_files')
os.mkdir('ad4_files')