diff --git a/app/forms.py b/app/forms.py index eaaf547..fb2ecf0 100644 --- a/app/forms.py +++ b/app/forms.py @@ -52,4 +52,4 @@ class generatePDBQTS(FlaskForm): name = StringField('Compound Name (Optional)') class PyMedSearch(FlaskForm): - query = StringField('Search Query for PubMed',default="Covid-19",validators=[DataRequired()]) \ No newline at end of file + query = StringField('Search Query for PubMed',default="Query",validators=[DataRequired()]) \ No newline at end of file diff --git a/app/misc.ini b/app/misc.ini index 875fa7d..cdf439c 100644 --- a/app/misc.ini +++ b/app/misc.ini @@ -9,4 +9,6 @@ PL01 = Failed to fetch the PDB, please check the PDB Code DB01 = This Job ID does not exist 😠. If you think this is an error, please contact us. -CW01 = Looks like an invalid PDB ID \ No newline at end of file +CW01 = Looks like an invalid PDB ID + +PC00 = Could not find any compound on PubChem matching the query. \ No newline at end of file diff --git a/app/templates/error.html b/app/templates/error.html index b605430..54656ba 100644 --- a/app/templates/error.html +++ b/app/templates/error.html @@ -3,7 +3,7 @@ {% block main %}

Oh Snap! An error occured

-

Error Code: {{code}}

+

Error Description: {{description}}

+
+
+ +
+ + + {% if result %} +

Search Results

+ {% for x in range(result|length) %} + + +
+
+
+
+ +
+
+
+
+
CID: {{result[x]["CID"]}}
+

Canonical SMILES: {{result[x]["CanonicalSMILES"]}}

+

Isomeric SMILES: {{result[x]["IsomericSMILES"]}}

+

2D Fingerprint {{result[x]["Fingerprint2D"]}}

+
+
+
+
+ {% endfor %} + {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index dfd33e2..142229b 100644 --- a/app/views.py +++ b/app/views.py @@ -14,6 +14,8 @@ from datetime import datetime,date import json import subprocess +import requests + import logging import logzero from logzero import logger @@ -100,6 +102,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()