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, 682🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1003118 Names: InChIKey: BOYOQILEMPLQLJ-RQZCQDPDS A-NSMILES: Oc1ccccc1c2nn...
Molecule Summary: ID: FYI-1005412 Names: InChIKey: YIMQCDZDWXUDCA-UHFFFAOYS A-NSMILES: OCC1CCC(CO)CC...
Molecule Summary: ID: FYI-1002585 Names: InChIKey: YTPCRCJHZLRLGU-SFHVURJKS A-NSMILES: O=C3c1ccccc1[...
Molecule Summary: ID: FYI-1002217 Names: InChIKey: PUPHWBDYYVQWSY-YPXUMCKCS A-NSMILES: Fc4c(F)c(F)c(...
Molecule Summary: ID: FYI-1000285 SMILES: CC(C)(O)c2ccc(C(=O)OCc1c cc(CCCBr)cc1)cc2Received at FYIce...