diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-09-10 00:49:32 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2020-09-10 00:49:32 +0530 |
commit | 85001f57a619086298af2c283d0e19e426b75dc3 (patch) | |
tree | 0c44d892aa0d57ab9f8807e4be3d3032732f80f3 | |
parent | e8c3a2e2a04488a23207076f7db14b267d25528c (diff) |
created a pdbqt convertor utility
-rw-r--r-- | app/forms.py | 6 | ||||
-rw-r--r-- | app/templates/home.html | 1 | ||||
-rw-r--r-- | app/templates/pdbqt_form.html | 42 | ||||
-rw-r--r-- | app/views.py | 75 |
4 files changed, 122 insertions, 2 deletions
diff --git a/app/forms.py b/app/forms.py index 4a3f880..eaaf547 100644 --- a/app/forms.py +++ b/app/forms.py @@ -45,5 +45,11 @@ class generateSMILES(FlaskForm): n = IntegerField('Number of Molecules to Generate',default=1,validators=[DataRequired()]) #modelSelection = SelectField('Model',choices=[("alpha","Alpha"),("beta","Beta")]) +class generatePDBQTS(FlaskForm): + jobType = SelectField(u'Generate for Protein or Ligand', choices=[("", "Protein or Ligand"),('protein', 'Protein (PDB)'), ('ligand', 'Ligand (SMILES)')], default='SelectOption') + pdb = StringField('PDB ID') + smiles = StringField('SMILES') + 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 diff --git a/app/templates/home.html b/app/templates/home.html index bf4cf32..f1f340a 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -23,6 +23,7 @@ <h3>Misc.</h3> <ul> + <li><a href="{{url_for('generate_pdbqts')}}">Generate PDBQTs</a> - Generate PDBQTs for your compounds or proteins</li> <li><a href="{{url_for('editor')}}">Editor</a> - Simple Molecular Editor powered by Kekule.js</li> <li><a href="{{ url_for('status')}}">Job Status</a> - Check the job status </li> <li><a href="{{ url_for('visualise')}}">Visualise</a> - Molecular Viewer </li> diff --git a/app/templates/pdbqt_form.html b/app/templates/pdbqt_form.html new file mode 100644 index 0000000..09cd1b0 --- /dev/null +++ b/app/templates/pdbqt_form.html @@ -0,0 +1,42 @@ + +{% extends 'base.html' %} + +{% block main %} + <h2>Generate PDBQTs</h2> + + <script> + function makeVisible() { + + var val = document.getElementById("jobType").value; + + if (val === "protein") { + document.getElementById("pdb").disabled = false; + document.getElementById('smiles').disabled = true; + document.getElementById('name').disabled = true; + } + else if (val=='ligand') { + document.getElementById('smiles').disabled = false; + document.getElementById("pdb").disabled = true; + document.getElementById("name").disabled = false; + } +} + </script> + + <form method="post" action="{{ url_for('generate_pdbqts') }}"> + {% include 'flash_messages.html' %} + {{ form.csrf_token }} + <div class="form-group"> + {{ form.jobType.label }} {{ form.jobType(**{"onchange":"makeVisible()","class":"form-control"}) }} + </div> + <div class="form-group"> + {{ form.pdb.label }} {{ form.pdb(**{"disabled":"false","class":"form-control"}) }} + </div> + <div class="form-group"> + {{ form.smiles.label }} {{ form.smiles(**{"disabled":"true","class":"form-control"}) }} + </div> + <div class="form-group"> + {{ form.name.label }} {{ form.name(**{"disabled":"true","class":"form-control"}) }} + </div> + <button type="submit" class="btn btn-primary">Submit</button> +</form> +{% endblock %}
\ No newline at end of file diff --git a/app/views.py b/app/views.py index 86a01fd..1e6b269 100644 --- a/app/views.py +++ b/app/views.py @@ -5,7 +5,7 @@ Werkzeug Documentation: http://werkzeug.pocoo.org/documentation/ """ import os from app import app -from flask import render_template, request, flash +from flask import render_template, request, flash, send_file from werkzeug.utils import secure_filename from random import choice, shuffle from string import digits, ascii_lowercase @@ -16,7 +16,7 @@ import subprocess # Note: that when using Flask-WTF we need to import the Form Class that we created # in forms.py -from .forms import MyForm, curieForm, statusForm, generateSMILES, PyMedSearch, dockSingleForm +from .forms import MyForm, curieForm, statusForm, generateSMILES, PyMedSearch, dockSingleForm, generatePDBQTS def gen_word(N, min_N_dig, min_N_low): choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low @@ -143,6 +143,77 @@ def wtform(): flash_errors(myform) return render_template('wtform.html', form=myform) +@app.route('/PDBQTs',methods=['GET','POST']) +def generate_pdbqts(): + myform = generatePDBQTS() + + if request.method == 'POST': + if myform.validate_on_submit(): + pdbId = myform.pdb.data + smiles = myform.smiles.data + name = myform.name.data + if (len(pdbId)==0) and (len(smiles)==0): + print("Nothing Submitted!") + flash("Invalid Submission!",'danger') + if len(smiles) != 0: + import oddt + try: + mol = oddt.toolkit.readstring('smi', smiles) + except: + return render_template('error.html',code="OD01",description="Could not convert SMILES to molecule, please check the SMILES") + try: + mol.make3D() + mol.calccharges() + except: + return render_template('error.html',code="OD02",description="Failed to add charges to molecule") + from oddt.docking.AutodockVina import write_vina_pdbqt + + try: + write_vina_pdbqt(mol,'app',flexible=False) + except: + return render_template('error.html',code="OD03",description="Failed to write the converted PDBQT file") + path = ".pdbqt" + if ".pdbqt" in name: + fname = name + else: + fname = name + ".pdbqt" + return send_file(path,attachment_filename=fname,as_attachment=True) + if len(pdbId) != 0: + from plip.basic import config + from plip.exchange.webservices import fetch_pdb + from plip.structure.preparation import create_folder_if_not_exists, extract_pdbid + from plip.structure.preparation import tilde_expansion, PDBComplex + + try: + pdbfile, pdbid = fetch_pdb(pdbId.lower()) + except: + return render_template('error.html',code="PL01",description="Failed to fetch the PDB, please check the PDB Code") + pdbpath = tilde_expansion('%s/%s.pdb' % (config.BASEPATH.rstrip('/'), pdbid)) + create_folder_if_not_exists(config.BASEPATH) + with open(pdbpath, 'w') as g: + g.write(pdbfile) + import oddt + from oddt.docking.AutodockVina import write_vina_pdbqt + try: + receptor = next(oddt.toolkit.readfile("pdb",pdbpath.split("./")[1])) + receptor.calccharges() + except Exception: + receptor = next(oddt.toolkits.rdk.readfile("pdb",pdbpath.split("./")[1])) + receptor.calccharges() + + try: + path = write_vina_pdbqt(receptor,'app',flexible=False) + except: + return render_template('error.html',code="OD03",description="Failed to write the converted PDBQT file") + os.rename(path,"app/.pdbqt") + path = ".pdbqt" + fname = pdbId.upper() + ".pdqbt" + return send_file(path,attachment_filename=fname,as_attachment=True) + flash_errors(myform) + return render_template('pdbqt_form.html',form=myform) + + + tfWorking = 0 if tfWorking == -1: |