mirror of
https://github.com/bckelley/avogadrio.git
synced 2026-08-24 10:14:10 -05:00
Add SMILES rendering
This commit is contained in:
+27
-6
@@ -8,11 +8,15 @@ $(document).ready ->
|
||||
|
||||
previewElement = $ 'body'
|
||||
compoundTextBox = $ '.comp-name'
|
||||
smilesTextBox = $ '.comp-smiles'
|
||||
invalidCompoundMessage = $ '.row-error'
|
||||
|
||||
getCompoundName = ->
|
||||
encodeURIComponent compoundTextBox.val().replace(/\s/g, '')
|
||||
|
||||
getCompoundSmiles = ->
|
||||
encodeURIComponent smilesTextBox.val()
|
||||
|
||||
# URL builder functions for API.
|
||||
|
||||
buildUrl = (width, height, foreground, background, name) ->
|
||||
@@ -21,23 +25,36 @@ $(document).ready ->
|
||||
buildMoleculeOnlyUrl = (width, height, foreground, name) ->
|
||||
"/api/name/#{width}/#{height}/#{foreground}/#{name}"
|
||||
|
||||
buildSmilesMoleculeOnlyUrl = (width, height, foreground, name) ->
|
||||
"/api/smiles/#{width}/#{height}/#{foreground}/#{name}"
|
||||
|
||||
checkMoleculeName = (name, success, fail) ->
|
||||
$.get "/api/name/exists/#{name}", (data) ->
|
||||
if data then success() else fail()
|
||||
|
||||
|
||||
checkSmiles = (smiles, success, fail) ->
|
||||
success()
|
||||
|
||||
# Actions to take when we refresh the preview.
|
||||
|
||||
failPreview = ->
|
||||
invalidCompoundMessage.show()
|
||||
|
||||
refreshPreview = ->
|
||||
compoundName = getCompoundName()
|
||||
url = buildMoleculeOnlyUrl screenWidth, screenHeight, foregroundColor, getCompoundName()
|
||||
previewElement.css 'background', "url(#{url})"
|
||||
resetBackground = (url) ->
|
||||
alert url
|
||||
previewElement.css 'background', "url('#{url}')"
|
||||
previewElement.css 'background-color', "##{backgroundColor}"
|
||||
previewElement.css 'background-position', '50% 50%'
|
||||
previewElement.css 'background-repeat', 'no-repeat'
|
||||
|
||||
|
||||
refreshPreview = ->
|
||||
url = buildMoleculeOnlyUrl screenWidth, screenHeight, foregroundColor, getCompoundName()
|
||||
resetBackground(url)
|
||||
|
||||
refreshSmilesPreview = ->
|
||||
url = buildSmilesMoleculeOnlyUrl screenWidth, screenHeight, foregroundColor, getCompoundSmiles()
|
||||
resetBackground(url)
|
||||
|
||||
# Let's initialize the color pickers.
|
||||
|
||||
$('.picker-fg').spectrum
|
||||
@@ -67,6 +84,10 @@ $(document).ready ->
|
||||
$('.update-btn').on 'click', (e) ->
|
||||
invalidCompoundMessage.hide()
|
||||
checkMoleculeName getCompoundName(), refreshPreview, failPreview
|
||||
|
||||
$('.update-smiles-btn').on 'click', (e) ->
|
||||
# invalidCompoundMessage.hide()
|
||||
checkSmiles getCompoundSmiles(), refreshSmilesPreview, failPreview
|
||||
|
||||
# Download button should open rendered image for download.
|
||||
|
||||
|
||||
@@ -62,6 +62,24 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tool-section">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="section-lbl">SMILES</div>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mtop-10">
|
||||
<div class="col-xs-12">
|
||||
<input type="text" class="comp-smiles dark-tbox" value="CCN(CC)C1=CC2=C(C=C1)N=C3C4=CC=CC=C4C(=O)C=C3O2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mtop-10">
|
||||
<div class="col-xs-12 text-right">
|
||||
<button class="update-smiles-btn">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tool-section mtop-10">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
|
||||
+10
-2
@@ -97,7 +97,11 @@ $app->get('/api/smiles/{width}/{height}/{bgcolor}/{fgcolor}/{smiles}', function
|
||||
$img->insert($molecule, 'center');
|
||||
|
||||
// Send image out
|
||||
echo $img->response();
|
||||
return new \Symfony\Component\HttpFoundation\Response(
|
||||
$img->response('png'),
|
||||
200,
|
||||
['Content-Type' => 'image/png']
|
||||
);
|
||||
});
|
||||
|
||||
$app->get('/api/name/{width}/{height}/{bgcolor}/{fgcolor}/{name}', function ($width, $height, $bgcolor, $fgcolor, $name) use ($app, $twig, $config) {
|
||||
@@ -116,7 +120,11 @@ $app->get('/api/name/{width}/{height}/{bgcolor}/{fgcolor}/{name}', function ($wi
|
||||
});
|
||||
|
||||
$app->get('/api/smiles/{width}/{height}/{color}/{smiles}', function ($width, $height, $color, $smiles) use ($app, $twig, $config) {
|
||||
echo renderScaledMolecule($width, $height, $color, $smiles)->response();
|
||||
return new \Symfony\Component\HttpFoundation\Response(
|
||||
renderScaledMolecule($width, $height, $color, $smiles)->response('png'),
|
||||
200,
|
||||
['Content-Type' => 'image/png']
|
||||
);
|
||||
});
|
||||
|
||||
$app->get('/api/name/exists/{name}', function ($name) use ($config) {
|
||||
|
||||
Reference in New Issue
Block a user