File: example14.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 (85 lines) | stat: -rw-r--r-- 2,952 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// Substructure searching - example14.cpp

#include <iostream>
#include <vector>
#include <GraphMol/GraphMol.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/Substruct/SubstructMatch.h>

int main( int argc , char **argv ) {

  RDKit::ROMOL_SPTR mol1( RDKit::SmilesToMol( "c1ccccc1O" ) );
  RDKit::RWMOL_SPTR patt( RDKit::SmartsToMol( "ccO" ) );
  RDKit::MatchVectType res;
  if( RDKit::SubstructMatch( *mol1 , *patt , res ) ) {
    std::cout << "Pattern matched molecule : " << std::endl;
    for( size_t i = 0 ; i < res.size() ; ++i ) {
      std::cout << "(" << res[i].first << "," << res[i].second << ")";
    }
    std::cout << std::endl;
  }


  std::vector<RDKit::MatchVectType> hits_vect;
  if( RDKit::SubstructMatch( *mol1 , *patt , hits_vect ) ) {
    for( size_t i = 0 ; i < hits_vect.size() ; ++i ) {
      std::cout << "Match " << i + 1 << " : ";
      for( size_t j = 0 ; j < hits_vect[i].size() ; ++j ) {
  	std::cout << "(" << hits_vect[i][j].first << ","
  		  << hits_vect[i][j].second << ")";
      }
      std::cout << std::endl;
    }
  }

  std::string file_root = getenv( "RDBASE" );
  file_root += "/Docs/Book";

  std::string sdf_file = file_root + "/data/actives_5ht3.sdf";
  RDKit::SDMolSupplier mol_supplier( sdf_file , true );
  RDKit::RWMOL_SPTR patt1( RDKit::SmartsToMol( "c[NH1]" ) );
  std::vector<RDKit::ROMOL_SPTR> matches;
  while( !mol_supplier.atEnd() ) {
    RDKit::ROMOL_SPTR mol3( mol_supplier.next() );
    if( mol3 && RDKit::SubstructMatch( *mol3 , *patt1 , res ) ) {
      matches.push_back( mol3 );
    }
  }
  std::cout << "There were " << matches.size() << " hits in the file." << std::endl;

  RDKit::ROMOL_SPTR mol4( RDKit::SmilesToMol( "C1=CC=CC=C1OC" ) );
  RDKit::RWMOL_SPTR smi_mol1( RDKit::SmilesToMol( "CO" ) );
  if( RDKit::SubstructMatch( *mol4 , *smi_mol1 , res ) ) {
    std::cout << "SMILES match" << std::endl;
  } else {
    std::cout << "Not SMILES match" << std::endl;
  }
  RDKit::RWMOL_SPTR smt_mol1( RDKit::SmartsToMol( "CO" ) );
  if( RDKit::SubstructMatch( *mol4 , *smt_mol1 , res ) ) {
    std::cout << "SMARTS match" << std::endl;
  } else {
    std::cout << "Not SMARTS match" << std::endl;
  }

  RDKit::RWMOL_SPTR smi_mol2( RDKit::SmilesToMol( "COC" ) );
  if( RDKit::SubstructMatch( *mol4 , *smi_mol2 , res ) ) {
    std::cout << "SMILES match" << std::endl;
  } else {
    std::cout << "Not SMILES match" << std::endl;
  }
  RDKit::RWMOL_SPTR smt_mol2( RDKit::SmartsToMol( "COC" ) );
  if( RDKit::SubstructMatch( *mol4 , *smt_mol2 , res ) ) {
    std::cout << "SMARTS match" << std::endl;
  } else {
    std::cout << "Not SMARTS match" << std::endl;
  }
  // Needs aromatic C
  RDKit::RWMOL_SPTR smt_mol3( RDKit::SmartsToMol( "COc" ) );
  if( RDKit::SubstructMatch( *mol4 , *smt_mol3 , res ) ) {
    std::cout << "SMARTS match" << std::endl;
  } else {
    std::cout << "Not SMARTS match" << std::endl;
  }
}