File: example6.cpp

package info (click to toggle)
rdkit 202503.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 222,000 kB
  • sloc: cpp: 411,111; python: 78,482; ansic: 26,181; java: 8,285; javascript: 4,404; sql: 2,393; yacc: 1,626; lex: 1,267; cs: 1,090; makefile: 581; xml: 229; fortran: 183; sh: 121
file content (50 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Working with molecules example6.cpp

#include <iostream>

#include <GraphMol/GraphMol.h>
#include <GraphMol/AtomIterators.h>
#include <GraphMol/SmilesParse/SmilesParse.h>

int main(int argc, char **argv) {
  std::shared_ptr<RDKit::ROMol> mol(RDKit::SmilesToMol("C1OC1"));

  for (auto atom : mol->atoms()) {
    std::cout << atom->getAtomicNum() << " ";
  }
  std::cout << std::endl;

  for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
    const RDKit::Atom *atom = mol->getAtomWithIdx(i);
    std::cout << atom->getAtomicNum() << " ";
  }
  std::cout << std::endl;

  for (auto bond : mol->bonds()) {
    std::cout << bond->getBondType() << " ";
  }
  std::cout << std::endl;

  for (unsigned int i = 0, is = mol->getNumBonds(); i < is; ++i) {
    const RDKit::Bond *bond = mol->getBondWithIdx(i);
    std::cout << bond->getIsAromatic() << " ";
  }
  std::cout << std::endl;

  std::shared_ptr<RDKit::ROMol> mol2(RDKit::SmilesToMol("C1OC1Cl"));
  const RDKit::Bond *bond = mol2->getBondBetweenAtoms(0, 1);
  std::cout << bond->getBeginAtomIdx() << " to " << bond->getBeginAtomIdx()
            << " is " << bond->getBondType() << std::endl;
  if (!mol2->getBondBetweenAtoms(0, 3)) {
    std::cout << "No bond between 0 and 3" << std::endl;
  }

  const RDKit::Atom *atom = mol2->getAtomWithIdx(2);
  for (const auto &nbri : make_iterator_range(mol->getAtomBonds(atom))) {
    const RDKit::Bond *bond = (*mol)[nbri];
    unsigned int nbr_idx = bond->getOtherAtomIdx(atom->getIdx());
    int nbr_atnum = bond->getOtherAtom(atom)->getAtomicNum();
    std::cout << nbr_idx << " : " << nbr_atnum << std::endl;
  }
}