diff --git a/Code/JavaWrappers/CMakeLists.txt b/Code/JavaWrappers/CMakeLists.txt index 728f29e33..30ad31561 100644 --- a/Code/JavaWrappers/CMakeLists.txt +++ b/Code/JavaWrappers/CMakeLists.txt @@ -17,6 +17,7 @@ if(WIN32) Optimizer MolAlign Alignment + SimDivPickers RDGeometryLib RDGeneral ) if(RDK_BUILD_INCHI_SUPPORT) set(RDKit_Wrapper_Libs RDInchiLib ${INCHI_LIBRARIES} ${RDKit_Wrapper_Libs}) @@ -31,6 +32,7 @@ else() Optimizer_static MolAlign_static Alignment_static + SimDivPickers_static RDGeometryLib_static RDGeneral_static ) if(RDK_BUILD_INCHI_SUPPORT) set(RDKit_Wrapper_Libs RDInchiLib_static Inchi_static ${RDKit_Wrapper_Libs}) diff --git a/Code/JavaWrappers/DiversityPick.h b/Code/JavaWrappers/DiversityPick.h new file mode 100644 index 000000000..aaed273f1 --- /dev/null +++ b/Code/JavaWrappers/DiversityPick.h @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +namespace { + class taniFunctor { + public: + taniFunctor(const std::vector &ebvs) : d_ebvs(ebvs) {} + double operator()(unsigned int i,unsigned int j) { + double res; + std::pair idxPair(i,j); + if(this->d_cache.count(idxPair)>0){ + res = this->d_cache[idxPair]; + } else { + res=1.-TanimotoSimilarity(d_ebvs[i],d_ebvs[j]); + this->d_cache[idxPair]=res; + } + return res; + } + private: + const std::vector &d_ebvs; + std::map,double> d_cache; + }; +} + +std::vector pickUsingFingerprints(const std::vector &ebvs,unsigned int nToPick + ){ + if(nToPick>=ebvs.size()) throw ValueErrorException("nToPick is larger than the vector size"); + std::vector res; + + RDPickers::MaxMinPicker picker; + taniFunctor ftor(ebvs); + res = picker.lazyPick(ftor,ebvs.size(),nToPick); + return res; +} diff --git a/Code/JavaWrappers/DiversityPick.i b/Code/JavaWrappers/DiversityPick.i new file mode 100644 index 000000000..4920e7a01 --- /dev/null +++ b/Code/JavaWrappers/DiversityPick.i @@ -0,0 +1,11 @@ + +%{ +#include +#include +#include "DiversityPick.h" +%} + +%template(EBV_Vect) std::vector< ExplicitBitVect >; + +%include "DiversityPick.h"; + diff --git a/Code/JavaWrappers/gmwrapper/GraphMolJava.i b/Code/JavaWrappers/gmwrapper/GraphMolJava.i index 60c7bba08..67b0dbee7 100644 --- a/Code/JavaWrappers/gmwrapper/GraphMolJava.i +++ b/Code/JavaWrappers/gmwrapper/GraphMolJava.i @@ -252,3 +252,5 @@ typedef unsigned long long int uintmax_t; #ifdef BUILD_INCHI_SUPPORT %include "../Inchi.i" #endif + +%include "../DiversityPick.i"