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, 748🔥, 0💬
Popular Posts:
How to validate and parse a Molecular Formula? To help you validating and parsing a molecular formul...
Molecule Summary: ID: FYI-1005590 Names: InChIKey: PKDGVIDISYJYFY-UHFFFAOYS A-NSMILES: CCCc1c(C(=O)O...
Molecule Summary: ID: FYI-1003966 Names: InChIKey: NMGSDTSOSIPXTN-UHFFFAOYS A-NSMILES: C=1=CCCCC1 Re...
Molecule Summary: ID: FYI-1000980 SMILES: S=C1S/C(=C/c2ccccc2C)C(= O)N1CCN(CC)CCReceived at FYIcente...
Molecule Summary: ID: FYI-1002788 Names: InChIKey: NGHDLLHBVDWOLF-LTGZKZEYS A-NSMILES: COc3cccc(NN=c...