Collections:
Call getSmiles() and getSmarts() Nested
How to call getSmiles() and getSmarts() methods in 2 promises one nested in the other?
✍: FYIcenter.com
One way to avoid the bug mentioned in the previous tutorial
is to call ketcher.getSmiles() and ketcher.getSmarts() methods
in 2 promises one nested in the other.
This can be done by calling ketcher.getSmiles() first to create the first promise, and calling ketcher.getSmarts() inside both fulfilled and rejected handlers as shown in diagram below:
The following HTML document shows you how to call ketcher.getSmiles() and ketcher.getSmarts() in nested promises.
<html> <!-- export-as-SMILES-SMARTS-nested.html Copyright (c) FYIcenter.com. --> <head> <title>Export Chemical Structure in SMILES and SMARTS Formats</title> </head> <body> <p>Create a chemical structure, then click export buttons below the editor:</p> <iframe id=frmKetcher src="/ketcher/index.html" style="width: 680px; height: 400px;"></iframe> <p><button onclick="exportBoth();">Export in SMILES and SMARTS in nested promises</button></p> <p>SMILES:</p> <pre id=smiles style="background-color: #ddd;"></pre> <p>SMARTS:</p> <pre id=smarts style="background-color: #ddd;"></pre> <script> function exportBoth() { frm = document.getElementById("frmKetcher"); ketcher = frm.contentWindow.ketcher; exportSMILES(); } function exportSMILES() { let promise = ketcher.getSmiles(); promise.then( function(value) { document.getElementById("smiles").innerHTML = value; exportSMARTS(); }, function(error) { document.getElementById("smiles").innerHTML = error.toString(); exportSMARTS(); } ); } function exportSMARTS() { let promise = ketcher.getSmarts(); promise.then( function(value) { document.getElementById("smarts").innerHTML = value; }, function(error) { document.getElementById("smarts").innerHTML = error.toString(); } ); } </script> </body> </html>
Open the above HTML document on your local Web server. Draw a simple molecule structure in the editor.
Click "Export in SMILES and SMARTS in nested promises" button, you will see that both promises work correctly with SMILES and SMARTS strings returned to the page.
⇒ Call getSmiles() and getSmarts() Chained
2024-01-24, 431🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1003958 Names: InChIKey: WEHZADJOHQUSDT-UHFFFAOYS A-NSMILES: CCc5nc(C(N)=O...
Molecule Summary: ID: FYI-1002859 Names: InChIKey: HZSYWLUXRWAWOM-UHFFFAOYS A-NSMILES: NS(=O)(=O)c1c...
Molecule Summary: ID: FYI-1002208 Names: InChIKey: DCUCCARRVUPXJK-GOPCVKJMS A-NSMILES: CC(C)[C@H](NC...
Molecule Summary: ID: FYI-1006456 Names: InChIKey: NGASABBDYZJAFR-UHFFFAOYS A-NSMILES: Cc1cc(C(C)(C)...
Molecule Summary: ID: FYI-1003120 Names: InChIKey: NPYPAHLBTDXSSS-UHFFFAOYS A-NSMILES: [K+] Received...