File: rdMolCatalog.cpp

package info (click to toggle)
rdkit 202009.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 129,624 kB
  • sloc: cpp: 288,030; python: 75,571; java: 6,999; ansic: 5,481; sql: 1,968; yacc: 1,842; lex: 1,254; makefile: 572; javascript: 461; xml: 229; fortran: 183; sh: 134; cs: 93
file content (130 lines) | stat: -rw-r--r-- 4,032 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
// $Id$
//
//  Copyright (C) 2006 Greg Landrum
//
#include "rdMolCatalog.h"
#include <RDBoost/python.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolCatalog/MolCatalog.h>
#include <GraphMol/MolCatalog/MolCatalogEntry.h>
#include <GraphMol/MolCatalog/MolCatalogParams.h>

namespace python = boost::python;
using namespace RDKit;
namespace {
struct molcatalog_pickle_suite : python::pickle_suite {
  static python::tuple getinitargs(const MolCatalog &self) {
    std::string res;
    res = self.Serialize();
    return python::make_tuple(python::object(python::handle<>(
        PyBytes_FromStringAndSize(res.c_str(), res.length()))));
  };
};

struct molcatalogentry_pickle_suite : python::pickle_suite {
  static python::tuple getinitargs(const MolCatalogEntry &self) {
    std::string res;
    res = self.Serialize();
    return python::make_tuple(python::object(python::handle<>(
        PyBytes_FromStringAndSize(res.c_str(), res.length()))));
  };
};

unsigned int GetBitEntryId(const MolCatalog *self, unsigned int idx) {
  if (idx > self->getFPLength()) {
    throw_index_error(idx);
  }
  return self->getIdOfEntryWithBitId(idx);
}

unsigned int GetEntryBitId(const MolCatalog *self, unsigned int idx) {
  if (idx > self->getNumEntries()) {
    throw_index_error(idx);
  }
  return self->getEntryWithIdx(idx)->getBitId();
}
std::string GetEntryDescription(const MolCatalog *self, unsigned int idx) {
  if (idx > self->getNumEntries()) {
    throw_index_error(idx);
  }
  return self->getEntryWithIdx(idx)->getDescription();
}
std::string GetBitDescription(const MolCatalog *self, unsigned int idx) {
  if (idx > self->getFPLength()) {
    throw_index_error(idx);
  }
  return self->getEntryWithBitId(idx)->getDescription();
}
INT_VECT GetEntryDownIds(const MolCatalog *self, unsigned int idx) {
  if (idx > self->getNumEntries()) {
    throw_index_error(idx);
  }
  return self->getDownEntryList(idx);
}

unsigned int AddEntry(MolCatalog *self, MolCatalogEntry *entry) {
  auto *cpy = new MolCatalogEntry(*entry);
  return self->addEntry(cpy);
  // return self->addEntry(entry);
}

void catalogEntrySetMol(MolCatalogEntry *self, const ROMol *mol) {
  auto *cpy = new ROMol(*mol);
  self->setMol(cpy);
}

const ROMol &catalogEntryGetMol(MolCatalogEntry &self) {
  return *self.getMol();
}

MolCatalog *createMolCatalog() {
  return new MolCatalog(new MolCatalogParams());
}
struct MolCatalog_wrapper {
  static void wrap() {
    python::class_<MolCatalog>("MolCatalog",
                               python::init<const std::string &>())
        .def("GetNumEntries", &MolCatalog::getNumEntries)
        .def("GetFPLength", &MolCatalog::getFPLength)
        .def("Serialize", &MolCatalog::Serialize)

        .def("GetBitDescription", GetBitDescription)
        .def("GetBitEntryId", GetBitEntryId)

        .def("GetEntryBitId", GetEntryBitId)
        .def("GetEntryDescription", GetEntryDescription)
        .def("GetEntryDownIds", GetEntryDownIds)

        .def("AddEntry", AddEntry)
        .def("AddEdge", &MolCatalog::addEdge)

        // enable pickle support
        .def_pickle(molcatalog_pickle_suite());
    python::def("CreateMolCatalog", createMolCatalog,
                python::return_value_policy<python::manage_new_object>());
  };
};
struct MolCatalogEntry_wrapper {
  static void wrap() {
    python::class_<MolCatalogEntry>("MolCatalogEntry", python::init<>())
        .def(python::init<const std::string &>())
        .def("GetDescription", &MolCatalogEntry::getDescription)
        .def("SetDescription", &MolCatalogEntry::setDescription)
        .def("GetMol", catalogEntryGetMol,
             python::return_internal_reference<1>())
        .def("SetMol", catalogEntrySetMol)
        .def("GetOrder", &MolCatalogEntry::getOrder)
        .def("SetOrder", &MolCatalogEntry::setOrder)

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

        ;
  };
};
}

BOOST_PYTHON_MODULE(rdMolCatalog) {
  MolCatalog_wrapper::wrap();
  MolCatalogEntry_wrapper::wrap();
}