Collections:
Call getSmiles() and getSmarts() Chained
How to call getSmiles() and getSmarts() methods in 2 promises one chained to the other?
✍: FYIcenter.com
Another way to avoid the bug mentioned in the previous tutorial is to call ketcher.getSmiles() and ketcher.getSmarts() methods in 2 chained promises.
Chained promises use fulfilled and rejected handlers of the previous promise to return the next promise.
The following HTML document showdraganddropsymbolindepictmode you how to call ketcher.getSmiles() and ketcher.getSmarts() in chained promises.
<html> <!-- export-as-SMILES-SMARTS-chained.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 chained 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> var ketcher = null; function exportBoth() { frm = document.getElementById("frmKetcher"); ketcher = frm.contentWindow.ketcher; promiseSmiles = ketcher.getSmiles(); promiseSmarts = promiseSmiles.then(consumeSmiles, consumeSmiles); promiseSmarts.then(consumeSmarts, consumeSmarts); } function consumeSmiles(result) { document.getElementById("smiles").innerHTML = result.toString(); return ketcher.getSmarts(); } function consumeSmarts(result) { document.getElementById("smarts").innerHTML = result.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 chained promises" button, you will see that both promises work correctly with SMILES and SMARTS strings returned to the page.
⇒ Export Chemical Structure in All Formats
2024-01-15, 346🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1002120 Names: InChIKey: RLGOMCLKLSMRAG-UHFFFAOYS A-NSMILES: CN(C)C(=O)c4c...
Molecule Summary: ID: FYI-1000968 SMILES: O=C1CSC(=S)N1CCCN1CCCCC1 Received at FYIcenter.com on: 202...
Molecule Summary: ID: FYI-1001164 SMILES: Oc1ccc(cc1)C1=NNC(=S)N1C C=CReceived at FYIcenter.com on: ...
Molecule Summary: ID: FYI-1000230 SMILES: CC12CCC3C(C1CCC2(C#C)O)C CC4=C3C=CC(=C4)OReceived at FYIce...
Molecule Summary: ID: FYI-1000956 SMILES: C#[CH:1] Received at FYIcenter.com on: 2021-08-07