File: FragCatalog.cpp

package info (click to toggle)
rdkit 201203-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 37,840 kB
  • sloc: cpp: 93,902; python: 51,897; java: 5,192; ansic: 3,497; xml: 2,499; sql: 1,641; yacc: 1,518; lex: 1,076; makefile: 325; fortran: 183; sh: 153; cs: 51
file content (153 lines) | stat: -rw-r--r-- 4,787 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// $Id: FragCatalog.cpp 1528 2010-09-26 17:04:37Z glandrum $
//
//  Copyright (C) 2003-2006 Rational Discovery LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <RDBoost/Wrap.h>

#include <boost/python.hpp>

#include <GraphMol/FragCatalog/FragCatGenerator.h>
#include <GraphMol/FragCatalog/FragCatParams.h>
#include <GraphMol/FragCatalog/FragCatalogEntry.h>


namespace python = boost::python;
namespace RDKit{

  struct fragcatalog_pickle_suite : python::pickle_suite
  {
    static python::tuple
    getinitargs(const FragCatalog& self)
    {
      std::string res;
      res = self.Serialize();
      return python::make_tuple(res);
    };
  };
  unsigned int GetBitEntryId(const FragCatalog *self,unsigned int idx){
    if(idx > self->getFPLength())
      throw_index_error(idx);
    return self->getIdOfEntryWithBitId(idx);
  }

  unsigned int GetEntryBitId(const FragCatalog *self,unsigned int idx){
    if(idx > self->getNumEntries())
      throw_index_error(idx);
    return self->getEntryWithIdx(idx)->getBitId();
  }
  std::string GetEntryDescription(const FragCatalog *self,unsigned int idx){
    if(idx > self->getNumEntries())
      throw_index_error(idx);
    return self->getEntryWithIdx(idx)->getDescription();
  }
  std::string GetBitDescription(const FragCatalog *self,unsigned int idx){
    if(idx > self->getFPLength())
      throw_index_error(idx);
    return self->getEntryWithBitId(idx)->getDescription();
  }
  unsigned int GetEntryOrder(const FragCatalog *self,unsigned int idx){
    if(idx > self->getNumEntries())
      throw_index_error(idx);
    return self->getEntryWithIdx(idx)->getOrder();
  }
  unsigned int GetBitOrder(const FragCatalog *self,unsigned int idx){
    if(idx > self->getFPLength())
      throw_index_error(idx);
    return self->getEntryWithBitId(idx)->getOrder();
  }
  INT_VECT GetEntryFuncGroupIds(const FragCatalog *self,unsigned int idx){
    if(idx > self->getNumEntries())
      throw_index_error(idx);
    INT_VECT res;
    INT_INT_VECT_MAP gps = self->getEntryWithIdx(idx)->getFuncGroupMap();
    for(INT_INT_VECT_MAP::const_iterator i=gps.begin();i!=gps.end();i++){
      for(INT_VECT_CI ivci=i->second.begin();ivci!=i->second.end();ivci++){
	res.push_back(*ivci);
      }
    }
    return res;
  }
  INT_VECT GetBitFuncGroupIds(const FragCatalog *self,unsigned int idx){
    if(idx > self->getFPLength())
      throw_index_error(idx);
    INT_VECT res;
    INT_INT_VECT_MAP gps = self->getEntryWithBitId(idx)->getFuncGroupMap();
    for(INT_INT_VECT_MAP::const_iterator i=gps.begin();i!=gps.end();i++){
      for(INT_VECT_CI ivci=i->second.begin();ivci!=i->second.end();ivci++){
	res.push_back(*ivci);
      }
    }
    return res;
  }
  INT_VECT GetEntryDownIds(const FragCatalog *self,unsigned int idx){
    if(idx > self->getNumEntries())
      throw_index_error(idx);
    return self->getDownEntryList(idx);
  }


  DOUBLE_VECT GetBitDiscrims(const FragCatalog *self,unsigned int idx){
    if(idx > self->getFPLength())
      throw_index_error(idx);
    DOUBLE_VECT res;
    const FragCatalogEntry *entry=self->getEntryWithBitId(idx);
    Subgraphs::DiscrimTuple tmp=entry->getDiscrims();
    res.push_back(tmp.get<0>());
    res.push_back(tmp.get<1>());
    res.push_back(tmp.get<2>());
    return res;
  }


  
  struct fragcat_wrapper {
    static void wrap() {

      // FIX: none of the functions giving access to the entries in the catalog
      // are  being exposed to python
      // right now, adding entries for example should happen through the
      // FragCatGenerator
      
      python::class_<FragCatalog>("FragCatalog", python::init<FragCatParams *>())
	.def(python::init<const std::string &>())
	.def("GetNumEntries", &FragCatalog::getNumEntries)
	.def("GetFPLength", &FragCatalog::getFPLength)
	.def("GetCatalogParams", (FragCatParams* (FragCatalog::*)())&FragCatalog::getCatalogParams,
	     python::return_value_policy<python::reference_existing_object>())
	.def("Serialize", &FragCatalog::Serialize)

	.def("GetBitDescription", &GetBitDescription)
	.def("GetBitOrder", &GetBitOrder)
	.def("GetBitFuncGroupIds", &GetBitFuncGroupIds)
	.def("GetBitEntryId", &GetBitEntryId)

	.def("GetEntryBitId", &GetEntryBitId)
	.def("GetEntryDescription", &GetEntryDescription)
	.def("GetEntryOrder", &GetEntryOrder)
	.def("GetEntryFuncGroupIds", &GetEntryFuncGroupIds)
	.def("GetEntryDownIds", &GetEntryDownIds)


	.def("GetBitDiscrims", &GetBitDiscrims)

	// enable pickle support
	.def_pickle(fragcatalog_pickle_suite())

	;
    };
  };

} //end of namespace

void wrap_fragcat() {
  RDKit::fragcat_wrapper::wrap();
}