aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2020-09-16 20:00:35 +0530
committerNavan Chauhan <navanchauhan@gmail.com>2020-09-16 20:00:35 +0530
commita76126e01e3e8d6ed47a823636a809dad1e58283 (patch)
treefb13239dcb0a06aea267e68d63dc02a4bdf790ea /app
parentca50f9cb6943f7010ab2eec1a23cad7896d7b553 (diff)
added pubchem search
Diffstat (limited to 'app')
-rw-r--r--app/forms.py2
-rw-r--r--app/misc.ini4
-rw-r--r--app/templates/error.html2
-rw-r--r--app/templates/home.html1
-rw-r--r--app/templates/search-pubchem.html48
-rw-r--r--app/views.py16
6 files changed, 70 insertions, 3 deletions
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 %}
<h2>Oh Snap! An error occured</h2>
- <p>Error Code: {{code}}</p>
+ <div class="alert alert-warning" role="alert">Error Code: {{code}}</div>
<p>Error Description: {{description}}</p>
<!--<section>
<style>
diff --git a/app/templates/home.html b/app/templates/home.html
index 10724d7..8386dac 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -18,6 +18,7 @@
<h3>Researching</h3>
<ul>
<li><a href="{{ url_for('pubmed') }}">PubMed Search</a> - Handy PubMed search with direct download links</li>
+ <li><a href="{{url_for('pubchem')}}">PubChem Search</a> - Get Compound SMILES</li>
<li>Qrious App - You can enter a question for a set of papers (e.g. ChemRxiv preprints) and it uses AI to answer it for each individual paper based on their abstract</li>
</ul>
diff --git a/app/templates/search-pubchem.html b/app/templates/search-pubchem.html
new file mode 100644
index 0000000..9b8e7cb
--- /dev/null
+++ b/app/templates/search-pubchem.html
@@ -0,0 +1,48 @@
+{% extends 'base.html' %}
+
+{% block main %}
+ <h1>SMILES Search</h1>
+ <p>Get Compound SMILES through PubChem.</p>
+ <form action="{{ url_for('pubchem') }}" method="post" enctype="multipart/form-data">
+ {% include 'flash_messages.html' %}
+ {{ form.csrf_token }}
+ <div class="form-row">
+ {{ form.query.label }}
+ {{ form.query(class="form-control")}}
+ </div>
+ <!--<div class="form-row">
+ {\{ form.modelSelection.label }}
+ {\{ form.modelSelection(class="form-control")}}
+ </div>-->
+ <br>
+ <div class="form-row">
+ <button type="submit" class="btn btn-primary">Search</button>
+ </div>
+ </form>
+
+ {% if result %}
+ <h3>Search Results</h3>
+ {% for x in range(result|length) %}
+ <!--<i>{\{result}}</i>-->
+ <!--<p>{{result[x]}}</p>-->
+ <div class="card mb-3">
+ <div class="row no-gutters">
+ <div class="col-md-4 text-white bg-dark">
+ <div class="card-body">
+ <img src="https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/{{result[x]['CID']}}/PNG" class="card-img">
+ </div>
+ </div>
+ <div class="col-md-8">
+ <div class="card-body">
+ <h5 class="card-title"><b>CID:</b> <a href="https://pubchem.ncbi.nlm.nih.gov/compound/{{result[x]['CID']}}">{{result[x]["CID"]}}</a></h5>
+ <p class="card-text"><b>Canonical SMILES: </b>{{result[x]["CanonicalSMILES"]}}</p>
+ <p class="card-text"><b>Isomeric SMILES: </b>{{result[x]["IsomericSMILES"]}}</p>
+ <p class="card-text"><b>2D Fingerprint </b>{{result[x]["Fingerprint2D"]}}</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ {% 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()