%module openbabel %begin %{ #define SWIG_PYTHON_2_UNICODE %} %{ // used to set import/export for Cygwin DLLs #ifdef WIN32 #define USING_OBDLL #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include %} #ifdef HAVE_EIGEN %{ #include #include %} #else %ignore OpenBabel::OBForceField::FastRotorSearch; %ignore OpenBabel::OBForceField::DiverseConfGen; #endif %include "std_list.i" %include "std_map.i" %include "std_vector.i" %include "std_string.i" %include "std_pair.i" namespace std { %define VVTEMPLATE_WRAP(name, T) %feature("ignore") vector< vector >::append; %feature("ignore") vector< vector >::assign; %feature("ignore") vector< vector >::back; %feature("ignore") vector< vector >::begin; %feature("ignore") vector< vector >::capacity; %feature("ignore") vector< vector >::clear; %feature("ignore") vector< vector >::empty; %feature("ignore") vector< vector >::end; %feature("ignore") vector< vector >::erase; %feature("ignore") vector< vector >::front; %feature("ignore") vector< vector >::get_allocator; %feature("ignore") vector< vector >::insert; %feature("ignore") vector< vector >::pop; %feature("ignore") vector< vector >::pop_back; %feature("ignore") vector< vector >::push_back; %feature("ignore") vector< vector >::rbegin; %feature("ignore") vector< vector >::rend; %feature("ignore") vector< vector >::reserve; %feature("ignore") vector< vector >::resize; %feature("ignore") vector< vector >::size; %feature("ignore") vector< vector >::swap; %template(vectorv ## name) vector< vector >; %enddef %define VECTORTEMPLATE_WRAP(vectorname, T) %feature("ignore") vector::append; %feature("ignore") vector::assign; %feature("ignore") vector::back; %feature("ignore") vector::begin; %feature("ignore") vector::capacity; %feature("ignore") vector::clear; %feature("ignore") vector::empty; %feature("ignore") vector::end; %feature("ignore") vector::erase; %feature("ignore") vector::front; %feature("ignore") vector::get_allocator; %feature("ignore") vector::insert; %feature("ignore") vector::pop; %feature("ignore") vector::pop_back; %feature("ignore") vector::push_back; %feature("ignore") vector::rbegin; %feature("ignore") vector::rend; %feature("ignore") vector::reserve; %feature("ignore") vector::resize; %feature("ignore") vector::size; %feature("ignore") vector::swap; %template(vector ## vectorname) vector; %enddef %define VECTORPAIRTEMPLATE_WRAP(vectorname, T1, T2) %feature("ignore") vector< pair >::append; %feature("ignore") vector< pair >::assign; %feature("ignore") vector< pair >::back; %feature("ignore") vector< pair >::begin; %feature("ignore") vector< pair >::capacity; %feature("ignore") vector< pair >::clear; %feature("ignore") vector< pair >::empty; %feature("ignore") vector< pair >::end; %feature("ignore") vector< pair >::erase; %feature("ignore") vector< pair >::front; %feature("ignore") vector< pair >::get_allocator; %feature("ignore") vector< pair >::insert; %feature("ignore") vector< pair >::pop; %feature("ignore") vector< pair >::pop_back; %feature("ignore") vector< pair >::push_back; %feature("ignore") vector< pair >::rbegin; %feature("ignore") vector< pair >::rend; %feature("ignore") vector< pair >::reserve; %feature("ignore") vector< pair >::resize; %feature("ignore") vector< pair >::size; %feature("ignore") vector< pair >::swap; %template(vpair ## vectorname) vector< pair >; %enddef VECTORTEMPLATE_WRAP(Int, int) VECTORTEMPLATE_WRAP(UnsignedInt, unsigned int) VVTEMPLATE_WRAP(Int, int) VECTORTEMPLATE_WRAP(Double, double) VECTORTEMPLATE_WRAP(ULong, unsigned long) VECTORTEMPLATE_WRAP(String, std::string) VECTORTEMPLATE_WRAP(Vector3, OpenBabel::vector3) VVTEMPLATE_WRAP(Vector3, OpenBabel::vector3) VECTORTEMPLATE_WRAP(OBMol, OpenBabel::OBMol) VECTORTEMPLATE_WRAP(OBBond, OpenBabel::OBBond) VECTORTEMPLATE_WRAP(OBResidue, OpenBabel::OBResidue) VECTORTEMPLATE_WRAP(OBRing, OpenBabel::OBRing) VECTORTEMPLATE_WRAP(pOBRing, OpenBabel::OBRing*) VECTORTEMPLATE_WRAP(pOBGenericData, OpenBabel::OBGenericData*) VECTORTEMPLATE_WRAP(pOBInternalCoord, OpenBabel::OBInternalCoord*) %template(pairUIntUInt) pair; VECTORPAIRTEMPLATE_WRAP(UIntUInt, unsigned int, unsigned int); %template(vvpairUIntUInt) vector< vector< pair > >; } %define CAST_GENERICDATA_TO(subclass) %inline %{ OpenBabel::OB ## subclass *to ## subclass(OpenBabel::OBGenericData *data) { return (OpenBabel::OB ## subclass *) data; } %} %enddef %inline %{ /* can't use macro -- AliasData not OBAliasData */ OpenBabel::AliasData *toAliasData(OpenBabel::OBGenericData *data) { return (OpenBabel::AliasData*) data; } %} CAST_GENERICDATA_TO(AngleData) CAST_GENERICDATA_TO(AtomClassData) CAST_GENERICDATA_TO(ChiralData) CAST_GENERICDATA_TO(CommentData) CAST_GENERICDATA_TO(ConformerData) CAST_GENERICDATA_TO(ExternalBondData) CAST_GENERICDATA_TO(GridData) CAST_GENERICDATA_TO(MatrixData) CAST_GENERICDATA_TO(NasaThermoData) CAST_GENERICDATA_TO(PairData) // CAST_GENERICDATA_TO(PairTemplate) CAST_GENERICDATA_TO(RateData) CAST_GENERICDATA_TO(RotamerList) CAST_GENERICDATA_TO(RotationData) CAST_GENERICDATA_TO(SerialNums) CAST_GENERICDATA_TO(SetData) CAST_GENERICDATA_TO(SymmetryData) CAST_GENERICDATA_TO(TorsionData) CAST_GENERICDATA_TO(UnitCell) CAST_GENERICDATA_TO(VectorData) CAST_GENERICDATA_TO(VibrationData) CAST_GENERICDATA_TO(VirtualBond) CAST_GENERICDATA_TO(TetrahedralStereo) CAST_GENERICDATA_TO(CisTransStereo) CAST_GENERICDATA_TO(SquarePlanarStereo) // This method is renamed to a valid Python method name, as otherwise // it cannot be used from Python %rename(inc) *::operator++; %ignore *::operator=; %ignore *::operator[]; %import %include %include %include %include %warnfilter(503) OpenBabel::matrix3x3; // Not wrapping any of the overloaded operators %include %include %include // CloneData should be used instead of the following method %ignore OpenBabel::OBBase::SetData; %include %include %include %include %include // To avoid warning in plugin.h about "Nothing known about std::binary_function" namespace std { template class binary_function {}; } %template(dummy) std::binary_function ; %include // To avoid warning in oberror.h about "Nothing known about std::stringbuf" namespace std { class stringbuf {}; } %warnfilter(503) OpenBabel::OBError; // Not wrapping any of the overloaded operators %include %include %include %include %include %include %include %include // Remove C++ iterators %pythoncode %{ def exceptionIter(*args): raise Exception("""\nThis method can only be used from C++. To iterate from Python use the Iter classes (OBMolAtomIter, etc.) as described at http://openbabel.org/wiki/Python""") %} %define IGNORE_ITER(parent, iteree) %ignore OpenBabel::parent::Begin ## iteree ## s; %ignore OpenBabel::parent::End ## iteree ## s; %ignore OpenBabel::parent::Begin ## iteree; %ignore OpenBabel::parent::Next ## iteree; %enddef IGNORE_ITER(OBMol, Bond) IGNORE_ITER(OBMol, Atom) IGNORE_ITER(OBMol, Residue) %include %pythoncode %{ OBMol.BeginAtoms = OBMol.EndAtoms = OBMol.BeginAtom = OBMol.EndAtom = exceptionIter OBMol.BeginBonds = OBMol.EndBonds = OBMol.BeginBond = OBMol.EndBond = exceptionIter OBMol.BeginResidues = OBMol.EndResidues = OBMol.BeginResidue = OBMol.EndResidue = exceptionIter %} %include %include %include %include %ignore OpenBabel::FptIndex; %include %ignore OpenBabel::OBDescriptor::LessThan; %include // Ignore shadowed methods %ignore OpenBabel::OBForceField::VectorSubtract(const double *const, const double *const, double *); %ignore OpenBabel::OBForceField::VectorMultiply(const double *const, const double, double *); %include %include %include %include %apply std::string& INPUT { std::string &start } // Required for OBChemTsfm.Init %apply std::string& INPUT { std::string &end } // Required for OBChemTsfm.Init %include %include %include %include %include %include %warnfilter(503) OpenBabel::OBBitVec; // Not wrapping any of the overloaded operators %include // Ignore shadowed method %ignore OpenBabel::OBRotor::GetRotAtoms() const; %include %ignore OpenBabel::Swab; %include %include #ifdef HAVE_EIGEN %include %include #endif // The following %ignores avoid warning messages due to shadowed classes. // This does not imply a loss of functionality as (in this case) // the shadowed class is identical (from the point of view of SWIG) to // the shadowing class. // This is because C++ references (&) are transformed by SWIG back into // pointers, so that OBAtomIter(OBMol &) would be treated the same as // OBAtomIter(OBMol *). %ignore OBAtomAtomIter(OBAtom &); %ignore OBAtomBondIter(OBAtom &); %ignore OBMolAngleIter(OBMol &); %ignore OBMolAtomIter(OBMol &); %ignore OBMolAtomBFSIter(OBMol &); %ignore OBMolAtomDFSIter(OBMol &); %ignore OBMolAtomBFSIter(OBMol &, int); %ignore OBMolAtomDFSIter(OBMol &, int); %ignore OBMolBondIter(OBMol &); %ignore OBMolBondBFSIter(OBMol &); %ignore OBMolBondBFSIter(OBMol &, int); %ignore OBMolPairIter(OBMol &); %ignore OBMolRingIter(OBMol &); %ignore OBMolTorsionIter(OBMol &); %ignore OBResidueIter(OBMol &); %ignore OBResidueAtomIter(OBResidue &); // These classes are renamed so that they can be replaced by Python // classes of the same name which provide Pythonic iterators // (see %pythoncode section below) %rename(_OBAtomAtomIter) OpenBabel::OBAtomAtomIter; %rename(_OBAtomBondIter) OpenBabel::OBAtomBondIter; %rename(_OBMolAngleIter) OpenBabel::OBMolAngleIter; %rename(_OBMolAtomIter) OpenBabel::OBMolAtomIter; %rename(_OBMolAtomBFSIter) OpenBabel::OBMolAtomBFSIter; %rename(_OBMolAtomDFSIter) OpenBabel::OBMolAtomDFSIter; %rename(_OBMolBondIter) OpenBabel::OBMolBondIter; %rename(_OBMolPairIter) OpenBabel::OBMolPairIter; %rename(_OBMolRingIter) OpenBabel::OBMolRingIter; %rename(_OBMolTorsionIter) OpenBabel::OBMolTorsionIter; %rename(_OBResidueIter) OpenBabel::OBResidueIter; %rename(_OBResidueAtomIter) OpenBabel::OBResidueAtomIter; %rename(_OBFingerprintIter) OpenBabel::PluginIter; %include // The following class, OBiter, is subclassed to provide Python iterators // equivalent to the C++ iterators in obiter.h and the plugin iterators %pythoncode %{ class OBIter(object): OBiterator = None # This is defined by the subclasses def __init__(self, *params): self.iter = self.OBiterator(*params) self.finished = False if not self.iter.__bool__(): self.finished = True def __iter__(self): return self def next(self): if not self.finished: b = self.iter.__ref__() self.iter.inc() if not self.iter.__bool__(): # There is nothing left to iterate over self.finished = True return b else: raise StopIteration __next__ = next class OBIterWithDepth(OBIter): def next(self): if not self.finished: b = self.iter.__ref__() depth = self.iter.CurrentDepth() self.iter.inc() if not self.iter.__bool__(): # There is nothing left to iterate over self.finished = True return b, depth else: raise StopIteration class OBAtomAtomIter(OBIter): """Iterator over the atoms attached to an atom.""" OBiterator = _OBAtomAtomIter class OBAtomBondIter(OBIter): """Iterator over the bonds attached to an atom.""" OBiterator = _OBAtomBondIter class OBMolAngleIter(OBIter): """Iterator over the angles in a molecule.""" OBiterator = _OBMolAngleIter class OBMolAtomIter(OBIter): """Iterator over the atoms in a molecule.""" OBiterator = _OBMolAtomIter class OBMolAtomBFSIter(OBIterWithDepth): """Iterator over the atoms in a molecule in a breadth-first manner.""" OBiterator = _OBMolAtomBFSIter class OBMolAtomDFSIter(OBIter): """Iterator over the atoms in a molecule in a depth-first manner.""" OBiterator = _OBMolAtomDFSIter class OBMolBondIter(OBIter): """Iterator over the bonds in a molecule.""" OBiterator = _OBMolBondIter class OBMolPairIter(OBIter): """Iterator over pairs of atoms in a molecule.""" OBiterator = _OBMolPairIter class OBMolRingIter(OBIter): """Iterator over the rings in a molecule.""" OBiterator = _OBMolRingIter class OBMolTorsionIter(OBIter): """Iterator over the torsion angles in a molecule.""" OBiterator = _OBMolTorsionIter class OBResidueIter(OBIter): """Iterator over the residues in a molecule.""" OBiterator = _OBResidueIter class OBResidueAtomIter(OBIter): """Iterator over the atoms in a residue.""" OBiterator = _OBResidueAtomIter %} %include "carrays.i" %array_class(double, doubleArray) %pythoncode %{ def double_array(mylist): """Create a C array of doubles from a list.""" c = doubleArray(len(mylist)) for i,v in enumerate(mylist): c[i] = v return c %} // Copy some of the global variables in cvar into the openbabel namespace %pythoncode %{ obErrorLog = cvar.obErrorLog ttab = cvar.ttab etab = cvar.etab isotab = cvar.isotab atomtyper = cvar.atomtyper aromtyper = cvar.aromtyper %} // Functions to set the log file to std::cout and std::cerr %ignore OBForceField::SetLogFile(std::ostream *pos); %extend OpenBabel::OBForceField { void SetLogToStdOut() { self->SetLogFile(&std::cout); } void SetLogToStdErr() { self->SetLogFile(&std::cerr); } }; %extend OpenBabel::OBMol { void SetTorsion(int i, int j, int k, int l, double ang) { self->SetTorsion(self->GetAtom(i), self->GetAtom(j), self->GetAtom(k), self->GetAtom(l), ang); } }; %pythoncode %{ def exception(*args): raise Exception("Use OBMol.CloneData instead. OBMol.SetData is only for use from C++.") OBMol.SetData = exception %} %include "stereo.i"