Commit 9647ea0c authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

update MarvinJS

WARNING: the API key to MarvinJS is now in settings.py
parent e23298d8
Pipeline #11871 passed with stages
in 14 minutes and 32 seconds
......@@ -13,8 +13,8 @@ function update_molecule_composition_fields(){
}
function showModalFromMe(src){
$("#marviniframe").attr("data-smiles",$(src).closest(".smiles-inpout-and-edit").find(".molecule-composition").val());
$("#marviniframe").attr("data-smile-target",$(src).closest(".smiles-inpout-and-edit").find(".molecule-composition").attr("id"));
$("#marvin-div").attr("data-smiles",$(src).closest(".smiles-inpout-and-edit").find(".molecule-composition").val());
$("#marvin-div").attr("data-smile-target",$(src).closest(".smiles-inpout-and-edit").find(".molecule-composition").attr("id"));
$("#modal-marvin").modal();
return false;
}
......@@ -31,12 +31,12 @@ function apply_molecule_composition_tuning(src){
$(document).ready(function(){
apply_molecule_composition_tuning(".formset-item");
var marvinModal = new MarvinModal(
"marviniframe",
"marvin-div",
'modal-marvin',
'smiles-textarea',
'marvinApplyButton',
function (smilesString){
$("#"+$("#marviniframe").attr("data-smile-target")).val(smilesString).change();
$("#"+$("#marvin-div").attr("data-smile-target")).val(smilesString).change();
}
);
});
\ No newline at end of file
$(document).ready(function(){
var marvinModal = new MarvinModal(
"marviniframe",
'marvin-div',
'modal-marvin',
'smiles-textarea',
'marvinApplyButton',
function (smilesString){
var fingerprint = $('input[name=fingerprint]:checked').val();
modifyUrl('similar_to',fingerprint+':'+smilesString);
var fingerprint = '';
if(smilesString.trim()!==''){
fingerprint = $('input[name=fingerprint]:checked').val();
modifyUrl('similar_to',fingerprint+':'+smilesString);
}else{
modifyUrl('similar_to', null);
}
}
);
});
\ No newline at end of file
......@@ -6,14 +6,16 @@ class MarvinModal {
this.textAreaEl = $('#' + textAreaId);
this.exportCallback = exportCallback;
this.marvinSketcherInstance = null;
MarvinJSUtil.getEditor(iframeId).then(function(sketcherInstance) {
this.marvinSketcherInstance = sketcherInstance;
this.marvinSketcherInstance.on('molchange', function(){
this.exportSmiles(function(smilesString){
this.textAreaEl.val(smilesString);
if (typeof ChemicalizeMarvinJs !== "undefined"){
ChemicalizeMarvinJs.createEditor('#'+iframeId).then(function(sketcherInstance) {
this.marvinSketcherInstance = sketcherInstance;
this.marvinSketcherInstance.on('molchange', function(){
this.exportSmiles(function(smilesString){
this.textAreaEl.val(smilesString);
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
}
this.modalEl.on('shown.bs.modal', function(){
//NB: this must be setup only once the modal is shown otherwise
// it doesn't work with Firefox (see https://bugzilla.mozilla.org/show_bug.cgi?id=941146)
......@@ -34,20 +36,29 @@ class MarvinModal {
}
exportSmiles(callback){
$("#marvinApplyButton").prop("disabled",false);
this.marvinSketcherInstance.exportStructure("mol").then(function(molStr) {
molToSmiles(molStr, callback);
}.bind(this));
if(this.marvinSketcherInstance!=null){
$("#marvinApplyButton").prop("disabled",false);
this.marvinSketcherInstance.exportStructure("mol").then(function(molStr) {
molToSmiles(molStr, callback);
}.bind(this));
}else{
$("#marvinApplyButton").prop("disabled",false);
callback(this.textAreaEl.val());
}
}
importSmiles(smilesString){
if(smilesString!==''){
$("#marvinApplyButton").prop("disabled",true);
smilesToMol(smilesString,
function(molString){
$("#marvinApplyButton").prop("disabled",false);
return this.marvinSketcherInstance.importStructure("mol", molString);
}.bind(this));
if(this.marvinSketcherInstance!=null){
if(smilesString!==''){
$("#marvinApplyButton").prop("disabled",true);
smilesToMol(smilesString,
function(molString){
$("#marvinApplyButton").prop("disabled",false);
return this.marvinSketcherInstance.importStructure("mol", molString);
}.bind(this));
}else{
return this.marvinSketcherInstance.clear();
}
}
}
}
}
\ No newline at end of file
......@@ -5,9 +5,10 @@
{% block extra_js %}
{{block.super}}
<script src="/static/marvinjs-18/js/util.js"></script>
<script src="/static/marvinjs-18/js/marvinjslauncher.js"></script>
<script src="/static/marvinjs-18/gui/lib/promise-1.0.0.min.js"></script>
{% if marvinjs_apikey != None %}
<script src="https://marvinjs.chemicalize.com/v1/{{ marvinjs_apikey }}/client-settings.js"></script>
<script src="https://marvinjs.chemicalize.com/v1/client.js"></script>
{% endif %}
<script src="/static/js/ippidb-compoundws.js"></script>
<script src="/static/js/ippidb-marvinjsmodal.js"></script>
<script src="/static/js/compound_list.js"></script>
......
......@@ -10,10 +10,11 @@
<div class="modal-body">
<p>Paste the SMILES of your molecule here:</p>
<textarea id="smiles-textarea" class="form-control"></textarea>
<p><b>or</b></p>
<p>Sketch or upload (in .mol format and in 2D only) the query structure here:</p>
<iframe id="marviniframe" src="/static/marvin-ippidbeditor.html" data-smiles="{{ smiles }}" data-fingerprint="{{ fingerprint }}" style="overflow: hidden; width:100%; min-height: 500px; border: 1px solid darkgray;" />
</iframe>
{% if marvinjs_apikey != None %}
<p><b>or</b></p>
<p>Sketch or upload (in .mol format and in 2D only) the query structure here:</p>
<div id="marvin-div" data-smiles="{{ smiles }}" data-fingerprint="{{ fingerprint }}" style="overflow: hidden; width:100%; height: 500px; border: 1px solid darkgray;"></div>
{% endif %}
</div>
<div class="modal-footer">
<div class="container-fluid">
......
......@@ -12,6 +12,7 @@ from django.shortcuts import render
from .contribute import *
from .compound_query import *
from django.conf import settings
def index(request):
......@@ -37,3 +38,6 @@ def adminSession(request):
def update(request):
return render(request, 'update.html')
def marvinjs(request):
return {'marvinjs_apikey': settings.MARVINJS_APIKEY}
......@@ -191,4 +191,6 @@ LOGOUT_REDIRECT_URL = '/'
################################################################################
CRISPY_TEMPLATE_PACK = 'bootstrap4'
################################################################################
\ No newline at end of file
################################################################################
MARVINJS_APIKEY = '185f39ab08424e0db1fee2dc9354d3fb'
\ No newline at end of file
......@@ -17,7 +17,6 @@ from django.utils.translation import gettext_lazy
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
......@@ -82,6 +81,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'ippidb.views.marvinjs',
],
},
},
......@@ -184,4 +184,7 @@ LOGOUT_REDIRECT_URL = '/'
################################################################################
CRISPY_TEMPLATE_PACK = 'bootstrap4'
################################################################################
\ No newline at end of file
################################################################################
# MARVINJS API KEY
MARVINJS_APIKEY = None
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment