mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
crude initial python wrapper
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <RDGeneral/BadFileException.h>
|
||||
#include <DataStructs/ExplicitBitVect.h>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
namespace RDKit {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
28
Code/DataStructs/Wrap/testFPB.py
Normal file
28
Code/DataStructs/Wrap/testFPB.py
Normal 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()
|
||||
36
Code/DataStructs/Wrap/wrap_FPB.cpp
Normal file
36
Code/DataStructs/Wrap/wrap_FPB.cpp
Normal 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(); }
|
||||
Reference in New Issue
Block a user