editor.struct().atoms - Get Atom List

Q

How to get a list of atoms currently in the Ketcher editor with the editor.struct().atoms property?

✍: FYIcenter.com

A

If you want to get a list of atoms currently in the Ketcher editor, you can use the editor.struct().atoms property on the Ketcher Editor interface.

Here is an HTML document that shows you how to get a list of atoms in Ketcher editor and print detailed information of the fist atom.

<html>
<!-- editor-get-first-atom.html Copyright (c) FYIcenter.com. -->
<head>
<title>Get the First Atom from Editor</title>
</head>
<body>
<p>Create a molecule structure, then click generate button below the editor:</p>
<iframe id=frmKetcher src="/ketcher/index.html"
  style="width: 680px; height: 400px;"></iframe>

<p><button onclick="generate();">Get the First Atom</button></p>
<p>Output:</p>
<pre id=output style="background-color: #ddd;"></pre>
<script>
  var ketcher = null;
  var display = document.getElementById("output");

function generate() {
  frm = document.getElementById("frmKetcher");
  ketcher = frm.contentWindow.ketcher;
  editor = ketcher.editor;
  structure = editor.struct();
  atoms = structure.atoms.entries();
  first = atoms.next().value;
  display.innerHTML = JSON.stringify(first, undefined, 2);
}
</script>
</body>
</html>

Open the above HTML document on your local Web server. Draw a benzene molecule in the editor.

Click "Get the First Atom" button, you will see that detailed information of the first atom of the structure in the editor is displayed.

[
  0,
  {
    "label": "C",
    "fragment": 1,
    "alias": null,
    "isotope": 0,
    "radical": 0,
    "cip": null,
    "charge": 0,
    "rglabel": null,
    "attpnt": null,
    "implicitHCount": null,
    "explicitValence": -1,
    "valence": 4,
    "implicitH": 1,
    "pp": {
      "x": 1.5746705613885816,
      "y": 2.574248795956401,
      "z": 0
    },
    "sgs": {},
    "ringBondCount": 0,
    "substitutionCount": 0,
    "unsaturatedAtom": 0,
    "hCount": 0,
    "aam": 0,
    "invRet": 0,
    "exactChangeFlag": 0,
    "rxnFragmentType": -1,
    "stereoLabel": null,
    "stereoParity": 0,
    "atomList": null,
    "neighbors": [
      13,
      16
    ],
    "badConn": false,
    "pseudo": ""
  }
]

 

editor.struct().bonds - Get Bond List

editor.struct() - Get Entire Structure

Ketcher Editor Interface

⇑⇑ Ketcher - Chemical Structure Editor

2023-12-01, 243🔥, 0💬