diff --git a/ippisite/ippidb/templates/compound_list.html b/ippisite/ippidb/templates/compound_list.html index f48c732f18f399514d8f747f3f6a557995ec4dc5..53d39762cc0e53fb5e0792e4f1036920e86a6a7d 100644 --- a/ippisite/ippidb/templates/compound_list.html +++ b/ippisite/ippidb/templates/compound_list.html @@ -174,6 +174,6 @@ {% include "slider_modal.html" with label="AlogP" param_name="a_log_p" param_min=a_log_p_min param_max=a_log_p_max param_value=a_log_p step='1' param_label='Select a cutoff value for the AlogP of the compounds to be selected'%} {% include "slider_modal.html" with label="H donors" param_name="nb_donor_h" param_min=nb_donor_h_min param_max=nb_donor_h_max param_value=nb_donor_h step='1' param_label='Select a cutoff value for the number of H donors in the compounds to be selected'%} {% include "slider_modal.html" with label="Publications" param_name="pubs" param_min=pubs_min param_max=pubs_max param_value=pubs step='1' param_label='Select a cutoff value for the number of publications mentioning the compounds to be selected'%} - {% include "marvinjs_modal.html" %} + {% include "marvinjs_modal.html" with smiles=similar_to %} {% endblock %} diff --git a/ippisite/ippidb/templates/marvinjs_modal.html b/ippisite/ippidb/templates/marvinjs_modal.html index 157a83a19943b0278346a68072a0982284e6caa7..2fb162352cf8ff42637e8933b0c32fba1a8063eb 100644 --- a/ippisite/ippidb/templates/marvinjs_modal.html +++ b/ippisite/ippidb/templates/marvinjs_modal.html @@ -9,7 +9,7 @@ </div> <div class="modal-body"> Sketch or upload (in .mol format and in 2D only) the query structure here - <iframe id="marviniframe" src="/static/marvin-ippidbeditor.html" style="overflow: hidden; min-width: 700px; min-height: 500px; border: 1px solid darkgray;" /> + <iframe id="marviniframe" src="/static/marvin-ippidbeditor.html" data-smiles="{{ smiles }}" style="overflow: hidden; min-width: 700px; min-height: 500px; border: 1px solid darkgray;" /> </iframe> </div> <div class="modal-footer"> @@ -21,10 +21,24 @@ var marvinSketcherInstance; MarvinJSUtil.getEditor("marviniframe").then(function(sketcherInstance) { marvinSketcherInstance = sketcherInstance; + $('#modal-marvin').on('shown.bs.modal', function (e) { + var smilesToLoad = $('#marviniframe').attr('data-smiles'); + if(smilesToLoad!=''){ + $.ajax({ + url: '/utils/smi2mol', + data: {'smiString':smilesToLoad}, + success: function(data){ + var molString = data.mol; + marvinSketcherInstance.importStructure("mol", molString).catch(function(error, toto) { + console.log("error importing MOL file into MarvinJS:", error); + }); + } + }); + } + }); $('#marvinApplyButton').click(function(){ $('#modal-marvin').modal('hide'); marvinSketcherInstance.exportStructure("mol").then(function(source) { - //alert(source); $.ajax({ url: '/utils/mol2smi', data: {'molString':source}, diff --git a/ippisite/ippidb/urls.py b/ippisite/ippidb/urls.py index b0cbe0f181aaab15f19a8d2a0b9c53021198f4b7..1b9bda0c803b04340c30c242e93a76b9798af65b 100644 --- a/ippisite/ippidb/urls.py +++ b/ippisite/ippidb/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ url(r'^admin-session/add/$', ippidb_wizard, name='ippidb'), url(r'^admin-session/update/$', views.update, name='update'), url(r'^utils/mol2smi$', views.convert_mol2smi, name='mol2smi'), + url(r'^utils/smi2mol$', views.convert_smi2mol, name='smi2mol'), ] from django.conf import settings diff --git a/ippisite/ippidb/views.py b/ippisite/ippidb/views.py index 9f85b1eacf41b34f96d954b062a9047a105d4a46..02e5b8b6aa66b779371cce23a50bc676e0d2d459 100644 --- a/ippisite/ippidb/views.py +++ b/ippisite/ippidb/views.py @@ -14,7 +14,7 @@ from formtools.wizard.views import SessionWizardView, NamedUrlSessionWizardView import ippidb from .forms import * -from .utils import mol2smi +from .utils import mol2smi, smi2mol from .models import Protein, Bibliography, ProteinDomainComplex, ProteinDomainBoundComplex, RefCompoundBiblio, TestActivityDescription, Compound, Ppi, Disease, Taxonomy, LeLleBiplotData, PcaBiplotData, PpiFamily, CompoundTanimoto, create_tanimoto from .ws import get_pdb_uniprot_mapping @@ -358,3 +358,9 @@ def convert_mol2smi(request): smiles_string = mol2smi(mol_string) resp = {'smiles': smiles_string} return JsonResponse(resp) + +def convert_smi2mol(request): + smi_string = request.GET.get('smiString') + mol_string = smi2mol(smi_string) + resp = {'mol': mol_string} + return JsonResponse(resp)