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
|
// $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();
}
|