ketcher.getRxn() - Export Reaction in RXN Format

Q

How to export the reaction structure in RXN format from the Ketcher with the ketcher.getRxn() method?

✍: FYIcenter.com

A

To export the reaction structure in RXN format from the Ketcher, you can use the getRxn() 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="exportRXN();">Export Reaction in RXN</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;

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.getRxn() method to export the reaction 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 reaction structure in RXN format from the Ketcher:

<html>
<!-- export-reaction-as-RXN.html Copyright (c) FYIcenter.com. -->
<head>
<title>Export Reaction Structure in RXN Format</title>
</head>
<body>
<p>Create a reaction 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="exportRXN();">Export Reaction in RXN</button></p>
<pre id=output style="background-color: #ddd;">
</pre>
<script>
function exportRXN() {
  frm = document.getElementById("frmKetcher");
  ketcher = frm.contentWindow.ketcher;
  promise = ketcher.getRxn();
  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 a simple reaction structure in the editor.

7. Click "Export Reaction in RXN" button, you will see the reaction structure represented in RXN format displayed:

ketcher.getRxn() - Export Reaction in RXN Format
ketcher.getRxn() - Export Reaction in RXN Format

 

ketcher.getSmiles() and ketcher.getSmarts()

ketcher.getMolfile() - Export Molecule in Molfile Format

Ketcher JavaScript API

⇑⇑ Ketcher - Chemical Structure Editor

2023-12-10, 322🔥, 0💬