File: example6.cpp

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (68 lines) | stat: -rw-r--r-- 2,115 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// 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 ) {

  RDKit::ROMOL_SPTR mol( RDKit::SmilesToMol( "C1OC1" ) );

  RDKit::ROMol::VERTEX_ITER it , end;
  boost::tie( it , end ) = mol->getVertices();
  while( it != end ) {
    const RDKit::Atom *atom = (*mol)[*it].get();
    std::cout << atom->getAtomicNum() << " ";
    ++it;
  }
  std::cout << std::endl;   

  for( RDKit::ROMol::AtomIterator ai = mol->beginAtoms() ; ai != mol->endAtoms() ; ++ai) {
    std::cout << (*ai)->getAtomicNum() << " ";
  }
  std::cout << std::endl;   
    
  for( unsigned int i = 0 , is = mol->getNumAtoms() ; i < is ; ++i ) {
    const RDKit::Atom *atom = mol->getAtomWithIdx( i ); 
    std::cout << atom->getAtomicNum() << " ";
  }
  std::cout << std::endl;   

  RDKit::ROMol::EDGE_ITER bond_it , bond_end;
  boost::tie( bond_it , bond_end ) = mol->getEdges();
  while( bond_it != bond_end ) {
    const RDKit::Bond *bond = (*mol)[*bond_it].get();
    std::cout << bond->getBondType() << " ";
    ++bond_it;
  }
  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;   

  RDKit::ROMOL_SPTR 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 );
  RDKit::ROMol::ADJ_ITER nbr , end_nbr;
  boost::tie( nbr , end_nbr ) = mol2->getAtomNeighbors( atom );
  while( nbr != end_nbr ) {
    const RDKit::Atom *nbr_atom = (*mol2)[*nbr].get();
    std::cout << nbr_atom->getIdx() << " : " << nbr_atom->getAtomicNum() << std::endl;
    ++nbr;
  }
  
}