// // Copyright (C) 2016 greg Landrum // // @@ 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 #include #include #include "wrap_helpers.h" namespace python = boost::python; using namespace RDKit; namespace { python::tuple taniNbrHelper(const FPBReader *self, const std::string &bytes, double threshold) { const boost::uint8_t *bv = reinterpret_cast(bytes.c_str()); std::vector > nbrs = self->getTanimotoNeighbors(bv, threshold); python::list result; for (unsigned int i = 0; i < nbrs.size(); ++i) { result.append(python::make_tuple(nbrs[i].first, nbrs[i].second)); } return python::tuple(result); } python::object getBytesHelper(const FPBReader *self, unsigned int which) { boost::shared_array bv = self->getBytes(which); python::object retval = python::object(python::handle<>(PyBytes_FromStringAndSize( reinterpret_cast(bv.get()), self->nBits() / 8))); return retval; } double getTaniHelper(const FPBReader *self, unsigned int which, const std::string &bytes) { const boost::uint8_t *bv = reinterpret_cast(bytes.c_str()); return self->getTanimoto(which, bv); } python::tuple getItemHelper(const FPBReader *self, unsigned int which) { std::pair, std::string> v = (*self)[which]; return python::make_tuple(v.first, v.second); } } std::string FPBReaderClassDoc = "A class for reading and searching FPB files from Andrew Dalke's chemfp.\n\ \n"; struct FPB_wrapper { static void wrap() { python::class_( "FPBReader", FPBReaderClassDoc.c_str(), python::init >( (python::arg("filename"), python::arg("lazy") = false), "docstring")) .def("Init", &FPBReader::init, "Read the fingerprints from the file. This can take a while.\n") .def("__len__", &FPBReader::length) .def("__getitem__", &getItemHelper) .def("GetNumBits", &FPBReader::nBits, "returns the number of bits in a fingerprint") .def("GetFP", &FPBReader::getFP, "returns a particular fingerprint as an ExplicitBitVect") .def("GetBytes", &getBytesHelper, "returns a particular fingerprint as bytes") .def("GetId", &FPBReader::getId, "returns the id of a particular fingerprint") .def("GetTanimoto", &getTaniHelper, "return the tanimoto similarity of a particular fingerprint to " "the bytes provided") .def("GetTanimotoNeighbors", &taniNbrHelper, (python::arg("bv"), python::arg("threshold") = 0.7), "returns tanimoto similarities to and indices of all neighbors " "above the specified threshold"); } }; void wrap_FPB() { FPB_wrapper::wrap(); }