crude initial python wrapper

This commit is contained in:
Greg Landrum
2016-01-01 11:54:52 +01:00
parent 2e9063964e
commit 08ce5a287d
5 changed files with 75 additions and 8 deletions

View File

@@ -15,6 +15,8 @@
#include <sstream>
#include <string>
#include <RDGeneral/BadFileException.h>
#include <DataStructs/ExplicitBitVect.h>
#include <boost/cstdint.hpp>
namespace RDKit {

View File

@@ -1,7 +1,8 @@
rdkit_python_extension(cDataStructs
DataStructs.cpp DiscreteValueVect.cpp SparseIntVect.cpp
wrap_SparseBV.cpp wrap_ExplicitBV.cpp wrap_BitOps.cpp
wrap_Utils.cpp
rdkit_python_extension(cDataStructs
DataStructs.cpp DiscreteValueVect.cpp SparseIntVect.cpp
wrap_SparseBV.cpp wrap_ExplicitBV.cpp wrap_BitOps.cpp
wrap_FPB.cpp
wrap_Utils.cpp
DEST DataStructs
LINK_LIBRARIES
RDGeneral DataStructs RDBoost)
@@ -12,7 +13,5 @@ add_pytest(pyDiscreteValueVect
${CMAKE_CURRENT_SOURCE_DIR}/testDiscreteValueVect.py)
add_pytest(pySparseIntVect
${CMAKE_CURRENT_SOURCE_DIR}/testSparseIntVect.py)
add_pytest(pyFPB
${CMAKE_CURRENT_SOURCE_DIR}/testFPB.py)

View File

@@ -28,6 +28,7 @@ void wrap_BitOps();
void wrap_Utils();
void wrap_discreteValVect();
void wrap_sparseIntVect();
void wrap_FPB();
template <typename T>
void convertToNumpyArray(const T &v, python::object destArray) {
@@ -76,6 +77,7 @@ BOOST_PYTHON_MODULE(cDataStructs) {
wrap_BitOps();
wrap_discreteValVect();
wrap_sparseIntVect();
wrap_FPB();
python::def(
"ConvertToNumpyArray",

View File

@@ -0,0 +1,28 @@
from rdkit import DataStructs
from rdkit import RDConfig
import unittest,os
def feq(a,b,tol=1e-4):
return abs(a-b)<tol
class TestCase(unittest.TestCase):
def setUp(self) :
self.filename = os.path.join(RDConfig.RDBaseDir,'Code','DataStructs','testData','zim.head100.fpb')
self.fpbr = DataStructs.FPBReader(self.filename)
self.fpbr.Init()
def test1Basics(self) :
self.assertEqual(len(self.fpbr),100)
self.assertEqual(self.fpbr.GetId(0),"ZINC00902219")
self.assertEqual(self.fpbr.GetId(3),"ZINC04803506")
fp = self.fpbr.GetFP(0)
self.assertEqual(fp.GetNumBits(),2048)
self.assertEqual(fp.GetNumOnBits(),17)
obs = (1, 80, 183, 222, 227, 231, 482, 650, 807,
811, 831, 888, 1335, 1411, 1664, 1820, 1917)
obl = tuple(fp.GetOnBits())
self.assertEqual(obs,obl)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,36 @@
//
// 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 <RDBoost/Wrap.h>
#include <DataStructs/FPBReader.h>
#include <RDBoost/PySequenceHolder.h>
#include "wrap_helpers.h"
namespace python = boost::python;
using namespace RDKit;
std::string FPBReaderClassDoc =
"A class for read-only interactions with FPB files from Andrew Dalke's chemfp.\n\
\n\
\n";
struct FPB_wrapper {
static void wrap() {
python::class_<FPBReader, boost::noncopyable>(
"FPBReader", FPBReaderClassDoc.c_str(), python::init<std::string>())
.def("Init", &FPBReader::init, "init.\n")
.def("__len__", &FPBReader::length)
//.def("__getitem__", &FPBReader::operator[]) careful about this leaking
.def("GetFP", &FPBReader::getFP,
python::return_value_policy<python::manage_new_object>())
.def("GetId", &FPBReader::getId)
.def("GetTanimoto", &FPBReader::getTanimoto);
}
};
void wrap_FPB() { FPB_wrapper::wrap(); }