Collections:
ketcher.getMolfile() - Export Molecule in Molfile Format
How to export the molecule structure in Molfile format from the Ketcher with the ketcher.getMolfile() method?
✍: FYIcenter.com
To export the molecule structure in Molfile format from the Ketcher, you can use the getMolfile() method provided by the Ketcher API as shown in below:
1. Load the Ketcher editor in an "iframe" HTML element:
<iframe id=frmKetcher src="/ketcher/index.html" style="width: 680px; height: 400px;"></iframe>
2. Create a "button" HTML element with a "click" event handler.
<p><button onclick="exportMolfile();">Export Molecule in Molfile</button></p>
3. Access the "ketcher" object from the "iframe" element in the "click" event handler directly, since the "iframe" element is already loaded:
frm = document.getElementById("frmKetcher"); ketcher = frm.contentWindow.ketcher;
4. Call the ketcher.getMolfile() method to export the molecule structure from the Ketcher editor. Note that this method returns a "promise" object, which represents a child thread to perform the task. We need to add two handlers through the promise.then() method to catch the result and error.
The following HTML document gives you an example of how to export the molecule structure in Molfile format from the Ketcher:
<html> <!-- export-molecule-as-Molfile.html Copyright (c) FYIcenter.com. --> <head> <title>Export Molecule Structure in Molfile Format</title> </head> <body> <p>Create a molecule structure, then click the export button below the editor:</p> <iframe id=frmKetcher src="/ketcher/index.html" style="width: 680px; height: 400px;"></iframe> <p><button onclick="exportMolfile();">Export Molecule in Molfile</button></p> <pre id=output style="background-color: #ddd;"> </pre> <script> function exportMolfile() { frm = document.getElementById("frmKetcher"); ketcher = frm.contentWindow.ketcher; promise = ketcher.getMolfile(); promise.then( function(value) { document.getElementById("output").innerHTML = value; }, function(error) { document.getElementById("output").innerHTML = error.toString(); } ); } </script> </body> </html>
5. Put the above HTML document on your local Web server and open it in your browser, you will see the Ketcher editor loaded and ready to use.
6. Draw an aspirin molecule structure in the editor.
7. Click "Export Molecule in Molfile" button, you will see the molecule structure represented in Molfile format displayed:
⇒ ketcher.getRxn() - Export Reaction in RXN Format
2024-03-17, 652🔥, 0💬
Popular Posts:
Molecule Summary: ID: FYI-1004777 Names: InChIKey: MBMTYTZDQFZPMJ-UONOGXRCS A-NSMILES: C[C@@]12CCC(=...
Molecule Summary: ID: FYI-1003816 Names: InChIKey: IXPRTBBVBMTJDL-UHFFFAOYS A-NSMILES: O=C(NCCn1cccn...
Molecule Summary: ID: FYI-1002578 Names: InChIKey: CBJXSIMXJKDGBS-UHFFFAOYS A-NSMILES: Cc4cnc(NC(=O)...
How Stereoinformation is stored in in SDF/Mol V3000 files? Similar to SDF/Mol V2000, stereoinformati...
Molecule Summary: ID: FYI-1003705 Names: InChIKey: MRLDSZFMHJZRMV-UHFFFAOYS A-NSMILES: CCCCCCCC(=O)O...