mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-07 22:44:25 +08:00
Cart fixes (#2462)
* Wrapper fixes: Tversky for De Morgan and java byte functions for ExplicitBitVect * Wrapper fixes: Tversky for De Morgan and java byte functions for ExplicitBitVect
This commit is contained in:
committed by
Greg Landrum
parent
b2a01a09ee
commit
ebaa7b64e3
@@ -43,6 +43,34 @@
|
||||
%ignore ExplicitBitVect::dp_bits;
|
||||
%ignore ExplicitBitVect::getOnBits (IntVect& v) const;
|
||||
%ignore ExplicitBitVect::ExplicitBitVect(unsigned int,bool);
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
|
||||
%template(UChar_Vect) std::vector<unsigned char>;
|
||||
%typemap(jni) std::string ExplicitBitVect::toByteArray "jbyteArray"
|
||||
%typemap(jtype) std::string ExplicitBitVect::toByteArray "byte[]"
|
||||
%typemap(jstype) std::string ExplicitBitVect::toByteArray "byte[]"
|
||||
%typemap(javaout) std::string ExplicitBitVect::toByteArray {
|
||||
return $jnicall;
|
||||
}
|
||||
%typemap(out) std::string ExplicitBitVect::toByteArray {
|
||||
$result = JCALL1(NewByteArray, jenv, $1.size());
|
||||
JCALL4(SetByteArrayRegion, jenv, $result, 0, $1.size(), (const jbyte*)$1.c_str());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
%typemap(javacode) ExplicitBitVect %{
|
||||
public static ExplicitBitVect fromByteArray(byte[] fp) {
|
||||
UChar_Vect vec = new UChar_Vect();
|
||||
vec.reserve(fp.length);
|
||||
for (int size=0;size<fp.length;++size) {
|
||||
vec.add(fp[size]);
|
||||
}
|
||||
return new ExplicitBitVect(vec);
|
||||
}
|
||||
%}
|
||||
|
||||
%include <DataStructs/ExplicitBitVect.h>
|
||||
%newobject ExplicitBitVect::getOnBits;
|
||||
%extend ExplicitBitVect {
|
||||
@@ -53,3 +81,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
|
||||
%extend ExplicitBitVect {
|
||||
const std::string toByteArray() {
|
||||
return ($self)->toString();
|
||||
}
|
||||
|
||||
ExplicitBitVect(const std::vector<unsigned char> & data ) {
|
||||
std::string str(data.begin(), data.end());
|
||||
return new ExplicitBitVect(str);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -62,5 +62,9 @@ SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(UInt_Pair_Vect, std::vector< std::pair<unsign
|
||||
%template(TanimotoSimilaritySIVu32) RDKit::TanimotoSimilarity<boost::uint32_t>;
|
||||
%template(TanimotoSimilaritySIVi32) RDKit::TanimotoSimilarity<boost::int32_t>;
|
||||
%template(TanimotoSimilaritySIVi64) RDKit::TanimotoSimilarity<boost::int64_t>;
|
||||
%template(TverskySimilarity) RDKit::TverskySimilarity<boost::uint32_t>;
|
||||
%template(TverskySimilarity) RDKit::TverskySimilarity<boost::int32_t>;
|
||||
%template(TverskySimilarity) RDKit::TverskySimilarity<boost::int64_t>;
|
||||
|
||||
|
||||
%include "MorganFingerprints.h"
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.junit.Test;
|
||||
public class FingerprintsTests extends GraphMolTest {
|
||||
|
||||
public void compareVectors(Int_Vect v1, Int_Vect v2) {
|
||||
assertEquals(v1.size(), v2.size());
|
||||
for (int i = 0; i < v1.size(); i++) {
|
||||
assertEquals(v1.get(i),v2.get(i));
|
||||
}
|
||||
@@ -138,6 +139,18 @@ public class FingerprintsTests extends GraphMolTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToByteArray() {
|
||||
String smiles = "Cc2nc1ccccc1o2";
|
||||
ROMol mol = RWMol.MolFromSmiles(smiles);
|
||||
ExplicitBitVect fp1 = RDKFuncs.PatternFingerprintMol(mol, 2048);
|
||||
byte[] fpBytes = fp1.toByteArray();
|
||||
ExplicitBitVect fp2 = ExplicitBitVect.fromByteArray(fpBytes);
|
||||
Int_Vect fp1Bits = fp1.getOnBits();
|
||||
Int_Vect fp2Bits = fp2.getOnBits();
|
||||
compareVectors(fp1Bits, fp2Bits);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
org.junit.runner.JUnitCore.main("org.RDKit.FingerprintsTests");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user