Get the wrappers working with SWIG 4.0 (#5795)

* extend the allowed valences of the alkali earths
make it possible to have preferred and arbitrary valence states (I thought this already worked)

* backup

* maybe needed

* copy in some swig3 files;
at this point the tests all work

* remove SWIG version lock

* changes in response to review
This commit is contained in:
Greg Landrum
2022-12-10 07:13:55 +01:00
committed by GitHub
parent 309ea55d16
commit aa336f3faf
12 changed files with 182 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
find_package(SWIG 3.0 EXACT REQUIRED)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -70,6 +70,8 @@ RDKit::ROMol * new_molzip(
%}
%include "std_string.i"
%newobject deleteSubstructs;
%newobject replaceSidechains;
%newobject replaceCores;

View File

@@ -65,7 +65,7 @@
UChar_Vect vec = new UChar_Vect();
vec.reserve(fp.length);
for (int size=0;size<fp.length;++size) {
vec.add(fp[size]);
vec.add((short)fp[size]);
}
return new ExplicitBitVect(vec);
}

View File

@@ -68,7 +68,7 @@ typedef std::vector<std::string> STR_VECT;
UChar_Vect vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add(b[size]);
vec.add((short)b[size]);
}
return new FilterCatalog(vec);
}
@@ -188,7 +188,7 @@ typedef std::vector<std::string> STR_VECT;
UChar_Vect vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add(b[size]);
vec.add((short)b[size]);
}
return new FilterCatalog(vec);
}

View File

@@ -39,9 +39,9 @@
#include <GraphMol/Fingerprints/MACCS.h>
%}
%template(UIntPair) std::pair<boost::uint32_t,boost::uint32_t>;
%template(UIntPairVect) std::vector<std::pair<boost::uint32_t,boost::uint32_t> >;
%template(BitInfoMap) std::map<boost::uint32_t,std::vector<std::pair<boost::uint32_t,boost::uint32_t> > >;
%template(UIntPair) std::pair<std::uint32_t,std::uint32_t>;
%template(UIntPairVect) std::vector<std::pair<std::uint32_t,std::uint32_t> >;
%template(BitInfoMap) std::map<unsigned int,std::vector<std::pair<unsigned int,unsigned int> > >;
%newobject RDKit::RDKFingerprintMol;
%newobject RDKit::LayeredFingerprintMol;
%newobject RDKit::PatternFingerprintMol;

View File

@@ -14,10 +14,12 @@
typedef std::vector<std::string> STR_VECT;
%}
%include "std_string.i"
%template(SparseIntVect64) RDKit::SparseIntVect<boost::int64_t>;
%template(StringMolMap) std::map<std::string, boost::shared_ptr<RDKit::ROMol>>;
%template(ROMol_Vect) std::vector<boost::shared_ptr<RDKit::ROMol>>;
%template(StringMolMap_Vect) std::vector<std::map<std::string, boost::shared_ptr<RDKit::ROMol>>>;
%template(StringROMol_VectMap) std::map<std::string,std::vector<boost::shared_ptr<RDKit::ROMol>>>;

View File

@@ -56,7 +56,7 @@
UChar_Vect vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add(b[size]);
vec.add((short)b[size]);
}
return new SubstructLibrary(vec);
}
@@ -107,7 +107,7 @@
UChar_Vect vec = new UChar_Vect();
vec.reserve(b.length);
for (int size=0;size<b.length;++size) {
vec.add(b[size]);
vec.add((short)b[size]);
}
return new SubstructLibrary(vec);
}

View File

@@ -20,7 +20,12 @@
}
};
%include <std_vector.i>
// suggested in the CHANGELOG for SWIG 4.0
%extend std::vector {
vector(size_type count) { return new std::vector< T >(count); }
}
%include "std_vector.i"

View File

@@ -245,7 +245,7 @@ public class AtomPairsTests extends GraphMolTest {
Match_Vect nz1 = fp1.getNonzero();
assertTrue(nz1.size() > 0);
roots.add(0);
roots.add(0L);
fp2 = RDKFuncs.getAtomPairFingerprint(mol, roots);
Match_Vect nz2 = fp2.getNonzero();
assertTrue(nz2.size() > 0);
@@ -263,7 +263,7 @@ public class AtomPairsTests extends GraphMolTest {
ROMol mol = RWMol.MolFromSmiles("OCCCC");
UInt_Vect roots = new UInt_Vect();
roots.add(0);
roots.add(0L);
fp1 = RDKFuncs.getTopologicalTorsionFingerprint(mol);
Long_Pair_Vect nz1 = fp1.getNonzero();

View File

@@ -125,7 +125,7 @@ public class Chemv2Tests extends GraphMolTest {
ROMol m = RWMol.MolFromSmiles("C[C@H]1CO1");
Atom a0 = m.getAtomWithIdx(0);
Int_Point2D_Map coords = new Int_Point2D_Map();
coords.set((int) a0.getIdx(), new Point2D(1.0, 1.5));
coords.set((int)a0.getIdx(), new Point2D(1.0, 1.5));
RDKFuncs.setPreferCoordGen(false);
long confIdx = m.compute2DCoords(coords);
Conformer c = m.getConformer((int) confIdx);

View File

@@ -0,0 +1,74 @@
/* -----------------------------------------------------------------------------
* std_map.i
*
* SWIG typemaps for std::map
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class K, class T> class map {
// add typemaps here
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef K key_type;
typedef T mapped_type;
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
const T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
%enddef
}

View File

@@ -0,0 +1,85 @@
/* -----------------------------------------------------------------------------
* std_vector.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef const value_type& const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef bool value_type;
typedef bool const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
void push_back(const value_type& x);
%extend {
bool get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
}
%define specialize_std_vector(T)
#warning "specialize_std_vector - specialization for type T no longer needed"
%enddef