diff options
Diffstat (limited to 'app/views.py')
-rw-r--r-- | app/views.py | 90 |
1 files changed, 41 insertions, 49 deletions
diff --git a/app/views.py b/app/views.py index dfd33e2..1f02162 100644 --- a/app/views.py +++ b/app/views.py @@ -14,6 +14,11 @@ from datetime import datetime,date import json import subprocess +import mysql.connector as con +from mysql.connector.errors import InterfaceError + +import requests + import logging import logzero from logzero import logger @@ -100,6 +105,20 @@ def pubmed(): flash_errors(form) return render_template('search.html',form=form) +@app.route('/Compound-Search',methods=['GET','POST']) +def pubchem(): + form = PyMedSearch() + + if request.method == 'POST' and form.validate_on_submit(): + q = form.query.data + response = requests.get('https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/%s/property/Fingerprint2D,CanonicalSMILES,IsomericSMILES/JSON' % q.strip()) + if response.status_code == 404: + return render_template('error.html',code="PC00",description=errors["PC00"]) + search = response.json()["PropertyTable"]["Properties"] + print(search) + return render_template('search-pubchem.html',result=search,form=form) + return render_template('search-pubchem.html',form=form) + @app.route('/Status',methods=['GET','POST']) def status(): taskStatusForm = statusForm() @@ -107,9 +126,12 @@ def status(): if request.method == 'POST': if taskStatusForm.validate_on_submit(): jobID = taskStatusForm.jobID.data - import mysql.connector as con - mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) - mycursor = mycon.cursor() + + try: + mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) + mycursor = mycon.cursor() + except InterfaceError: + return render_template('error.html',code="DB00",description=errors['DB00']) sqlQuery = 'select id, protein_name, ligand_name, date, description, done, pdb from curieweb where id="%s"' % (jobID) mycursor.execute(sqlQuery) records = mycursor.fetchall() @@ -136,37 +158,6 @@ def status(): flash_errors(taskStatusForm) return render_template('job_status_form.html',form=taskStatusForm) -@app.route('/basic-form', methods=['GET', 'POST']) -def basic_form(): - if request.method == 'POST': - firstname = request.form['firstname'] - lastname = request.form['lastname'] - email = request.form['email'] - - return render_template('result.html', - firstname=firstname, - lastname=lastname, - email=email) - - return render_template('form.html') - -@app.route('/wtform', methods=['GET', 'POST']) -def wtform(): - myform = MyForm() - - if request.method == 'POST': - if myform.validate_on_submit(): - # Note the difference when retrieving form data using Flask-WTF - # Here we use myform.firstname.data instead of request.form['firstname'] - firstname = myform.firstname.data - lastname = myform.lastname.data - email = myform.email.data - - flash('You have successfully filled out the form', 'success') - return render_template('result.html', firstname=firstname, lastname=lastname, email=email) - - flash_errors(myform) - return render_template('wtform.html', form=myform) @app.route('/PDBQTs',methods=['GET','POST']) def generate_pdbqts(): @@ -288,8 +279,8 @@ def generate(): return render_template('generate.html',expName=j["exp_name"],epochs=j["num_epochs"],optimizer=j["optimizer"].capitalize(), form=form) -@app.route('/Dock', methods=['GET', 'POST']) -def dock_upload(): +@app.route('/Dock-Manual', methods=['GET', 'POST']) +def dock_manual(): form = curieForm() if request.method == 'POST' and form.validate_on_submit(): @@ -301,9 +292,11 @@ def dock_upload(): sx,sy,sz = str(form.size_x.data), str(form.size_y.data), str(form.size_z.data) email = form.email.data - import mysql.connector as con - mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) - mycursor = mycon.cursor() + try: + mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) + mycursor = mycon.cursor() + except InterfaceError: + return render_template("error.html",code="DB00",description=errors['DB00']) import tempfile with tempfile.TemporaryDirectory() as directory: @@ -332,10 +325,10 @@ def dock_upload(): return render_template('display_result.html', filename="OwO", description=description,job=jobID) flash_errors(form) - return render_template('dock_upload.html', form=form) + return render_template('dock_manual.html', form=form) -@app.route('/Dock-Single', methods=['GET', 'POST']) -def dock_upload_single(): +@app.route('/Dock-Automatic', methods=['GET', 'POST']) +def dock_automatic(): form = dockSingleForm() if request.method == 'POST' and form.validate_on_submit(): @@ -349,9 +342,11 @@ def dock_upload_single(): if len(pdb) != 4: return render_template("error.html",code="CW01",description=errors['CW01']) - import mysql.connector as con - mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) - mycursor = mycon.cursor() + try: + mycon = con.connect(host=app.config['DB_HOST'],user=app.config['DB_USER'],password=app.config['DB_PASSWORD'],port=app.config['DB_PORT'],database=app.config['DB_NAME']) + mycursor = mycon.cursor() + except InterfaceError: + return render_template('error.html',code="DB00",description=errors['DB00']) sqlQuery = "insert into curieweb (id, email, pdb, ligand_smile, ligand_name, date, description) values (%s,%s,%s,%s,%s,CURDATE(),%s) " jobID = gen_word(16, 1, 1) @@ -369,7 +364,7 @@ def dock_upload_single(): return render_template('display_result.html', filename="OwO", description=description,job=jobID) flash_errors(form) - return render_template('dock_upload_single.html', form=form) + return render_template('dock_automatic.html', form=form) ### # The functions below should be applicable to all Flask apps. @@ -390,9 +385,6 @@ def send_text_file(file_name): file_dot_text = file_name + '.txt' return app.send_static_file(file_dot_text) -@app.route('/debug-sentry') -def trigger_error(): - division_by_zero = 1 / 0 @app.after_request def add_header(response): |