mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
initial import
This commit is contained in:
15
Code/Catalogs/Catalog.cpp
Executable file
15
Code/Catalogs/Catalog.cpp
Executable file
@@ -0,0 +1,15 @@
|
||||
// $Id: Catalog.cpp 4942 2006-02-17 01:19:53Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
//
|
||||
|
||||
#include "Catalog.h"
|
||||
|
||||
namespace RDCatalog {
|
||||
|
||||
|
||||
}
|
||||
|
||||
469
Code/Catalogs/Catalog.h
Executable file
469
Code/Catalogs/Catalog.h
Executable file
@@ -0,0 +1,469 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#ifndef __RD_CATALOG_H__
|
||||
#define __RD_CATALOG_H__
|
||||
|
||||
// Boost graph stuff
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include <boost/property_map.hpp>
|
||||
|
||||
// for some typedefs
|
||||
#include <RDGeneral/types.h>
|
||||
#include <RDGeneral/StreamOps.h>
|
||||
|
||||
namespace RDCatalog {
|
||||
const int versionMajor=1;
|
||||
const int versionMinor=0;
|
||||
const int versionPatch=0;
|
||||
const int endianId=0xDEADBEEF;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//! abstract base class for a catalog object
|
||||
template <class entryType, class paramType>
|
||||
class Catalog {
|
||||
public:
|
||||
//------------------------------------
|
||||
Catalog() : d_fpLength(0), dp_cParams(0) {};
|
||||
|
||||
//------------------------------------
|
||||
virtual ~Catalog(){
|
||||
if (dp_cParams) {
|
||||
delete dp_cParams;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! return a serialized form of the Catalog as an std::string
|
||||
virtual std::string Serialize() const = 0;
|
||||
|
||||
//------------------------------------
|
||||
//! adds an entry to the catalog
|
||||
/*!
|
||||
|
||||
\param entry the entry to be added
|
||||
\param updateFPLength (optional) if this is true, our internal
|
||||
fingerprint length will also be updated.
|
||||
|
||||
*/
|
||||
virtual unsigned int addEntry(entryType *entry, bool updateFPLength = true) = 0;
|
||||
|
||||
//------------------------------------
|
||||
//! returns a particular entry in the Catalog
|
||||
virtual const entryType* getEntryWithIdx(unsigned int idx) const = 0;
|
||||
|
||||
//------------------------------------
|
||||
//! returns the number of entries
|
||||
virtual unsigned int getNumEntries() const = 0;
|
||||
|
||||
//------------------------------------
|
||||
//! returns the length of our fingerprint
|
||||
unsigned int getFPLength() const {return d_fpLength;}
|
||||
|
||||
//------------------------------------
|
||||
//! sets our fingerprint length
|
||||
void setFPLength(unsigned int val) {d_fpLength = val;}
|
||||
|
||||
//------------------------------------
|
||||
//! sets our parameters by copying the \c params argument
|
||||
void setCatalogParams(paramType *params) {
|
||||
PRECONDITION(params,"bad parameter object");
|
||||
//if we already have a paramter object throw an exception
|
||||
PRECONDITION(!dp_cParams,"A parameter object already exists on the catalog" );
|
||||
/*
|
||||
if (dp_cParams) {
|
||||
// we already have parameter object on the catalog
|
||||
// can't overwrite it
|
||||
PRECONDITION(0, "A parameter object already exist on the catalog");
|
||||
}*/
|
||||
dp_cParams = new paramType(*params);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a pointer to our parameters
|
||||
const paramType *getCatalogParams() const { return dp_cParams;}
|
||||
|
||||
protected:
|
||||
// this is the ID that will be assigned to the next entry
|
||||
// added to the catalog - need not be same as the number of entries
|
||||
// in the catalog and does not correspond with the
|
||||
// id of the entry in the catalog.
|
||||
// this is more along the lines of bitId
|
||||
unsigned int d_fpLength; //!< the length of our fingerprint
|
||||
paramType *dp_cParams; //!< our params object
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//! A Catalog with a hierarchical structure
|
||||
/*!
|
||||
|
||||
The entries of a HierarchCatalog are arranged in a directed graph
|
||||
|
||||
<b>The difference between <i>Indices</i> and <i>Bit Ids</i></b>
|
||||
|
||||
A HierarchCatalog may contain more entries than the user is actually
|
||||
interested in. For example a HierarchCatalog constructed to contain
|
||||
orders 5 through 8 may well contain information about orders 1-5,
|
||||
in order to facilitate some search optimizations.
|
||||
|
||||
- <i>Bit Ids</i> refer to the "interesting" bits.
|
||||
So, in the above example, Bit Id \c 0 will be the first entry
|
||||
with order 5.
|
||||
- <i>Indices</i> refer to the underlying structure of the catalog.
|
||||
So, in the above example, the entry with index \c 0 will be
|
||||
the first entry with order 1.
|
||||
|
||||
*/
|
||||
template <class entryType, class paramType, class orderType>
|
||||
class HierarchCatalog : public Catalog <entryType, paramType> {
|
||||
// the entries in the catalog can be traversed using the edges
|
||||
// in a desired order
|
||||
public:
|
||||
//! used by the BGL to set up the node properties in our graph
|
||||
struct vertex_entry_t {
|
||||
enum { num=1003 };
|
||||
typedef boost::vertex_property_tag kind;
|
||||
};
|
||||
typedef boost::property<vertex_entry_t, entryType *> EntryProperty;
|
||||
|
||||
//! the type of the graph itself:
|
||||
typedef boost::adjacency_list<boost::vecS,
|
||||
boost::vecS, // FIX: should be using setS for edges so that parallel edges are never added (page 225 BGL book)
|
||||
// but that seems result in compile errors
|
||||
boost::bidirectionalS,
|
||||
EntryProperty> CatalogGraph;
|
||||
|
||||
typedef boost::graph_traits<CatalogGraph> CAT_GRAPH_TRAITS;
|
||||
typedef typename CAT_GRAPH_TRAITS::vertex_iterator VER_ITER;
|
||||
typedef std::pair<VER_ITER, VER_ITER> ENT_ITER_PAIR;
|
||||
typedef typename CAT_GRAPH_TRAITS::adjacency_iterator DOWN_ENT_ITER;
|
||||
typedef std::pair<DOWN_ENT_ITER, DOWN_ENT_ITER> DOWN_ENT_ITER_PAIR;
|
||||
|
||||
//------------------------------------
|
||||
HierarchCatalog<entryType, paramType, orderType>() {};
|
||||
|
||||
//------------------------------------
|
||||
//! Construct by making a copy of the input \c params object
|
||||
HierarchCatalog<entryType, paramType, orderType>(paramType *params) : Catalog<entryType,paramType>() {
|
||||
this->setCatalogParams(params);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! Construct from a \c pickle (a serialized form of the HierarchCatalog)
|
||||
HierarchCatalog<entryType, paramType, orderType>(const std::string &pickle) {
|
||||
this->initFromString(pickle);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
~HierarchCatalog() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! serializes this object to a stream
|
||||
void toStream(std::ostream &ss) const {
|
||||
// the i/o header:
|
||||
RDKit::streamWrite(ss,endianId);
|
||||
RDKit::streamWrite(ss,versionMajor);
|
||||
RDKit::streamWrite(ss,versionMinor);
|
||||
RDKit::streamWrite(ss,versionPatch);
|
||||
|
||||
// information about the catalog itself:
|
||||
int tmpUInt;
|
||||
tmpUInt = this->getFPLength();
|
||||
RDKit::streamWrite(ss,tmpUInt);
|
||||
tmpUInt = this->getNumEntries();
|
||||
RDKit::streamWrite(ss,tmpUInt);
|
||||
|
||||
//std::cout << ">>>>-------------------------------" << std::endl;
|
||||
//std::cout << "\tlength: " << getFPLength() << " " << getNumEntries() << std::endl;
|
||||
|
||||
// add the params object:
|
||||
this->getCatalogParams()->toStream(ss);
|
||||
//std::cout << "\tparams: " << getCatalogParams()->getLowerFragLength();
|
||||
//std::cout << " " << getCatalogParams()->getUpperFragLength();
|
||||
//std::cout << " " << getCatalogParams()->getNumFuncGroups();
|
||||
//std::cout << std::endl;
|
||||
|
||||
// write the entries in order:
|
||||
for(unsigned int i=0;i<getNumEntries();i++){
|
||||
this->getEntryWithIdx(i)->toStream(ss);
|
||||
}
|
||||
|
||||
// finally the adjacency list:
|
||||
for(unsigned int i=0;i<getNumEntries();i++){
|
||||
RDKit::INT_VECT children=this->getDownEntryList(i);
|
||||
tmpUInt = children.size();
|
||||
RDKit::streamWrite(ss,tmpUInt);
|
||||
for(RDKit::INT_VECT::const_iterator ivci=children.begin();
|
||||
ivci!=children.end();
|
||||
ivci++){
|
||||
RDKit::streamWrite(ss,*ivci);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! serializes this object and returns the resulting \c pickle
|
||||
std::string Serialize() const {
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
|
||||
this->toStream(ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! fills the contents of this object from a stream containing a \c pickle
|
||||
void initFromStream(std::istream &ss) {
|
||||
int tmpInt;
|
||||
// FIX: at the moment we ignore the header info:
|
||||
RDKit::streamRead(ss,tmpInt);
|
||||
RDKit::streamRead(ss,tmpInt);
|
||||
RDKit::streamRead(ss,tmpInt);
|
||||
RDKit::streamRead(ss,tmpInt);
|
||||
|
||||
unsigned int tmpUInt;
|
||||
RDKit::streamRead(ss,tmpUInt);// fp length
|
||||
this->setFPLength(tmpUInt);
|
||||
|
||||
unsigned int numEntries;
|
||||
RDKit::streamRead(ss,numEntries);
|
||||
//std::cout << "<<<-------------------------------" << std::endl;
|
||||
//std::cout << "\tlength: " << getFPLength() << " " << numEntries << std::endl;
|
||||
|
||||
|
||||
// grab the params:
|
||||
paramType *params = new paramType();
|
||||
params->initFromStream(ss);
|
||||
this->setCatalogParams(params);
|
||||
|
||||
//std::cout << "\tparams: " << getCatalogParams()->getLowerFragLength();
|
||||
//std::cout << " " << getCatalogParams()->getUpperFragLength();
|
||||
//std::cout << " " << getCatalogParams()->getNumFuncGroups();
|
||||
//std::cout << std::endl;
|
||||
|
||||
// now all of the entries:
|
||||
for(unsigned int i=0;i<numEntries;i++){
|
||||
entryType *entry = new entryType();
|
||||
entry->initFromStream(ss);
|
||||
this->addEntry(entry,false);
|
||||
}
|
||||
|
||||
// and, finally, the adjacency list:
|
||||
for(unsigned int i=0;i<numEntries;i++){
|
||||
unsigned int nNeighbors;
|
||||
RDKit::streamRead(ss,nNeighbors);
|
||||
for(unsigned int j=0;j<nNeighbors;j++){
|
||||
RDKit::streamRead(ss,tmpInt);
|
||||
this->addEdge(i,tmpInt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
unsigned int getNumEntries() const {
|
||||
return boost::num_vertices(d_graph);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! fills the contents of this object from a string containing a \c pickle
|
||||
void initFromString(const std::string &text){
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
|
||||
// initialize the stream:
|
||||
ss.write(text.c_str(),text.length());
|
||||
// now start reading out values:
|
||||
this->initFromStream(ss);
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! add a new entry to the catalog
|
||||
/*!
|
||||
|
||||
\param entry the entry to be added
|
||||
\param updateFPLength (optional) if this is true, our internal
|
||||
fingerprint length will also be updated.
|
||||
|
||||
*/
|
||||
unsigned int addEntry(entryType *entry, bool updateFPLength = true){
|
||||
PRECONDITION(entry,"bad arguments");
|
||||
if (updateFPLength) {
|
||||
unsigned int fpl = this->getFPLength();
|
||||
entry->setBitId(fpl);
|
||||
fpl++;
|
||||
this->setFPLength(fpl);
|
||||
}
|
||||
unsigned int eid = boost::add_vertex(EntryProperty(entry), d_graph);
|
||||
orderType etype = entry->getOrder();
|
||||
// REVIEW: this initialization is not required: the STL map, in
|
||||
// theory, will create a new object when operator[] is called
|
||||
// for a new item
|
||||
if (d_orderMap.find(etype) == d_orderMap.end()) {
|
||||
RDKit::INT_VECT nets;
|
||||
d_orderMap[etype] = nets;
|
||||
}
|
||||
d_orderMap[etype].push_back(eid);
|
||||
return eid;
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! adds an edge between two entries in the catalog
|
||||
/*!
|
||||
Since we are using a bidirectional graph - the order in
|
||||
which the ids are supplied here makes a difference
|
||||
|
||||
\param id1 index of the edge's beginning
|
||||
\param id2 index of the edge's end
|
||||
|
||||
*/
|
||||
void addEdge(unsigned int id1, unsigned int id2) {
|
||||
unsigned int nents = getNumEntries();
|
||||
RANGE_CHECK(0, id1, nents-1);
|
||||
RANGE_CHECK(0, id2, nents-1);
|
||||
// FIX: if we boost::setS for the edgeList BGL will
|
||||
// do the checking for duplicity (parallel edges)
|
||||
// But for reasons unknown setS results in compile
|
||||
// errors while using adjacent_vertices.
|
||||
typename CAT_GRAPH_TRAITS::edge_descriptor edge;
|
||||
bool found;
|
||||
boost::tie(edge,found) = boost::edge(boost::vertex(id1,d_graph),
|
||||
boost::vertex(id2,d_graph),
|
||||
d_graph);
|
||||
if (!found) {
|
||||
boost::add_edge(id1, id2, d_graph);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a pointer to our entry with a particular index
|
||||
const entryType *getEntryWithIdx(unsigned int idx) const {
|
||||
RANGE_CHECK(0,idx,getNumEntries()-1);
|
||||
int vd = boost::vertex(idx, d_graph);
|
||||
typename boost::property_map < CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
return pMap[vd];
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a pointer to our entry with a particular bit ID
|
||||
const entryType *getEntryWithBitId(unsigned int idx) const {
|
||||
RANGE_CHECK(0,idx,this->getFPLength()-1);
|
||||
typename boost::property_map < CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
const entryType *res=NULL;
|
||||
for(unsigned int i=idx;i<this->getNumEntries();i++){
|
||||
const entryType *e=pMap[i];
|
||||
if(e->getBitId()==idx){
|
||||
res=e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns the index of the entry with a particular bit ID
|
||||
int getIdOfEntryWithBitId(unsigned int idx) const {
|
||||
RANGE_CHECK(0,idx,this->getFPLength()-1);
|
||||
typename boost::property_map < CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
int res=-1;
|
||||
for(unsigned int i=idx;i<this->getNumEntries();i++){
|
||||
const entryType *e=pMap[i];
|
||||
if(e->getBitId()==idx){
|
||||
res=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a list of the indices of entries below the one passed in
|
||||
RDKit::INT_VECT getDownEntryList(unsigned int idx) const {
|
||||
RDKit::INT_VECT res;
|
||||
DOWN_ENT_ITER nbrIdx, endIdx;
|
||||
boost::tie(nbrIdx, endIdx) = boost::adjacent_vertices(idx, d_graph);
|
||||
while (nbrIdx != endIdx) {
|
||||
res.push_back(*nbrIdx);
|
||||
nbrIdx++;
|
||||
}
|
||||
//std::cout << res.size() << "\n";
|
||||
return res;
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a list of the indices that have a particular order
|
||||
const RDKit::INT_VECT &getEntriesOfOrder(orderType ord) {
|
||||
return d_orderMap[ord];
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
//! returns a list of the indices that have a particular order
|
||||
/*!
|
||||
\overload
|
||||
*/
|
||||
const RDKit::INT_VECT &getEntriesOfOrder(orderType ord) const {
|
||||
typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
|
||||
elem = d_orderMap.find(ord);
|
||||
CHECK_INVARIANT(elem!=d_orderMap.end()," catalog does not contain any entries of the order specified");
|
||||
return elem->second;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// graphs that store the entries in the catalog in a hierachical manner
|
||||
CatalogGraph d_graph;
|
||||
// a map that maps the order type of entries in the catalog to
|
||||
// a vector of vertex indices in the graphs above
|
||||
// e.g. for a catalog with molecular fragments, the order of a fragment can
|
||||
// simply be the number of bond in it. The list this oder maps to is all the
|
||||
// vertex ids of these fragment in the catalog that have this many bonds in them
|
||||
std::map<orderType, RDKit::INT_VECT> d_orderMap;
|
||||
|
||||
//------------------------------------
|
||||
//! clear any memory that we've used
|
||||
void destroy() {
|
||||
ENT_ITER_PAIR entItP = boost::vertices(d_graph);
|
||||
typename boost::property_map < CatalogGraph, vertex_entry_t>::type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
while (entItP.first != entItP.second) {
|
||||
delete pMap[*(entItP.first++)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//! a linear Catalog (analogous to an std::vector)
|
||||
/*!
|
||||
Here there is no particular hierarchy, simply a
|
||||
collection of entries.
|
||||
*/
|
||||
template <class entryType, class orderType>
|
||||
class LinearCatalog : public Catalog <entryType, orderType> {
|
||||
// here there is no particular hierarchy of entries
|
||||
// we simply model it as a vector of entries
|
||||
// FIX: for retrieval purposes a better model map be std::map
|
||||
|
||||
public:
|
||||
std::string Serialize();
|
||||
|
||||
unsigned int addEntry(entryType *entry, bool updateFPLength = true);
|
||||
|
||||
const entryType *getEntryWithIdx(unsigned int idx) const;
|
||||
|
||||
private:
|
||||
std::vector<entryType*> d_vector;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
13
Code/Catalogs/CatalogEntry.cpp
Executable file
13
Code/Catalogs/CatalogEntry.cpp
Executable file
@@ -0,0 +1,13 @@
|
||||
// $Id: CatalogEntry.cpp 4942 2006-02-17 01:19:53Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#include "CatalogEntry.h"
|
||||
|
||||
namespace RDCatalog {
|
||||
CatalogEntry::~CatalogEntry() {}
|
||||
|
||||
}
|
||||
45
Code/Catalogs/CatalogEntry.h
Executable file
45
Code/Catalogs/CatalogEntry.h
Executable file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_CATALOGENTRY_H__
|
||||
#define __RD_CATALOGENTRY_H__
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace RDCatalog {
|
||||
|
||||
//! Abstract base class to be used to represent an entry in a Catalog
|
||||
class CatalogEntry {
|
||||
public:
|
||||
virtual ~CatalogEntry() = 0;
|
||||
|
||||
//! sets our bit Id
|
||||
void setBitId(int bid) {d_bitId = bid;};
|
||||
|
||||
//! returns our bit Id
|
||||
int getBitId() const {return d_bitId;};
|
||||
|
||||
//! returns a text description of this entry
|
||||
virtual std::string getDescription() const = 0;
|
||||
|
||||
//! serializes (pickles) to a stream
|
||||
virtual void toStream(std::ostream &ss) const = 0;
|
||||
//! returns a string with a serialized (pickled) representation
|
||||
virtual std::string Serialize() const = 0;
|
||||
//! initializes from a stream pickle
|
||||
virtual void initFromStream(std::istream &ss) = 0;
|
||||
//! initializes from a string pickle
|
||||
virtual void initFromString(const std::string &text) = 0;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
int d_bitId; //!< our bit Id. This needs to be signed so that we can mark uninitialized entries.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
12
Code/Catalogs/CatalogParams.cpp
Executable file
12
Code/Catalogs/CatalogParams.cpp
Executable file
@@ -0,0 +1,12 @@
|
||||
// $Id: CatalogParams.cpp 4942 2006-02-17 01:19:53Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#include "CatalogParams.h"
|
||||
|
||||
namespace RDCatalog {
|
||||
CatalogParams::~CatalogParams() {};
|
||||
}
|
||||
37
Code/Catalogs/CatalogParams.h
Executable file
37
Code/Catalogs/CatalogParams.h
Executable file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_CATALOGPARAMS_H__
|
||||
#define __RD_CATALOGPARAMS_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace RDCatalog {
|
||||
//! abstract base class for the container used to create a catalog
|
||||
class CatalogParams {
|
||||
public:
|
||||
virtual ~CatalogParams() = 0;
|
||||
|
||||
//! returns our type string
|
||||
std::string getTypeStr() const { return d_typeStr; };
|
||||
|
||||
//! sets our type string
|
||||
void setTypeStr(const std::string &typeStr) { d_typeStr=typeStr; };
|
||||
|
||||
//! serializes (pickles) to a stream
|
||||
virtual void toStream(std::ostream &) const = 0;
|
||||
//! returns a string with a serialized (pickled) representation
|
||||
virtual std::string Serialize() const = 0;
|
||||
//! initializes from a stream pickle
|
||||
virtual void initFromStream(std::istream &ss) = 0;
|
||||
//! initializes from a string pickle
|
||||
virtual void initFromString(const std::string &text) = 0;
|
||||
|
||||
protected:
|
||||
std::string d_typeStr; //!< our type string
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
117
Code/Catalogs/Catalogs.dsp
Executable file
117
Code/Catalogs/Catalogs.dsp
Executable file
@@ -0,0 +1,117 @@
|
||||
# Microsoft Developer Studio Project File - Name="Catalogs" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=Catalogs - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Catalogs.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Catalogs.mak" CFG="Catalogs - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Catalogs - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "Catalogs - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Catalogs - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Catalogs___Win32_Release"
|
||||
# PROP BASE Intermediate_Dir "Catalogs___Win32_Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Catalogs___Win32_Release"
|
||||
# PROP Intermediate_Dir "Catalogs___Win32_Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "." /I "$(RDBASE)/code" /I "$(RDBASE)/code/graphmol" /I "$(RDBASE)/External/$(BOOSTBASE)" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "Catalogs - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Catalogs___Win32_Debug0"
|
||||
# PROP BASE Intermediate_Dir "Catalogs___Win32_Debug0"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Catalogs___Win32_Debug0"
|
||||
# PROP Intermediate_Dir "Catalogs___Win32_Debug0"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I "$(RDBASE)/code" /I "$(RDBASE)/code/graphmol" /I "$(RDBASE)/External/$(BOOSTBASE)" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Catalogs - Win32 Release"
|
||||
# Name "Catalogs - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Catalog.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CatalogEntry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CatalogParams.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Catalog.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CatalogEntry.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CatalogParams.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
204
Code/Catalogs/Catalogs.vcproj
Executable file
204
Code/Catalogs/Catalogs.vcproj
Executable file
@@ -0,0 +1,204 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="libCatalogs"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Catalogs___Win32_Release"
|
||||
IntermediateDirectory=".\Catalogs___Win32_Release"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\Catalogs___Win32_Release/Catalogs.pch"
|
||||
AssemblerListingLocation=".\Catalogs___Win32_Release/"
|
||||
ObjectFile=".\Catalogs___Win32_Release/"
|
||||
ProgramDataBaseFileName=".\Catalogs___Win32_Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\Catalogs___Win32_Release\Catalogs.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Catalogs___Win32_Debug0"
|
||||
IntermediateDirectory=".\Catalogs___Win32_Debug0"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Catalogs___Win32_Debug0/Catalogs.pch"
|
||||
AssemblerListingLocation=".\Catalogs___Win32_Debug0/"
|
||||
ObjectFile=".\Catalogs___Win32_Debug0/"
|
||||
ProgramDataBaseFileName=".\Catalogs___Win32_Debug0/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\Catalogs___Win32_Debug0\Catalogs.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath="Catalog.cpp">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CatalogEntry.cpp">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CatalogParams.cpp">
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath="Catalog.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CatalogEntry.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CatalogParams.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\VTune\Catalogs.vpj">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
14
Code/Catalogs/Makefile
Executable file
14
Code/Catalogs/Makefile
Executable file
@@ -0,0 +1,14 @@
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
include $(RDBASE)/Code/rdrules.make
|
||||
CXXFLAGS=$(BASECXXFLAGS) $(VFLIBINC)
|
||||
|
||||
SOURCES=Catalog.cpp CatalogParams.cpp CatalogEntry.cpp
|
||||
LIB=$(RDCATALOGLIB)
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
ar -rv $@ $?
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIB) $(DEPENDS)
|
||||
|
||||
include $(DEPENDS)
|
||||
|
||||
28
Code/ChemicalFeatures/ChemicalFeature.h
Normal file
28
Code/ChemicalFeatures/ChemicalFeature.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __CHEMICALFEATURE_H_11012005_1310__
|
||||
#define __CHEMICALFEATURE_H_11012005_1310__
|
||||
|
||||
#include <Geometry/point.h>
|
||||
namespace ChemicalFeatures {
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//! abstract base class for chemical feature
|
||||
class ChemicalFeature {
|
||||
public:
|
||||
ChemicalFeature() {};
|
||||
virtual ~ChemicalFeature() {};
|
||||
|
||||
virtual const std::string& getType() const = 0;
|
||||
|
||||
virtual const std::string& getFamily() const = 0;
|
||||
|
||||
virtual RDGeom::Point3D getPos() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
63
Code/ChemicalFeatures/FreeChemicalFeature.cpp
Normal file
63
Code/ChemicalFeatures/FreeChemicalFeature.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// $Id: FreeChemicalFeature.cpp 4943 2006-02-17 01:21:27Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2005-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "FreeChemicalFeature.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace ChemicalFeatures {
|
||||
const int ci_FEAT_VERSION=0x0010; //!< version number to use in pickles
|
||||
|
||||
std::string FreeChemicalFeature::toString() const {
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
|
||||
unsigned int tInt = ci_FEAT_VERSION;
|
||||
ss.write((const char *)&(tInt),sizeof(tInt));
|
||||
tInt = d_family.size()+1;
|
||||
ss.write((const char *)&(tInt),sizeof(tInt));
|
||||
ss.write(d_family.c_str(),tInt*sizeof(char));
|
||||
tInt = d_type.size()+1;
|
||||
ss.write((const char *)&(tInt),sizeof(tInt));
|
||||
ss.write(d_type.c_str(),tInt*sizeof(char));
|
||||
ss.write((const char *)&d_position.x,sizeof(d_position.x));
|
||||
ss.write((const char *)&d_position.y,sizeof(d_position.y));
|
||||
ss.write((const char *)&d_position.z,sizeof(d_position.z));
|
||||
std::string res(ss.str());
|
||||
return res;
|
||||
};
|
||||
void FreeChemicalFeature::initFromString(const std::string &pickle){
|
||||
std::stringstream ss(pickle,
|
||||
std::ios_base::binary|std::ios_base::in|std::ios_base::out);
|
||||
int version=0;
|
||||
unsigned int tInt;
|
||||
ss.read((char *)&tInt,sizeof(tInt));
|
||||
switch(tInt){
|
||||
case 0x0010:
|
||||
version=1;
|
||||
break;
|
||||
default:
|
||||
throw("Unknown version type for FreeChemicalFeature");
|
||||
}
|
||||
|
||||
char *tmpChr;
|
||||
ss.read((char *)&(tInt),sizeof(tInt));
|
||||
tmpChr = new char[tInt];
|
||||
ss.read(tmpChr,tInt*sizeof(char));
|
||||
d_family = tmpChr;
|
||||
delete [] tmpChr;
|
||||
|
||||
ss.read((char *)&(tInt),sizeof(tInt));
|
||||
tmpChr = new char[tInt];
|
||||
ss.read(tmpChr,tInt*sizeof(char));
|
||||
d_type = tmpChr;
|
||||
delete [] tmpChr;
|
||||
|
||||
ss.read((char *)&d_position.x,sizeof(d_position.x));
|
||||
ss.read((char *)&d_position.y,sizeof(d_position.x));
|
||||
ss.read((char *)&d_position.z,sizeof(d_position.x));
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
77
Code/ChemicalFeatures/FreeChemicalFeature.h
Normal file
77
Code/ChemicalFeatures/FreeChemicalFeature.h
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __FREECHEMICALFEATURE_H_13012005_1023__
|
||||
#define __FREECHEMICALFEATURE_H_13012005_1023__
|
||||
|
||||
#include <Geometry/point.h>
|
||||
#include <ChemicalFeatures/ChemicalFeature.h>
|
||||
|
||||
namespace ChemicalFeatures {
|
||||
|
||||
//------------------------------------------------------
|
||||
//! Class for chemical features that do orignate from molecules
|
||||
// e.g. pharamcophores, site-maps etc.
|
||||
class FreeChemicalFeature : public ChemicalFeature {
|
||||
public:
|
||||
FreeChemicalFeature(std::string family, std::string type,
|
||||
const RDGeom::Point3D &loc) :
|
||||
d_family(family), d_type(type), d_position(loc) {
|
||||
}
|
||||
|
||||
FreeChemicalFeature(std::string family, const RDGeom::Point3D &loc) :
|
||||
d_family(family), d_type(""), d_position(loc) {
|
||||
}
|
||||
|
||||
explicit FreeChemicalFeature(const std::string &pickle) {
|
||||
this->initFromString(pickle);
|
||||
}
|
||||
FreeChemicalFeature() :
|
||||
d_family(""), d_type(""), d_position(RDGeom::Point3D(0.0, 0.0, 0.0)) {
|
||||
}
|
||||
|
||||
FreeChemicalFeature(const FreeChemicalFeature &other) :
|
||||
d_family(other.getFamily()), d_type(other.getType()), d_position(other.getPos()) {
|
||||
}
|
||||
|
||||
~FreeChemicalFeature() {}
|
||||
|
||||
const std::string& getFamily() const {
|
||||
return d_family;
|
||||
}
|
||||
|
||||
const std::string& getType() const {
|
||||
return d_type;
|
||||
}
|
||||
|
||||
RDGeom::Point3D getPos() const {
|
||||
return d_position;
|
||||
}
|
||||
|
||||
void setFamily(const std::string &family) {
|
||||
d_family = family;
|
||||
}
|
||||
|
||||
void setType(const std::string &type) {
|
||||
d_type = type;
|
||||
}
|
||||
|
||||
void setPos(const RDGeom::Point3D &loc) {
|
||||
d_position = loc;
|
||||
}
|
||||
|
||||
std::string toString() const;
|
||||
void initFromString(const std::string &pickle);
|
||||
|
||||
private:
|
||||
std::string d_family;
|
||||
std::string d_type;
|
||||
RDGeom::Point3D d_position;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
18
Code/ChemicalFeatures/Makefile
Normal file
18
Code/ChemicalFeatures/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
include $(RDBASE)/Code/rdrules.make
|
||||
CXXFLAGS=$(BASECXXFLAGS)
|
||||
|
||||
SOURCES=FreeChemicalFeature.cpp
|
||||
LIB=libChemicalFeatures.a
|
||||
$(LIB): $(OBJS)
|
||||
ar -rv $@ $?
|
||||
|
||||
regrs: testExecs/main.exe
|
||||
|
||||
testExecs/main.exe: testChemicalFeatures.o $(LIB)
|
||||
$(CXX) $(CXXFLAGS) -o $@ testChemicalFeatures.o $(RDCHEMFEATS) $(RDGENERAL)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIB) $(DEPENDS) testExecs/main.exe testChemicalFeatures.o
|
||||
|
||||
include $(DEPENDS)
|
||||
72
Code/ChemicalFeatures/Wrap/FreeChemicalFeature.cpp
Normal file
72
Code/ChemicalFeatures/Wrap/FreeChemicalFeature.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// $Id: FreeChemicalFeature.cpp 4944 2006-02-17 01:23:55Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#define NO_IMPORT_ARRAY
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
#include <RDGeneral/types.h>
|
||||
#include<RDGeneral/Invariant.h>
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
#include <ChemicalFeatures/FreeChemicalFeature.h>
|
||||
|
||||
namespace ChemicalFeatures {
|
||||
|
||||
// allows BitVects to be pickled
|
||||
struct chemfeat_pickle_suite : python::pickle_suite
|
||||
{
|
||||
static python::tuple
|
||||
getinitargs(const FreeChemicalFeature& self)
|
||||
{
|
||||
return python::make_tuple(self.toString());
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
std::string featClassDoc="Class to represent a free chemical feature.\n\
|
||||
These chemical features are not derived from a molecule, though they can be matched \n\
|
||||
to features from a molecule\n";
|
||||
struct freefeat_wrapper {
|
||||
static void wrap() {
|
||||
python::class_<FreeChemicalFeature>("FreeChemicalFeature", featClassDoc.c_str(),
|
||||
python::init<const std::string &>()) //<>("Default Constructor"))
|
||||
.def(python::init<>("Default Constructor"))
|
||||
.def(python::init<std::string, std::string, const RDGeom::Point3D &>
|
||||
(python::args("family", "type", "loc"),
|
||||
"Constructor with family, type and location specified"))
|
||||
.def(python::init<std::string, const RDGeom::Point3D &>
|
||||
(python::args("family", "loc"),
|
||||
"constructor with family and location specified, empty type"))
|
||||
.def("SetFamily", &FreeChemicalFeature::setFamily,
|
||||
"Set the family of the feature")
|
||||
.def("SetType", &FreeChemicalFeature::setType,
|
||||
"Set the sepcific type for the feature")
|
||||
.def("GetFamily", &FreeChemicalFeature::getFamily,
|
||||
"Get the family of the feature",
|
||||
python::return_value_policy<python::copy_const_reference>())
|
||||
.def("GetType", &FreeChemicalFeature::getType,
|
||||
"Get the sepcific type for the feature",
|
||||
python::return_value_policy<python::copy_const_reference>())
|
||||
.def("SetPos", &FreeChemicalFeature::setPos,
|
||||
"Set the feature position")
|
||||
.def("GetPos", &FreeChemicalFeature::getPos,
|
||||
"Get the psotion for the feature")
|
||||
.def_pickle(chemfeat_pickle_suite())
|
||||
;
|
||||
//python::def("FreeChemicalFeature", ChemicalFeatures::makeFreeChemFeat,
|
||||
// (python::arg("family")="", python::arg("type")="",
|
||||
// python::arg("pos")=python::list()),
|
||||
// "This a kind of faking a constructor for FreeChemicalFeature");
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void wrap_freefeat() {
|
||||
ChemicalFeatures::freefeat_wrapper::wrap();
|
||||
}
|
||||
|
||||
25
Code/ChemicalFeatures/Wrap/rdChemicalFeatures.cpp
Normal file
25
Code/ChemicalFeatures/Wrap/rdChemicalFeatures.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// $Id: rdChemicalFeatures.cpp 4944 2006-02-17 01:23:55Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#include <RDBoost/Wrap.h>
|
||||
#include <ChemicalFeatures/FreeChemicalFeature.h>
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
|
||||
void wrap_freefeat();
|
||||
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(rdChemicalFeatures)
|
||||
{
|
||||
python::scope().attr("__doc__") =
|
||||
"Module containing free chemical feature functionality\n\
|
||||
These are feature that ar not derived from molecules. They are \n\
|
||||
are typically derived from pharmacophores and site-map.\n";
|
||||
|
||||
wrap_freefeat();
|
||||
}
|
||||
24
Code/ChemicalFeatures/Wrap/setup.py
Executable file
24
Code/ChemicalFeatures/Wrap/setup.py
Executable file
@@ -0,0 +1,24 @@
|
||||
# Run this with:
|
||||
# python setup.py install --install-lib=$RDBASE/Python
|
||||
from RDBuild import *
|
||||
from distutils.core import setup,Extension
|
||||
|
||||
|
||||
libDirs += [
|
||||
rdLibDir,
|
||||
os.path.join(RDConfig.RDBaseDir,'Code','Geometry'),
|
||||
os.path.join(RDConfig.RDBaseDir,'Code','ChemicalFeatures'),
|
||||
]
|
||||
|
||||
libraries += ["ChemicalFeatures","RDGeometry", "RDGeneral",]
|
||||
|
||||
|
||||
setup(name="Chem.rdChemicalFeatures", version="2.0",
|
||||
ext_modules=[Extension("Chem.rdChemicalFeatures",
|
||||
["rdChemicalFeatures.cpp",
|
||||
"FreeChemicalFeature.cpp"],
|
||||
library_dirs=libDirs,
|
||||
libraries=libraries,
|
||||
extra_link_args=linkArgs,
|
||||
extra_compile_args=compileArgs)])
|
||||
|
||||
62
Code/ChemicalFeatures/Wrap/testFeatures.py
Normal file
62
Code/ChemicalFeatures/Wrap/testFeatures.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import Chem
|
||||
from Chem import ChemicalFeatures
|
||||
import unittest
|
||||
import cPickle
|
||||
from Geometry import rdGeometry as geom
|
||||
|
||||
def feq(v1,v2,tol2=1e-4):
|
||||
return abs(v1-v2)<=tol2
|
||||
|
||||
def lstFeq(l1, l2, tol=1.e-4):
|
||||
if (len(l1) != len(l2)):
|
||||
return 0
|
||||
for i in range(len(l1)):
|
||||
if not feq(l1[i], l2[i], tol):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def ptFeq(pt1, pt2, tol=0.0001):
|
||||
dist = pt1.Distance(pt2)
|
||||
return feq(dist, 0.0, tol)
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def testBasic(self):
|
||||
ffeat = ChemicalFeatures.FreeChemicalFeature()
|
||||
ffeat.SetFamily("HBondDonor")
|
||||
self.failUnless(ffeat.GetFamily() == "HBondDonor")
|
||||
ffeat.SetPos(geom.Point3D(1.0, 2.0, 3.0))
|
||||
pos = ffeat.GetPos()
|
||||
self.failUnless(ptFeq(pos, geom.Point3D(1.0, 2.0, 3.0)))
|
||||
|
||||
ffeat.SetType("HBondDonor1")
|
||||
self.failUnless(ffeat.GetType() == "HBondDonor1")
|
||||
|
||||
ffeat = ChemicalFeatures.FreeChemicalFeature("HBondDonor", "HBondDonor1", geom.Point3D(1.0, 2.0, 3.0))
|
||||
self.failUnless(ffeat.GetFamily() == "HBondDonor")
|
||||
self.failUnless(ffeat.GetType() == "HBondDonor1")
|
||||
pos = ffeat.GetPos()
|
||||
self.failUnless(ptFeq(pos, geom.Point3D(1.0, 2.0, 3.0)))
|
||||
|
||||
ffeat = ChemicalFeatures.FreeChemicalFeature(type="HBondDonor1", family="HBondDonor",
|
||||
loc=geom.Point3D(1.0, 2.0, 3.0))
|
||||
self.failUnless(ffeat.GetFamily() == "HBondDonor")
|
||||
self.failUnless(ffeat.GetType() == "HBondDonor1")
|
||||
pos = ffeat.GetPos()
|
||||
self.failUnless(ptFeq(pos, geom.Point3D(1.0, 2.0, 3.0)))
|
||||
|
||||
def testPickle(self):
|
||||
ffeat = ChemicalFeatures.FreeChemicalFeature("HBondDonor", "HBondDonor1", geom.Point3D(1.0, 2.0, 3.0))
|
||||
pkl = cPickle.dumps(ffeat)
|
||||
ffeat2 = cPickle.loads(pkl)
|
||||
self.failUnless(ffeat2.GetFamily()==ffeat.GetFamily());
|
||||
self.failUnless(ffeat2.GetType()==ffeat.GetType());
|
||||
self.failUnless(ptFeq(ffeat2.GetPos(),ffeat.GetPos()))
|
||||
|
||||
if __name__ == '__main__':
|
||||
print "Testing ChemicalFeatures Wrapper code:"
|
||||
unittest.main()
|
||||
|
||||
14
Code/ChemicalFeatures/Wrap/test_list.py
Normal file
14
Code/ChemicalFeatures/Wrap/test_list.py
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
tests=[
|
||||
("python","testFeatures.py",{})
|
||||
]
|
||||
|
||||
|
||||
|
||||
longTests=[]
|
||||
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
sys.exit(len(failed))
|
||||
252
Code/ChemicalFeatures/Wrap/wrapChemicalFeatures.vcproj
Normal file
252
Code/ChemicalFeatures/Wrap/wrapChemicalFeatures.vcproj
Normal file
@@ -0,0 +1,252 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="wrapChemicalFeatures"
|
||||
ProjectGUID="{1D23BB8D-2E2E-4FBE-88B3-986B13576972}"
|
||||
SccProjectName="wrapChemicalFeatures"
|
||||
SccLocalPath=".">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="DebugPython|Win32"
|
||||
OutputDirectory=".\wrapChemicalFeatures_Win32_DebugPython"
|
||||
IntermediateDirectory=".\wrapChemicalFeatures_Win32_DebugPython"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\wrapChemicalFeatures_Win32_DebugPython/wrapChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\wrapChemicalFeatures_Win32_DebugPython/"
|
||||
ObjectFile=".\wrapChemicalFeatures_Win32_DebugPython/"
|
||||
ProgramDataBaseFileName=".\wrapChemicalFeatures_Win32_DebugPython/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_python.lib; vflib.lib;libDatastructs.lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib boost_python.lib"
|
||||
OutputFile="DebugPython/rdChemicalFeatures_d.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\wrapChemicalFeatures_Win32_DebugPython/rdChemicalFeatures_new_d.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\wrapChemicalFeatures_Win32_DebugPython/rdChemicalFeatures_new_d.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\wrapChemicalFeatures_Win32_DebugPython/wrapChemicalFeatures.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy DebugPython\rdChemicalFeatures_new_d.dll "$(RDBASE)"\Python\Chem"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Debug/wrapChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib boost_python-vc71-mt-gd-$(BOOSTVERSION).lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib"
|
||||
OutputFile="Debug/rdChemicalFeatures.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/rdChemicalFeatures.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Debug/rdChemicalFeatures.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Debug/wrapChemicalFeatures.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Debug\rdChemicalFeatures.dll "$(RDBASE)"\Python\Chem"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/wrapChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib boost_python-vc71-mt-$(BOOSTVERSION).lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib"
|
||||
OutputFile="Release/rdChemicalFeatures.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
ProgramDatabaseFile=".\Release/rdChemicalFeatures.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Release/rdChemicalFeatures.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Release/wrapChemicalFeatures.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Release\rdChemicalFeatures.dll "$(RDBASE)"\Python\Chem"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\FreeChemicalFeature.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\rdChemicalFeatures.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
137
Code/ChemicalFeatures/libChemicalFeatures.vcproj
Normal file
137
Code/ChemicalFeatures/libChemicalFeatures.vcproj
Normal file
@@ -0,0 +1,137 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="libChemicalFeatures"
|
||||
ProjectGUID="{636B9719-70AC-4074-883E-8DAE1BD0F684}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\libChemicalFeatures___Win32_Debug0"
|
||||
IntermediateDirectory=".\libChemicalFeatures___Win32_Debug0"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\libChemicalFeatures___Win32_Debug0/libChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\libChemicalFeatures___Win32_Debug0/"
|
||||
ObjectFile=".\libChemicalFeatures___Win32_Debug0/"
|
||||
ProgramDataBaseFileName=".\libChemicalFeatures___Win32_Debug0/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\libChemicalFeatures___Win32_Debug0\libChemicalFeatures.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\libChemicalFeatures___Win32_Release"
|
||||
IntermediateDirectory=".\libChemicalFeatures___Win32_Release"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\libChemicalFeatures___Win32_Release/libChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\libChemicalFeatures___Win32_Release/"
|
||||
ObjectFile=".\libChemicalFeatures___Win32_Release/"
|
||||
ProgramDataBaseFileName=".\libChemicalFeatures___Win32_Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\libChemicalFeatures___Win32_Release\libChemicalFeatures.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\FreeChemicalFeature.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
43
Code/ChemicalFeatures/testChemicalFeatures.cpp
Normal file
43
Code/ChemicalFeatures/testChemicalFeatures.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// $Id: testChemicalFeatures.cpp 4943 2006-02-17 01:21:27Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2005-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
//
|
||||
|
||||
#include "FreeChemicalFeature.h"
|
||||
#include <Geometry/point.h>
|
||||
#include <iostream>
|
||||
#include <RDGeneral/Invariant.h>
|
||||
|
||||
using namespace ChemicalFeatures;
|
||||
|
||||
|
||||
void test1() {
|
||||
std::cout << "-----------------------------------------" << std::endl;
|
||||
std::cout << "Test1" << std::endl;
|
||||
|
||||
FreeChemicalFeature f1("foo","bar",RDGeom::Point3D(0,0,0));
|
||||
TEST_ASSERT(f1.getFamily()=="foo");
|
||||
TEST_ASSERT(f1.getType()=="bar");
|
||||
|
||||
FreeChemicalFeature f2;
|
||||
f2.initFromString(f1.toString());
|
||||
TEST_ASSERT(f2.getFamily()=="foo");
|
||||
TEST_ASSERT(f2.getType()=="bar");
|
||||
|
||||
FreeChemicalFeature f3(f1.toString());
|
||||
TEST_ASSERT(f3.getFamily()=="foo");
|
||||
TEST_ASSERT(f3.getType()=="bar");
|
||||
|
||||
|
||||
std::cout << "Done" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
test1();
|
||||
return 0;
|
||||
}
|
||||
|
||||
156
Code/ChemicalFeatures/testChemicalFeatures.vcproj
Normal file
156
Code/ChemicalFeatures/testChemicalFeatures.vcproj
Normal file
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="testChemicalFeatures"
|
||||
ProjectGUID="{4559772E-98D5-431C-9323-657ABE1EF042}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/Code"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\Debug/testChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib "
|
||||
OutputFile="./testExecs/main.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Debug/testChemicalFeatures.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/Code"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/testChemicalFeatures.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib "
|
||||
OutputFile="./testExecs/main.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
ProgramDatabaseFile=".\Release/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/testChemicalFeatures.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\testChemicalFeatures.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
12
Code/ChemicalFeatures/test_list.py
Normal file
12
Code/ChemicalFeatures/test_list.py
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
tests=[
|
||||
("testExecs/main.exe","",{}),
|
||||
|
||||
]
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
sys.exit(len(failed))
|
||||
13
Code/DataManip/MetricMatrixCalc/Makefile
Executable file
13
Code/DataManip/MetricMatrixCalc/Makefile
Executable file
@@ -0,0 +1,13 @@
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
include $(RDBASE)/Code/rdrules.make
|
||||
CXXFLAGS=$(RDOPTFLAGS) $(BOOSTINC) -I$(RDCODEDIR)
|
||||
|
||||
regrs: testExecs/testMatCalc.exe
|
||||
|
||||
testExecs/testMatCalc.exe: testMatCalc.o
|
||||
g++ -o $@ $(CXXFLAGS) $^ $(RDGENERAL)
|
||||
|
||||
clean:
|
||||
rm -f testMatCalc.o testExecs/testMatCalc.exe $(DEPENDS)
|
||||
|
||||
include $(DEPENDS)
|
||||
58
Code/DataManip/MetricMatrixCalc/MetricFuncs.h
Executable file
58
Code/DataManip/MetricMatrixCalc/MetricFuncs.h
Executable file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_METRICFUNCS_H__
|
||||
#define __RD_METRICFUNCS_H__
|
||||
#include <cmath>
|
||||
#include <DataStructs/BitOps.h>
|
||||
|
||||
namespace RDDataManip {
|
||||
|
||||
template <typename T1, typename T2> double EuclideanDistance(const T1 &v1, const T2 &v2, int dim)
|
||||
{
|
||||
int i;
|
||||
double diff, dist = 0.0;
|
||||
for (i = 0; i < dim; i++) {
|
||||
diff = (double)v1[i] - (double)v2[i];
|
||||
dist += (diff*diff);
|
||||
}
|
||||
return sqrt(dist);
|
||||
};
|
||||
|
||||
template <typename T1, typename T2> double TanimotoDistance(const T1 &bv1, const T2 &bv2, int dim)
|
||||
{
|
||||
// the dim parameter is actually irrelevant here but we have to include it to deal with
|
||||
// template version of setMetricFunc in MetricMatricCalc
|
||||
return (1.0 - TanimotoSimilarity(bv1, bv2));
|
||||
}
|
||||
|
||||
template <typename T1, typename T2> double TanimotoSimilarity(const T1 &bv1, const T2 &bv2, int dim)
|
||||
{
|
||||
double res;
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits()){
|
||||
// fold down automatically:
|
||||
unsigned int nb1=bv1.GetNumBits();
|
||||
unsigned int nb2=bv2.GetNumBits();
|
||||
|
||||
if(nb1 < nb2){
|
||||
T2 *bv3=FoldFingerprint(bv2,nb2/nb1);
|
||||
res = TanimotoSimilarity(bv1,*bv3);
|
||||
delete bv3;
|
||||
} else {
|
||||
T2 *bv3=FoldFingerprint(bv1,nb1/nb2);
|
||||
res = TanimotoSimilarity(*bv3,bv2);
|
||||
delete bv3;
|
||||
}
|
||||
} else {
|
||||
res = TanimotoSimilarity(bv1, bv2);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
97
Code/DataManip/MetricMatrixCalc/MetricMatrixCalc.h
Executable file
97
Code/DataManip/MetricMatrixCalc/MetricMatrixCalc.h
Executable file
@@ -0,0 +1,97 @@
|
||||
// $Id: MetricMatrixCalc.h 4945 2006-02-17 01:28:12Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_METRICMATRIXCAL_H__
|
||||
#define __RD_METRICMATRIXCAL_H__
|
||||
|
||||
#include "MetricFuncs.h"
|
||||
#include <RDGeneral/Invariant.h>
|
||||
|
||||
namespace RDDataManip {
|
||||
|
||||
/*! \brief A generic metric matrix calculator (e.g simialrity matrix or
|
||||
* ditance matrix)
|
||||
*
|
||||
* This templated class needs some explanation\n
|
||||
* vectType is a container that can support [] operator \n
|
||||
* entryType is the type of entry that is returned by the [] operator\n
|
||||
* Examples of the container include PySequenceHolder which is wrapper around
|
||||
* a python sequence objects like lists and tuples. \n
|
||||
* Examples of the entryType include a sequence of double, floats, and Explicit Bit Vectors
|
||||
*
|
||||
*/
|
||||
template <class vectType, class entryType> class MetricMatrixCalc {
|
||||
public:
|
||||
/*! \brief Default Constructor
|
||||
*
|
||||
*/
|
||||
MetricMatrixCalc() {};
|
||||
|
||||
/*! \brief Set the metric function
|
||||
*
|
||||
* Set the pointer to the mertic funvtion to be used by the metric calculator
|
||||
*
|
||||
* ARGUMENTS:
|
||||
*
|
||||
* mFunc - pointer to the metric funtion
|
||||
*/
|
||||
void setMetricFunc(double (*mFunc)(const entryType &, const entryType &, int)) {
|
||||
dp_metricFunc = mFunc;
|
||||
}
|
||||
|
||||
/*! \brief The calculator function
|
||||
*
|
||||
* ARGUMENTS:
|
||||
*
|
||||
* descrips - vectType container with a entryType for each item\n
|
||||
* nItems - the number of item in the descripts.
|
||||
* In several cases this argument is irrelvant since vectType probably supports
|
||||
* a size() member function, But we would like this interface to take for example
|
||||
* a double** as the and correctly parse the row and columns. \n
|
||||
* dim - the dimension of the
|
||||
* distMat - pointer to an array to write the distance matrix to
|
||||
* it is assumed that the right sized array has already be allocated.
|
||||
*
|
||||
* FIX: we can probably make this function create the correct sized distMat and return
|
||||
* it to the caller, but when pushing he result out to a python array not sure how to
|
||||
* avoid copy the entire distance matrix in that case
|
||||
*
|
||||
* RETURNS:
|
||||
*
|
||||
* pointer to a 1D array of doubles. Only the lower triangle elements are
|
||||
* included in the array
|
||||
*/
|
||||
void calcMetricMatrix(const vectType &descripts, int nItems, int dim,
|
||||
double *distMat) {
|
||||
int i, j, itab, id;
|
||||
CHECK_INVARIANT(distMat, "invalid pointer to a distance matix");
|
||||
|
||||
for (i = 1; i < nItems; i++) {
|
||||
//itab = nItems*i - (i+1)*(i+2)/2;
|
||||
itab = i*(i-1)/2;
|
||||
for (j = 0; j < i; j++) {
|
||||
id = itab + j;
|
||||
distMat[id] = dp_metricFunc(descripts[i], descripts[j], dim);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
// pointer to the metric function
|
||||
/*! \brief pointer to the metric function
|
||||
*
|
||||
* In several cases the last argument 'dim' should be irrelevant,
|
||||
* For example when entryType is a bit vector the size is of the vector
|
||||
* or the dimension can be obtained by asking the bit vector itself. However
|
||||
* we woul like this interface to support other containers lines double*
|
||||
* in which case the 'dim' value is useful in cumputing the metric.
|
||||
*/
|
||||
double (*dp_metricFunc)(const entryType &, const entryType &, int);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
7
Code/DataManip/MetricMatrixCalc/Wrap/Makefile
Executable file
7
Code/DataManip/MetricMatrixCalc/Wrap/Makefile
Executable file
@@ -0,0 +1,7 @@
|
||||
|
||||
$(RDBASE)/Python/DataManip/Metric/rdMetricMatrixCalc.so: rdMetricMatrixCalc.cpp
|
||||
python setup.py install --install-lib=$(RDBASE)/Python
|
||||
|
||||
clean:
|
||||
if test -e $(RDBASE)/Python/DataManip/Metric/rdMetricMatrixCalc.so; then rm $(RDBASE)/Python/DataManip/Metric/rdMetricMatrixCalc.so; fi
|
||||
if test -e build; then rm -rf build; fi
|
||||
282
Code/DataManip/MetricMatrixCalc/Wrap/rdMetricMatrixCalc.cpp
Executable file
282
Code/DataManip/MetricMatrixCalc/Wrap/rdMetricMatrixCalc.cpp
Executable file
@@ -0,0 +1,282 @@
|
||||
// $Id: rdMetricMatrixCalc.cpp 4945 2006-02-17 01:28:12Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#define PY_ARRAY_UNIQUE_SYMBOL rdmetric_array_API
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/numeric.hpp>
|
||||
#include "Numeric/arrayobject.h"
|
||||
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
#include <RDBoost/Wrap.h>
|
||||
|
||||
#include <RDGeneral/types.h>
|
||||
|
||||
#include <DataManip/MetricMatrixCalc/MetricMatrixCalc.h>
|
||||
#include <DataManip/MetricMatrixCalc/MetricFuncs.h>
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <string>
|
||||
|
||||
using namespace RDDataManip;
|
||||
|
||||
void wrap_MMcalc();
|
||||
|
||||
namespace python = boost::python;
|
||||
namespace RDDataManip {
|
||||
|
||||
PyObject *getEuclideanDistMat(python::object descripMat) {
|
||||
// Bit of a pain involved here, we accept three types of PyObjects here
|
||||
// 1. A Numeric Array
|
||||
// - first find what 'type' of entry we have (float, double and int is all we recognize for now)
|
||||
// - then point to contiguous piece of memory from the array that contains the data with a type*
|
||||
// - then make a new type** pointer so that double index into this contiguous memory will work
|
||||
// and then pass it along to the distance calculator
|
||||
// 2. A list of Numeric Vector (or 1D arrays)
|
||||
// - in this case wrap descripMat with a PySequenceHolder<type*> where type is the
|
||||
// type of entry in vector (accepted types are int, double and float
|
||||
// - Then pass the PySequenceHolder to the metrci calculator
|
||||
// 3. A list (or tuple) of lists (or tuple)
|
||||
// - In this case other than wrapping descripMat with a PySequenceHolder
|
||||
// each of the indivual list in there are also wrapped by a PySequenceHolder
|
||||
// - so the distance calculator is passed in a "PySequenceHolder<PySequenceHolder<double>>"
|
||||
// - FIX: not that we always convert entry values to double here, even if we passed
|
||||
// in a list of list of ints (or floats). Given that lists can be heterogeneous, I do not
|
||||
// know how to ask a list what type of entries if contains.
|
||||
//
|
||||
// OK my brain is going to explode now
|
||||
|
||||
// first deal with situation where we have an Numeric Array
|
||||
PyObject *descMatObj = descripMat.ptr();
|
||||
PyArrayObject *distRes;
|
||||
if (PyArray_Check(descMatObj)) {
|
||||
// get the dimensions of the array
|
||||
int nrows = ((PyArrayObject *)descMatObj)->dimensions[0];
|
||||
int ncols = ((PyArrayObject *)descMatObj)->dimensions[1];
|
||||
int i;
|
||||
CHECK_INVARIANT((nrows > 0) && (ncols > 0), "");
|
||||
|
||||
int dMatLen = nrows*(nrows-1)/2;
|
||||
|
||||
// now that we have the dimensions declare the distance matrix which is always a
|
||||
// 1D double array
|
||||
distRes = (PyArrayObject *)PyArray_FromDims(1, &dMatLen, PyArray_DOUBLE);
|
||||
|
||||
// grab a pointer to the data in the array so that we can directly put values in there
|
||||
// and avoid copying (as I understand it PyArray_FromDimsAndData will do it here for us
|
||||
// because python will never free the malloced memory this way)
|
||||
double *dMat = (double *)distRes->data;
|
||||
|
||||
// if we have double array
|
||||
PyArrayObject *copy;
|
||||
copy = (PyArrayObject *)PyArray_ContiguousFromObject(descMatObj,
|
||||
((PyArrayObject *)descMatObj)->descr->type_num,
|
||||
2,2);
|
||||
if (((PyArrayObject *)descMatObj)->descr->type_num == PyArray_DOUBLE) {
|
||||
double *desc = (double *)copy->data;
|
||||
|
||||
// REVIEW: create an adaptor object to hold a double * and support
|
||||
// operator[]() so that we don't have to do this stuff:
|
||||
|
||||
// here is the 2D array trick this so that when the distance calaculator
|
||||
// asks for desc2D[i] we basically get the ith row as double*
|
||||
double **desc2D = new double*[nrows];
|
||||
for (i = 0; i < nrows; i++) {
|
||||
desc2D[i] = desc;
|
||||
desc += ncols;
|
||||
}
|
||||
MetricMatrixCalc<double**, double*> mmCalc;
|
||||
mmCalc.setMetricFunc(&EuclideanDistance<double *, double *>);
|
||||
mmCalc.calcMetricMatrix(desc2D, nrows, ncols, dMat);
|
||||
|
||||
delete [] desc2D;
|
||||
// we got the distance matrix we are happy so return
|
||||
return PyArray_Return(distRes);
|
||||
}
|
||||
|
||||
// if we have a float array
|
||||
else if (((PyArrayObject *)descMatObj)->descr->type_num == PyArray_FLOAT) {
|
||||
float* desc = (float *)copy->data;
|
||||
float **desc2D = new float*[nrows];
|
||||
for (i = 0; i < nrows; i++) {
|
||||
desc2D[i] = desc;
|
||||
desc += ncols;
|
||||
}
|
||||
MetricMatrixCalc<float**, float*> mmCalc;
|
||||
mmCalc.setMetricFunc(&EuclideanDistance<float *, float*>);
|
||||
mmCalc.calcMetricMatrix(desc2D, nrows, ncols, dMat);
|
||||
delete [] desc2D;
|
||||
return PyArray_Return(distRes);
|
||||
}
|
||||
|
||||
// if we have an interger array
|
||||
else if (((PyArrayObject *)descMatObj)->descr->type_num == PyArray_INT) {
|
||||
int *desc = (int *)copy->data;
|
||||
int **desc2D = new int*[nrows];
|
||||
for (i = 0; i < nrows; i++) {
|
||||
desc2D[i] = desc;
|
||||
desc += ncols;
|
||||
}
|
||||
MetricMatrixCalc<int**, int*> mmCalc;
|
||||
mmCalc.setMetricFunc(&EuclideanDistance<int *, int*>);
|
||||
mmCalc.calcMetricMatrix(desc2D, nrows, ncols, dMat);
|
||||
delete [] desc2D;
|
||||
return PyArray_Return(distRes);
|
||||
}
|
||||
else {
|
||||
// unreconiged type for the matrix, throw up
|
||||
throw_value_error("The array has to be of type int, float, or double for GetEuclideanDistMat");
|
||||
}
|
||||
} // done with an array input
|
||||
else {
|
||||
// REVIEW: removed a ton of code here
|
||||
|
||||
// we have probably have a list or a tuple
|
||||
|
||||
int nrows, ncols, i;
|
||||
ncols = 0;
|
||||
nrows = python::extract<int>(descripMat.attr("__len__")());
|
||||
CHECK_INVARIANT(nrows > 0, "Empty list passed in");
|
||||
|
||||
int dMatLen = nrows*(nrows-1)/2;
|
||||
distRes = (PyArrayObject *)PyArray_FromDims(1, &dMatLen, PyArray_DOUBLE);
|
||||
double *dMat = (double *)distRes->data;
|
||||
|
||||
// assume that we a have a list of list of values (that can be extracted to double)
|
||||
std::vector<PySequenceHolder<double> > dData;
|
||||
dData.reserve(nrows);
|
||||
for (i = 0; i < nrows; i++) {
|
||||
//PySequenceHolder<double> row(seq[i]);
|
||||
PySequenceHolder<double> row(descripMat[i]);
|
||||
if(i==0){
|
||||
ncols = row.size();
|
||||
} else if( row.size() != ncols ){
|
||||
throw_value_error("All subsequences must be the same length");
|
||||
}
|
||||
dData.push_back(row);
|
||||
}
|
||||
|
||||
MetricMatrixCalc< std::vector<PySequenceHolder<double> >, PySequenceHolder<double> > mmCalc;
|
||||
mmCalc.setMetricFunc(&EuclideanDistance< PySequenceHolder<double>, PySequenceHolder<double> >);
|
||||
mmCalc.calcMetricMatrix(dData, nrows, ncols, dMat);
|
||||
}
|
||||
return PyArray_Return(distRes);
|
||||
}
|
||||
|
||||
PyObject *getTanimotoDistMat(python::object bitVectList) {
|
||||
// we will assume here that we have a either a list of ExplicitBitVectors or
|
||||
// SparseBitVects
|
||||
int nrows = python::extract<int>(bitVectList.attr("__len__")());
|
||||
CHECK_INVARIANT(nrows > 1, "");
|
||||
|
||||
// First check what type of vector we have
|
||||
python::object v1 = bitVectList[0];
|
||||
python::extract<ExplicitBitVect> ebvWorks(v1);
|
||||
python::extract<SparseBitVect> sbvWorks(v1);
|
||||
if(!ebvWorks.check() && !sbvWorks.check()){
|
||||
throw_value_error("GetTanimotoDistMat can only take a sequence of ExplicitBitVects or SparseBitvects");
|
||||
}
|
||||
|
||||
int dMatLen = nrows*(nrows-1)/2;
|
||||
PyArrayObject *simRes = (PyArrayObject *)PyArray_FromDims(1, &dMatLen, PyArray_DOUBLE);
|
||||
double *sMat = (double *)simRes->data;
|
||||
|
||||
if (ebvWorks.check()) {
|
||||
PySequenceHolder<ExplicitBitVect> dData(bitVectList);
|
||||
MetricMatrixCalc<PySequenceHolder<ExplicitBitVect>, ExplicitBitVect> mmCalc;
|
||||
mmCalc.setMetricFunc(&TanimotoDistance<ExplicitBitVect, ExplicitBitVect>);
|
||||
mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
|
||||
}
|
||||
else if (sbvWorks.check()) {
|
||||
PySequenceHolder<SparseBitVect> dData(bitVectList);
|
||||
MetricMatrixCalc<PySequenceHolder<SparseBitVect>, SparseBitVect> mmCalc;
|
||||
mmCalc.setMetricFunc(&TanimotoDistance<SparseBitVect, SparseBitVect>);
|
||||
mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
|
||||
}
|
||||
return PyArray_Return(simRes);
|
||||
}
|
||||
|
||||
PyObject *getTanimotoSimMat(python::object bitVectList) {
|
||||
// we will assume here that we have a either a list of ExplicitBitVectors or
|
||||
// SparseBitVects
|
||||
int nrows = python::extract<int>(bitVectList.attr("__len__")());
|
||||
CHECK_INVARIANT(nrows > 1, "");
|
||||
|
||||
// First check what type of vector we have
|
||||
python::object v1 = bitVectList[0];
|
||||
python::extract<ExplicitBitVect> ebvWorks(v1);
|
||||
python::extract<SparseBitVect> sbvWorks(v1);
|
||||
if(!ebvWorks.check() && !sbvWorks.check()){
|
||||
throw_value_error("GetTanimotoDistMat can only take a sequence of ExplicitBitVects or SparseBitvects");
|
||||
}
|
||||
|
||||
int dMatLen = nrows*(nrows-1)/2;
|
||||
PyArrayObject *simRes = (PyArrayObject *)PyArray_FromDims(1, &dMatLen, PyArray_DOUBLE);
|
||||
double *sMat = (double *)simRes->data;
|
||||
|
||||
if (ebvWorks.check()) {
|
||||
PySequenceHolder<ExplicitBitVect> dData(bitVectList);
|
||||
MetricMatrixCalc<PySequenceHolder<ExplicitBitVect>, ExplicitBitVect> mmCalc;
|
||||
mmCalc.setMetricFunc(&TanimotoSimilarity<ExplicitBitVect, ExplicitBitVect>);
|
||||
mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
|
||||
}
|
||||
else if (sbvWorks.check()) {
|
||||
PySequenceHolder<SparseBitVect> dData(bitVectList);
|
||||
MetricMatrixCalc<PySequenceHolder<SparseBitVect>, SparseBitVect> mmCalc;
|
||||
mmCalc.setMetricFunc(&TanimotoSimilarity<SparseBitVect, SparseBitVect>);
|
||||
mmCalc.calcMetricMatrix(dData, nrows, 0, sMat);
|
||||
}
|
||||
return PyArray_Return(simRes);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(rdMetricMatrixCalc)
|
||||
{
|
||||
python::scope().attr("__doc__") =
|
||||
"Module containing the calculator for metric matrix calculation, \n"
|
||||
"e.g. simialrity and distance matrices"
|
||||
;
|
||||
|
||||
import_array();
|
||||
python::register_exception_translator<IndexErrorException>(&translate_index_error);
|
||||
python::register_exception_translator<ValueErrorException>(&translate_value_error);
|
||||
|
||||
std::string docString;
|
||||
docString = "Compute the distance matrix from a descriptor matrix using Euclidean distance metric\n\n\
|
||||
ARGUMENTS: \n\
|
||||
\n\
|
||||
descripMat - A python object of any one of the folliwng type \n\
|
||||
1. A numeric array of dimensions n by m where n is the number of items in the data set \n\
|
||||
and m is the number of descriptors \n\
|
||||
2. A list of Numeric Vectors (or 1D arrays), each entry in the list corresponds \n\
|
||||
to descriptor vector for one item \n\
|
||||
3. A list (or tuple) of list (or tuple) of values, where the values can be extracted to \n\
|
||||
double. \n\n\
|
||||
RETURNS: \n\
|
||||
A numeric 1 dimensional array containing the lower triangle elements of the symmetric distance matrix\n\n";
|
||||
|
||||
python::def("GetEuclideanDistMat", RDDataManip::getEuclideanDistMat,
|
||||
docString.c_str());
|
||||
|
||||
docString = "Compute the distance matrix from a list of BitVects \n\n\
|
||||
ARGUMENTS: \n\
|
||||
\n\
|
||||
bitVectList - a list of bit vectors. Currently this works only for a list of explicit bit vectors, \n\
|
||||
needs to be expanded to support a lsit of SparseBitVects\n\n\
|
||||
RETURNS: \n\
|
||||
A numeric 1 dimensional array containing the lower triangle elements of the\n\
|
||||
symmetric distance matrix\n\n";
|
||||
python::def("GetTanimotoDistMat", RDDataManip::getTanimotoDistMat,
|
||||
docString.c_str());
|
||||
|
||||
docString = "Compute the similarity matrix from a list of BitVects \n\n\
|
||||
ARGUMENTS: \n\
|
||||
\n\
|
||||
bitVectList - a list of bit vectors. Currently this works only for a list of explicit bit vectors, \n\
|
||||
needs to be expanded to support a lsit of SparseBitVects\n\n\
|
||||
RETURNS: \n\
|
||||
A numeric 1 dimensional array containing the lower triangle elements of the symmetric similarity matrix\n\n";
|
||||
python::def("GetTanimotoSimMat", RDDataManip::getTanimotoSimMat,
|
||||
docString.c_str());
|
||||
}
|
||||
18
Code/DataManip/MetricMatrixCalc/Wrap/setup.py
Executable file
18
Code/DataManip/MetricMatrixCalc/Wrap/setup.py
Executable file
@@ -0,0 +1,18 @@
|
||||
# Run this with:
|
||||
# python setup.py install --install-lib=$RDBASE/Python
|
||||
from RDBuild import *
|
||||
from distutils.core import setup,Extension
|
||||
|
||||
|
||||
libDirs +=[
|
||||
rdBitDir,
|
||||
]
|
||||
|
||||
libraries += ["DataStructs", "RDGeneral", "RDBoost"]
|
||||
setup(name="DataManip.Metric.rdMetricMatrixCalc", version="2.0",
|
||||
ext_modules=[Extension("DataManip.Metric.rdMetricMatrixCalc",
|
||||
["rdMetricMatrixCalc.cpp"],
|
||||
library_dirs=libDirs,
|
||||
libraries=libraries,
|
||||
extra_link_args=linkArgs,
|
||||
extra_compile_args=compileArgs)])
|
||||
156
Code/DataManip/MetricMatrixCalc/Wrap/testMatricCalc.py
Executable file
156
Code/DataManip/MetricMatrixCalc/Wrap/testMatricCalc.py
Executable file
@@ -0,0 +1,156 @@
|
||||
import RDConfig
|
||||
import unittest
|
||||
from DataManip.Metric import rdMetricMatrixCalc as rdmmc
|
||||
from Numeric import *
|
||||
import random
|
||||
import DataStructs
|
||||
|
||||
def feq(v1,v2,tol2=1e-4):
|
||||
return abs(v1-v2)<=tol2
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) :
|
||||
pass
|
||||
|
||||
def test0DistsArray(self) :
|
||||
exp = array([1., 1.414213, 1.0], 'd')
|
||||
|
||||
# initialize a double array and check if get back the expected distances
|
||||
desc = zeros((3,2), 'd')
|
||||
desc[1,0] = 1.0
|
||||
desc[2,0] = 1.0
|
||||
desc[2,1] = 1.0
|
||||
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
# repeat with an flaot array
|
||||
desc = zeros((3,2), 'f')
|
||||
desc[1,0] = 1.0
|
||||
desc[2,0] = 1.0
|
||||
desc[2,1] = 1.0
|
||||
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
# finally with an interger array
|
||||
desc = zeros((3,2), 'i')
|
||||
desc[1,0] = 1
|
||||
desc[2,0] = 1
|
||||
desc[2,1] = 1
|
||||
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
def ctest1DistsListArray(self):
|
||||
exp = array([1., 1.414213, 1.0], 'd')
|
||||
|
||||
desc = [array([0.0, 0.0], 'd'),
|
||||
array([1.0, 0.0], 'd'),
|
||||
array([1.0, 1.0], 'd')]
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
# repeat the test with a list of arrays of floats
|
||||
desc = [array([0.0, 0.0], 'f'),
|
||||
array([1.0, 0.0], 'f'),
|
||||
array([1.0, 1.0], 'f')]
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
# repeat the test with a list of arrays of ints
|
||||
desc = [array([0, 0], 'i'),
|
||||
array([1, 0], 'i'),
|
||||
array([1, 1], 'i')]
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
def test2DistListList(self) :
|
||||
exp = array([1., 1.414213, 1.0], 'd')
|
||||
|
||||
desc = [[0.0, 0.0],
|
||||
[1.0, 0.0],
|
||||
[1.0, 1.0]]
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
#test with ints
|
||||
desc = [[0, 0],
|
||||
[1, 0],
|
||||
[1, 1]]
|
||||
dmat = rdmmc.GetEuclideanDistMat(desc)
|
||||
for i in range(shape(dmat)[0]) :
|
||||
assert feq(dmat[i], exp[i])
|
||||
|
||||
def test3Compare(self) :
|
||||
n = 30
|
||||
m = 5
|
||||
|
||||
dscArr = zeros((n,m), 'd')
|
||||
for i in range(n):
|
||||
for j in range(m):
|
||||
dscArr[i,j] = random.random()
|
||||
dmatArr = rdmmc.GetEuclideanDistMat(dscArr)
|
||||
|
||||
dscLL = []
|
||||
for i in range(n) :
|
||||
row = []
|
||||
for j in range(m):
|
||||
row.append(dscArr[i,j])
|
||||
dscLL.append(row)
|
||||
dmatLL = rdmmc.GetEuclideanDistMat(dscLL)
|
||||
|
||||
assert shape(dmatArr) == shape(dmatLL)
|
||||
|
||||
for i in range(n*(n-1)/2):
|
||||
assert feq(dmatArr[i], dmatLL[i])
|
||||
|
||||
def test4ebv(self) :
|
||||
|
||||
n = 30
|
||||
m = 2048
|
||||
dm = 800
|
||||
lst = []
|
||||
for i in range(n):
|
||||
v = DataStructs.ExplicitBitVect(m)
|
||||
for j in range(dm) :
|
||||
v.SetBit(random.randrange(0, m))
|
||||
lst.append(v)
|
||||
|
||||
dMat = rdmmc.GetTanimotoDistMat(lst)
|
||||
|
||||
sMat = rdmmc.GetTanimotoSimMat(lst)
|
||||
|
||||
for i in range(n*(n-1)/2) :
|
||||
assert feq(sMat[i] + dMat[i], 1.0)
|
||||
|
||||
def test5sbv(self) :
|
||||
|
||||
n = 30
|
||||
m = 2048
|
||||
dm = 800
|
||||
lst = []
|
||||
for i in range(n):
|
||||
v = DataStructs.SparseBitVect(m)
|
||||
for j in range(dm) :
|
||||
v.SetBit(random.randrange(0, m))
|
||||
lst.append(v)
|
||||
|
||||
dMat = rdmmc.GetTanimotoDistMat(lst)
|
||||
|
||||
sMat = rdmmc.GetTanimotoSimMat(lst)
|
||||
|
||||
for i in range(n*(n-1)/2) :
|
||||
assert feq(sMat[i] + dMat[i], 1.0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
12
Code/DataManip/MetricMatrixCalc/Wrap/test_list.py
Executable file
12
Code/DataManip/MetricMatrixCalc/Wrap/test_list.py
Executable file
@@ -0,0 +1,12 @@
|
||||
|
||||
tests=[
|
||||
("python","testMatricCalc.py",{}),
|
||||
]
|
||||
|
||||
longTests=[]
|
||||
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
sys.exit(len(failed))
|
||||
250
Code/DataManip/MetricMatrixCalc/Wrap/wrapMetricMatrixCalc.vcproj
Executable file
250
Code/DataManip/MetricMatrixCalc/Wrap/wrapMetricMatrixCalc.vcproj
Executable file
@@ -0,0 +1,250 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="wrapMetricMatrixCalc"
|
||||
ProjectGUID="{65160106-70A9-4BC1-A0FC-CC7740E5E210}"
|
||||
RootNamespace="wrapMetricMatrixCalc"
|
||||
SccProjectName="wrapMetricMatrixCalc"
|
||||
SccLocalPath=".">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="DebugPython|Win32"
|
||||
OutputDirectory=".\wrapMetricMatrixCalc_Win32_DebugPython"
|
||||
IntermediateDirectory=".\wrapMetricMatrixCalc_Win32_DebugPython"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\wrapMetricMatrixCalc_Win32_DebugPython/wrapMetricMatrixCalc.pch"
|
||||
AssemblerListingLocation=".\wrapMetricMatrixCalc_Win32_DebugPython/"
|
||||
ObjectFile=".\wrapMetricMatrixCalc_Win32_DebugPython/"
|
||||
ProgramDataBaseFileName=".\wrapMetricMatrixCalc_Win32_DebugPython/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_python.lib; vflib.lib;libDatastructs.lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib boost_python.lib"
|
||||
OutputFile="DebugPython/rdMetricMatrixCalc_d.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\wrapMetricMatrixCalc_Win32_DebugPython/rdMetricMatrixCalc_d.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\wrapMetricMatrixCalc_Win32_DebugPython/rdMetricMatrixCalc_d.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\wrapMetricMatrixCalc_Win32_DebugPython/wrapMetricMatrixCalc.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy DebugPython\rdMetricMatrixCalc_d.dll "$(RDBASE)"\Python\Chem"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Debug/wrapMetricMatrixCalc.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib boost_python-vc71-mt-gd-$(BOOSTVERSION).lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib"
|
||||
OutputFile="Debug/rdMetricMatrixCalc.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/rdMetricMatrixCalc.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Debug/rdMetricMatrixCalc.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Debug/wrapMetricMatrixCalc.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Debug\rdMetricMatrixCalc.dll "$(RDBASE)"\Python\DataManip\Metric"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(PYTHONHOME)\include,$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/External/vflib-2.0/include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/wrapMetricMatrixCalc.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib boost_python-vc71-mt-$(BOOSTVERSION).lib $(PYTHONVERS).lib BLAS.lib LAPACK.lib"
|
||||
OutputFile="Release/rdMetricMatrixCalc.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)\External\Lapack\win32,$(RDBASE)/External/boost/lib"
|
||||
IgnoreDefaultLibraryNames="msvcprtdlib.lib"
|
||||
ProgramDatabaseFile=".\Release/rdMetricMatrixCalc.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Release/rdMetricMatrixCalc.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Release/wrapMetricMatrixCalc.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Release\rdMetricMatrixCalc.dll "$(RDBASE)"\Python\DataManip\Metric"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\rdMetricMatrixCalc.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
0
Code/DataManip/MetricMatrixCalc/testExecs/.cvskeep
Executable file
0
Code/DataManip/MetricMatrixCalc/testExecs/.cvskeep
Executable file
50
Code/DataManip/MetricMatrixCalc/testMatCalc.cpp
Executable file
50
Code/DataManip/MetricMatrixCalc/testMatCalc.cpp
Executable file
@@ -0,0 +1,50 @@
|
||||
// $Id: testMatCalc.cpp 4945 2006-02-17 01:28:12Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "MetricFuncs.h"
|
||||
#include "MetricMatrixCalc.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <time.h>
|
||||
|
||||
using namespace RDDataManip;
|
||||
int main() {
|
||||
|
||||
int n = 10;
|
||||
int m = 3;
|
||||
int dlen = n*(n-1)/2;
|
||||
int i, j;
|
||||
double *desc = new double[n*m];
|
||||
double **desc2D = new double*[n];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
desc2D[i] = desc;
|
||||
desc += m;
|
||||
}
|
||||
desc = desc2D[0];
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = 0; j < m ; j++) {
|
||||
desc[i*m + j] = ((double)rand())/10;
|
||||
}
|
||||
}
|
||||
|
||||
//double x = EuclideanDistance(desc2D[0], desc2D[1], m);
|
||||
double *dmat = new double[dlen];
|
||||
MetricMatrixCalc<double**, double*> mmCalc;
|
||||
mmCalc.setMetricFunc(&EuclideanDistance<double *, double *>);
|
||||
mmCalc.calcMetricMatrix(desc2D, n, m, dmat);
|
||||
|
||||
for (i = 0; i < dlen; i++) {
|
||||
std::cout << dmat[i] << "\n";
|
||||
}
|
||||
|
||||
delete [] desc2D;
|
||||
delete [] desc;
|
||||
delete [] dmat;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
177
Code/DataManip/MetricMatrixCalc/testMatCalc.vcproj
Executable file
177
Code/DataManip/MetricMatrixCalc/testMatCalc.vcproj
Executable file
@@ -0,0 +1,177 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="testMatCalc"
|
||||
ProjectGUID="{D9D29F03-FC1E-4B7D-AA08-DED741874D9A}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\testMatCalc___Win32_Debug"
|
||||
IntermediateDirectory=".\testMatCalc___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/code"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\testMatCalc___Win32_Debug/testMatCalc.pch"
|
||||
AssemblerListingLocation=".\testMatCalc___Win32_Debug/"
|
||||
ObjectFile=".\testMatCalc___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\testMatCalc___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib "
|
||||
ShowProgress="0"
|
||||
OutputFile="./testExecs/testMatCalc.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\testMatCalc___Win32_Debug/testMatCalc.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\testMatCalc___Win32_Debug/testMatCalc.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/code"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/testMatCalc.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib "
|
||||
OutputFile=".\testExecs\testMatCalc.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
ProgramDatabaseFile=".\Release/testMatCalc.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/testMatCalc.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath="testMatCalc.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
11
Code/DataManip/MetricMatrixCalc/test_list.py
Executable file
11
Code/DataManip/MetricMatrixCalc/test_list.py
Executable file
@@ -0,0 +1,11 @@
|
||||
tests=[
|
||||
("testExecs/testMatCalc.exe","", {})
|
||||
]
|
||||
|
||||
longTests=[]
|
||||
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
sys.exit(len(failed))
|
||||
660
Code/DataStructs/BitOps.cpp
Executable file
660
Code/DataStructs/BitOps.cpp
Executable file
@@ -0,0 +1,660 @@
|
||||
// $Id: BitOps.cpp 5061 2006-03-08 00:36:29Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <RDBoost/Exceptions.h>
|
||||
#include "BitVects.h"
|
||||
#include "BitOps.h"
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <RDGeneral/StreamOps.h>
|
||||
#include <RDGeneral/types.h>
|
||||
|
||||
int getBitId(const char *&text,int format,int size,int curr){
|
||||
PRECONDITION(text,"no text");
|
||||
int res=-1;
|
||||
if( (format==0) ||
|
||||
( (format == 1) && (size >= std::numeric_limits<unsigned short>::max()) ) ) {
|
||||
int tmp;
|
||||
tmp = *(int *)text;
|
||||
text += sizeof(tmp);
|
||||
res=tmp;
|
||||
} else if (format == 1) { // version 16 and on bits sotred as short ints
|
||||
unsigned short tmp;
|
||||
tmp = *(unsigned short *)text;
|
||||
text += sizeof(tmp);
|
||||
res=tmp;
|
||||
} else if (format == 2) { // run length encoded format
|
||||
res = curr + RDKit::pullPackedIntFromString(text);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AllProbeBitsMatch(const std::string &probe,const std::string &ref){
|
||||
return AllProbeBitsMatch(probe.c_str(),ref.c_str());
|
||||
}
|
||||
|
||||
bool AllProbeBitsMatch(const char *probe,const char *ref){
|
||||
PRECONDITION(probe,"no probe text");
|
||||
PRECONDITION(ref,"no probe text");
|
||||
int probeFormat=0;
|
||||
int refFormat=0;
|
||||
int version=0;
|
||||
|
||||
int probeSize = *(int *)probe;
|
||||
probe+=sizeof(probeSize);
|
||||
if(probeSize<0){
|
||||
version = -1*probeSize;
|
||||
if (version == 16) {
|
||||
probeFormat=1;
|
||||
}
|
||||
else if (version == 32) {
|
||||
probeFormat=2;
|
||||
}
|
||||
else {
|
||||
throw("Unknown version type for the encode bit vect");
|
||||
}
|
||||
probeSize = *(int *)probe;
|
||||
probe+=sizeof(probeSize);
|
||||
}
|
||||
|
||||
int refSize = *(int *)ref;
|
||||
ref+=sizeof(refSize);
|
||||
if(refSize<0){
|
||||
version = -1*refSize;
|
||||
if (version == 16) {
|
||||
refFormat=1;
|
||||
}
|
||||
else if (version == 32) {
|
||||
refFormat=2;
|
||||
}
|
||||
else {
|
||||
throw("Unknown version type for the encode bit vect");
|
||||
}
|
||||
refSize = *(int *)ref;
|
||||
ref+=sizeof(refSize);
|
||||
}
|
||||
|
||||
|
||||
int nProbeOn = *(int *)probe;
|
||||
probe+=sizeof(nProbeOn);
|
||||
int nRefOn = *(int *)ref;
|
||||
ref+=sizeof(nRefOn);
|
||||
|
||||
int currProbeBit=0;
|
||||
currProbeBit=getBitId(probe,probeFormat,probeSize,currProbeBit);
|
||||
nProbeOn--;
|
||||
|
||||
int currRefBit=0;
|
||||
currRefBit=getBitId(ref,refFormat,refSize,currRefBit);
|
||||
nRefOn--;
|
||||
|
||||
while(nProbeOn){
|
||||
while(currRefBit<currProbeBit && nRefOn>0){
|
||||
if(refFormat==2) currRefBit++;
|
||||
currRefBit=getBitId(ref,refFormat,refSize,currRefBit);
|
||||
nRefOn--;
|
||||
}
|
||||
if(currRefBit!=currProbeBit) return false;
|
||||
if(probeFormat==2) currProbeBit++;
|
||||
currProbeBit=getBitId(probe,probeFormat,probeSize,currProbeBit);
|
||||
nProbeOn--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
bool AllProbeBitsMatch(const T1 &probe,const std::string &pkl){
|
||||
const char *text=pkl.c_str();
|
||||
int format=0;
|
||||
int nOn=0,size,version=0;
|
||||
size = *(int *)text;
|
||||
text+=sizeof(size);
|
||||
if(size<0){
|
||||
version = -1*size;
|
||||
if (version == 16) {
|
||||
format=1;
|
||||
}
|
||||
else if (version == 32) {
|
||||
format=2;
|
||||
}
|
||||
else {
|
||||
throw("Unknown version type for the encode bit vect");
|
||||
}
|
||||
size = *(int *)text;
|
||||
text+=sizeof(size);
|
||||
}
|
||||
nOn = *(int *)text;
|
||||
text+=sizeof(nOn);
|
||||
|
||||
int currBit=0;
|
||||
currBit=getBitId(text,format,size,currBit);
|
||||
nOn--;
|
||||
std::vector<int> obl;
|
||||
probe.GetOnBits(obl);
|
||||
|
||||
|
||||
//for(int i=0;i<probe.GetNumBits();i++){
|
||||
// if(probe.GetBit(i)){
|
||||
for(std::vector<int>::const_iterator i=obl.begin();i!=obl.end();i++){
|
||||
while(currBit<*i && nOn>0){
|
||||
if(format==2) currBit++;
|
||||
currBit=getBitId(text,format,size,currBit);
|
||||
nOn--;
|
||||
}
|
||||
if(currBit!=*i) return false;
|
||||
//}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template bool AllProbeBitsMatch(const SparseBitVect& bv1,const std::string &pkl);
|
||||
template bool AllProbeBitsMatch(const ExplicitBitVect& bv1,const std::string &pkl);
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// NumOnBitsInCommon(T1,T2)
|
||||
// Returns the number of on bits which are set in both T1 and T2.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
int
|
||||
NumOnBitsInCommon(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
return OnBitsInCommon(bv1,bv2).size();
|
||||
}
|
||||
|
||||
int
|
||||
NumOnBitsInCommon(const ExplicitBitVect& bv1,
|
||||
const ExplicitBitVect& bv2)
|
||||
{
|
||||
//std::cout << "nobic" << std::endl;
|
||||
int res = 0;
|
||||
unsigned int _sz = bv1.GetNumBits()<bv2.GetNumBits()?bv1.GetNumBits():bv2.GetNumBits();
|
||||
for(unsigned int i=0;i<_sz;i++) {
|
||||
if((*bv1.dp_bits)[i] && (*bv2.dp_bits)[i]) res+=1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// In all these similarity metrics the notation is selected to be
|
||||
// consistent with J.W. Raymond and P. Willett, JCAMD _16_ 59-71 (2002)
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// TanimotoSimilarity(T1,T2)
|
||||
// returns the Tanamoto similarity between T1 and T2, a double.
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator&, GetNumBits()
|
||||
// and GetOnBits().
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
TanimotoSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
if((y+z-x)==0.0) return 1.0;
|
||||
else return x / (y+z-x);
|
||||
}
|
||||
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
CosineSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(y*z>0.0){
|
||||
return x / sqrt(y*z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
KulczynskiSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(y*z>0.0){
|
||||
return x*(y+z)/(2*y*z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
DiceSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(y+z>0.0){
|
||||
return 2*x/(y+z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
SokalSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
return x/(2*y+2*z-3*x);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
McConnaugheySimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(y*z>0.0){
|
||||
return (x*(y+z)-(y*z))/(y*z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T tmin(T v1,T v2) {
|
||||
if(v1<v2) return v1;
|
||||
return v2;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T tmax(T v1,T v2) {
|
||||
if(v1>v2) return v1;
|
||||
return v2;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
AsymmetricSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(tmin(y,z)>0){
|
||||
return x/tmin(y,z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
BraunBlanquetSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
double y = bv1.GetNumOnBits();
|
||||
double z = bv2.GetNumOnBits();
|
||||
|
||||
if(tmax(y,z)>0){
|
||||
return x/tmax(y,z);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
RusselSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
double x = NumOnBitsInCommon(bv1,bv2);
|
||||
return x/bv1.GetNumBits();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// OnBitSimilarity(T1,T2)
|
||||
// Returns the percentage of possible on bits in common
|
||||
// between T1 and T2 (a double)
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator|, operator&
|
||||
// and GetOnBits().
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
OnBitSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
|
||||
double num = NumOnBitsInCommon(bv1,bv2);
|
||||
double denom=(bv1|bv2).GetNumOnBits();
|
||||
|
||||
if(denom>0){
|
||||
return num/denom;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// NumBitsInCommon(T1,T2)
|
||||
// Returns the number of bits in common (on and off)
|
||||
// between T1 and T2 (an int)
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator^, GetNumBits().
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
const int
|
||||
NumBitsInCommon(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
|
||||
return bv1.GetNumBits() - (bv1^bv2).GetNumOnBits();
|
||||
}
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// AllBitSimilarity(T1,T2)
|
||||
// Returns the percentage of bits in common (on and off)
|
||||
// between T1 and T2 (a double)
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator^, GetNumBits()
|
||||
// and GetNumOnBits().
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
AllBitSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
|
||||
return double(NumBitsInCommon(bv1,bv2))/bv1.GetNumBits();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// OnBitsInCommon(T1,T2)
|
||||
// Returns the on bits which are set in both T1 and T2.
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator&, GetNumBits()
|
||||
// and GetOnBits(), the return value is an IntVect.
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects, the return value
|
||||
// is a tuple of ints.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
IntVect
|
||||
OnBitsInCommon(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
IntVect res;
|
||||
(bv1&bv2).GetOnBits(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// OffBitsInCommon(T1,T2)
|
||||
// Returns the off bits which are set in both T1 and T2.
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator|, operator~,
|
||||
// GetNumBits() and GetOnBits(), the return value is an IntVect.
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects, the return value
|
||||
// is a tuple of ints.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
IntVect
|
||||
OffBitsInCommon(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
IntVect res;
|
||||
(~(bv1|bv2)).GetOnBits(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// OnBitProjSimilarity(T1,T2)
|
||||
// Returns the projected similarity between the on bits of
|
||||
// T1 and T2.
|
||||
//
|
||||
// The on bit projected similarity of T1 onto T2 is the
|
||||
// percentage of T1's on bits which are on in T2.
|
||||
//
|
||||
// This type of measure may be useful for substructure-type
|
||||
// searches.
|
||||
//
|
||||
// Two values are returned, the projection of T1 onto T2
|
||||
// and the projection of T2 onto T1
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator&, GetNumBits()
|
||||
// and GetNumOnBits(), the return value is an DoubleVect with
|
||||
// two elements.
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects, the return value
|
||||
// is a 2-tuple of doubles.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
DoubleVect
|
||||
OnBitProjSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
DoubleVect res(2,0.0);
|
||||
double num=NumOnBitsInCommon(bv1,bv2);
|
||||
if(num){
|
||||
res[0] = num/bv1.GetNumOnBits();
|
||||
res[1] = num/bv2.GetNumOnBits();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// OffBitProjSimilarity(T1,T2)
|
||||
// Returns the projected similarity between the off bits of
|
||||
// T1 and T2.
|
||||
//
|
||||
// The off bit projected similarity of T1 onto T2 is the
|
||||
// percentage of T1's off bits which are off in T2.
|
||||
//
|
||||
// This type of measure may be useful for substructure-type
|
||||
// searches.
|
||||
//
|
||||
// Two values are returned, the projection of T1 onto T2
|
||||
// and the projection of T2 onto T1
|
||||
//
|
||||
// T1 and T2 should be the same length.
|
||||
//
|
||||
// C++ Notes: T1 and T2 must support operator|, GetNumBits()
|
||||
// and GetNumOffBits(), the return value is an DoubleVect with
|
||||
// two elements.
|
||||
//
|
||||
// Python Notes: T1 and T2 are BitVects, the return value
|
||||
// is a 2-tuple of doubles.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
template <typename T1, typename T2>
|
||||
DoubleVect
|
||||
OffBitProjSimilarity(const T1& bv1,
|
||||
const T2& bv2)
|
||||
{
|
||||
if(bv1.GetNumBits()!=bv2.GetNumBits())
|
||||
throw ValueErrorException("BitVects must be same length");
|
||||
DoubleVect res(2,0.0);
|
||||
double num=(bv1|bv2).GetNumOffBits();
|
||||
if(num){
|
||||
res[0] = num/bv1.GetNumOffBits();
|
||||
res[1] = num/bv2.GetNumOffBits();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <typename T1>
|
||||
T1 *
|
||||
FoldFingerprint(const T1 &bv1,unsigned int factor)
|
||||
{
|
||||
if(factor <=0 || factor >= bv1.GetNumBits())
|
||||
throw ValueErrorException("invalid fold factor");
|
||||
|
||||
int initSize = bv1.GetNumBits();
|
||||
int resSize = initSize/factor;
|
||||
T1 *res = new T1(resSize);
|
||||
|
||||
IntVect onBits;
|
||||
bv1.GetOnBits(onBits);
|
||||
for(IntVectIter iv=onBits.begin();iv!=onBits.end();iv++){
|
||||
int pos = (*iv) % resSize;
|
||||
res->SetBit(pos);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T1>
|
||||
std::string
|
||||
BitVectToText(const T1& bv1){
|
||||
std::string res(bv1.GetNumBits(),'0');
|
||||
for(unsigned int i=0;i<bv1.GetNumBits();i++){
|
||||
if(bv1.GetBit(i)) res[i] = '1';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template const double TanimotoSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double CosineSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double KulczynskiSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double DiceSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double SokalSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double McConnaugheySimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double AsymmetricSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double BraunBlanquetSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double RusselSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double OnBitSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const int NumBitsInCommon(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template const double AllBitSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template int NumOnBitsInCommon(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template IntVect OnBitsInCommon(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template IntVect OffBitsInCommon(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template DoubleVect OnBitProjSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
template DoubleVect OffBitProjSimilarity(const SparseBitVect& bv1,const SparseBitVect& bv2);
|
||||
|
||||
template const double TanimotoSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double CosineSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double KulczynskiSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double DiceSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double SokalSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double McConnaugheySimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double AsymmetricSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double BraunBlanquetSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double RusselSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double OnBitSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const int NumBitsInCommon(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template const double AllBitSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template IntVect OnBitsInCommon(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template IntVect OffBitsInCommon(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template DoubleVect OnBitProjSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
template DoubleVect OffBitProjSimilarity(const ExplicitBitVect& bv1,const ExplicitBitVect& bv2);
|
||||
|
||||
template SparseBitVect *FoldFingerprint(const SparseBitVect &,unsigned int);
|
||||
template ExplicitBitVect *FoldFingerprint(const ExplicitBitVect &,unsigned int);
|
||||
|
||||
template std::string BitVectToText(const SparseBitVect &);
|
||||
template std::string BitVectToText(const ExplicitBitVect &);
|
||||
|
||||
|
||||
|
||||
|
||||
211
Code/DataStructs/BitOps.h
Executable file
211
Code/DataStructs/BitOps.h
Executable file
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_BITOPS_H__
|
||||
#define __RD_BITOPS_H__
|
||||
/*! \file BitOps.h
|
||||
|
||||
\brief Contains general bit-comparison and similarity operations.
|
||||
|
||||
The notation used to document the similarity metrics is:
|
||||
- \c V1_n: number of bits in vector 1
|
||||
- \c V1_o: number of on bits in vector 1
|
||||
- <tt>(V1&V2)_o</tt>: number of on bits in the intersection of vectors 1 and 2
|
||||
|
||||
*/
|
||||
|
||||
#include "BitVects.h"
|
||||
#include <sstream>
|
||||
|
||||
bool AllProbeBitsMatch(const char *probe,const char *ref);
|
||||
bool AllProbeBitsMatch(const std::string &probe,const std::string &ref);
|
||||
|
||||
|
||||
template <typename T1>
|
||||
bool AllProbeBitsMatch(const T1 &probe,const std::string &pkl);
|
||||
|
||||
|
||||
//! returns the number of on bits in common between two bit vectors
|
||||
/*!
|
||||
\return (bv1&bv2)_o
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
int
|
||||
NumOnBitsInCommon(const T1& bv1,const T2& bv2);
|
||||
|
||||
int
|
||||
NumOnBitsInCommon(const ExplicitBitVect & bv1,const ExplicitBitVect & bv2);
|
||||
|
||||
//! returns the Tanimoto similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / [bv1_o + bv2_o - (bv1&bv2)_o]</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
TanimotoSimilarity(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns the Cosine similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / sqrt(bv1_o + bv2_o)</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
CosineSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Kulczynski similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o * [bv1_o + bv2_o] / [2 * bv1_o * bv2_o]</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
KulczynskiSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Dice similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>2*(bv1&bv2)_o / [bv1_o + bv2_o]</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
DiceSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Sokal similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / [2*bv1_o + 2*bv2_o - 3*(bv1&bv2)_o]</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
SokalSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the McConnaughey similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>[(bv1&bv2)_o * (bv1_o + bv2_o) - (bv1_o * bv2_o)] / (bv1_o * bv2_o)</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
McConnaugheySimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Asymmetric similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / min(bv1_o,bv2_o)</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
AsymmetricSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Braun-Blanquet similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / max(bv1_o,bv2_o)</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
BraunBlanquetSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
//! returns the Russel similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / bv1_o</tt>
|
||||
|
||||
<b>Note:</b> that this operation is non-commutative:
|
||||
RusselSimilarity(bv1,bv2) != RusselSimilarity(bv2,bv1)
|
||||
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
RusselSimilarity(const T1& bv1,
|
||||
const T2& bv2);
|
||||
|
||||
|
||||
//! returns the on bit similarity between two bit vects
|
||||
/*!
|
||||
\return <tt>(bv1&bv2)_o / (bv1|bv2)_o </tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
OnBitSimilarity(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns the number of common bits (on and off) between two bit vects
|
||||
/*!
|
||||
\return <tt>bv1_n - (bv1^bv2)_o</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const int
|
||||
NumBitsInCommon(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns the commong-bit similarity (on and off) between two bit vects
|
||||
/*!
|
||||
\return <tt>[bv1_n - (bv1^bv2)_o] / bv1_n</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
const double
|
||||
AllBitSimilarity(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns an IntVect with indices of all on bits in common between two bit vects
|
||||
template <typename T1, typename T2>
|
||||
IntVect
|
||||
OnBitsInCommon(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns an IntVect with indices of all off bits in common between two bit vects
|
||||
template <typename T1, typename T2>
|
||||
IntVect
|
||||
OffBitsInCommon(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns the on-bit projected similarities between two bit vects
|
||||
/*!
|
||||
\return two values, as a DoubleVect:
|
||||
- <tt>(bv1&bv2)_o / bv1_o</tt>
|
||||
- <tt>(bv1&bv2)_o / bv2_o</tt>
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
DoubleVect
|
||||
OnBitProjSimilarity(const T1& bv1,const T2& bv2);
|
||||
|
||||
//! returns the on-bit projected similarities between two bit vects
|
||||
/*!
|
||||
\return two values, as a DoubleVect:
|
||||
- <tt>[bv1_n - (bv1|bv2)_o] / [bv1_n - bv1_o]</tt>
|
||||
- <tt>[bv2_n - (bv1|bv2)_o] / [bv2_n - bv2_o]</tt>
|
||||
|
||||
<b>Note:</b> <tt>bv1_n = bv2_n</tt>
|
||||
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
DoubleVect
|
||||
OffBitProjSimilarity(const T1& bv1,const T2& bv2);
|
||||
|
||||
|
||||
//! folds a bit vector \c factor times and returns the result
|
||||
/*!
|
||||
\param bv1 the vector to be folded
|
||||
\param factor (optional) the number of times to fold it
|
||||
|
||||
\return a pointer to the folded fingerprint, which is
|
||||
<tt>bv1_n/factor</tt> long.
|
||||
|
||||
<b>Note:</b> The caller is responsible for <tt>delete</tt>ing the result.
|
||||
*/
|
||||
template <typename T1>
|
||||
T1 *
|
||||
FoldFingerprint(const T1& bv1,unsigned int factor=2);
|
||||
|
||||
//! returns a text representation of a bit vector (a string of 0s and 1s)
|
||||
/*!
|
||||
\param bv1 the vector to be folded
|
||||
|
||||
\return an std::string
|
||||
|
||||
*/
|
||||
template <typename T1>
|
||||
std::string
|
||||
BitVectToText(const T1& bv1);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
81
Code/DataStructs/BitVect.cpp
Executable file
81
Code/DataStructs/BitVect.cpp
Executable file
@@ -0,0 +1,81 @@
|
||||
// $Id: BitVect.cpp 5062 2006-03-08 01:43:55Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "BitVect.h"
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
#include <RDGeneral/StreamOps.h>
|
||||
#include "base64.h"
|
||||
#ifdef WIN32
|
||||
#include <ios>
|
||||
#endif
|
||||
|
||||
BitVect::~BitVect() {}; // must always implement virtual destructors
|
||||
|
||||
void BitVect::InitFromText(const char *data,const unsigned int dataLen,
|
||||
bool isBase64,bool allowOldFormat){
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::in|std::ios_base::out);
|
||||
if(isBase64){
|
||||
unsigned int actualLen;
|
||||
char *decoded;
|
||||
decoded = Base64Decode((const char *)data,&actualLen);
|
||||
ss.write(decoded,actualLen);
|
||||
free(decoded);
|
||||
} else {
|
||||
ss.write(data,dataLen);
|
||||
}
|
||||
|
||||
int format=0;
|
||||
unsigned int nOn=0;
|
||||
int size;
|
||||
int version=0;
|
||||
|
||||
// earlier versions of the code did not have the version number encoded, so
|
||||
// we'll use that to distinguish version 0
|
||||
ss.read((char *)&size,sizeof(size));
|
||||
if(size<0){
|
||||
version = -1*size;
|
||||
if (version == 16) {
|
||||
format=1;
|
||||
}
|
||||
else if (version == 32) {
|
||||
format=2;
|
||||
}
|
||||
else {
|
||||
throw ValueErrorException("bad version in BitVect pickle");
|
||||
}
|
||||
|
||||
ss.read((char *)&size,sizeof(size));
|
||||
} else if( !allowOldFormat ) {
|
||||
throw ValueErrorException("invalid BitVect pickle");
|
||||
}
|
||||
ss.read((char *)&nOn,sizeof(nOn));
|
||||
_InitForSize(static_cast<int>(size));
|
||||
|
||||
// if the either have older version or or version 16 with ints for on bits
|
||||
if( (format==0) ||
|
||||
( (format == 1) && (size >= std::numeric_limits<unsigned short>::max()) ) ) {
|
||||
unsigned int tmp;
|
||||
for(unsigned int i=0; i<nOn; i++){
|
||||
ss.read((char *)&tmp,sizeof(tmp));
|
||||
SetBit(tmp);
|
||||
}
|
||||
} else if (format == 1) { // version 16 and on bits sotred as short ints
|
||||
unsigned short tmp;
|
||||
for(unsigned int i=0; i<nOn; i++){
|
||||
ss.read((char *)&tmp,sizeof(tmp));
|
||||
SetBit(tmp);
|
||||
}
|
||||
} else if (format == 2) { // run length encoded format
|
||||
unsigned int curr=0;
|
||||
for (unsigned int i=0; i<nOn; i++) {
|
||||
curr += RDKit::readPackedIntFromStream(ss);
|
||||
SetBit(curr);
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
62
Code/DataStructs/BitVect.h
Executable file
62
Code/DataStructs/BitVect.h
Executable file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Copyright (c) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_BITVECT_H__
|
||||
#define __RD_BITVECT_H__
|
||||
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
typedef vector<int> IntVect;
|
||||
typedef IntVect::iterator IntVectIter;
|
||||
typedef vector<double> DoubleVect;
|
||||
typedef DoubleVect::iterator DoubleVectIter;
|
||||
const int ci_BITVECT_VERSION=0x0020; //!< version number to use in pickles
|
||||
|
||||
//! Abstract base class for storing BitVectors
|
||||
class BitVect{
|
||||
public:
|
||||
virtual ~BitVect() = 0;
|
||||
//! sets a particular bit and returns its original value
|
||||
virtual bool SetBit(const unsigned int which) = 0;
|
||||
//! unsets a particular bit and returns its original value
|
||||
virtual bool UnSetBit(const unsigned int which) = 0;
|
||||
//! returns the value of a particular bit
|
||||
virtual bool GetBit(const unsigned int which) const = 0;
|
||||
//! returns the number of bits (the length of the BitVect)
|
||||
virtual const unsigned int GetNumBits() const = 0;
|
||||
//! returns the number of on bits
|
||||
virtual const unsigned int GetNumOnBits() const = 0;
|
||||
//! returns the number of off bits
|
||||
virtual const unsigned int GetNumOffBits() const =0;
|
||||
//! replaces the contents of \c v with indices of our on bits
|
||||
virtual void GetOnBits (IntVect& v) const = 0;
|
||||
//! clears (sets to off) all of our bits
|
||||
virtual void ClearBits() = 0;
|
||||
|
||||
//! initializes this BitVect from a pickle
|
||||
/*!
|
||||
\param data the raw pickle data
|
||||
\param dataLen the length of \c data
|
||||
\param isBase64 (optional) if this is set, \c data is assumed to
|
||||
be base64 encoded.
|
||||
\param allowOldFormat (optional) allows a very old form of the BitVect
|
||||
representation to be recognized. This argument disables a large
|
||||
amount of error checking and it is strongly suggested that it not
|
||||
be used in client code.
|
||||
*/
|
||||
void InitFromText(const char *data,const unsigned int dataLen,
|
||||
bool isBase64=false,bool allowOldFormat=false);
|
||||
|
||||
//! returns a serialized (pickled) version of this BitVect
|
||||
virtual std::string ToString() const = 0;
|
||||
|
||||
virtual bool operator[] (const unsigned int which) const = 0;
|
||||
|
||||
private:
|
||||
virtual void _InitForSize(const unsigned int size) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
30
Code/DataStructs/BitVectUtils.h
Executable file
30
Code/DataStructs/BitVectUtils.h
Executable file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Copyright (c) 2002-2006 greg Landrum, Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_BITVECTS_UTILS_H__
|
||||
#define __RD_BITVECTS_UTILS_H__
|
||||
|
||||
#include "BitVects.h"
|
||||
#include <string>
|
||||
|
||||
//! \brief Construct a BitVect from the ASCII representation of a
|
||||
//! Daylight fingerprint string
|
||||
template <typename T>
|
||||
void FromDaylightString(T &sbv,std::string s);
|
||||
|
||||
//! \brief Construct a BitVect from the ASCII representation of a
|
||||
//! bit string (i.e. a bunch of zeros and ones)
|
||||
template <typename T>
|
||||
void FromBitString(T &sbv,const std::string &s);
|
||||
|
||||
|
||||
//! Convert a SparseBitVector to an ExplicitBitVector
|
||||
/*!
|
||||
\return a pointer to an ExplicitBitVector
|
||||
<b>Note:</b> the caller is responsible for <tt>delete</tt>ing this.
|
||||
|
||||
*/
|
||||
ExplicitBitVect *convertToExplicit(const SparseBitVect *sbv);
|
||||
#endif
|
||||
20
Code/DataStructs/BitVects.h
Executable file
20
Code/DataStructs/BitVects.h
Executable file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright (c) 2001-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
/*! \file BitVects.h
|
||||
|
||||
\brief Pulls in all the BitVect classes
|
||||
|
||||
*/
|
||||
#ifndef __BITVECTS_H__
|
||||
#define __BITVECTS_H__
|
||||
|
||||
#include "BitVect.h"
|
||||
#include "ExplicitBitVect.h"
|
||||
#include "SparseBitVect.h"
|
||||
typedef SparseBitVect SBV;
|
||||
typedef ExplicitBitVect EBV;
|
||||
|
||||
#endif
|
||||
156
Code/DataStructs/BitVectsTest.vcproj
Executable file
156
Code/DataStructs/BitVectsTest.vcproj
Executable file
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="testDatastructs"
|
||||
ProjectGUID="{219B86E8-EEC8-4C8C-AB3C-5795CCE4D212}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\datastructs_test___Win32_Debug"
|
||||
IntermediateDirectory=".\datastructs_test___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(RDBASE)\external\boost\include\$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\datastructs_test___Win32_Debug/BitVectsTest.pch"
|
||||
AssemblerListingLocation=".\datastructs_test___Win32_Debug/"
|
||||
ObjectFile=".\datastructs_test___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\datastructs_test___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib "
|
||||
OutputFile="./testExecs/test.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\datastructs_test___Win32_Debug/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\datastructs_test___Win32_Debug/BitVectsTest.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(RDBASE)\external\boost\include\$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/BitVectsTest.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib "
|
||||
OutputFile="testExecs/test.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
ProgramDatabaseFile=".\Release/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/BitVectsTest.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\testDatastructs.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
23
Code/DataStructs/DatastructsException.h
Normal file
23
Code/DataStructs/DatastructsException.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (C) 2005-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#ifndef _DATASTRUCTS_EXCEPTION_H_20050126
|
||||
#define _DATASTRUCTS_EXCEPTION_H_20050126
|
||||
|
||||
class DatastructsException : public std::exception {
|
||||
public:
|
||||
//! construct with an error message
|
||||
DatastructsException(const char *msg) : _msg(msg) {};
|
||||
//! construct with an error message
|
||||
DatastructsException(const std::string msg) : _msg(msg) {};
|
||||
//! get the error message
|
||||
const char *message () const { return _msg.c_str(); };
|
||||
~DatastructsException () throw () {};
|
||||
private:
|
||||
std::string _msg;
|
||||
};
|
||||
|
||||
#endif
|
||||
87
Code/DataStructs/DiscreteDistMat.cpp
Normal file
87
Code/DataStructs/DiscreteDistMat.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// $Id: DiscreteDistMat.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "DiscreteDistMat.h"
|
||||
#include "DiscreteValueVect.h"
|
||||
#include <iostream>
|
||||
#include "DatastructsException.h"
|
||||
|
||||
void _fillDistMat(unsigned int dmat[], unsigned int nBits) {
|
||||
unsigned int i,j, a, b, ta, tb, dist;
|
||||
int temp;
|
||||
unsigned int mask = ((1<<nBits) -1);
|
||||
for (i = 0; i < 256; ++i) {
|
||||
for (j = 0; j < 256; ++j) {
|
||||
dist = 0;
|
||||
a = i;
|
||||
b = j;
|
||||
while (a || b) {
|
||||
ta = a&mask;
|
||||
tb = b&mask;
|
||||
temp = ta-tb;
|
||||
if (temp > 0) {
|
||||
dist += temp;
|
||||
} else {
|
||||
dist -= temp;
|
||||
}
|
||||
a >>= nBits;
|
||||
b >>= nBits;
|
||||
}
|
||||
dmat[i*256 + j] = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DiscreteDistMat::DiscreteDistMat() {
|
||||
// fill in the distance matrix table
|
||||
|
||||
// one bit per value table
|
||||
_fillDistMat(d_oneBitTab, 1);
|
||||
|
||||
// two bits per value table
|
||||
_fillDistMat(d_twoBitTab, 2);
|
||||
|
||||
// four bits per value table
|
||||
_fillDistMat(d_fourBitTab, 4);
|
||||
}
|
||||
|
||||
unsigned int DiscreteDistMat::getDist(unsigned char v1,
|
||||
unsigned char v2,
|
||||
DiscreteValueVect::DiscreteValueType type) {
|
||||
unsigned int res=0;
|
||||
int temp;
|
||||
unsigned int id = static_cast<unsigned int>(v1)*256 + static_cast<unsigned int>(v2);
|
||||
switch(type) {
|
||||
case DiscreteValueVect::ONEBITVALUE :
|
||||
res = d_oneBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::TWOBITVALUE :
|
||||
res = d_twoBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::FOURBITVALUE :
|
||||
res = d_fourBitTab[id];
|
||||
break;
|
||||
case DiscreteValueVect::EIGHTBITVALUE :
|
||||
temp = static_cast<unsigned int>(v1) - static_cast<unsigned int>(v2);
|
||||
if (temp < 0) {
|
||||
res -= temp;
|
||||
} else {
|
||||
res += temp;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// ummm.. we shouldn't have come here
|
||||
throw DatastructsException("We shouldn't be here");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static DiscreteDistMat discreteDMat;
|
||||
DiscreteDistMat *getDiscreteDistMat() {
|
||||
return &discreteDMat;
|
||||
}
|
||||
|
||||
|
||||
26
Code/DataStructs/DiscreteDistMat.h
Normal file
26
Code/DataStructs/DiscreteDistMat.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_DISCRETEDISTMAT_H__
|
||||
#define __RD_DISCRETEDISTMAT_H__
|
||||
#include "DiscreteValueVect.h"
|
||||
|
||||
class DiscreteDistMat {
|
||||
public:
|
||||
DiscreteDistMat();
|
||||
~DiscreteDistMat(){};
|
||||
unsigned int getDist(unsigned char v1,
|
||||
unsigned char v2,
|
||||
DiscreteValueVect::DiscreteValueType type);
|
||||
|
||||
private:
|
||||
unsigned int d_oneBitTab[256*256];
|
||||
unsigned int d_twoBitTab[256*256];
|
||||
unsigned int d_fourBitTab[256*256];
|
||||
|
||||
};
|
||||
|
||||
extern DiscreteDistMat *getDiscreteDistMat();
|
||||
#endif
|
||||
116
Code/DataStructs/DiscreteValueVect.cpp
Normal file
116
Code/DataStructs/DiscreteValueVect.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "DiscreteValueVect.h"
|
||||
#include <RDGeneral/Invariant.h>
|
||||
#include "DatastructsException.h"
|
||||
#include "DiscreteDistMat.h"
|
||||
#include <RDBoost/Exceptions.h>
|
||||
|
||||
DiscreteValueVect::DiscreteValueVect(const DiscreteValueVect &other) {
|
||||
d_type = other.getValueType();
|
||||
d_bitsPerVal = other.getNumBitsPerVal();
|
||||
d_numInts = other.getNumInts();
|
||||
d_length = other.getLength();
|
||||
d_valsPerInt = BITS_PER_INT/d_bitsPerVal;
|
||||
const unsigned int *odata = other.getData();
|
||||
unsigned int *data = new unsigned int[d_numInts];
|
||||
memcpy(static_cast<void *>(data), static_cast<const void *>(odata),
|
||||
d_numInts*sizeof(unsigned int));
|
||||
d_data.reset(data);
|
||||
}
|
||||
|
||||
unsigned int DiscreteValueVect::getVal(unsigned int i) const {
|
||||
RANGE_CHECK(0, i, d_length-1);
|
||||
unsigned int shift = d_bitsPerVal*(i%d_valsPerInt);
|
||||
unsigned int intId = i/d_valsPerInt;
|
||||
return ( (d_data[intId] >> shift) & d_mask);
|
||||
}
|
||||
|
||||
void DiscreteValueVect::setVal(unsigned int i, unsigned int val) {
|
||||
RANGE_CHECK(0, i, d_length-1);
|
||||
if ((val & d_mask) != val) {
|
||||
throw ValueErrorException("Value out of range");
|
||||
}
|
||||
unsigned int shift = d_bitsPerVal*(i%d_valsPerInt);
|
||||
unsigned int intId = i/d_valsPerInt;
|
||||
unsigned int mask = ((1<<d_bitsPerVal) -1) << shift;
|
||||
mask = ~mask;
|
||||
d_data[intId] = (d_data[intId]&mask)|(val << shift);
|
||||
}
|
||||
|
||||
unsigned int DiscreteValueVect::getTotalVal() const {
|
||||
unsigned int i, j, res = 0;
|
||||
|
||||
for (i = 0; i < d_numInts; ++i) {
|
||||
for (j = 0; j < d_valsPerInt; ++j) {
|
||||
res += ((d_data[i] >> (j*d_bitsPerVal)) & d_mask);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned int DiscreteValueVect::getLength() const {
|
||||
return d_length;
|
||||
}
|
||||
|
||||
const unsigned int *DiscreteValueVect::getData() const {
|
||||
return d_data.get();
|
||||
}
|
||||
|
||||
unsigned int computeL1Norm(const DiscreteValueVect &v1, const DiscreteValueVect &v2) {
|
||||
if (v1.getLength() != v2.getLength()) {
|
||||
throw ValueErrorException("Comparing vectors of different lengths");
|
||||
}
|
||||
|
||||
DiscreteValueVect::DiscreteValueType valType = v1.getValueType();
|
||||
|
||||
if (valType != v2.getValueType()) {
|
||||
throw ValueErrorException("Comparing vector of different value types");
|
||||
}
|
||||
|
||||
const unsigned int* data1 = v1.getData();
|
||||
const unsigned int* data2 = v2.getData();
|
||||
|
||||
unsigned int res = 0;
|
||||
if (valType <= DiscreteValueVect::EIGHTBITVALUE) {
|
||||
DiscreteDistMat *dmat = getDiscreteDistMat();
|
||||
|
||||
unsigned char *cd1 = (unsigned char *)(data1);
|
||||
unsigned char *cd2 = (unsigned char *)(data2);
|
||||
const unsigned char *cend = cd1 + (v1.getNumInts()*4);
|
||||
while (cd1 != cend) {
|
||||
if (*cd1 == *cd2) {
|
||||
cd1++;
|
||||
cd2++;
|
||||
continue;
|
||||
}
|
||||
res += dmat->getDist(*cd1, *cd2, valType);
|
||||
cd1++;
|
||||
cd2++;
|
||||
}
|
||||
} else {
|
||||
// we have a sixteen bits per value type
|
||||
// REVIEW: we are making an assumption here that a short
|
||||
// is 16 bit - may fail on a different compiler
|
||||
const unsigned short int *sd1 = (unsigned short int *)(data1);
|
||||
const unsigned short int *sd2 = (unsigned short int *)(data2);
|
||||
|
||||
const unsigned short int *send = sd1 + (v1.getNumInts()*2);
|
||||
while (sd1 != send) {
|
||||
if (*sd1 == *sd2) {
|
||||
sd1++;
|
||||
sd2++;
|
||||
continue;
|
||||
}
|
||||
res += abs((*sd1) - (*sd2));
|
||||
sd1++;
|
||||
sd2++;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
72
Code/DataStructs/DiscreteValueVect.h
Normal file
72
Code/DataStructs/DiscreteValueVect.h
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_DISCRETE_VALUE_VECT_20050124__
|
||||
#define __RD_DISCRETE_VALUE_VECT_20050124__
|
||||
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
// we are making an assumption here that and unsigned int is 32 bits long
|
||||
const unsigned int BITS_PER_INT=32;
|
||||
|
||||
class DiscreteValueVect {
|
||||
public:
|
||||
typedef boost::shared_array<unsigned int> DATA_SPTR;
|
||||
|
||||
typedef enum {
|
||||
ONEBITVALUE=0,
|
||||
TWOBITVALUE,
|
||||
FOURBITVALUE,
|
||||
EIGHTBITVALUE,
|
||||
SIXTEENBITVALUE,
|
||||
} DiscreteValueType;
|
||||
|
||||
DiscreteValueVect(DiscreteValueType valType, unsigned length) : d_type(valType), d_length(length) {
|
||||
d_bitsPerVal = (1 << static_cast<unsigned int>(valType));
|
||||
d_valsPerInt = BITS_PER_INT/d_bitsPerVal;
|
||||
d_numInts = (length + d_valsPerInt -1)/d_valsPerInt;
|
||||
d_mask = ((1<<d_bitsPerVal) -1);
|
||||
unsigned int *data = new unsigned int[d_numInts];
|
||||
memset(static_cast<void *>(data),0,d_numInts*sizeof(unsigned int));
|
||||
d_data.reset(data);
|
||||
}
|
||||
|
||||
//! Copy constructor
|
||||
DiscreteValueVect(const DiscreteValueVect& other);
|
||||
|
||||
~DiscreteValueVect() {}
|
||||
|
||||
unsigned int getVal(unsigned int i) const;
|
||||
void setVal(unsigned int i, unsigned int val);
|
||||
unsigned int getTotalVal() const;
|
||||
|
||||
unsigned int getLength() const;
|
||||
|
||||
const unsigned int *getData() const;
|
||||
unsigned int getNumBitsPerVal() const {
|
||||
return d_bitsPerVal;
|
||||
}
|
||||
|
||||
DiscreteValueType getValueType() const {
|
||||
return d_type;
|
||||
}
|
||||
|
||||
unsigned int getNumInts() const {
|
||||
return d_numInts;
|
||||
}
|
||||
|
||||
private:
|
||||
DiscreteValueType d_type;
|
||||
unsigned int d_bitsPerVal;
|
||||
unsigned int d_valsPerInt;
|
||||
unsigned int d_numInts;
|
||||
unsigned int d_length;
|
||||
unsigned int d_mask;
|
||||
DATA_SPTR d_data;
|
||||
};
|
||||
|
||||
unsigned int computeL1Norm(const DiscreteValueVect &v1, const DiscreteValueVect &v2);
|
||||
|
||||
#endif
|
||||
166
Code/DataStructs/ExplicitBitVect.cpp
Executable file
166
Code/DataStructs/ExplicitBitVect.cpp
Executable file
@@ -0,0 +1,166 @@
|
||||
// $Id: ExplicitBitVect.cpp 5062 2006-03-08 01:43:55Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2001-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <iostream>
|
||||
#include <RDBoost/Exceptions.h>
|
||||
#include "ExplicitBitVect.h"
|
||||
#include <RDGeneral/StreamOps.h>
|
||||
#include "base64.h"
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
#ifdef WIN32
|
||||
#include <ios>
|
||||
#endif
|
||||
|
||||
|
||||
ExplicitBitVect::ExplicitBitVect(const std::string s)
|
||||
{
|
||||
d_size=0;dp_bits = 0;
|
||||
InitFromText(s.c_str(),s.length());
|
||||
}
|
||||
ExplicitBitVect::ExplicitBitVect(const char *data,const unsigned int dataLen)
|
||||
{
|
||||
d_size=0;dp_bits = 0;
|
||||
InitFromText(data,dataLen);
|
||||
}
|
||||
|
||||
ExplicitBitVect::ExplicitBitVect(const ExplicitBitVect& other){
|
||||
d_size = other.d_size;
|
||||
dp_bits = new boost::dynamic_bitset<>(*(other.dp_bits));
|
||||
};
|
||||
|
||||
ExplicitBitVect& ExplicitBitVect::operator=(const ExplicitBitVect& other){
|
||||
d_size = other.d_size;
|
||||
dp_bits = new boost::dynamic_bitset<>(*(other.dp_bits));
|
||||
return *this;
|
||||
};
|
||||
bool ExplicitBitVect::operator[] (const unsigned int which) const {
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
return (bool)(*dp_bits)[which];
|
||||
};
|
||||
bool ExplicitBitVect::SetBit(const unsigned int which){
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
if((bool)(*dp_bits)[which]){
|
||||
return true;
|
||||
} else {
|
||||
(*dp_bits)[which] = 1;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
bool ExplicitBitVect::UnSetBit(const unsigned int which){
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
if((bool)(*dp_bits)[which]){
|
||||
(*dp_bits)[which] = 0;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
bool ExplicitBitVect::GetBit(const unsigned int which) const {
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
return((bool)(*dp_bits)[which]);
|
||||
};
|
||||
|
||||
ExplicitBitVect ExplicitBitVect::operator^ (const ExplicitBitVect &other) const {
|
||||
ExplicitBitVect ans(d_size);
|
||||
*(ans.dp_bits) = (*dp_bits) ^ *(other.dp_bits);
|
||||
return(ans);
|
||||
};
|
||||
|
||||
ExplicitBitVect ExplicitBitVect::operator& (const ExplicitBitVect &other) const {
|
||||
ExplicitBitVect ans(d_size);
|
||||
*(ans.dp_bits) = (*dp_bits) & *(other.dp_bits);
|
||||
return(ans);
|
||||
};
|
||||
|
||||
ExplicitBitVect ExplicitBitVect::operator| (const ExplicitBitVect &other) const {
|
||||
ExplicitBitVect ans(d_size);
|
||||
*(ans.dp_bits) = (*dp_bits) | *(other.dp_bits);
|
||||
return(ans);
|
||||
};
|
||||
|
||||
ExplicitBitVect ExplicitBitVect::operator~ () const {
|
||||
ExplicitBitVect ans(d_size);
|
||||
*(ans.dp_bits) = ~(*dp_bits);
|
||||
return(ans);
|
||||
};
|
||||
|
||||
const unsigned int ExplicitBitVect::GetNumBits() const {
|
||||
return d_size;
|
||||
};
|
||||
const unsigned int ExplicitBitVect::GetNumOnBits() const {
|
||||
return dp_bits->count();
|
||||
};
|
||||
const unsigned int ExplicitBitVect::GetNumOffBits() const {
|
||||
return d_size - dp_bits->count();
|
||||
};
|
||||
|
||||
// the contents of v are blown out
|
||||
void ExplicitBitVect::GetOnBits (IntVect& v) const {
|
||||
unsigned int nOn = GetNumOnBits();
|
||||
if(!v.empty()) IntVect().swap(v);
|
||||
v.reserve(nOn);
|
||||
for(unsigned int i=0;i<d_size;i++){
|
||||
if((bool)(*dp_bits)[i]) v.push_back(i);
|
||||
}
|
||||
};
|
||||
|
||||
void ExplicitBitVect::_InitForSize(unsigned int size) {
|
||||
d_size = size;
|
||||
if(dp_bits) delete dp_bits;
|
||||
dp_bits = new boost::dynamic_bitset<>(size);
|
||||
};
|
||||
|
||||
|
||||
ExplicitBitVect::~ExplicitBitVect() {
|
||||
if(dp_bits) delete dp_bits;
|
||||
};
|
||||
|
||||
std::string
|
||||
ExplicitBitVect::ToString() const
|
||||
{
|
||||
// This Function replaces the older version (version 16) of writing the onbits to
|
||||
// a string
|
||||
// the old version does not perform any run length encoding, it only checks to see if
|
||||
// the length of the bitvect can be short ints and writes the on bits as shorts
|
||||
// other wise the onbits are all written as ints
|
||||
|
||||
// here we do run length encoding and the version number has been bumped to 32 as well.
|
||||
// only the reader needs to take care of readinf all legacy versions
|
||||
// also in this scheme each bit number written to the string is checked to see how many
|
||||
// bytes it needs
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
|
||||
|
||||
unsigned int nOnBits=GetNumOnBits();
|
||||
int tVers = ci_BITVECT_VERSION*-1;
|
||||
ss.write((const char *)&(tVers),sizeof(tVers));
|
||||
ss.write((const char *)&d_size,sizeof(d_size));
|
||||
ss.write((const char *)&nOnBits,sizeof(nOnBits));
|
||||
|
||||
int prev = -1;
|
||||
unsigned int zeroes;
|
||||
for(unsigned int i=0;i<d_size;i++){
|
||||
if( (bool)(*dp_bits)[i] ){
|
||||
zeroes = i - prev -1;
|
||||
RDKit::appendPackedIntToStream(ss, zeroes);
|
||||
prev = i;
|
||||
}
|
||||
}
|
||||
zeroes = d_size - prev -1;
|
||||
RDKit::appendPackedIntToStream(ss, zeroes);
|
||||
std::string res(ss.str());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
61
Code/DataStructs/ExplicitBitVect.h
Executable file
61
Code/DataStructs/ExplicitBitVect.h
Executable file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Copyright (c) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_EXPLICITBITVECTS_H__
|
||||
#define __RD_EXPLICITBITVECTS_H__
|
||||
|
||||
#include <boost/dynamic_bitset.hpp>
|
||||
#include "BitVect.h"
|
||||
|
||||
//! a class for bit vectors that are densely occupied
|
||||
/*!
|
||||
ExplicitBitVect objects store all of their bits, using
|
||||
a boost::dynamic_bitset
|
||||
|
||||
These are very fast, but can require large amounts of memory for large,
|
||||
sparsely occupied vectors.
|
||||
|
||||
*/
|
||||
class ExplicitBitVect : public BitVect {
|
||||
public:
|
||||
ExplicitBitVect() : dp_bits(0), d_size(0) {};
|
||||
//! initialize with a particular size;
|
||||
explicit ExplicitBitVect(unsigned int size) : dp_bits(0), d_size(0) {_InitForSize(size);};
|
||||
ExplicitBitVect(const ExplicitBitVect& other);
|
||||
//! construct from a string pickle
|
||||
ExplicitBitVect(const std::string);
|
||||
//! construct from a text pickle
|
||||
ExplicitBitVect(const char *,const unsigned int);
|
||||
|
||||
~ExplicitBitVect();
|
||||
|
||||
ExplicitBitVect& operator=(const ExplicitBitVect& other);
|
||||
bool operator[] (const unsigned int which) const;
|
||||
bool SetBit(const unsigned int which);
|
||||
bool UnSetBit(const unsigned int which);
|
||||
bool GetBit(const unsigned int which) const;
|
||||
|
||||
ExplicitBitVect operator^ (const ExplicitBitVect &other) const;
|
||||
ExplicitBitVect operator& (const ExplicitBitVect &other) const;
|
||||
ExplicitBitVect operator| (const ExplicitBitVect &other) const;
|
||||
ExplicitBitVect operator~ () const;
|
||||
const unsigned int GetNumBits() const;
|
||||
const unsigned int GetNumOnBits() const;
|
||||
const unsigned int GetNumOffBits() const;
|
||||
|
||||
void GetOnBits (IntVect& v) const;
|
||||
|
||||
// FIX: complete these
|
||||
void ClearBits() { ; };
|
||||
std::string ToString() const;
|
||||
|
||||
boost::dynamic_bitset<> *dp_bits; //!< our raw storage
|
||||
private:
|
||||
unsigned int d_size;
|
||||
void _InitForSize(const unsigned int size);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
23
Code/DataStructs/Makefile
Executable file
23
Code/DataStructs/Makefile
Executable file
@@ -0,0 +1,23 @@
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
include $(RDBASE)/Code/rdrules.make
|
||||
|
||||
CXXFLAGS=$(RDOPTFLAGS) -I$(RDBASE)/Code/DataStructs -I$(RDBASE)/Code $(BOOSTINC) -Wall
|
||||
SOURCES=BitVect.cpp SparseBitVect.cpp ExplicitBitVect.cpp Utils.cpp \
|
||||
base64.cpp BitOps.cpp DiscreteDistMat.cpp DiscreteValueVect.cpp
|
||||
LIB=libDataStructs.a
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
ar -rv $@ $^
|
||||
|
||||
testExecs/test.exe: testDatastructs.o $(LIB)
|
||||
g++ $(CXXFLAGS) -o $@ $^ $(RDGENERAL)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(LIB) testDatastructs.o testExecs/test.exe $(DEPENDS)
|
||||
|
||||
regrs: testExecs/test.exe
|
||||
|
||||
testExecs/bench.exe: bench.o $(LIB)
|
||||
g++ $(CXXFLAGS) -o $@ $^ $(RDGENERAL)
|
||||
|
||||
include $(DEPENDS)
|
||||
337
Code/DataStructs/SparseBitVect.cpp
Executable file
337
Code/DataStructs/SparseBitVect.cpp
Executable file
@@ -0,0 +1,337 @@
|
||||
// $Id: SparseBitVect.cpp 5062 2006-03-08 01:43:55Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2001-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "SparseBitVect.h"
|
||||
#include <RDBoost/Exceptions.h>
|
||||
|
||||
#include "base64.h"
|
||||
#include <RDGeneral/StreamOps.h>
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <ios>
|
||||
#endif
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Construct a SparseBitVect from a binary string.
|
||||
// The format of the string should be
|
||||
// the format produced by SparseBitVect::ToString
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect::SparseBitVect(const std::string s)
|
||||
{
|
||||
d_size=0;dp_bits = 0;
|
||||
InitFromText(s.c_str(),s.length());
|
||||
}
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Construct a SparseBitVect from a binary string stored as a char *.
|
||||
// The format of the string should be
|
||||
// the format produced by SparseBitVect::ToString
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect::SparseBitVect(const char *data,const unsigned int dataLen)
|
||||
{
|
||||
d_size=0;dp_bits = 0;
|
||||
InitFromText(data,dataLen);
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Operator[]
|
||||
// Returns the state of the ith bit.
|
||||
//
|
||||
// **C++ NOTE** The state of BitVects cannot be changed using
|
||||
// operator&. So this will not work:
|
||||
// SBV[i] = 0;
|
||||
// In Python this type of assignment **is** valid.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::operator[](const unsigned int which) const
|
||||
{
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
if(dp_bits->count(which)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Assignment operator
|
||||
// The bits of the other SBV are copied.
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect&
|
||||
SparseBitVect::operator=(const SparseBitVect& other)
|
||||
{
|
||||
IntSet *bv=other.dp_bits;
|
||||
if(dp_bits) delete dp_bits;
|
||||
d_size = other.GetNumBits();
|
||||
dp_bits = new IntSet;
|
||||
std::copy(bv->begin(),bv->end(),std::inserter(*dp_bits,dp_bits->end()));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------
|
||||
//
|
||||
// Operator|
|
||||
// allows SBV3 = SBV1|SBV2;
|
||||
//
|
||||
// -------------------------------------------------------
|
||||
SparseBitVect
|
||||
SparseBitVect::operator| (const SparseBitVect &other) const
|
||||
{
|
||||
SparseBitVect ans(d_size);
|
||||
std::set_union(dp_bits->begin(),dp_bits->end(),
|
||||
other.dp_bits->begin(),other.dp_bits->end(),
|
||||
std::inserter(*(ans.dp_bits),ans.dp_bits->end()));
|
||||
return ans;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Operator&
|
||||
// allows SBV3 = SBV1&SBV2;
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect
|
||||
SparseBitVect::operator& (const SparseBitVect &other) const
|
||||
{
|
||||
SparseBitVect ans(d_size);
|
||||
std::set_intersection(dp_bits->begin(),dp_bits->end(),
|
||||
other.dp_bits->begin(),other.dp_bits->end(),
|
||||
std::inserter(*(ans.dp_bits),ans.dp_bits->end()));
|
||||
return ans;
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Operator^
|
||||
// allows SBV3 = SBV1^SBV2;
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect
|
||||
SparseBitVect::operator^ (const SparseBitVect &other) const
|
||||
{
|
||||
SparseBitVect ans(d_size);
|
||||
std::set_symmetric_difference(dp_bits->begin(),dp_bits->end(),
|
||||
other.dp_bits->begin(),other.dp_bits->end(),
|
||||
std::inserter(*(ans.dp_bits),ans.dp_bits->end()));
|
||||
return(ans);
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Operator~ (the negation operator)
|
||||
// allows SBV2 = ~SBV1;
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
SparseBitVect
|
||||
SparseBitVect::operator~ () const
|
||||
{
|
||||
SparseBitVect ans(d_size);
|
||||
for(unsigned int i=0;i<d_size;i++){
|
||||
if(!GetBit(i)) ans.SetBit(i);
|
||||
}
|
||||
|
||||
return(ans);
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// GetBit(int which)
|
||||
// Returns the state of bit which
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::GetBit(const unsigned int which) const
|
||||
{
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
if(dp_bits->count(which)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// GetBit(const IntVectIter which) (C++ SPECIFIC)
|
||||
// Returns the state of bit which
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::GetBit (const IntVectIter which) const
|
||||
{
|
||||
if(*which < 0 || static_cast<unsigned int>(*which) >= d_size){
|
||||
throw IndexErrorException(*which);
|
||||
}
|
||||
if(dp_bits->count(*which)) return true;
|
||||
else return false;
|
||||
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// GetBit(const IntSetIter which) (C++ SPECIFIC)
|
||||
// Returns the state of bit which
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::GetBit (const IntSetIter which) const
|
||||
{
|
||||
if(*which < 0 || static_cast<unsigned int>(*which) >= d_size){
|
||||
throw IndexErrorException(*which);
|
||||
}
|
||||
if(dp_bits->count(*which)) return true;
|
||||
else return false;
|
||||
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Sets bit which to be on.
|
||||
//
|
||||
// Returns the original state of the bit
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::SetBit(const unsigned int which)
|
||||
{
|
||||
if(!dp_bits){
|
||||
throw ValueErrorException("BitVect not properly initialized.");
|
||||
}
|
||||
std::pair<IntSetIter,bool> res;
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
res = dp_bits->insert(which);
|
||||
return !(res.second);
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// SetBit(const IntSetIter which) (C++ SPECIFIC)
|
||||
// Sets bit which to be on.
|
||||
//
|
||||
// Returns the original state of the bit
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::SetBit(const IntSetIter which)
|
||||
{
|
||||
if(!dp_bits){
|
||||
throw ValueErrorException("BitVect not properly initialized.");
|
||||
}
|
||||
std::pair<IntSetIter,bool> res;
|
||||
if(*which < 0 || static_cast<unsigned int>(*which) >= d_size){
|
||||
throw IndexErrorException(*which);
|
||||
}
|
||||
res = dp_bits->insert(*which);
|
||||
return !(res.second);
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// Sets bit which to be off.
|
||||
//
|
||||
// Returns the original state of the bit
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
bool
|
||||
SparseBitVect::UnSetBit(const unsigned int which)
|
||||
{
|
||||
if(!dp_bits){
|
||||
throw ValueErrorException("BitVect not properly initialized.");
|
||||
}
|
||||
if(which < 0 || which >= d_size){
|
||||
throw IndexErrorException(which);
|
||||
}
|
||||
|
||||
if(dp_bits->count(which)){
|
||||
dp_bits->erase(dp_bits->find(which));
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// GetOnBits(IntVect &which)
|
||||
// C++: Passes the set of on bits out in the IntVect passed in.
|
||||
// The contents of IntVect are destroyed.
|
||||
//
|
||||
// Python: Returns the tuple of on bits
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
void
|
||||
SparseBitVect::GetOnBits(IntVect& v) const
|
||||
{
|
||||
if(!dp_bits){
|
||||
throw ValueErrorException("BitVect not properly initialized.");
|
||||
}
|
||||
unsigned int nOn = GetNumOnBits();
|
||||
if(!v.empty()) IntVect().swap(v);
|
||||
v.reserve(nOn);
|
||||
v.resize(nOn);
|
||||
std::copy(dp_bits->begin(),dp_bits->end(),v.begin());
|
||||
};
|
||||
|
||||
// """ -------------------------------------------------------
|
||||
//
|
||||
// ToString()
|
||||
// Returns a binary string with the contents of the BitVector
|
||||
//
|
||||
// """ -------------------------------------------------------
|
||||
std::string SparseBitVect::ToString() const {
|
||||
// This Function replaces the older version (version 16) of writing the onbits to
|
||||
// a string
|
||||
// the old version does not perform any run length encoding, it only checks to see if
|
||||
// the length of the bitvect can be short ints and writes the on bits as shorts
|
||||
// other wise the onbits are all written as ints
|
||||
|
||||
// here we do run length encoding and the version number has been bumped to 32 as well.
|
||||
// only the reader needs to take care of readinf all legacy versions
|
||||
// also in this scheme each bit number written to the string is checked to see how many
|
||||
// bytes it needs
|
||||
std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
|
||||
|
||||
unsigned int nOnBits=GetNumOnBits();
|
||||
int tVers =ci_BITVECT_VERSION*-1;
|
||||
|
||||
ss.write((const char *)&(tVers),sizeof(tVers));
|
||||
ss.write((const char *)&d_size,sizeof(d_size));
|
||||
ss.write((const char *)&nOnBits,sizeof(nOnBits));
|
||||
int prev = -1;
|
||||
unsigned int zeroes;
|
||||
for (IntSetIter i=dp_bits->begin(); i!=dp_bits->end(); i++) {
|
||||
zeroes = *i - prev -1;
|
||||
RDKit::appendPackedIntToStream(ss, zeroes);
|
||||
prev = *i;
|
||||
}
|
||||
zeroes = d_size - prev -1;
|
||||
RDKit::appendPackedIntToStream(ss, zeroes);
|
||||
|
||||
std::string res(ss.str());
|
||||
return res;
|
||||
}
|
||||
|
||||
void SparseBitVect::_InitForSize(unsigned int size){
|
||||
d_size=size;
|
||||
if(dp_bits) delete dp_bits;
|
||||
dp_bits=new IntSet;
|
||||
};
|
||||
82
Code/DataStructs/SparseBitVect.h
Executable file
82
Code/DataStructs/SparseBitVect.h
Executable file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Copyright (c) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_SPARSEBITVECTS_H__
|
||||
#define __RD_SPARSEBITVECTS_H__
|
||||
|
||||
#include "BitVect.h"
|
||||
|
||||
#include <set>
|
||||
using std::set;
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
|
||||
typedef set<int> IntSet;
|
||||
typedef IntSet::iterator IntSetIter;
|
||||
typedef IntSet::const_iterator IntSetConstIter;
|
||||
|
||||
//! a class for bit vectors that are sparsely occupied.
|
||||
/*!
|
||||
SparseBitVect objects store only their on bits, in an
|
||||
std::set.
|
||||
|
||||
They are, as you might expect, quite memory efficient for sparsely populated
|
||||
vectors but become rather a nightmare if they need to be negated.
|
||||
|
||||
*/
|
||||
class SparseBitVect : public BitVect{
|
||||
public:
|
||||
SparseBitVect() : dp_bits(0), d_size(0) {};
|
||||
//! initialize with a particular size;
|
||||
explicit SparseBitVect(unsigned int size): dp_bits(0), d_size(0) {_InitForSize(size); };
|
||||
|
||||
//! copy constructor
|
||||
SparseBitVect(const SparseBitVect& other){
|
||||
d_size=0;dp_bits = 0;
|
||||
_InitForSize(other.GetNumBits());
|
||||
IntSet *bv=other.dp_bits;
|
||||
std::copy(bv->begin(),bv->end(),std::inserter(*dp_bits,dp_bits->end()));
|
||||
}
|
||||
//! construct from a string pickle
|
||||
SparseBitVect(const std::string);
|
||||
//! construct from a text pickle
|
||||
SparseBitVect(const char *data,const unsigned int dataLen);
|
||||
|
||||
SparseBitVect& operator=(const SparseBitVect&);
|
||||
~SparseBitVect(){ delete dp_bits; };
|
||||
|
||||
bool operator[](const unsigned int which) const;
|
||||
SparseBitVect operator| (const SparseBitVect&) const;
|
||||
SparseBitVect operator& (const SparseBitVect&) const;
|
||||
SparseBitVect operator^ (const SparseBitVect&) const;
|
||||
SparseBitVect operator~ () const;
|
||||
|
||||
//! returns a (const) pointer to our raw storage
|
||||
const IntSet *GetBitSet() const { return dp_bits;}
|
||||
|
||||
const unsigned int GetNumBits() const { return d_size; };
|
||||
bool SetBit(const unsigned int which);
|
||||
bool SetBit(const IntSetIter which);
|
||||
bool UnSetBit(const unsigned int which);
|
||||
bool GetBit (const unsigned int which) const;
|
||||
bool GetBit(const IntVectIter which) const;
|
||||
bool GetBit(const IntSetIter which) const;
|
||||
|
||||
const unsigned int GetNumOnBits() const { return dp_bits->size(); };
|
||||
const unsigned int GetNumOffBits() const { return d_size - dp_bits->size(); };
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
void GetOnBits (IntVect& v) const;
|
||||
void ClearBits() { dp_bits->clear(); };
|
||||
IntSet *dp_bits; //!< our raw data, exposed for the sake of efficiency
|
||||
private:
|
||||
unsigned int d_size;
|
||||
void _InitForSize(const unsigned int size);
|
||||
};
|
||||
|
||||
#endif
|
||||
217
Code/DataStructs/Utils.cpp
Executable file
217
Code/DataStructs/Utils.cpp
Executable file
@@ -0,0 +1,217 @@
|
||||
// $Id: Utils.cpp 5061 2006-03-08 00:36:29Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2002-2006 greg Landrum, Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include "BitVects.h"
|
||||
#include "BitVectUtils.h"
|
||||
#include <RDGeneral/Invariant.h>
|
||||
#include <iostream>
|
||||
|
||||
//! Convert a SparseBitVector to an ExplicitBitVector
|
||||
ExplicitBitVect *convertToExplicit(const SparseBitVect *sbv) {
|
||||
unsigned int sl = sbv->GetNumBits();
|
||||
ExplicitBitVect *ebv = new ExplicitBitVect(sl);
|
||||
const IntSet *bset = sbv->GetBitSet();
|
||||
for (IntSetConstIter it = bset->begin(); it != bset->end(); it++) {
|
||||
ebv->SetBit(*it);
|
||||
}
|
||||
return ebv;
|
||||
}
|
||||
|
||||
void a2b(const char *,char *);
|
||||
|
||||
//! \brief Construct a BitVect from the ASCII representation of a
|
||||
//! Daylight fingerprint string
|
||||
template <typename T>
|
||||
void FromDaylightString(T &sbv,std::string s)
|
||||
{
|
||||
sbv.ClearBits();
|
||||
int length = s.length();
|
||||
int nBits;
|
||||
|
||||
if(s[length-1] == '\n') length -= 1;
|
||||
|
||||
// 4 bytes in the ascii correspond to 3 bytes in the binary
|
||||
// plus there's one extra ascii byte for the pad marker
|
||||
length -= 1;
|
||||
nBits = (3*length/4)*8;
|
||||
|
||||
switch(s[length]){
|
||||
case '1': nBits -= 16;break;
|
||||
case '2': nBits -= 8;break;
|
||||
case '3': break;
|
||||
default: throw "ValueError bad daylight fingerprint string";
|
||||
}
|
||||
int i=0,nBitsDone=0;
|
||||
while(i < length){
|
||||
char bytes[3];
|
||||
a2b(s.c_str()+i,bytes);
|
||||
for(int j=0;j<3 && nBitsDone < nBits;j++){
|
||||
unsigned char query=0x80;
|
||||
for(int k=0;k<8;k++) {
|
||||
if(bytes[j]&query){
|
||||
sbv.SetBit(nBitsDone);
|
||||
}
|
||||
query >>= 1;
|
||||
nBitsDone++;
|
||||
}
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
template void FromDaylightString(SparseBitVect &sbv,std::string s);
|
||||
template void FromDaylightString(ExplicitBitVect &sbv,std::string s);
|
||||
|
||||
//! \brief Construct a BitVect from the ASCII representation of a
|
||||
//! BitString
|
||||
template <typename T>
|
||||
void FromBitString(T &sbv,const std::string &s)
|
||||
{
|
||||
PRECONDITION(s.length()<=sbv.GetNumBits(),"bad bitvect length");
|
||||
sbv.ClearBits();
|
||||
for(unsigned int i=0;i<sbv.GetNumBits();++i){
|
||||
if(s[i]=='1') sbv.SetBit(i);
|
||||
}
|
||||
}
|
||||
|
||||
template void FromBitString(SparseBitVect &sbv,const std::string &s);
|
||||
template void FromBitString(ExplicitBitVect &sbv,const std::string &s);
|
||||
|
||||
|
||||
//! converts 4 ascii bytes at a4 to 3 binary bytes
|
||||
/*!
|
||||
THE FOLLOWING IS TAKEN FROM THE DAYLIGHT CONTRIB PROGRAM
|
||||
ascii2bits.c
|
||||
*********************************************************************
|
||||
*** a2b - converts 4 ascii bytes at a4 to 3 binary
|
||||
*** bytes at b3.
|
||||
***
|
||||
*** ASCII: |=======+=======+=======+=======| etc.
|
||||
*** ^
|
||||
*** becomes... 3 <-> 4
|
||||
*** v
|
||||
*** BINARY: |=====+=====+=====+=====| etc.
|
||||
********************************************************************
|
||||
*/
|
||||
void a2b(const char *a4, char *b3)
|
||||
{
|
||||
int i;
|
||||
char byte=0x00, b=0x00;
|
||||
|
||||
/*********************************************
|
||||
*** Use the Daylight mapping to convert each
|
||||
*** ascii char to its 6-bit code.
|
||||
***
|
||||
*** a4: |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (printable)
|
||||
*** |=======+=======+=======+=======|
|
||||
*** becomes...
|
||||
*** a4: |00xxxxxx00xxxxxx00xxxxxx00xxxxxx
|
||||
*** |=======+=======+=======+=======|
|
||||
*********************************************/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
switch (a4[i]) {
|
||||
case '.': byte = 0x00; break; /* 00 = __000000 */
|
||||
case '+': byte = 0x01; break; /* 01 = __000001 */
|
||||
case '0': byte = 0x02; break; /* 02 = __000010 */
|
||||
case '1': byte = 0x03; break; /* 03 = __000011 */
|
||||
case '2': byte = 0x04; break; /* 04 = __000100 */
|
||||
case '3': byte = 0x05; break; /* 05 = __000101 */
|
||||
case '4': byte = 0x06; break; /* 06 = __000110 */
|
||||
case '5': byte = 0x07; break; /* 07 = __000111 */
|
||||
case '6': byte = 0x08; break; /* 08 = __001000 */
|
||||
case '7': byte = 0x09; break; /* 09 = __001001 */
|
||||
case '8': byte = 0x0a; break; /* 10 = __001010 */
|
||||
case '9': byte = 0x0b; break; /* 11 = __001011 */
|
||||
case 'A': byte = 0x0c; break; /* 12 = __001100 */
|
||||
case 'B': byte = 0x0d; break; /* 13 = __001101 */
|
||||
case 'C': byte = 0x0e; break; /* 14 = __001110 */
|
||||
case 'D': byte = 0x0f; break; /* 15 = __001111 */
|
||||
case 'E': byte = 0x10; break; /* 16 = __010000 */
|
||||
case 'F': byte = 0x11; break; /* 17 = __010001 */
|
||||
case 'G': byte = 0x12; break; /* 18 = __010010 */
|
||||
case 'H': byte = 0x13; break; /* 19 = __010011 */
|
||||
case 'I': byte = 0x14; break; /* 20 = __010100 */
|
||||
case 'J': byte = 0x15; break; /* 21 = __010101 */
|
||||
case 'K': byte = 0x16; break; /* 22 = __010110 */
|
||||
case 'L': byte = 0x17; break; /* 23 = __010111 */
|
||||
case 'M': byte = 0x18; break; /* 24 = __011000 */
|
||||
case 'N': byte = 0x19; break; /* 25 = __011001 */
|
||||
case 'O': byte = 0x1a; break; /* 26 = __011010 */
|
||||
case 'P': byte = 0x1b; break; /* 27 = __011011 */
|
||||
case 'Q': byte = 0x1c; break; /* 28 = __011100 */
|
||||
case 'R': byte = 0x1d; break; /* 29 = __011101 */
|
||||
case 'S': byte = 0x1e; break; /* 30 = __011110 */
|
||||
case 'T': byte = 0x1f; break; /* 31 = __011111 */
|
||||
case 'U': byte = 0x20; break; /* 32 = __100000 */
|
||||
case 'V': byte = 0x21; break; /* 33 = __100001 */
|
||||
case 'W': byte = 0x22; break; /* 34 = __100010 */
|
||||
case 'X': byte = 0x23; break; /* 35 = __100011 */
|
||||
case 'Y': byte = 0x24; break; /* 36 = __100100 */
|
||||
case 'Z': byte = 0x25; break; /* 37 = __100101 */
|
||||
case 'a': byte = 0x26; break; /* 38 = __100110 */
|
||||
case 'b': byte = 0x27; break; /* 39 = __100111 */
|
||||
case 'c': byte = 0x28; break; /* 40 = __101000 */
|
||||
case 'd': byte = 0x29; break; /* 41 = __101001 */
|
||||
case 'e': byte = 0x2a; break; /* 42 = __101010 */
|
||||
case 'f': byte = 0x2b; break; /* 43 = __101011 */
|
||||
case 'g': byte = 0x2c; break; /* 44 = __101100 */
|
||||
case 'h': byte = 0x2d; break; /* 45 = __101101 */
|
||||
case 'i': byte = 0x2e; break; /* 46 = __101110 */
|
||||
case 'j': byte = 0x2f; break; /* 47 = __101111 */
|
||||
case 'k': byte = 0x30; break; /* 48 = __110000 */
|
||||
case 'l': byte = 0x31; break; /* 49 = __110001 */
|
||||
case 'm': byte = 0x32; break; /* 50 = __110010 */
|
||||
case 'n': byte = 0x33; break; /* 51 = __110011 */
|
||||
case 'o': byte = 0x34; break; /* 52 = __110100 */
|
||||
case 'p': byte = 0x35; break; /* 53 = __110101 */
|
||||
case 'q': byte = 0x36; break; /* 54 = __110110 */
|
||||
case 'r': byte = 0x37; break; /* 55 = __110111 */
|
||||
case 's': byte = 0x38; break; /* 56 = __111000 */
|
||||
case 't': byte = 0x39; break; /* 57 = __111001 */
|
||||
case 'u': byte = 0x3a; break; /* 58 = __111010 */
|
||||
case 'v': byte = 0x3b; break; /* 59 = __111011 */
|
||||
case 'w': byte = 0x3c; break; /* 60 = __111100 */
|
||||
case 'x': byte = 0x3d; break; /* 61 = __111101 */
|
||||
case 'y': byte = 0x3e; break; /* 62 = __111110 */
|
||||
case 'z': byte = 0x3f; break; /* 63 = __111111 */
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
*** Now copy the 4x6=24 bits from a4 to b3.
|
||||
***
|
||||
*** a4: |--000000--111111--222222--333333
|
||||
*** |=======+=======+=======+=======|
|
||||
***
|
||||
*** b3: |000000111111222222333333
|
||||
*** |=====+=====+=====+=====|
|
||||
*********************************************/
|
||||
if (i == 0)
|
||||
b3[0] = (byte << 2); /*** 6 bits into 1st byte ***/
|
||||
else if (i == 1) {
|
||||
b3[0] |= ((b = byte) >> 4); /*** 2 bits into 1st byte ***/
|
||||
b3[1] = ((b = byte) << 4); /*** 4 bits into 2nd byte ***/
|
||||
} else if (i == 2) {
|
||||
b3[1] |= ((b = byte) >> 2); /*** 4 bits into 2nd byte ***/
|
||||
b3[2] = ((b = byte) << 6); /*** 2 bits into 3rd byte ***/
|
||||
} else if (i == 3)
|
||||
b3[2] |= byte; /*** 6 bits into 3rd byte ***/
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Demo Data:
|
||||
// 256 bits:
|
||||
//.b7HEa..ccc+gWEIr89.8lV8gOF3aXFFR.+Ps.mZ6lg.2
|
||||
//
|
||||
// 00000010 01110010 01010011 01000010 01100000
|
||||
// 00000000 10100010 10001010 00000001 10110010
|
||||
// 00100100 00010100 11011100 10100010 11000000
|
||||
// 00101011 00011000 01001010 10110001 10100100
|
||||
// 01000101 10011010 00110100 01010001 01110100
|
||||
// 00000000 01011011 11100000 00001100 10100101
|
||||
// 00100011 00011011
|
||||
|
||||
40
Code/DataStructs/Wrap/DataStructs.cpp
Executable file
40
Code/DataStructs/Wrap/DataStructs.cpp
Executable file
@@ -0,0 +1,40 @@
|
||||
// $Id: DataStructs.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2001-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <RDBoost/Wrap.h>
|
||||
#include "DataStructs.h"
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
void wrap_SBV();
|
||||
void wrap_EBV();
|
||||
void wrap_BitOps();
|
||||
void wrap_Utils();
|
||||
void wrap_discreteValVect();
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(cDataStructs)
|
||||
{
|
||||
python::scope().attr("__doc__") =
|
||||
"Module containing an assortment of functionality for basic data structures.\n"
|
||||
"\n"
|
||||
"At the moment the data structures defined are:\n"
|
||||
" Bit Vector classes (for storing signatures, fingerprints and the like:\n"
|
||||
" - ExplicitBitVect: class for relatively small (10s of thousands of bits) or\n"
|
||||
" dense bit vectors.\n"
|
||||
" - SparseBitVect: class for large, sparse bit vectors\n"
|
||||
;
|
||||
|
||||
python::register_exception_translator<IndexErrorException>(&translate_index_error);
|
||||
python::register_exception_translator<ValueErrorException>(&translate_value_error);
|
||||
wrap_Utils();
|
||||
wrap_SBV();
|
||||
wrap_EBV();
|
||||
wrap_BitOps();
|
||||
wrap_discreteValVect();
|
||||
}
|
||||
6
Code/DataStructs/Wrap/DataStructs.h
Executable file
6
Code/DataStructs/Wrap/DataStructs.h
Executable file
@@ -0,0 +1,6 @@
|
||||
//
|
||||
// Copyright (c) 2001-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
|
||||
49
Code/DataStructs/Wrap/DiscreteValueVect.cpp
Normal file
49
Code/DataStructs/Wrap/DiscreteValueVect.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// $Id: DiscreteValueVect.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2005-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#include <RDGeneral/types.h>
|
||||
#include<RDGeneral/Invariant.h>
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
#include <DataStructs/DiscreteValueVect.h>
|
||||
|
||||
std::string disValVectDoc = "A container class for storing discrete integer values\n";
|
||||
|
||||
struct discreteValVec_wrapper {
|
||||
static void wrap() {
|
||||
python::enum_<DiscreteValueVect::DiscreteValueType>("DiscreteValueType")
|
||||
.value("ONEBITVALUE", DiscreteValueVect::ONEBITVALUE)
|
||||
.value("TWOBITVALUE", DiscreteValueVect::TWOBITVALUE)
|
||||
.value("FOURBITVALUE", DiscreteValueVect::FOURBITVALUE)
|
||||
.value("EIGHTBITVALUE", DiscreteValueVect::EIGHTBITVALUE)
|
||||
.value("SIXTEENBITVALUE", DiscreteValueVect::SIXTEENBITVALUE)
|
||||
;
|
||||
|
||||
python::class_<DiscreteValueVect>("DiscreteValueVect",
|
||||
disValVectDoc.c_str(),
|
||||
python::init<DiscreteValueVect::DiscreteValueType, unsigned int>("Constructor"))
|
||||
.def("__len__", &DiscreteValueVect::getLength,
|
||||
"Get the number of entries in the vector")
|
||||
.def("__setitem__", &DiscreteValueVect::setVal,
|
||||
"Set the value at a specified location")
|
||||
.def("__getitem__", &DiscreteValueVect::getVal,
|
||||
"Get the value at a specified location")
|
||||
.def("GetValueType", &DiscreteValueVect::getValueType,
|
||||
"Get the type of value stored in the vector")
|
||||
.def("GetTotalVal", &DiscreteValueVect::getTotalVal,
|
||||
"Get the sum of the values in the vector, basically L1 norm")
|
||||
;
|
||||
|
||||
python::def("ComputeL1Norm", computeL1Norm,
|
||||
"Compute the distance between two discrete vector values\n");
|
||||
}
|
||||
};
|
||||
|
||||
void wrap_discreteValVect() {
|
||||
discreteValVec_wrapper::wrap();
|
||||
}
|
||||
|
||||
10
Code/DataStructs/Wrap/Makefile
Executable file
10
Code/DataStructs/Wrap/Makefile
Executable file
@@ -0,0 +1,10 @@
|
||||
|
||||
SOURCES=DataStructs.cpp DataStructs.h wrap_BitOps.cpp wrap_ExplicitBV.cpp wrap_helpers.h \
|
||||
wrap_SparseBV.cpp wrap_Utils.cpp
|
||||
|
||||
$(RDBASE)/Python/DataStructs/cDataStructs.so: $(SOURCES) ../libDataStructs.a
|
||||
python setup.py install --install-lib=$(RDBASE)/Python
|
||||
|
||||
clean:
|
||||
if test -e $(RDBASE)/Python/DataStructs/cDataStructs.so; then rm $(RDBASE)/Python/DataStructs/cDataStructs.so; fi
|
||||
if test -e build; then rm -rf build; fi
|
||||
116
Code/DataStructs/Wrap/datastructs test.dsp
Executable file
116
Code/DataStructs/Wrap/datastructs test.dsp
Executable file
@@ -0,0 +1,116 @@
|
||||
# Microsoft Developer Studio Project File - Name="datastructs test" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=datastructs test - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "datastructs test.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "datastructs test.mak" CFG="datastructs test - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "datastructs test - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "datastructs test - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "datastructs test - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"test.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "datastructs test - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "datastructs_test___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "datastructs_test___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "datastructs_test___Win32_Debug"
|
||||
# PROP Intermediate_Dir "datastructs_test___Win32_Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"test.exe" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "datastructs test - Win32 Release"
|
||||
# Name "datastructs test - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\test.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Group "external"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
150
Code/DataStructs/Wrap/datastructs test.vcproj
Executable file
150
Code/DataStructs/Wrap/datastructs test.vcproj
Executable file
@@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="datastructs test"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\datastructs_test___Win32_Debug"
|
||||
IntermediateDirectory=".\datastructs_test___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="5"
|
||||
PrecompiledHeaderFile=".\datastructs_test___Win32_Debug/datastructs test.pch"
|
||||
AssemblerListingLocation=".\datastructs_test___Win32_Debug/"
|
||||
ObjectFile=".\datastructs_test___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\datastructs_test___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="test.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\datastructs_test___Win32_Debug/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\datastructs_test___Win32_Debug/datastructs test.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/Code,$(RDBASE)/Code/GraphMol/,$(RDBASE)/external/boost_1_30_0"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/datastructs test.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="./testExecs/main.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
ProgramDatabaseFile=".\Release/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/datastructs test.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\BitVects\main.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
180
Code/DataStructs/Wrap/datastructs.dsp
Executable file
180
Code/DataStructs/Wrap/datastructs.dsp
Executable file
@@ -0,0 +1,180 @@
|
||||
# Microsoft Developer Studio Project File - Name="datastructs" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=datastructs - Win32 DebugPython
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "datastructs.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "datastructs.mak" CFG="datastructs - Win32 DebugPython"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "datastructs - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "datastructs - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "datastructs - Win32 DebugPython" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName "datastructs"
|
||||
# PROP Scc_LocalPath "."
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "datastructs - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "$(PYTHONHOME)\include" /I "$(RDBASE)/External/$(BOOSTBASE)" /I "$(RDBASE)/Code" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /Zm400 /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python.lib /nologo /subsystem:windows /dll /machine:I386 /out:"Release/cDataStructs.dll" /libpath:"$(PYTHONHOME)\libs" /libpath:"$(RDBASE)/External/$(BOOSTBASE)/libs/python/build/bin/boost_python.dll/msvc/release/runtime-link-dynamic/"
|
||||
# SUBTRACT LINK32 /verbose /pdb:none /incremental:yes
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=copy dll
|
||||
PostBuild_Cmds=copy Release\cDataStructs.dll $(RDBASE)\Python\Datastructs
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "datastructs - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /GR /GX /Zi /Od /I "$(PYTHONHOME)\include" /I "$(RDBASE)/External/$(BOOSTBASE)" /I "$(RDBASE)/Code" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /GZ /Zm400 /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python_debug.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug/cDataStructs.dll" /pdbtype:sept /libpath:"$(PYTHONHOME)\libs" /libpath:"$(RDBASE)/External/$(BOOSTBASE)/libs/python/build/bin/boost_python.dll/msvc/debug/runtime-link-dynamic/"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=copy dll
|
||||
PostBuild_Cmds=copy Debug\cDataStructs.dll $(RDBASE)\Python\Datastructs
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "datastructs - Win32 DebugPython"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "datastructs___Win32_DebugPython"
|
||||
# PROP BASE Intermediate_Dir "datastructs___Win32_DebugPython"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "datastructs___Win32_DebugPython"
|
||||
# PROP Intermediate_Dir "datastructs___Win32_DebugPython"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /GR /GX /Zi /Od /I "$(RDBASE)\external\boost_1_24_0" /I "$(PYTHONHOME)\include" /I "$(RDBASE)/External/$(BOOSTBASE)" /I "$(RDBASE)/Code" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "TEST_EXPORTS" /D "BOOST_DEBUG_PYTHON" /FD /GZ /c
|
||||
# SUBTRACT CPP /Fr /YX
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"DebugPython/cDataStructs_d.dll" /pdbtype:sept /libpath:"c:\python20\activepython-2.0.0-202\src\core\pcbuild" /libpath:"$(PYTHONHOME)\libs" /libpath:"$(BOOSTBASE)\libs\python\build\bin-stage"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=copy dll
|
||||
PostBuild_Cmds=copy DebugPython\cDataStructs_d.dll $(RDBASE)\Python\Datastructs
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "datastructs - Win32 Release"
|
||||
# Name "datastructs - Win32 Debug"
|
||||
# Name "datastructs - Win32 DebugPython"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DataStructs.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RDBoost\Wrap.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wrap_BitOps.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wrap_ExplicitBV.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wrap_SparseBV.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\wrap_Utils.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitUtils.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bitvects.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
397
Code/DataStructs/Wrap/datastructs.vcproj
Executable file
397
Code/DataStructs/Wrap/datastructs.vcproj
Executable file
@@ -0,0 +1,397 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="wrapDatastructs"
|
||||
SccProjectName="datastructs"
|
||||
SccLocalPath=".">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\Debug"
|
||||
IntermediateDirectory=".\Debug"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(PYTHONHOME)\include,$(RDBASE)\External\Boost\include\$(BOOSTBASE),$(RDBASE)\Code"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Debug/datastructs.pch"
|
||||
AssemblerListingLocation=".\Debug/"
|
||||
ObjectFile=".\Debug/"
|
||||
ProgramDataBaseFileName=".\Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python-vc71-mt-gd-$(BOOSTVERSION).lib boost_log-vc71-mt-gd-$(BOOSTVERSION).lib "
|
||||
OutputFile="Debug/cDataStructs.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)/External/boost/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\Debug/cDataStructs.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Debug/cDataStructs.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Debug/datastructs.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Debug\cDataStructs.dll "$(RDBASE)"\Python\Datastructs"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="DebugPython|Win32"
|
||||
OutputDirectory=".\datastructs___Win32_DebugPython"
|
||||
IntermediateDirectory=".\datastructs___Win32_DebugPython"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(PYTHONHOME)\include,$(RDBASE)\External\Boost\include\$(BOOSTBASE),$(RDBASE)\Code"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\datastructs___Win32_DebugPython/datastructs.pch"
|
||||
AssemblerListingLocation=".\datastructs___Win32_DebugPython/"
|
||||
ObjectFile=".\datastructs___Win32_DebugPython/"
|
||||
ProgramDataBaseFileName=".\datastructs___Win32_DebugPython/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="3"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python.lib"
|
||||
OutputFile="DebugPython/cDataStructs_d.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)/External/boost/lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\datastructs___Win32_DebugPython/cDataStructs_d.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\datastructs___Win32_DebugPython/cDataStructs_d.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\datastructs___Win32_DebugPython/datastructs.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy DebugPython\cDataStructs_d.dll "$(RDBASE)"\Python\Datastructs"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\Release"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="2"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/Zm400 "
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(PYTHONHOME)\include,$(RDBASE)\External\Boost\include\$(BOOSTBASE),$(RDBASE)\Code"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/datastructs.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
IgnoreImportLibrary="TRUE"
|
||||
AdditionalDependencies="odbc32.lib odbccp32.lib $(PYTHONVERS).lib boost_python-vc71-mt-$(BOOSTVERSION).lib boost_log-vc71-mt-$(BOOSTVERSION).lib "
|
||||
OutputFile="Release/cDataStructs.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(PYTHONHOME)\libs,$(RDBASE)/External/boost/lib"
|
||||
ProgramDatabaseFile=".\Release/cDataStructs.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary=".\Release/cDataStructs.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
MkTypLibCompatible="TRUE"
|
||||
SuppressStartupBanner="TRUE"
|
||||
TargetEnvironment="1"
|
||||
TypeLibraryName=".\Release/datastructs.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
Description="copy dll"
|
||||
CommandLine="copy Release\cDataStructs.dll "$(RDBASE)"\Python\Datastructs"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath="DataStructs.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugPython|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;$(NoInherit)"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DiscreteValueVect.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="wrap_BitOps.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugPython|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;$(NoInherit)"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="wrap_ExplicitBV.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugPython|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;$(NoInherit)"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="wrap_SparseBV.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugPython|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;$(NoInherit)"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="wrap_Utils.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="DebugPython|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;TEST_EXPORTS;BOOST_DEBUG_PYTHON;$(NoInherit)"
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;$(NoInherit)"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath="BitUtils.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="bitvects.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
26
Code/DataStructs/Wrap/setup.py
Executable file
26
Code/DataStructs/Wrap/setup.py
Executable file
@@ -0,0 +1,26 @@
|
||||
# Run this with:
|
||||
# python setup.py install --install-lib=$RDBASE/Python
|
||||
from RDBuild import *
|
||||
from distutils.core import setup,Extension
|
||||
|
||||
|
||||
libDirs += [
|
||||
os.path.join(RDConfig.RDBaseDir,'Code','DataStructs'),
|
||||
]
|
||||
|
||||
libraries += ["DataStructs","RDBoost",'RDGeneral']
|
||||
|
||||
setup(name="DataStructs.cDataStructs",version="2.0",
|
||||
ext_modules=[Extension("DataStructs.cDataStructs",
|
||||
["DataStructs.cpp",
|
||||
"DiscreteValueVect.cpp",
|
||||
"wrap_SparseBV.cpp",
|
||||
"wrap_ExplicitBV.cpp",
|
||||
'wrap_BitOps.cpp',
|
||||
'wrap_Utils.cpp',
|
||||
],
|
||||
library_dirs=libDirs,
|
||||
libraries=libraries,
|
||||
extra_link_args=linkArgs,
|
||||
extra_compile_args=compileArgs)])
|
||||
|
||||
94
Code/DataStructs/Wrap/testBV.py
Executable file
94
Code/DataStructs/Wrap/testBV.py
Executable file
@@ -0,0 +1,94 @@
|
||||
import DataStructs
|
||||
import RDConfig
|
||||
import unittest
|
||||
import cPickle as pickle
|
||||
import random
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
def setUp(self) :
|
||||
pass
|
||||
|
||||
def test0FromList(self) :
|
||||
bv1 = DataStructs.SparseBitVect(1000)
|
||||
bv2 = DataStructs.SparseBitVect(1000)
|
||||
obits = range(0,1000, 3)
|
||||
|
||||
for bit in obits :
|
||||
bv1.SetBit(bit)
|
||||
|
||||
bv2.SetBitsFromList(obits)
|
||||
|
||||
for i in range(1000) :
|
||||
assert bv1.GetBit(i) == bv2.GetBit(i)
|
||||
|
||||
|
||||
bv1 = DataStructs.ExplicitBitVect(1000)
|
||||
bv2 = DataStructs.ExplicitBitVect(1000)
|
||||
obits = range(0,1000, 3)
|
||||
|
||||
for bit in obits :
|
||||
bv1.SetBit(bit)
|
||||
|
||||
bv2.SetBitsFromList(obits)
|
||||
|
||||
for i in range(1000) :
|
||||
assert bv1.GetBit(i) == bv2.GetBit(i)
|
||||
|
||||
def test1SparsePickle(self) :
|
||||
nbits = 10000
|
||||
bv1 = DataStructs.SparseBitVect(nbits)
|
||||
for i in range(1000) :
|
||||
x = random.randrange(0,nbits)
|
||||
bv1.SetBit(x)
|
||||
|
||||
pkl = pickle.dumps(bv1,1)
|
||||
bv2 = pickle.loads(pkl)
|
||||
for i in range(nbits) :
|
||||
assert bv1[i] == bv2[i]
|
||||
|
||||
def test2ExplicitPickle(self):
|
||||
nbits = 10000
|
||||
bv1 = DataStructs.ExplicitBitVect(nbits)
|
||||
for i in range(1000) :
|
||||
x = random.randrange(0,nbits)
|
||||
bv1.SetBit(x)
|
||||
|
||||
pkl = pickle.dumps(bv1,1)
|
||||
bv2 = pickle.loads(pkl)
|
||||
for i in range(nbits) :
|
||||
assert bv1[i] == bv2[i]
|
||||
|
||||
def test3Bounds(self) :
|
||||
nbits = 10
|
||||
bv1 = DataStructs.ExplicitBitVect(nbits)
|
||||
bv1[0]
|
||||
try:
|
||||
bv1[11]
|
||||
except IndexError:
|
||||
ok = 1
|
||||
except:
|
||||
ok = -1
|
||||
else:
|
||||
ok = 0
|
||||
assert ok>0,ok
|
||||
|
||||
def test4OnBitsInCommon(self) :
|
||||
sz=100
|
||||
bv1 = DataStructs.ExplicitBitVect(sz)
|
||||
bv2 = DataStructs.ExplicitBitVect(sz)
|
||||
for i in range(0,sz,2):
|
||||
bv1.SetBit(i)
|
||||
if i < 3*sz/4:
|
||||
bv2.SetBit(i)
|
||||
self.failUnless(DataStructs.AllProbeBitsMatch(bv1,bv1.ToBinary()))
|
||||
self.failUnless(DataStructs.AllProbeBitsMatch(bv2,bv1.ToBinary()))
|
||||
self.failIf(DataStructs.AllProbeBitsMatch(bv1,bv2.ToBinary()))
|
||||
self.failUnless(DataStructs.AllProbeBitsMatch(bv2,bv2.ToBinary()))
|
||||
|
||||
def test5FromBitString(self):
|
||||
s1 = '1010'
|
||||
bv = DataStructs.CreateFromBitString(s1)
|
||||
self.failUnless(len(bv)==4)
|
||||
self.failUnless(list(bv.GetOnBits())==[0,2])
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
120
Code/DataStructs/Wrap/testDiscreteValueVect.py
Normal file
120
Code/DataStructs/Wrap/testDiscreteValueVect.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import RDConfig
|
||||
import os,sys
|
||||
import unittest
|
||||
import DataStructs as ds
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
def setUp(self) :
|
||||
pass
|
||||
|
||||
def test1Discrete(self):
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.ONEBITVALUE, 30)
|
||||
for i in range(15):
|
||||
v1[2*i] = 1;
|
||||
|
||||
self.failUnless(len(v1) == 30)
|
||||
self.failUnless(v1.GetTotalVal() == 15)
|
||||
|
||||
for i in range(len(v1)):
|
||||
self.failUnless(v1[i] == (i+1)%2)
|
||||
|
||||
self.failUnlessRaises(ValueError, lambda : v1.__setitem__(5, 2))
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.TWOBITVALUE, 30)
|
||||
for i in range(len(v1)):
|
||||
v1[i] = i%4;
|
||||
|
||||
self.failUnless(len(v1) == 30)
|
||||
for i in range(len(v1)):
|
||||
self.failUnless(v1[i] == i%4)
|
||||
|
||||
self.failUnlessRaises(ValueError, lambda : v1.__setitem__(10, 6))
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.FOURBITVALUE, 30)
|
||||
for i in range(len(v1)):
|
||||
v1[i] = i%16;
|
||||
|
||||
self.failUnless(len(v1) == 30)
|
||||
self.failUnless(v1.GetTotalVal() == 211)
|
||||
for i in range(len(v1)):
|
||||
self.failUnless(v1[i] == i%16)
|
||||
|
||||
self.failUnlessRaises(ValueError, lambda : v1.__setitem__(10, 16))
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.EIGHTBITVALUE, 32)
|
||||
for i in range(len(v1)):
|
||||
v1[i] = i%256;
|
||||
|
||||
self.failUnless(len(v1) == 32)
|
||||
self.failUnless(v1.GetTotalVal() == 496)
|
||||
for i in range(len(v1)):
|
||||
self.failUnless(v1[i] == i%256)
|
||||
|
||||
self.failUnlessRaises(ValueError, lambda : v1.__setitem__(10, 256))
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.SIXTEENBITVALUE, 300)
|
||||
for i in range(len(v1)):
|
||||
v1[i] = i%300;
|
||||
|
||||
self.failUnless(len(v1) == 300)
|
||||
self.failUnless(v1.GetTotalVal() == 44850)
|
||||
self.failUnlessRaises(ValueError, lambda : v1.__setitem__(10, 65536))
|
||||
|
||||
def test2VectDistances(self):
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.ONEBITVALUE, 30)
|
||||
v2 = ds.DiscreteValueVect(ds.DiscreteValueType.ONEBITVALUE, 30)
|
||||
for i in range(15):
|
||||
v1[2*i] = 1
|
||||
v2[2*i] = 1
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 0)
|
||||
for i in range(30):
|
||||
if (i%3 == 0):
|
||||
v2[i] = 1
|
||||
else:
|
||||
v2[i] = 0
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 15)
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.TWOBITVALUE, 30)
|
||||
v2 = ds.DiscreteValueVect(ds.DiscreteValueType.TWOBITVALUE, 30)
|
||||
|
||||
for i in range(30):
|
||||
v1[i] = i%4
|
||||
v2[i] = (i+1)%4
|
||||
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 44)
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.FOURBITVALUE, 16)
|
||||
v2 = ds.DiscreteValueVect(ds.DiscreteValueType.FOURBITVALUE, 16)
|
||||
for i in range(16):
|
||||
v1[i] = i%16
|
||||
v2[i] = i%5
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 90)
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.EIGHTBITVALUE, 5)
|
||||
v2 = ds.DiscreteValueVect(ds.DiscreteValueType.EIGHTBITVALUE, 5)
|
||||
v1[0] = 34
|
||||
v1[1] = 167
|
||||
v1[2] = 3
|
||||
v1[3] = 56
|
||||
v1[4] = 128
|
||||
|
||||
v2[0] = 14
|
||||
v2[1] = 67
|
||||
v2[2] = 103
|
||||
v2[3] = 6
|
||||
v2[4] = 228
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 370)
|
||||
|
||||
v1 = ds.DiscreteValueVect(ds.DiscreteValueType.SIXTEENBITVALUE, 3)
|
||||
v2 = ds.DiscreteValueVect(ds.DiscreteValueType.SIXTEENBITVALUE, 3)
|
||||
v1[0] = 2345
|
||||
v1[1] = 64578
|
||||
v1[2] = 34
|
||||
|
||||
v2[0] = 1345
|
||||
v2[1] = 54578
|
||||
v2[2] = 10034
|
||||
self.failUnless(ds.ComputeL1Norm(v1, v2) == 21000)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
16
Code/DataStructs/Wrap/test_list.py
Executable file
16
Code/DataStructs/Wrap/test_list.py
Executable file
@@ -0,0 +1,16 @@
|
||||
|
||||
tests=[
|
||||
("python","testBV.py",{}),
|
||||
("python","testDiscreteValueVect.py",{}),
|
||||
]
|
||||
|
||||
|
||||
|
||||
longTests=[]
|
||||
if __name__=='__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
sys.exit(len(failed))
|
||||
|
||||
|
||||
201
Code/DataStructs/Wrap/wrap_BitOps.cpp
Executable file
201
Code/DataStructs/Wrap/wrap_BitOps.cpp
Executable file
@@ -0,0 +1,201 @@
|
||||
// $Id: wrap_BitOps.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <boost/python.hpp>
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <DataStructs/BitOps.h>
|
||||
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
// sometimes I <heart> C++ syntax:
|
||||
// the following piece of grossness is, apparently, how
|
||||
// you cast a pointer to a function that takes default
|
||||
// arguments. If you leave out the "=2" bit, you don't
|
||||
// get the default arg values.
|
||||
//SBV *(*ff1)(const SBV&,int=2) = FoldFingerprint;
|
||||
// this is fi xfor VC++ which doesn't seem to like the "=2" passed in above
|
||||
SBV *ff1(const SBV &bv1, int factor=2) {
|
||||
return FoldFingerprint(bv1,factor);
|
||||
}
|
||||
|
||||
//ff1 = &FoldFingerprint(const SBV&, int=2);
|
||||
//EBV *(*ff2)(const EBV&,int) = FoldFingerprint;
|
||||
// same fix as above for VC 7.1
|
||||
EBV *ff2(const EBV &ev1, int factor=2) {
|
||||
return FoldFingerprint(ev1,factor);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
double SimilarityWrapper(const T &bv1,const std::string &pkl,
|
||||
const double (*metric)(const T &,const T &)){
|
||||
double res=0.0;
|
||||
T bv2(pkl);
|
||||
if(bv1.GetNumBits()>bv2.GetNumBits()){
|
||||
T *bv1tmp = FoldFingerprint(bv1,bv1.GetNumBits()/bv2.GetNumBits());
|
||||
res = metric(*bv1tmp,bv2);
|
||||
delete bv1tmp;
|
||||
} else if(bv2.GetNumBits()>bv1.GetNumBits()){
|
||||
T *bv2tmp = FoldFingerprint(bv2,bv2.GetNumBits()/bv1.GetNumBits());
|
||||
res = metric(bv1,*bv2tmp);
|
||||
delete bv2tmp;
|
||||
} else {
|
||||
res = metric(bv1,bv2);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double TanimotoSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))TanimotoSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double CosineSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))CosineSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double KulczynskiSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))KulczynskiSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double DiceSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))DiceSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double SokalSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))SokalSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double McConnaugheySimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))McConnaugheySimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double AsymmetricSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))AsymmetricSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double BraunBlanquetSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))BraunBlanquetSimilarity);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
double RusselSimilarity_w(const T &bv1,const std::string &pkl){
|
||||
return SimilarityWrapper(bv1,pkl,
|
||||
(const double (*)(const T&,const T&))RusselSimilarity);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(sbv_fold_overloads, ff1, 1, 2);
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(ebv_fold_overloads, ff2, 1, 2);
|
||||
|
||||
#define DBL_DEF(_name_,_fn_,_help_) \
|
||||
python::def(_name_,(const double (*)(const SBV &,const SBV &))_fn_); \
|
||||
python::def(_name_,(const double (*)(const EBV &,const EBV &))_fn_,_help_);\
|
||||
|
||||
#define BIG_DEF(_name_,_fn_,_fn_w_,_help_) \
|
||||
python::def(_name_,(const double (*)(const SBV &,const SBV &))_fn_); \
|
||||
python::def(_name_,(const double (*)(const EBV &,const EBV &))_fn_,_help_);\
|
||||
python::def(_name_,(double (*)(const SBV &,const std::string &))_fn_w_,_help_);\
|
||||
python::def(_name_,(double (*)(const EBV &,const std::string &))_fn_w_,_help_);\
|
||||
|
||||
struct BitOps_wrapper {
|
||||
static void wrap(){
|
||||
BIG_DEF("TanimotoSimilarity",TanimotoSimilarity,TanimotoSimilarity_w,
|
||||
"B(bv1&bv2) / (B(bv1) + B(bv2) - B(bv1&bv2))")
|
||||
BIG_DEF("CosineSimilarity",CosineSimilarity,CosineSimilarity_w,
|
||||
"B(bv1&bv2) / sqrt(B(bv1) * B(bv2))")
|
||||
BIG_DEF("KulczynskiSimilarity",KulczynskiSimilarity,KulczynskiSimilarity_w,
|
||||
"B(bv1&bv2)*(B(bv1) + B(bv2)) / (2 * B(bv1) * B(bv2))")
|
||||
BIG_DEF("DiceSimilarity",DiceSimilarity,DiceSimilarity_w,
|
||||
"2*B(bv1&bv2) / (B(bv1) + B(bv2))")
|
||||
BIG_DEF("SokalSimilarity",SokalSimilarity,SokalSimilarity_w,
|
||||
"B(bv1&bv2) / (2*B(bv1) + 2*B(bv2) - 3*B(bv1&bv2))")
|
||||
|
||||
BIG_DEF("McConnaugheySimilarity",McConnaugheySimilarity,McConnaugheySimilarity_w,
|
||||
"(B(bv1&bv2) * (B(bv1)+B(bv2)) - B(bv1)*B(bv2)) / (B(bv1) * B(bv2))")
|
||||
BIG_DEF("AsymmetricSimilarity",AsymmetricSimilarity,AsymmetricSimilarity_w,
|
||||
"B(bv1&bv2) / min(B(bv1),B(bv2))")
|
||||
BIG_DEF("BraunBlanquetSimilarity",BraunBlanquetSimilarity,BraunBlanquetSimilarity_w,
|
||||
"B(bv1&bv2) / max(B(bv1),B(bv2))")
|
||||
BIG_DEF("RusselSimilarity",RusselSimilarity,RusselSimilarity_w,
|
||||
"B(bv1&bv2) / B(bv1)")
|
||||
|
||||
DBL_DEF("OnBitSimilarity",OnBitSimilarity,
|
||||
"B(bv1&bv2) / B(bv1|bv2)")
|
||||
DBL_DEF("AllBitSimilarity",AllBitSimilarity,
|
||||
"(B(bv1) - B(bv1^bv2)) / B(bv1)")
|
||||
python::def("OnBitProjSimilarity",
|
||||
(DoubleVect (*)(const SBV&,const SBV&))OnBitProjSimilarity);
|
||||
python::def("OnBitProjSimilarity",
|
||||
(DoubleVect (*)(const EBV&,const EBV&))OnBitProjSimilarity,
|
||||
"Returns a 2-tuple: (B(bv1&bv2) / B(bv1), B(bv1&bv2) / B(bv2))");
|
||||
python::def("OffBitProjSimilarity",
|
||||
(DoubleVect (*)(const SBV&,const SBV&))OffBitProjSimilarity);
|
||||
python::def("OffBitProjSimilarity",
|
||||
(DoubleVect (*)(const EBV&,const EBV&))OffBitProjSimilarity);
|
||||
|
||||
python::def("NumBitsInCommon",
|
||||
(const int (*)(const SBV&,const SBV&))NumBitsInCommon);
|
||||
python::def("NumBitsInCommon",
|
||||
(const int (*)(const EBV&,const EBV&))NumBitsInCommon,
|
||||
"Returns the total number of bits in common between the two bit vectors\n"
|
||||
);
|
||||
python::def("OnBitsInCommon",
|
||||
(IntVect (*)(const SBV&,const SBV&))OnBitsInCommon);
|
||||
python::def("OnBitsInCommon",
|
||||
(IntVect (*)(const EBV&,const EBV&))OnBitsInCommon,
|
||||
"Returns the number of on bits in common between the two bit vectors\n"
|
||||
);
|
||||
python::def("OffBitsInCommon",
|
||||
(IntVect (*)(const SBV&,const SBV&))OffBitsInCommon);
|
||||
python::def("OffBitsInCommon",
|
||||
(IntVect (*)(const EBV&,const EBV&))OffBitsInCommon,
|
||||
"Returns the number of off bits in common between the two bit vectors\n"
|
||||
);
|
||||
|
||||
python::def("FoldFingerprint",
|
||||
ff1,
|
||||
sbv_fold_overloads(python::args("bv","foldFactor")
|
||||
)[python::return_value_policy<python::manage_new_object>()]);
|
||||
python::def("FoldFingerprint",
|
||||
ff2,
|
||||
ebv_fold_overloads(python::args("bv","foldFactor"),
|
||||
"Returns a folded version of the bit vector\n"
|
||||
)[python::return_value_policy<python::manage_new_object>()]);
|
||||
|
||||
python::def("AllProbeBitsMatch",(bool (*)(const SBV &,const std::string &))AllProbeBitsMatch);
|
||||
python::def("AllProbeBitsMatch",(bool (*)(const EBV &,const std::string &))AllProbeBitsMatch);
|
||||
|
||||
python::def("BitVectToText",
|
||||
(std::string (*)(const SBV&))BitVectToText);
|
||||
python::def("BitVectToText",
|
||||
(std::string (*)(const EBV&))BitVectToText,
|
||||
"Returns a string of zeros and ones representing the bit vector."
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void wrap_BitOps() {
|
||||
BitOps_wrapper::wrap();
|
||||
}
|
||||
|
||||
101
Code/DataStructs/Wrap/wrap_ExplicitBV.cpp
Executable file
101
Code/DataStructs/Wrap/wrap_ExplicitBV.cpp
Executable file
@@ -0,0 +1,101 @@
|
||||
// $Id: wrap_ExplicitBV.cpp 5061 2006-03-08 00:36:29Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <RDBoost/Wrap.h>
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
#include "wrap_helpers.h"
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
// allows BitVects to be pickled
|
||||
struct ebv_pickle_suite : python::pickle_suite
|
||||
{
|
||||
static python::tuple
|
||||
getinitargs(const ExplicitBitVect& self)
|
||||
{
|
||||
return python::make_tuple(self.ToString());
|
||||
};
|
||||
};
|
||||
|
||||
void SetBitsFromList(ExplicitBitVect *bv, python::object onBitList) {
|
||||
PySequenceHolder<int> bitL(onBitList);
|
||||
for (unsigned int i=0; i<bitL.size(); i++) {
|
||||
bv->SetBit(bitL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ebvClassDoc="A class to store explicit bit vectors.\n\
|
||||
\n\
|
||||
This class is most useful for situations where the size of the vector\n\
|
||||
is relatively small (tens of thousands or smaller).\n\
|
||||
\n\
|
||||
For larger vectors, use the _SparseBitVect_ class instead.\n\
|
||||
\n\
|
||||
As you would expect, _ExplicitBitVects_ support a set of binary operations\n\
|
||||
so you can do things like:\n\
|
||||
bv3 = bv1 & bv2 (bitwise and)\n\
|
||||
bv3 = bv1 | bv2 (bitwise or)\n\
|
||||
bv3 = bv1 ^ bv2 (bitwise xor)\n\
|
||||
bv3 = ~bv1 (bitwise negation)\n\
|
||||
\n\
|
||||
Bits can be set and read using either the Set/UnsetBit() and GetBit() methods\n\
|
||||
or by indexing (i.e. bv[i] = 1 or if bv[i]).\n\
|
||||
\n";
|
||||
|
||||
struct EBV_wrapper {
|
||||
static void wrap(){
|
||||
python::class_<ExplicitBitVect>("ExplicitBitVect",ebvClassDoc.c_str(),
|
||||
python::init<unsigned int>())
|
||||
.def(python::init<std::string>())
|
||||
.def("SetBit",(bool (EBV::*)(unsigned int))&EBV::SetBit,
|
||||
"Turns on a particular bit on. Returns the original state of the bit.\n")
|
||||
.def("SetBitsFromList",SetBitsFromList,
|
||||
"Turns on a set of bits. The argument should be a tuple or list of bit ids.\n")
|
||||
.def("UnSetBit",(bool (EBV::*)(unsigned int))&EBV::UnSetBit,
|
||||
"Turns on a particular bit off. Returns the original state of the bit.\n")
|
||||
.def("GetBit",(bool (EBV::*)(unsigned int) const)&EBV::GetBit,
|
||||
"Returns the value of a bit.\n")
|
||||
.def("GetNumBits",&EBV::GetNumBits,
|
||||
"Returns the number of bits in the vector (the vector's size).\n")
|
||||
.def("__len__",&EBV::GetNumBits)
|
||||
.def("GetNumOnBits",&EBV::GetNumOnBits,
|
||||
"Returns the number of on bits.\n")
|
||||
.def("GetNumOffBits",&EBV::GetNumOffBits,
|
||||
"Returns the number of off bits.\n")
|
||||
.def("__getitem__",
|
||||
(const int (*)(const EBV&,unsigned int))get_VectItem)
|
||||
.def("__setitem__",
|
||||
(const int (*)(EBV&,unsigned int,int))set_VectItem)
|
||||
.def("GetOnBits",
|
||||
(IntVect (*)(const EBV&))GetOnBits,
|
||||
"Returns a tuple containing IDs of the on bits.\n")
|
||||
.def("ToBinary",&EBV::ToString,
|
||||
"Returns a binary string representation of the vector.\n")
|
||||
.def("FromBase64",
|
||||
(void (*)(EBV &,const std::string &))InitFromBase64,
|
||||
"Initializes the vector from a base64 string (the Daylight encoding).\n")
|
||||
.def("ToBase64",
|
||||
(std::string (*)(EBV &))ToBase64,
|
||||
"Converts the vector to a base64 string (the Daylight encoding).\n")
|
||||
.def(python::self & python::self)
|
||||
.def(python::self | python::self)
|
||||
.def(python::self ^ python::self)
|
||||
.def(~python::self)
|
||||
|
||||
.def_pickle(ebv_pickle_suite())
|
||||
;
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void wrap_EBV() {
|
||||
EBV_wrapper::wrap();
|
||||
|
||||
|
||||
}
|
||||
|
||||
100
Code/DataStructs/Wrap/wrap_SparseBV.cpp
Executable file
100
Code/DataStructs/Wrap/wrap_SparseBV.cpp
Executable file
@@ -0,0 +1,100 @@
|
||||
// $Id: wrap_SparseBV.cpp 5061 2006-03-08 00:36:29Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <RDBoost/Wrap.h>
|
||||
#include <RDBoost/PySequenceHolder.h>
|
||||
|
||||
#include "wrap_helpers.h"
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
// allows BitVects to be pickled
|
||||
struct sbv_pickle_suite : python::pickle_suite
|
||||
{
|
||||
static python::tuple
|
||||
getinitargs(const SparseBitVect& self)
|
||||
{
|
||||
return python::make_tuple(self.ToString());
|
||||
};
|
||||
};
|
||||
|
||||
void SetBitsFromList(SparseBitVect *bv, python::object onBitList) {
|
||||
PySequenceHolder<int> bitL(onBitList);
|
||||
for (unsigned int i = 0; i < bitL.size(); i++) {
|
||||
bv->SetBit(bitL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
std::string sbvClassDoc="A class to store sparse bit vectors.\n\
|
||||
\n\
|
||||
This class is most useful for situations where the size of the vector\n\
|
||||
is large and relatively few bits are set\n\
|
||||
\n\
|
||||
For smaller or denser vectors, the _ExplicitBitVect_ class is much faster.\n\
|
||||
\n\
|
||||
As you would expect, _SparseBitVects_ support a set of binary operations\n\
|
||||
so you can do things like:\n\
|
||||
bv3 = bv1 & bv2 (bitwise and)\n\
|
||||
bv3 = bv1 | bv2 (bitwise or)\n\
|
||||
bv3 = bv1 ^ bv2 (bitwise xor)\n\
|
||||
bv3 = ~bv1 (bitwise negation) NOTE: this operation is likely\n\
|
||||
to be VERY slow and inefficient.\n\
|
||||
\n\
|
||||
Bits can be set and read using either the Set/UnsetBit() and GetBit() methods\n\
|
||||
or by indexing (i.e. bv[i] = 1 or if bv[i]).\n\
|
||||
\n";
|
||||
struct SBV_wrapper {
|
||||
static void wrap(){
|
||||
python::class_<SparseBitVect>("SparseBitVect",
|
||||
sbvClassDoc.c_str(),
|
||||
python::init<unsigned int>())
|
||||
.def(python::init<std::string>())
|
||||
.def("SetBit",(bool (SBV::*)(unsigned int))&SBV::SetBit,
|
||||
"Turns on a particular bit on. Returns the original state of the bit.\n")
|
||||
.def("SetBitsFromList",SetBitsFromList,
|
||||
"Turns on a set of bits. The argument should be a tuple or list of bit ids.\n")
|
||||
.def("UnSetBit",(bool (SBV::*)(unsigned int))&SBV::UnSetBit,
|
||||
"Turns on a particular bit off. Returns the original state of the bit.\n")
|
||||
.def("GetBit",(bool (SBV::*)(unsigned int) const)&SBV::GetBit,
|
||||
"Returns the value of a bit.\n")
|
||||
.def("GetNumBits",&SBV::GetNumBits,
|
||||
"Returns the number of bits in the vector (the vector's size).\n")
|
||||
.def("__len__",&SBV::GetNumBits)
|
||||
.def("GetNumOnBits",&SBV::GetNumOnBits,
|
||||
"Returns the number of on bits.\n")
|
||||
.def("GetNumOffBits",&SBV::GetNumOffBits,
|
||||
"Returns the number of off bits.\n")
|
||||
.def("__getitem__",
|
||||
(const int (*)(const SBV&,unsigned int))get_VectItem)
|
||||
.def("__setitem__",
|
||||
(const int (*)(SBV&,unsigned int,int))set_VectItem)
|
||||
.def("GetOnBits",
|
||||
(IntVect (*)(const SBV&))GetOnBits,
|
||||
"Returns a tuple containing IDs of the on bits.\n")
|
||||
.def("ToBinary",&SBV::ToString,
|
||||
"Returns a binary string representation of the vector.\n")
|
||||
.def("FromBase64",
|
||||
(void (*)(SBV &,const std::string &))InitFromBase64,
|
||||
"Initializes the vector from a base64 string (the Daylight encoding).\n")
|
||||
.def("ToBase64",
|
||||
(std::string (*)(SBV &))ToBase64,
|
||||
"Converts the vector to a base64 string (the Daylight encoding).\n")
|
||||
|
||||
.def(python::self & python::self)
|
||||
.def(python::self | python::self)
|
||||
.def(python::self ^ python::self)
|
||||
.def(~python::self)
|
||||
|
||||
.def_pickle(sbv_pickle_suite())
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
void wrap_SBV() {
|
||||
SBV_wrapper::wrap();
|
||||
}
|
||||
|
||||
42
Code/DataStructs/Wrap/wrap_Utils.cpp
Executable file
42
Code/DataStructs/Wrap/wrap_Utils.cpp
Executable file
@@ -0,0 +1,42 @@
|
||||
// $Id: wrap_Utils.cpp 5054 2006-03-06 22:39:29Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <DataStructs/BitVectUtils.h>
|
||||
#include <RDBoost/Wrap.h>
|
||||
namespace python = boost::python;
|
||||
|
||||
ExplicitBitVect *createFromBitString(const std::string &bits){
|
||||
ExplicitBitVect *res=new ExplicitBitVect(bits.length());
|
||||
FromBitString(*res,bits);
|
||||
return res;
|
||||
}
|
||||
|
||||
struct Utils_wrapper {
|
||||
static void wrap(){
|
||||
python::def("ConvertToExplicit", convertToExplicit,
|
||||
python::return_value_policy<python::manage_new_object>());
|
||||
python::def("CreateFromBitString",createFromBitString,
|
||||
python::return_value_policy<python::manage_new_object>());
|
||||
|
||||
python::def("InitFromDaylightString",
|
||||
(void (*)(SparseBitVect &,std::string))FromDaylightString);
|
||||
python::def("InitFromDaylightString",
|
||||
(void (*)(ExplicitBitVect &,std::string))FromDaylightString,
|
||||
"Fill a BitVect using an ASCII (Daylight) encoding of fingerprint.\n\
|
||||
\n\
|
||||
**Arguments**\n\
|
||||
- bv: either a _SparseBitVect_ or an _ExplicitBitVect_\n\
|
||||
- txt: a string with the Daylight encoding (this is the text that\n\
|
||||
the Daylight tools put in the FP field of a TDT)\n\
|
||||
\n");
|
||||
}
|
||||
};
|
||||
|
||||
void wrap_Utils() {
|
||||
Utils_wrapper::wrap();
|
||||
}
|
||||
|
||||
58
Code/DataStructs/Wrap/wrap_helpers.h
Executable file
58
Code/DataStructs/Wrap/wrap_helpers.h
Executable file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// Copyright (C) 2003-2006 greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_WRAPHELPERS_H__
|
||||
#define __RD_WRAPHELPERS_H__
|
||||
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <DataStructs/BitOps.h>
|
||||
#include <RDBoost/Wrap.h>
|
||||
#include <DataStructs/base64.h>
|
||||
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
template <typename T>
|
||||
void InitFromBase64(T& self,const std::string &inD)
|
||||
{
|
||||
self.InitFromText(inD.c_str(),inD.length(),true);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
std::string ToBase64(T& self)
|
||||
{
|
||||
std::string tmp;
|
||||
tmp = self.ToString();
|
||||
return Base64Encode(tmp.c_str(),tmp.length());
|
||||
};
|
||||
|
||||
// used to support __getitem__
|
||||
template <typename T>
|
||||
const int get_VectItem(const T& self,unsigned int which)
|
||||
{
|
||||
return self.GetBit(which);
|
||||
}
|
||||
|
||||
// used to support __setitem__
|
||||
template <typename T>
|
||||
const int set_VectItem(T& self, const unsigned int which, const int val)
|
||||
{
|
||||
if(val){
|
||||
return self.SetBit(which);
|
||||
} else {
|
||||
return self.UnSetBit(which);
|
||||
}
|
||||
}
|
||||
|
||||
// used to support GetOnBits()
|
||||
template <typename T>
|
||||
IntVect GetOnBits(const T& self)
|
||||
{
|
||||
IntVect res;
|
||||
self.GetOnBits(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
136
Code/DataStructs/base64.cpp
Executable file
136
Code/DataStructs/base64.cpp
Executable file
@@ -0,0 +1,136 @@
|
||||
// $Id: base64.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (c) 2002-2006 greg landrum and rational discovery llc
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include "base64.h"
|
||||
// Encoding table from RFC 2045
|
||||
//
|
||||
// Value Encoding Value Encoding Value Encoding Value Encoding
|
||||
// 0 A 17 R 34 i 51 z
|
||||
// 1 B 18 S 35 j 52 0
|
||||
// 2 C 19 T 36 k 53 1
|
||||
// 3 D 20 U 37 l 54 2
|
||||
// 4 E 21 V 38 m 55 3
|
||||
// 5 F 22 W 39 n 56 4
|
||||
// 6 G 23 X 40 o 57 5
|
||||
// 7 H 24 Y 41 p 58 6
|
||||
// 8 I 25 Z 42 q 59 7
|
||||
// 9 J 26 a 43 r 60 8
|
||||
// 10 K 27 b 44 s 61 9
|
||||
// 11 L 28 c 45 t 62 +
|
||||
// 12 M 29 d 46 u 63 /
|
||||
// 13 N 30 e 47 v
|
||||
// 14 O 31 f 48 w (pad) =
|
||||
// 15 P 32 g 49 x
|
||||
// 16 Q 33 h 50 y
|
||||
|
||||
const int MaxLineLength=72;
|
||||
|
||||
char *Base64Encode(const char *inText,const unsigned int inLen){
|
||||
return Base64Encode((const unsigned char *)inText,inLen);
|
||||
}
|
||||
|
||||
|
||||
char *Base64Encode(const unsigned char *inText,const unsigned int inLen){
|
||||
// Notes:
|
||||
// - whoever calls us is responsible for free'ing the result we return
|
||||
// - we cheat and don't worry about breaking lines
|
||||
static unsigned char transTable[64]={'A','B','C','D','E','F','G','H',
|
||||
'I','J','K','L','M','N','O','P',
|
||||
'Q','R','S','T','U','V','W','X',
|
||||
'Y','Z','a','b','c','d','e','f',
|
||||
'g','h','i','j','k','l','m','n',
|
||||
'o','p','q','r','s','t','u','v',
|
||||
'w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9','+','/'};
|
||||
|
||||
char *res;
|
||||
int resSize;
|
||||
resSize = (4*inLen)/3;
|
||||
while(resSize % 4) resSize++;
|
||||
res = (char *)malloc(resSize+1);
|
||||
unsigned int i = 0;
|
||||
int pos = 0;
|
||||
while(i < inLen){
|
||||
res[pos++]= transTable[inText[i]>>2];
|
||||
if( i+1 < inLen){
|
||||
res[pos++]= transTable[((inText[i]&3)<<4)|(inText[i+1]>>4)];
|
||||
if(i+2 < inLen){
|
||||
res[pos++] = transTable[((inText[i+1]&0xF)<<2)|(inText[i+2]>>6)];
|
||||
res[pos++] = transTable[inText[i+2]&0x3F];
|
||||
} else {
|
||||
// single padding
|
||||
res[pos++] = transTable[((inText[i+1]&0xF)<<2)];
|
||||
res[pos++] = '=';
|
||||
}
|
||||
} else {
|
||||
// double padding
|
||||
res[pos++] = transTable[((inText[i]&3)<<4)];
|
||||
res[pos++] = '=';
|
||||
res[pos++] = '=';
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
res[resSize] = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
char *Base64Decode(const char *inText,unsigned int *size){
|
||||
// Notes:
|
||||
// - whoever calls us is responsible for free'ing the result we return
|
||||
|
||||
unsigned char transTable[256];
|
||||
int inLen = strlen(inText);
|
||||
|
||||
int i;
|
||||
// FIX: we don't really need to build this table here
|
||||
for(i= 0;i<255;i++){
|
||||
transTable[i]= 0x80;
|
||||
}
|
||||
for(i='A';i<='Z';i++) transTable[i] = (unsigned char)i-'A';
|
||||
for(i='a';i<='z';i++) transTable[i] = (unsigned char)i-'a'+26;
|
||||
for(i='0';i<='9';i++) transTable[i] = (unsigned char)i-'0'+52;
|
||||
transTable['+']=62;
|
||||
transTable['/']=63;
|
||||
|
||||
int outLen = 3*inLen/4;
|
||||
char *res = (char *)calloc(outLen,sizeof(char));
|
||||
int pos = 0;
|
||||
i = 0;
|
||||
// decode 4 bytes at a time
|
||||
unsigned char block[4];
|
||||
int nInBlock=0;
|
||||
while(i < inLen){
|
||||
unsigned char c = inText[i];
|
||||
|
||||
// above we set 0x80 as the junk marker in the translation table
|
||||
if ( !(transTable[c]&0x80) ){
|
||||
block[nInBlock++] = transTable[c];
|
||||
if( nInBlock == 4 ) {
|
||||
// finished a block
|
||||
res[pos++] = (block[0]<<2)|(block[1]>>4);
|
||||
res[pos++] = (block[1]<<4)|(block[2]>>2);
|
||||
res[pos++] = (block[2]<<6)|block[3];
|
||||
nInBlock = 0;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// okay, now there can be 2 or 3 chars remaining to be processed
|
||||
// (before the padding)
|
||||
if(nInBlock>1){
|
||||
res[pos++] = (block[0]<<2)|(block[1]>>4);
|
||||
if(nInBlock > 2){
|
||||
res[pos++] = (block[1]<<4)|(block[2]>>2);
|
||||
res[pos] = (block[2]<<6);
|
||||
}
|
||||
}
|
||||
*size = pos;
|
||||
return res;
|
||||
}
|
||||
35
Code/DataStructs/base64.h
Executable file
35
Code/DataStructs/base64.h
Executable file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Copyright (C) 2002-2006 Greg Landrum and Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#ifndef __RD_BASE64_H__
|
||||
#define __RD_BASE64_H__
|
||||
/*! \file base64.h
|
||||
|
||||
\brief Functionality for base64 encoding/decoding
|
||||
|
||||
*/
|
||||
|
||||
//! return the base64 encoding of an array of unsigned chars
|
||||
/*!
|
||||
<b>Note:</b> The caller is responsible for calling \c free on the
|
||||
char array returned by this function.
|
||||
*/
|
||||
char *Base64Encode(const unsigned char *,const unsigned int);
|
||||
|
||||
//! return the base64 encoding of an array of chars
|
||||
/*!
|
||||
<b>Note:</b> The caller is responsible for calling \c free on the
|
||||
char array returned by this function.
|
||||
*/
|
||||
char *Base64Encode(const char *,const unsigned int);
|
||||
|
||||
//! return the decoded version of a base64 encoded char array
|
||||
/*!
|
||||
<b>Note:</b> The caller is responsible for calling \c free on the
|
||||
char array returned by this function.
|
||||
*/
|
||||
char *Base64Decode(const char *,unsigned int *);
|
||||
|
||||
#endif
|
||||
116
Code/DataStructs/libDataStructs.dsp
Executable file
116
Code/DataStructs/libDataStructs.dsp
Executable file
@@ -0,0 +1,116 @@
|
||||
# Microsoft Developer Studio Project File - Name="libDatastructs" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=libDatastructs - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "libDatastructs.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "libDatastructs.mak" CFG="libDatastructs - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "libDatastructs - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "libDatastructs - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "libDatastructs - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "libDatastructs___Win32_Release"
|
||||
# PROP BASE Intermediate_Dir "libDatastructs___Win32_Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "libDatastructs___Win32_Release"
|
||||
# PROP Intermediate_Dir "libDatastructs___Win32_Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "." /I "$(RDBASE)/code" /I "$(RDBASE)/code/graphmol" /I "$(RDBASE)/External/$(BOOSTBASE)" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "libDatastructs - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "libDatastructs___Win32_Debug0"
|
||||
# PROP BASE Intermediate_Dir "libDatastructs___Win32_Debug0"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "libDatastructs___Win32_Debug0"
|
||||
# PROP Intermediate_Dir "libDatastructs___Win32_Debug0"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I "$(RDBASE)/code" /I "$(RDBASE)/code/graphmol" /I "$(RDBASE)/External/$(BOOSTBASE)" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "libDatastructs - Win32 Release"
|
||||
# Name "libDatastructs - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\base64.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\BitOps.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\BitVect.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\ExplicitBitVect.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\SparseBitVect.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BitVects\Utils.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
265
Code/DataStructs/libDatastructs.vcproj
Executable file
265
Code/DataStructs/libDatastructs.vcproj
Executable file
@@ -0,0 +1,265 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="libDatastructs"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\libDatastructs___Win32_Debug0"
|
||||
IntermediateDirectory=".\libDatastructs___Win32_Debug0"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\libDatastructs___Win32_Debug0/libDatastructs.pch"
|
||||
AssemblerListingLocation=".\libDatastructs___Win32_Debug0/"
|
||||
ObjectFile=".\libDatastructs___Win32_Debug0/"
|
||||
ProgramDataBaseFileName=".\libDatastructs___Win32_Debug0/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\libDatastructs___Win32_Debug0\libDatastructs.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\libDatastructs___Win32_Release"
|
||||
IntermediateDirectory=".\libDatastructs___Win32_Release"
|
||||
ConfigurationType="4"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories=".,$(RDBASE)/code,$(RDBASE)/External/boost/include/$(BOOSTBASE)"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="2"
|
||||
PrecompiledHeaderFile=".\libDatastructs___Win32_Release/libDatastructs.pch"
|
||||
AssemblerListingLocation=".\libDatastructs___Win32_Release/"
|
||||
ObjectFile=".\libDatastructs___Win32_Release/"
|
||||
ProgramDataBaseFileName=".\libDatastructs___Win32_Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
OutputFile=".\libDatastructs___Win32_Release\libDatastructs.lib"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath="base64.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="BitOps.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="BitVect.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DiscreteDistMat.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DiscreteValueVect.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ExplicitBitVect.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="SparseBitVect.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Utils.cpp">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""
|
||||
BasicRuntimeChecks="3"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions=""/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath=".\DiscreteDistMat.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\DiscreteValueVect.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
371
Code/DataStructs/testDatastructs.cpp
Normal file
371
Code/DataStructs/testDatastructs.cpp
Normal file
@@ -0,0 +1,371 @@
|
||||
// $Id: testDatastructs.cpp 4946 2006-02-17 01:44:04Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2001-2006 Rational Discovery LLC
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
//
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include "BitVects.h"
|
||||
#include "BitOps.h"
|
||||
#include "BitVectUtils.h"
|
||||
#include <cmath>
|
||||
#include "DiscreteValueVect.h"
|
||||
#include <RDGeneral/Invariant.h>
|
||||
#include <RDGeneral/RDLog.h>
|
||||
#include <RDBoost/Exceptions.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
template< typename T >
|
||||
inline void TXTMSG(const char *__a__,T __b__){ BOOST_LOG(rdInfoLog) << (__a__) << " " << (__b__) << std::endl; }
|
||||
|
||||
template<typename T> void Test(T arg){
|
||||
T t1(20);
|
||||
TXTMSG("Set 10:",t1.SetBit(10));
|
||||
TXTMSG("Set 11:",t1.SetBit(11));
|
||||
TXTMSG("Set 14:",t1.SetBit(14));
|
||||
TXTMSG("Set 10:",t1.SetBit(10));
|
||||
TXTMSG("Get 14:",t1.GetBit(14));
|
||||
TXTMSG("Num:",t1.GetNumBits());
|
||||
TXTMSG("NumOn:",t1.GetNumOnBits());
|
||||
TXTMSG("NumOff:",t1.GetNumOffBits());
|
||||
|
||||
IntVect onBits;
|
||||
t1.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
T t2(t1);
|
||||
//onBits = t2.GetOnBits();
|
||||
TXTMSG("t2[19]:",t2[19]);
|
||||
TXTMSG("t2[14]:",t2[14]);
|
||||
|
||||
t2 = t1;
|
||||
//onBits = t2.GetOnBits();
|
||||
TXTMSG("t2[19]:",t2[19]);
|
||||
t2.UnSetBit(14);
|
||||
TXTMSG("t2[14]:",t2[14]);
|
||||
t2.SetBit(15);
|
||||
t2.SetBit(17);
|
||||
|
||||
|
||||
cout << "t1: ";
|
||||
t1.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "t2: ";
|
||||
t2.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "t1|t2: ";
|
||||
T t3=t1|t2;
|
||||
t3.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "t1&t2: ";
|
||||
t3=t1 & t2;
|
||||
t3.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "t1^t2: ";
|
||||
t3=t1 ^ t2;
|
||||
t3.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "~t1: ";
|
||||
t3= ~t1;
|
||||
t3.GetOnBits(onBits);
|
||||
std::copy(onBits.begin(),onBits.end(),std::ostream_iterator<int>(std::cout,", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
try{
|
||||
t3.GetBit(4000);
|
||||
} catch (IndexErrorException) {
|
||||
cout << " except " << endl;
|
||||
} catch (...) {
|
||||
cout << " ERROR EXCEPT " << endl;
|
||||
}
|
||||
|
||||
T t4(t1.ToString());
|
||||
cout << "tan(t1,t4): " << TanimotoSimilarity(t1,t4) << endl;
|
||||
|
||||
T *t5 = FoldFingerprint(t1);
|
||||
TEST_ASSERT(t5->GetNumBits() == t1.GetNumBits()/2);
|
||||
TEST_ASSERT(t5->GetBit(0));
|
||||
TEST_ASSERT(t5->GetBit(1));
|
||||
TEST_ASSERT(t5->GetBit(4));
|
||||
TEST_ASSERT(!t5->GetBit(2));
|
||||
TEST_ASSERT(!t5->GetBit(3));
|
||||
delete t5;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void TaniTest(T &arg){
|
||||
std::string fps[4] = {
|
||||
".b+HHa.EgU6+ibEIr89.CpX0g8FZiXH+R0+Ps.mr6tg.2",
|
||||
".b7HEa..ccc+gWEIr89.8lV8gOF3aXFFR.+Ps.mZ6lg.2",
|
||||
".H+nHq2EcY09y5EIr9e.8p50h0NgiWGNx4+Hm+Gbslw.2",
|
||||
".1.HHa..cUI6i5E2rO8.Op10d0NoiWGVx.+Hm.Gb6lo.2",
|
||||
};
|
||||
double dists[] = {
|
||||
1.0,0.788991,0.677165,0.686957,
|
||||
1.0,0.578125,0.591304,
|
||||
1.0,0.732759,
|
||||
1.0
|
||||
};
|
||||
int idx=0;
|
||||
for(int i=0;i<4;i++){
|
||||
T v1(256);
|
||||
FromDaylightString(v1,fps[i]);
|
||||
for(int j=i;j<4;j++){
|
||||
T v2(256);
|
||||
FromDaylightString(v2,fps[j]);
|
||||
double tani=TanimotoSimilarity(v1,v2);
|
||||
TEST_ASSERT(abs(tani-dists[idx])<1e-4);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void ProbeTest(T &arg){
|
||||
int sz=1000;
|
||||
T t1(sz),t2(sz);
|
||||
for(int i=0;i<sz;i+=2){
|
||||
t1.SetBit(i);
|
||||
if(i<3*sz/4) t2.SetBit(i);
|
||||
}
|
||||
std::string pkl=t1.ToString();
|
||||
TEST_ASSERT(AllProbeBitsMatch(t1,pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2,pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t1.ToString(),pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2.ToString(),pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t1.ToString().c_str(),pkl.c_str()));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2.ToString().c_str(),pkl.c_str()));
|
||||
pkl = t2.ToString();
|
||||
TEST_ASSERT(!AllProbeBitsMatch(t1,pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2,pkl));
|
||||
TEST_ASSERT(!AllProbeBitsMatch(t1.ToString(),pkl));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2.ToString(),pkl));
|
||||
TEST_ASSERT(!AllProbeBitsMatch(t1.ToString().c_str(),pkl.c_str()));
|
||||
TEST_ASSERT(AllProbeBitsMatch(t2.ToString().c_str(),pkl.c_str()));
|
||||
}
|
||||
|
||||
|
||||
void test1DiscreteVect() {
|
||||
DiscreteValueVect vect1(DiscreteValueVect::ONEBITVALUE, 30);
|
||||
unsigned int i;
|
||||
for (i = 0; i < 15; ++i) {
|
||||
vect1.setVal(2*i, 1);
|
||||
}
|
||||
|
||||
CHECK_INVARIANT(vect1.getLength() == 30, "");
|
||||
CHECK_INVARIANT(vect1.getTotalVal() == 15, "");
|
||||
for (i = 0; i < vect1.getLength(); ++i) {
|
||||
CHECK_INVARIANT(vect1.getVal(i) == (i+1)%2, "");
|
||||
}
|
||||
try {
|
||||
vect1.setVal(28,2);
|
||||
} catch (ValueErrorException &dexp) {
|
||||
std::cout << "Expected failure: " << dexp.message() << "\n";
|
||||
}
|
||||
|
||||
// all these tests should fail if unsigned int changes from being
|
||||
// 32 bits
|
||||
DiscreteValueVect vect2(DiscreteValueVect::TWOBITVALUE, 30);
|
||||
for (i = 0; i < vect2.getLength(); ++i) {
|
||||
vect2.setVal(i, i%4);
|
||||
}
|
||||
|
||||
for (i = 0; i < vect2.getLength(); ++i) {
|
||||
CHECK_INVARIANT(vect2.getVal(i) == i%4, "");
|
||||
}
|
||||
CHECK_INVARIANT(vect2.getTotalVal() == 43, "");
|
||||
try {
|
||||
vect2.setVal(28,10);
|
||||
} catch (ValueErrorException &dexp) {
|
||||
std::cout << "Expected failure: " << dexp.message() << "\n";
|
||||
}
|
||||
|
||||
DiscreteValueVect vect4(DiscreteValueVect::FOURBITVALUE, 30);
|
||||
for (i = 0; i < vect4.getLength(); ++i) {
|
||||
vect4.setVal(i, i%16);
|
||||
}
|
||||
|
||||
for (i = 0; i < vect4.getLength(); ++i) {
|
||||
CHECK_INVARIANT(vect4.getVal(i) == i%16, "");
|
||||
}
|
||||
CHECK_INVARIANT(vect4.getTotalVal() == 211, "");
|
||||
try {
|
||||
vect4.setVal(28,16);
|
||||
} catch (ValueErrorException &dexp) {
|
||||
std::cout << "Expected failure: " << dexp.message() << "\n";
|
||||
}
|
||||
|
||||
DiscreteValueVect vect8(DiscreteValueVect::EIGHTBITVALUE, 32);
|
||||
for (i = 0; i < vect8.getLength(); ++i) {
|
||||
vect8.setVal(i, i%256);
|
||||
}
|
||||
|
||||
for (i = 0; i < vect8.getLength(); ++i) {
|
||||
CHECK_INVARIANT(vect8.getVal(i) == i%256, "");
|
||||
}
|
||||
CHECK_INVARIANT(vect8.getTotalVal() == 496, "");
|
||||
try {
|
||||
vect8.setVal(28,257);
|
||||
} catch (ValueErrorException &dexp) {
|
||||
std::cout << "Expected failure: " << dexp.message() << "\n";
|
||||
}
|
||||
|
||||
DiscreteValueVect vect16(DiscreteValueVect::SIXTEENBITVALUE, 300);
|
||||
for (i = 0; i < vect16.getLength(); ++i) {
|
||||
vect16.setVal(i, i%300);
|
||||
}
|
||||
|
||||
for (i = 0; i < vect16.getLength(); ++i) {
|
||||
CHECK_INVARIANT(vect16.getVal(i) == i%300, "");
|
||||
}
|
||||
|
||||
CHECK_INVARIANT(vect16.getTotalVal() == 44850, "");
|
||||
vect16.setVal(28,65535);
|
||||
try {
|
||||
vect16.setVal(28,65536);
|
||||
} catch (ValueErrorException &dexp) {
|
||||
std::cout << "Expected failure: " << dexp.message() << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void test2DiscreteVectDists() {
|
||||
DiscreteValueVect v1(DiscreteValueVect::ONEBITVALUE, 30);
|
||||
DiscreteValueVect v2(DiscreteValueVect::ONEBITVALUE, 30);
|
||||
unsigned int i;
|
||||
for (i = 0; i < 15; ++i) {
|
||||
v1.setVal(2*i, 1);
|
||||
v2.setVal(2*i, 1);
|
||||
}
|
||||
CHECK_INVARIANT(computeL1Norm(v1, v2) == 0, " ");
|
||||
for (i = 0; i < 30; ++i) {
|
||||
v2.setVal(i, i%2);
|
||||
}
|
||||
|
||||
CHECK_INVARIANT(computeL1Norm(v1, v2) == 30, " ");
|
||||
|
||||
for (i = 0; i < 30; ++i) {
|
||||
if (i%3 == 0) {
|
||||
v2.setVal(i, 1);
|
||||
} else {
|
||||
v2.setVal(i,0);
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_INVARIANT(computeL1Norm(v1, v2) == 15, " ");
|
||||
|
||||
DiscreteValueVect v21(DiscreteValueVect::TWOBITVALUE, 30);
|
||||
DiscreteValueVect v22(DiscreteValueVect::TWOBITVALUE, 30);
|
||||
for (i = 0; i < 30; ++i) {
|
||||
v21.setVal(i, i%4);
|
||||
v22.setVal(i, i%4);
|
||||
}
|
||||
CHECK_INVARIANT(computeL1Norm(v21, v22) == 0, " ");
|
||||
for (i = 0; i < 30; ++i) {
|
||||
v22.setVal(i, (i+1)%4);
|
||||
}
|
||||
CHECK_INVARIANT(computeL1Norm(v21, v22) == 44, " ");
|
||||
|
||||
DiscreteValueVect v41(DiscreteValueVect::FOURBITVALUE, 16);
|
||||
DiscreteValueVect v42(DiscreteValueVect::FOURBITVALUE, 16);
|
||||
for (i = 0; i < 16; ++i) {
|
||||
v41.setVal(i, i%16);
|
||||
v42.setVal(i, i%16);
|
||||
}
|
||||
CHECK_INVARIANT(computeL1Norm(v41, v42) == 0, " ");
|
||||
|
||||
for (i = 0; i < 16; ++i) {
|
||||
v42.setVal(i, i%5);
|
||||
}
|
||||
CHECK_INVARIANT(computeL1Norm(v41, v42) ==90, " ");
|
||||
|
||||
DiscreteValueVect v43(v42);
|
||||
CHECK_INVARIANT(computeL1Norm(v42, v43) == 0, " ");
|
||||
|
||||
DiscreteValueVect v81(DiscreteValueVect::EIGHTBITVALUE, 5);
|
||||
DiscreteValueVect v82(DiscreteValueVect::EIGHTBITVALUE, 5);
|
||||
v81.setVal(0, 34); v82.setVal(0, 34);
|
||||
v81.setVal(1, 167); v82.setVal(1, 167);
|
||||
v81.setVal(2, 3); v82.setVal(2, 3);
|
||||
v81.setVal(3, 56); v82.setVal(3, 56);
|
||||
v81.setVal(4, 128); v82.setVal(4, 128);
|
||||
CHECK_INVARIANT(computeL1Norm(v81, v82) == 0, " ");
|
||||
|
||||
v82.setVal(0, 14); v82.setVal(1, 67);
|
||||
v82.setVal(2, 103); v82.setVal(3, 6);
|
||||
v82.setVal(4, 228);
|
||||
CHECK_INVARIANT(computeL1Norm(v81, v82) == 370, "");
|
||||
|
||||
DiscreteValueVect v161(DiscreteValueVect::SIXTEENBITVALUE, 3);
|
||||
DiscreteValueVect v162(DiscreteValueVect::SIXTEENBITVALUE, 3);
|
||||
v161.setVal(0, 2345); v162.setVal(0, 2345);
|
||||
v161.setVal(1, 64578); v162.setVal(1, 64578);
|
||||
v161.setVal(2, 34); v162.setVal(2, 34);
|
||||
CHECK_INVARIANT(computeL1Norm(v161, v162) == 0, " ");
|
||||
|
||||
v162.setVal(0, 1345);
|
||||
v162.setVal(1, 54578);
|
||||
v162.setVal(2, 10034);
|
||||
CHECK_INVARIANT(computeL1Norm(v161, v162) == 21000, " ");
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
try{
|
||||
throw IndexErrorException(3);
|
||||
} catch (IndexErrorException) {
|
||||
cerr << "pass" << endl;
|
||||
}
|
||||
|
||||
stringstream ss(ios_base::binary|ios_base::out|ios_base::in);
|
||||
int v1=4,v2=5,v3,v4;
|
||||
|
||||
ss.write((const char *)&v1,sizeof(v1));
|
||||
ss.write((const char *)&v2,sizeof(v2));
|
||||
#if 0
|
||||
ss.close();
|
||||
fstream ss2("blah.bin",ios_base::binary|ios_base::in);
|
||||
ss2.read((char *)&v3,sizeof(v3));
|
||||
ss2.read((char *)&v4,sizeof(v4));
|
||||
#endif
|
||||
ss.seekp(0,ios_base::beg);
|
||||
ss.read((char *)&v3,sizeof(v3));
|
||||
ss.read((char *)&v4,sizeof(v4));
|
||||
|
||||
TXTMSG("v3",v3);
|
||||
TXTMSG("v4",v4);
|
||||
|
||||
cerr << " SPARSE -----------------------------------------" << endl;
|
||||
SparseBitVect sparseFoo(10);
|
||||
Test(sparseFoo);
|
||||
TaniTest(sparseFoo);
|
||||
ProbeTest(sparseFoo);
|
||||
cerr << " Explicit -----------------------------------------" << endl;
|
||||
ExplicitBitVect explicitFoo(10);
|
||||
Test(explicitFoo);
|
||||
TaniTest(explicitFoo);
|
||||
cerr << " Done" << endl;
|
||||
|
||||
std::cout << " Test DiscreteValue Vectors 1 ------------------------------------" << endl;
|
||||
test1DiscreteVect();
|
||||
std::cout << " Test DiscreteValue Vectors 2 ------------------------------------" << endl;
|
||||
test2DiscreteVectDists();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
9
Code/DataStructs/test_list.py
Executable file
9
Code/DataStructs/test_list.py
Executable file
@@ -0,0 +1,9 @@
|
||||
|
||||
tests=[
|
||||
("testExecs/test.exe","",{}),
|
||||
]
|
||||
|
||||
|
||||
|
||||
longTests=[]
|
||||
|
||||
30
Code/Demos/PgSQL/funcs/Makefile
Normal file
30
Code/Demos/PgSQL/funcs/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile--
|
||||
# Makefile for tutorial
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql-server/src/tutorial/Makefile,v 1.16 2002/09/05 18:28:46 petere Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
|
||||
CXXFLAGS = $(BASECXXFLAGS) $(RDKITINCFLAGS) -fpic -I/usr/src/redhat/SOURCES/postgresql-8.0.1/src/include
|
||||
DLSUFFIX=.so
|
||||
|
||||
#DLOBJS= $(RDBASE)/bin/funcs$(DLSUFFIX)
|
||||
DLOBJS= funcs$(DLSUFFIX)
|
||||
|
||||
QUERIES= test1.sql
|
||||
|
||||
all: $(DLOBJS) $(QUERIES)
|
||||
|
||||
#$(RDBASE)/bin/funcs$(DLSUFFIX): funcs.o
|
||||
# g++ -shared -o $(RDBASE)/bin/funcs$(DLSUFFIX) funcs.o
|
||||
# g++ -shared -o $(RDBASE)/bin/funcs$(DLSUFFIX) funcs.o $(RDSMILES) $(RDSUBSTRUCT) $(RDKIT) $(RDGENERAL)
|
||||
funcs$(DLSUFFIX): funcs.o
|
||||
g++ -shared -o funcs$(DLSUFFIX) funcs.o $(RDSMILES) $(RDSUBSTRUCT) $(RDKIT) $(RDGENERAL) $(RDGEOMETRY) $(RDFINGERPRINTS) $(RDSUBGRAPHS) $(VFLIB) $(LAPACKLIB)
|
||||
|
||||
clean:
|
||||
rm -f $(DLOBJS)
|
||||
100
Code/Demos/PgSQL/funcs/funcs.cpp
Normal file
100
Code/Demos/PgSQL/funcs/funcs.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// $Id$
|
||||
//
|
||||
// Copyright (C) 2005 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
|
||||
extern "C" {
|
||||
#include "postgres.h"
|
||||
#include "fmgr.h" /* for argument/result macros */
|
||||
#include "libpq/pqformat.h" /* needed for send/recv functions */
|
||||
#include <stdlib.h>
|
||||
}
|
||||
#ifdef gettext
|
||||
#undef gettext
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include <DataStructs/BitVects.h>
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
#include <GraphMol/SmilesParse/SmilesParse.h>
|
||||
#include <GraphMol/Substruct/SubstructMatch.h>
|
||||
#include <GraphMol/Fingerprints/Fingerprints.h>
|
||||
|
||||
|
||||
/* These prototypes just prevent possible warnings from gcc. */
|
||||
|
||||
extern "C" {
|
||||
PG_FUNCTION_INFO_V1(substruct);
|
||||
Datum substruct(PG_FUNCTION_ARGS);
|
||||
PG_FUNCTION_INFO_V1(substructfp);
|
||||
Datum substructfp(PG_FUNCTION_ARGS);
|
||||
PG_FUNCTION_INFO_V1(fpsize);
|
||||
Datum fpsize(PG_FUNCTION_ARGS);
|
||||
}
|
||||
|
||||
|
||||
Datum substruct(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *smi = PG_GETARG_TEXT_P(0);
|
||||
text *sma = PG_GETARG_TEXT_P(1);
|
||||
|
||||
RDKit::RWMol *probe=0;
|
||||
|
||||
std::string smiS(VARDATA(smi),VARSIZE(smi)-VARHDRSZ);
|
||||
std::string smaS(VARDATA(sma),VARSIZE(sma)-VARHDRSZ);
|
||||
bool res = false;
|
||||
//elog(INFO,"smi(%d,%d,%d): %s\n",smi->vl_len,VARSIZE(smi),VARHDRSZ,smiS.c_str());
|
||||
RDKit::RWMol *mol=RDKit::SmilesToMol(smiS);
|
||||
if(mol) {
|
||||
probe=RDKit::SmartsToMol(smaS);
|
||||
if(probe){
|
||||
RDKit::MatchVectType matchVect;
|
||||
res = RDKit::SubstructMatch(mol,probe,matchVect);
|
||||
}
|
||||
delete mol;
|
||||
}
|
||||
//elog(INFO,"%d %s",res,smiS.c_str());
|
||||
PG_RETURN_INT32(res);
|
||||
}
|
||||
|
||||
Datum substructfp(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *smi = PG_GETARG_TEXT_P(0);
|
||||
int fpSize=2048;
|
||||
std::string smiS(VARDATA(smi),VARSIZE(smi)-VARHDRSZ);
|
||||
|
||||
ExplicitBitVect *bv=0;
|
||||
RDKit::RWMol *mol=RDKit::SmilesToMol(smiS);
|
||||
if(mol) {
|
||||
try{
|
||||
bv = DaylightFingerprintMol(mol,1,7,fpSize);
|
||||
} catch (...) {
|
||||
bv = new ExplicitBitVect(fpSize);
|
||||
}
|
||||
delete mol;
|
||||
} else {
|
||||
bv = new ExplicitBitVect(fpSize);
|
||||
}
|
||||
std::string pkl=bv->ToString();
|
||||
delete bv;
|
||||
|
||||
StringInfoData buf;
|
||||
pq_begintypsend(&buf);
|
||||
pq_sendtext(&buf,pkl.c_str(),pkl.size());
|
||||
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
||||
}
|
||||
|
||||
Datum fpsize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int res=0;
|
||||
if(!PG_ARGISNULL(0)) {
|
||||
bytea *buf=PG_GETARG_BYTEA_P(0);
|
||||
std::string pkl(VARDATA(buf),VARSIZE(buf)-VARHDRSZ);
|
||||
ExplicitBitVect bv(pkl);
|
||||
res = bv.GetNumBits();
|
||||
}
|
||||
PG_RETURN_INT32(res);
|
||||
|
||||
}
|
||||
42
Code/Demos/PgSQL/funcs/test1.sql
Normal file
42
Code/Demos/PgSQL/funcs/test1.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
---------------------------------------------------------------------------
|
||||
--
|
||||
-- funcs.sql-
|
||||
-- Tutorial on using functions in POSTGRES.
|
||||
--
|
||||
--
|
||||
-- Copyright (c) 1994-5, Regents of the University of California
|
||||
--
|
||||
-- $Id: funcs.source,v 1.5 2001/10/26 20:45:33 tgl Exp $
|
||||
--
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-----------------------------
|
||||
-- Creating C Functions
|
||||
-- in addition to SQL functions, you can also create C functions.
|
||||
-- See funcs.c for the definition of the C functions.
|
||||
-----------------------------
|
||||
|
||||
CREATE FUNCTION substruct(text,text) RETURNS int
|
||||
AS '/home2/glandrum/RD/trunk/Code/Demos/PgSQL/funcs/funcs' LANGUAGE 'c';
|
||||
CREATE FUNCTION substructfp(text) RETURNS bytea
|
||||
AS '/home2/glandrum/RD/trunk/Code/Demos/PgSQL/funcs/funcs' LANGUAGE 'c';
|
||||
CREATE FUNCTION fpsize(bytea) RETURNS int
|
||||
AS '/home2/glandrum/RD/trunk/Code/Demos/PgSQL/funcs/funcs' LANGUAGE 'c';
|
||||
|
||||
SELECT substruct('c1ccccc1C','cC');
|
||||
drop table temp;
|
||||
create table temp (id text,smiles varchar(256));
|
||||
insert into temp values ('mol-1','CCC');
|
||||
insert into temp values ('mol-2','Cc1ncccc1');
|
||||
select * from temp where substruct(smiles,'Cc1ncccc1')=1;
|
||||
|
||||
-- select * from d1 where substruct(smiles,'Cc1ncccc1')=1;
|
||||
|
||||
select substructfp('c1ccccc1');
|
||||
select substructfp('');
|
||||
select fpsize(substructfp(''));
|
||||
|
||||
|
||||
DROP FUNCTION substruct(text,text);
|
||||
DROP FUNCTION substructfp(text);
|
||||
|
||||
106
Code/Demos/RDKit/Minimize/MinimizeCLI.cpp
Normal file
106
Code/Demos/RDKit/Minimize/MinimizeCLI.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
// $Id: MinimizeCLI.cpp 4421 2005-02-09 16:55:05Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2004 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
#include <iostream>
|
||||
#include <RDGeneral/Invariant.h>
|
||||
#include <RDGeneral/utils.h>
|
||||
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
#include <GraphMol/FileParsers/FileParsers.h>
|
||||
#include <GraphMol/FileParsers/MolSupplier.h>
|
||||
|
||||
#include <GraphMol/ForceFieldHelpers/UFF/AtomTyper.h>
|
||||
#include <GraphMol/ForceFieldHelpers/UFF/Builder.h>
|
||||
#include <ForceField/ForceField.h>
|
||||
|
||||
using namespace RDKit;
|
||||
|
||||
|
||||
void runMol(ROMol *mol,int checkEvery=10,bool verbose=true){
|
||||
ForceFields::ForceField *field;
|
||||
try{
|
||||
field=UFF::constructForceField(mol,2.5);
|
||||
} catch (...) {
|
||||
field=0;
|
||||
}
|
||||
if(field){
|
||||
field->initialize();
|
||||
int needMore=1;
|
||||
int nPasses=0;
|
||||
while(needMore){
|
||||
#if 1
|
||||
needMore = field->minimize(checkEvery);
|
||||
if(verbose) std::cerr << "\t" << ++nPasses << std::endl;
|
||||
#else
|
||||
needMore = field->minimize(1);
|
||||
std::cout << MolToMolBlock(mol) << "$$$$" << std::endl;
|
||||
#endif
|
||||
}
|
||||
std::cout << MolToMolBlock(mol) << "$$$$" << std::endl;
|
||||
delete field;
|
||||
} else {
|
||||
std::cerr << "failed";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void runMolFile(std::string fileName,int checkEvery=10){
|
||||
RWMol *mol=MolFileToMol(fileName,false);
|
||||
TEST_ASSERT(mol);
|
||||
MolOps::sanitizeMol(*mol);
|
||||
|
||||
ROMol *mol2=MolOps::addHs(mol,false,true);
|
||||
|
||||
runMol(mol2,checkEvery);
|
||||
|
||||
delete mol;
|
||||
delete mol2;
|
||||
}
|
||||
|
||||
void runSDFile(std::string fileName,int checkEvery=10){
|
||||
SDMolSupplier suppl(fileName,false);
|
||||
|
||||
RWMol *mol;
|
||||
|
||||
mol = (RWMol *)suppl.next();
|
||||
while(mol){
|
||||
std::string name;
|
||||
mol->getProp("_Name",name);
|
||||
std::cerr << "Mol: " << name << std::endl;
|
||||
try{
|
||||
MolOps::sanitizeMol(*mol);
|
||||
} catch (...) {
|
||||
std::cerr << " sanitization failed" << std::endl;
|
||||
delete mol;
|
||||
mol = 0;
|
||||
}
|
||||
if(mol){
|
||||
ROMol *mol2=MolOps::addHs(mol,false,true);
|
||||
delete mol;
|
||||
runMol(mol2,checkEvery,false);
|
||||
delete mol2;
|
||||
}
|
||||
mol = (RWMol *)suppl.next();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
//
|
||||
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
int main(int argc,char *argv[]){
|
||||
PRECONDITION(argc>1,"bad arguments");
|
||||
std::string fileName=argv[1];
|
||||
int checkEvery=10;
|
||||
std::cerr << ">" << fileName<< " " << fileName.find(".sdf") << std::endl;
|
||||
if(fileName.find(".sdf")==std::string::npos){
|
||||
runMolFile(fileName,checkEvery);
|
||||
} else {
|
||||
runSDFile(fileName,checkEvery);
|
||||
}
|
||||
|
||||
std::cerr << "done" << std::endl;
|
||||
}
|
||||
152
Code/Demos/RDKit/Minimize/MinimizeCLI.vcproj
Normal file
152
Code/Demos/RDKit/Minimize/MinimizeCLI.vcproj
Normal file
@@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="demo - MinimizeCLI"
|
||||
ProjectGUID="{A33253EE-6147-4E21-997E-C68509F218EA}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\DemoMinimizeCLI___Win32_Debug"
|
||||
IntermediateDirectory=".\DemoMinimizeCLI___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/Code"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\DemoMinimizeCLI___Win32_Debug/DemoMinimizeCLI.pch"
|
||||
AssemblerListingLocation=".\DemoMinimizeCLI___Win32_Debug/"
|
||||
ObjectFile=".\DemoMinimizeCLI___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\DemoMinimizeCLI___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="MinimizeCLI.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\DemoMinimizeCLI___Win32_Debug/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\DemoMinimizeCLI___Win32_Debug/DemoMinimizeCLI.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),$(RDBASE)/Code"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/DemoMinimizeCLI.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="MinimizeCLI.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
ProgramDatabaseFile=".\Release/test.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/DemoMinimizeCLI.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\MinimizeCLI.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
18
Code/Demos/RDKit/TemplEnum/Makefile
Executable file
18
Code/Demos/RDKit/TemplEnum/Makefile
Executable file
@@ -0,0 +1,18 @@
|
||||
include $(RDBASE)/Code/rdvars.make
|
||||
CXXFLAGS=$(BASECXXFLAGS)
|
||||
|
||||
LDFLAGS= $(RDFILEPARSE) $(RDSMILES) $(RDSUBSTRUCT) $(VFLIB) $(RDKIT) $(RDBITVECS) \
|
||||
$(RDMOLTRANSFORMS) $(RDGENERAL) $(RDGEOMETRY)
|
||||
|
||||
OBJS=main.o TemplEnumTools.o
|
||||
|
||||
main.exe: $(OBJS)
|
||||
g++ -o main.exe $(CXXFLAGS) $(OBJS) $(LDFLAGS)
|
||||
|
||||
SIMPLEOBJS=simple.o TemplEnumTools.o
|
||||
simple.exe: $(SIMPLEOBJS)
|
||||
g++ -o simple.exe $(CXXFLAGS) $(SIMPLEOBJS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f main.exe $(OBJS)
|
||||
|
||||
39
Code/Demos/RDKit/TemplEnum/TemplEnum.h
Executable file
39
Code/Demos/RDKit/TemplEnum/TemplEnum.h
Executable file
@@ -0,0 +1,39 @@
|
||||
// $Id: TemplEnum.h 4421 2005-02-09 16:55:05Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
#ifndef _TEMPLENUM_H_
|
||||
#define _TEMPLENUM_H_
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
|
||||
namespace TemplateEnum {
|
||||
using namespace RDKit;
|
||||
|
||||
class EnumException : public std::exception {
|
||||
public :
|
||||
EnumException(const char *msg) : _msg(msg) {};
|
||||
EnumException(const std::string msg) : _msg(msg) {};
|
||||
const char *message () const { return _msg.c_str(); };
|
||||
~EnumException () throw () {};
|
||||
private :
|
||||
std::string _msg;
|
||||
};
|
||||
|
||||
void orientSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molAttachIdx,int sidechainAttachIdx);
|
||||
|
||||
typedef std::vector< RWMOL_SPTR_VECT > VECT_RWMOL_SPTR_VECT;
|
||||
void markAttachmentPoints(RWMOL_SPTR *mol,char frontMarker='X');
|
||||
void markAttachmentPoints(RWMol *mol,char frontMarker='X');
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains,char frontMarker='Y');
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *mol,VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains=true);
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainName);
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
#endif
|
||||
|
||||
419
Code/Demos/RDKit/TemplEnum/TemplEnumTools.cpp
Executable file
419
Code/Demos/RDKit/TemplEnum/TemplEnumTools.cpp
Executable file
@@ -0,0 +1,419 @@
|
||||
// $Id: TemplEnumTools.cpp 4421 2005-02-09 16:55:05Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003,2004 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
#include "TemplEnum.h"
|
||||
#include <Geometry/Transform3D.h>
|
||||
#include <GraphMol/MolTransforms/MolTransforms.h>
|
||||
#include <GraphMol/FileParsers/FileParsers.h>
|
||||
#define FEQ(_a_,_b_) (fabs((_a_)-(_b_))<1e-4)
|
||||
|
||||
namespace TemplateEnum {
|
||||
using namespace RDKit;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// transforms a sidechain so that it is oriented better for attachment
|
||||
// to a molecule
|
||||
//
|
||||
// Arguments:
|
||||
// mol: core molecule
|
||||
// sidechain: sidechain to attach.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void orientSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molAttachIdx,int sidechainAttachIdx){
|
||||
PRECONDITION(mol,"bad molecule");
|
||||
PRECONDITION(sidechain,"bad molecule");
|
||||
|
||||
// ---------
|
||||
// start by getting our 4 atoms
|
||||
// ---------
|
||||
Atom *molConnAtom,*molAttachAtom;
|
||||
Atom *chainConnAtom,*chainAttachAtom;
|
||||
molAttachAtom = mol->getAtomWithIdx(molAttachIdx);
|
||||
chainAttachAtom = sidechain->getAtomWithIdx(sidechainAttachIdx);
|
||||
PRECONDITION(molAttachAtom->getDegree()==1,"attachment points must be degree 1");
|
||||
PRECONDITION(chainAttachAtom->getDegree()==1,"attachment points must be degree 1");
|
||||
RWMol::ADJ_ITER nbrIdx,endNbrs;
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(molAttachAtom);
|
||||
molConnAtom=mol->getAtomWithIdx(*nbrIdx);
|
||||
boost::tie(nbrIdx,endNbrs) = sidechain->getAtomNeighbors(chainAttachAtom);
|
||||
chainConnAtom=sidechain->getAtomWithIdx(*nbrIdx);
|
||||
|
||||
//-----------------------------------------
|
||||
// Notation:
|
||||
// Pmc: molecule connection point (the atom that will be
|
||||
// removed from the molecule).
|
||||
// Pma: molecule attachment point (the atom to which we'll form
|
||||
// the bond).
|
||||
// Psc: sidechain connection point
|
||||
// Psa: sidechain attachment point
|
||||
// Vm: Pmc-Pma (molecular attachment vector)
|
||||
// Vs: Psc-Psa (sidechain attachment vector)
|
||||
//
|
||||
//-----------------------------------------
|
||||
RDGeom::Transform3D sidechainTform,templateTform,tmpTform;
|
||||
|
||||
RDGeom::Point3D Vm,Um,Pmc,Pma;
|
||||
RDGeom::Point3D Vs,Us,Psc,Psa;
|
||||
Pmc = molConnAtom->getPos();
|
||||
Pma = molAttachAtom->getPos();
|
||||
std::cerr << "p=array(["<<Pma.x<<","<<Pma.y<<","<<Pma.z<<"])" << std::endl;
|
||||
Psc = chainConnAtom->getPos();
|
||||
Psa = chainAttachAtom->getPos();
|
||||
|
||||
templateTform.setToIdentity();
|
||||
Vm = Pmc - Pma;
|
||||
// note the opposite direction here:
|
||||
Vs = Psa - Psc;
|
||||
Um = Vm;
|
||||
Um.normalize();
|
||||
std::cerr << "Um=array(["<<Um.x<<","<<Um.y<<","<<Um.z<<"])" << std::endl;
|
||||
Us = Vs;
|
||||
Us.normalize();
|
||||
std::cerr << "Us=array(["<<Us.x<<","<<Us.y<<","<<Us.z<<"])" << std::endl;
|
||||
// translate Psc -> Pma
|
||||
//RDGeom::Point3D headTrans = Pma-Psc;
|
||||
|
||||
templateTform.setToIdentity();
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Pma);
|
||||
templateTform = templateTform*tmpTform;
|
||||
|
||||
double sinT,cosT;
|
||||
cosT = Us.dotProduct(Um);
|
||||
if(cosT>1.0) cosT = 1.0;
|
||||
if(fabs(cosT)<1.0){
|
||||
tmpTform.setToIdentity();
|
||||
sinT = sqrt(1.0-cosT*cosT);
|
||||
RDGeom::Point3D rotnAxis=Us.crossProduct(Um);
|
||||
rotnAxis.normalize();
|
||||
std::cerr << "ax=array(["<<rotnAxis.x<<","<<rotnAxis.y<<","<<rotnAxis.z<<"])" << std::endl;
|
||||
tmpTform.SetRotation(cosT,sinT,rotnAxis);
|
||||
templateTform = templateTform*tmpTform;
|
||||
} else if(cosT==1.0){
|
||||
RDGeom::Point3D normal(1,0,0);
|
||||
if(fabs(Us.dotProduct(normal))==1.0){
|
||||
normal = RDGeom::Point3D(0,1,0);
|
||||
}
|
||||
RDGeom::Point3D rotnAxis=Us.crossProduct(normal);
|
||||
templateTform.SetRotation(-1,0,rotnAxis);
|
||||
}
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Psc*-1.0);
|
||||
templateTform = templateTform*tmpTform;
|
||||
|
||||
// ---------
|
||||
// transform the atomic positions in the sidechain:
|
||||
// ---------
|
||||
MolTransforms::transformMolsAtoms(sidechain,templateTform);
|
||||
|
||||
|
||||
// that's it!
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// attaches a sidechain fragment to a molecule.
|
||||
//
|
||||
// Arguments:
|
||||
// mol: molecule to be modified
|
||||
// sidechain: sidechain to attach. The sidechain is copied in.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
// bondType: type of the bond to form between the atoms
|
||||
//
|
||||
// The connector atoms are *NOT* part of the final molecule, they
|
||||
// merely serve to establish where things connect.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void molAddSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molConnectorIdx,int sidechainConnectorIdx,
|
||||
Bond::BondType bondType){
|
||||
PRECONDITION(mol,"bad molecule provided");
|
||||
PRECONDITION(sidechain,"bad sidechain provided");
|
||||
int origNumAtoms=mol->getNumAtoms();
|
||||
mol->insertMol(sidechain);
|
||||
|
||||
// get pointers to the two connectors (these are the atoms
|
||||
// we'll end up removing)
|
||||
Atom *molConnAtom,*sidechainConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(molConnectorIdx);
|
||||
sidechainConnAtom = mol->getAtomWithIdx(sidechainConnectorIdx+origNumAtoms);
|
||||
|
||||
// now use those pointers to get the atoms which will remain
|
||||
// (we're going to connect these) and remove the original
|
||||
// connection points from the molecule
|
||||
Atom *tmpAtom;
|
||||
RWMol::ADJ_ITER nbrIdx,endNbrs;
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(molConnAtom);
|
||||
|
||||
// we are assuming that the first neighbor is the correct one.
|
||||
// Really we should be able to assume that there is only a single
|
||||
// attachment point.
|
||||
tmpAtom = molConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
// repeat that process for the sidechain:
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(sidechainConnAtom);
|
||||
tmpAtom = sidechainConnAtom;
|
||||
sidechainConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
|
||||
// finally connect the remaining atoms:
|
||||
mol->addBond(molConnAtom,sidechainConnAtom,bondType);
|
||||
}
|
||||
|
||||
|
||||
// used as a starting point for connection bookmarks
|
||||
const int CONNECT_BOOKMARK_START=0x23424223;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Loop through all the atoms and bookmark the attachment points
|
||||
//
|
||||
// attachment points are assumed to have one of these properties:
|
||||
// - "molFileAlias" (set by the mol file parser)
|
||||
// - "dummyLabel" (set by the SMILES parser)
|
||||
// frontMarker is the "recognition character" to be used to pick
|
||||
// valid labels. e.g. if the frontMarker is 'X', a label beginning
|
||||
// with 'Y' will not be marked.
|
||||
//
|
||||
// In addition to bookmarking the attachment points, we also set
|
||||
// the "maxAttachIdx" property, which holds an integer with the
|
||||
// maximum attachment bookmark index. This is used in the
|
||||
// enumeration to prevent us from having to scan through all the
|
||||
// molecule's bookmarks
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void markAttachmentPoints(RWMOL_SPTR mol,char frontMarker){
|
||||
markAttachmentPoints(mol.get(),frontMarker);
|
||||
}
|
||||
void markAttachmentPoints(RWMol *mol,char frontMarker){
|
||||
PRECONDITION(mol,"bad molecule");
|
||||
|
||||
RWMol::AtomIterator atomIt;
|
||||
int maxAttachIdx=0;
|
||||
|
||||
// scan through the atoms and mark those that have aliases
|
||||
// (these might be attachment points)
|
||||
for(atomIt=mol->beginAtoms();atomIt!=mol->endAtoms();atomIt++){
|
||||
// start by finding possible attachment point properties:
|
||||
std::string attachLabel="";
|
||||
if((*atomIt)->hasProp("molFileAlias")){
|
||||
(*atomIt)->getProp("molFileAlias",attachLabel);
|
||||
} else if((*atomIt)->hasProp("dummyLabel")){
|
||||
(*atomIt)->getProp("dummyLabel",attachLabel);
|
||||
}
|
||||
|
||||
// if we got one and it starts with the appropriate front
|
||||
// marker, proceed:
|
||||
if(attachLabel!="" && attachLabel[0]==frontMarker ){
|
||||
// to avoid trouble later, we guarantee that the attachment
|
||||
// point has degree 1 (one bond to it).
|
||||
if((*atomIt)->getDegree()>1)
|
||||
throw EnumException("More than one bond to an attachment point.");
|
||||
|
||||
int offset = CONNECT_BOOKMARK_START;
|
||||
if(attachLabel.length()>1){
|
||||
if(attachLabel[1]>='a' && attachLabel[1]<='z'){
|
||||
offset += (int)attachLabel[1] - (int)'a';
|
||||
}
|
||||
}
|
||||
mol->setAtomBookmark(*atomIt,offset);
|
||||
if(offset>maxAttachIdx) maxAttachIdx=offset;
|
||||
}
|
||||
}
|
||||
if(maxAttachIdx){
|
||||
mol->setProp("maxAttachIdx",maxAttachIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// loops through the sidechain molecules and calls
|
||||
// _markAttachmentPoints()_ on each.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains,char frontMarker){
|
||||
PRECONDITION(sidechains,"bad sidechain list");
|
||||
RWMOL_SPTR_VECT::iterator mpvI;
|
||||
for(mpvI=sidechains->begin();mpvI!=sidechains->end();mpvI++){
|
||||
markAttachmentPoints(*mpvI,frontMarker);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Enumerates the library around a template and returns the result.
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *templateMol,
|
||||
VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains){
|
||||
PRECONDITION(templateMol,"bad molecule");
|
||||
RWMOL_SPTR_VECT res,tmp;
|
||||
res.push_back(RWMOL_SPTR(new RWMol(*templateMol)));
|
||||
|
||||
// if there's no attachment point on the molecule or no
|
||||
// sidechains, return now:
|
||||
if(!templateMol->hasProp("maxAttachIdx") || sidechains.size()==0 )
|
||||
return res;
|
||||
|
||||
int maxIdx;
|
||||
templateMol->getProp("maxAttachIdx",maxIdx);
|
||||
|
||||
tmp.clear();
|
||||
// loop over the sidechains and attach them
|
||||
for(unsigned int i=0;i<sidechains.size();i++){
|
||||
int tgtMark=CONNECT_BOOKMARK_START+i;
|
||||
// here's another boundary condition
|
||||
if(tgtMark>maxIdx) break;
|
||||
|
||||
/// loop over all atoms with the appropriate mark
|
||||
// This means that if a mol has two attachment points with the
|
||||
// same name (e.g. two Xa's) they'll always have the same
|
||||
// sidechain attached to them. This is a feature.
|
||||
RWMOL_SPTR_VECT::iterator sidechainIt;
|
||||
for(sidechainIt=sidechains[i].begin();
|
||||
sidechainIt!=sidechains[i].end();
|
||||
sidechainIt++){
|
||||
// we've got our sidechain, find the atom it attaches from
|
||||
if( (*sidechainIt)->hasAtomBookmark(CONNECT_BOOKMARK_START) ){
|
||||
//
|
||||
// NOTE: If there's more than one marked atom in the sidechain,
|
||||
/// we'll only use the first for the moment.
|
||||
//
|
||||
int sidechainAtomIdx = (*sidechainIt)->getAtomWithBookmark(CONNECT_BOOKMARK_START)->getIdx();
|
||||
|
||||
// now add the sidechain to each molecule
|
||||
RWMOL_SPTR_VECT::iterator templMolIt;
|
||||
// loop over all the mols we've generated to this point
|
||||
for(templMolIt=res.begin();templMolIt!=res.end();templMolIt++){
|
||||
RWMol *templ = new RWMol(**templMolIt);
|
||||
std::string name,tmpStr;
|
||||
if(templ->hasProp("_Name")){
|
||||
templ->getProp("_Name",tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
while(templ->hasAtomBookmark(tgtMark)){
|
||||
// this is the atom we'll be replacing in the template
|
||||
Atom *at = templ->getAtomWithBookmark(tgtMark);
|
||||
|
||||
// copy and transform the sidechain:
|
||||
RWMol *sidechain;
|
||||
if(orientSidechains){
|
||||
sidechain = new RWMol(*(sidechainIt->get()));
|
||||
orientSidechain(templ,sidechain,
|
||||
at->getIdx(),sidechainAtomIdx);
|
||||
} else {
|
||||
sidechain = sidechainIt->get();
|
||||
}
|
||||
// FIX: need to use the actual bond order here:
|
||||
molAddSidechain(templ,sidechain,
|
||||
at->getIdx(),sidechainAtomIdx,
|
||||
Bond::SINGLE);
|
||||
if(sidechain->hasProp("_Name")){
|
||||
sidechain->getProp("_Name",tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
templ->clearAtomBookmark(tgtMark,at);
|
||||
if(orientSidechains){
|
||||
delete sidechain;
|
||||
}
|
||||
}
|
||||
//std::cout << templ << "> " << MolToSmiles(*templ) << std::endl;
|
||||
if(name != "") templ->setProp("_Name",name);
|
||||
tmp.push_back(RWMOL_SPTR(templ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if we just made any molecules, free up the memory used by the
|
||||
// existing result set and move the molecules we just generated
|
||||
// over
|
||||
if(tmp.size()){
|
||||
#if 0
|
||||
RWMOL_SPTR_VECT::iterator tmpMolIt;
|
||||
for(tmpMolIt=res.begin();tmpMolIt!=res.end();tmpMolIt++){
|
||||
delete *tmpMolIt;
|
||||
}
|
||||
#endif
|
||||
res = tmp;
|
||||
tmp.clear();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Reads a template and library of sidechains from input files.
|
||||
// the template file should be a mol file and the sidechain files
|
||||
// SD files
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainNames){
|
||||
PRECONDITION(templateName,"bad template file name passed in");
|
||||
|
||||
// build and mark the template molecule
|
||||
RWMol *templ = MolFileToMol(templateName,false);
|
||||
if(!templ) throw EnumException("could not construct template molecule");
|
||||
markAttachmentPoints(templ,'X');
|
||||
|
||||
// now build and mark each set of sidechains:
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
VECT_RWMOL_SPTR_VECT allSidechains;
|
||||
for(std::vector<const char*>::const_iterator i=sidechainNames.begin();
|
||||
i!=sidechainNames.end();i++){
|
||||
sidechains = SDFileToMols(*i,false);
|
||||
if(!sidechains.size()){
|
||||
std::string err="no sidechains read from file: ";
|
||||
err += *i;
|
||||
throw EnumException(err.c_str());
|
||||
}
|
||||
prepareSidechains(&sidechains,'X');
|
||||
allSidechains.push_back(sidechains);
|
||||
}
|
||||
|
||||
// enumerate the library:
|
||||
RWMOL_SPTR_VECT library=enumerateLibrary(templ,allSidechains);
|
||||
|
||||
|
||||
//--------------------------
|
||||
//
|
||||
// Clean up the molecules and sidechains we constructed along the
|
||||
// way.
|
||||
//
|
||||
//--------------------------
|
||||
delete templ;
|
||||
#if 0
|
||||
VECT_RWMOL_SPTR_VECT::iterator vmpvI;
|
||||
for(vmpvI=allSidechains.begin();vmpvI!=allSidechains.end();vmpvI++){
|
||||
RWMOL_SPTR_VECT::iterator mpvI;
|
||||
for(mpvI=vmpvI->begin();mpvI!=vmpvI->end();mpvI++){
|
||||
delete *mpvI;
|
||||
}
|
||||
vmpvI->clear();
|
||||
}
|
||||
#endif
|
||||
allSidechains.clear();
|
||||
|
||||
return library;
|
||||
}
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
|
||||
20
Code/Demos/RDKit/TemplEnum/Ts.1.sdf
Executable file
20
Code/Demos/RDKit/TemplEnum/Ts.1.sdf
Executable file
@@ -0,0 +1,20 @@
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (3)
|
||||
Lig1
|
||||
|
||||
$$$$
|
||||
20
Code/Demos/RDKit/TemplEnum/Ts.4.sdf
Normal file
20
Code/Demos/RDKit/TemplEnum/Ts.4.sdf
Normal file
@@ -0,0 +1,20 @@
|
||||
Structure4
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (6)
|
||||
Lig4
|
||||
|
||||
$$$$
|
||||
80
Code/Demos/RDKit/TemplEnum/Ts.sdf
Executable file
80
Code/Demos/RDKit/TemplEnum/Ts.sdf
Executable file
@@ -0,0 +1,80 @@
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (3)
|
||||
Lig1
|
||||
|
||||
$$$$
|
||||
Structure2
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (4)
|
||||
Lig2
|
||||
|
||||
$$$$
|
||||
Structure3
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (5)
|
||||
Lig3
|
||||
|
||||
$$$$
|
||||
Structure4
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -1.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
1 3 1 0 0 0 0
|
||||
1 4 1 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (6)
|
||||
Lig4
|
||||
|
||||
$$$$
|
||||
17
Code/Demos/RDKit/TemplEnum/box.1.mol
Executable file
17
Code/Demos/RDKit/TemplEnum/box.1.mol
Executable file
@@ -0,0 +1,17 @@
|
||||
box.mol
|
||||
ChemDraw05280309452D
|
||||
|
||||
5 5 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.5000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0
|
||||
2 3 1 0
|
||||
3 4 1 0
|
||||
4 1 1 0
|
||||
2 5 1 0
|
||||
A 5
|
||||
Xa
|
||||
M END
|
||||
17
Code/Demos/RDKit/TemplEnum/box.1a.mol
Executable file
17
Code/Demos/RDKit/TemplEnum/box.1a.mol
Executable file
@@ -0,0 +1,17 @@
|
||||
box.mol
|
||||
ChemDraw05280309452D
|
||||
|
||||
5 5 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0
|
||||
2 3 1 0
|
||||
3 4 1 0
|
||||
4 1 1 0
|
||||
2 5 1 0
|
||||
A 5
|
||||
Xa
|
||||
M END
|
||||
29
Code/Demos/RDKit/TemplEnum/box.mol
Executable file
29
Code/Demos/RDKit/TemplEnum/box.mol
Executable file
@@ -0,0 +1,29 @@
|
||||
box.mol
|
||||
ChemDraw05280309452D
|
||||
|
||||
8 8 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.5000 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.5000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.5000 -1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.5000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0
|
||||
2 3 1 0
|
||||
3 4 1 0
|
||||
4 1 1 0
|
||||
1 5 1 0
|
||||
4 6 1 0
|
||||
3 7 1 0
|
||||
2 8 1 0
|
||||
A 5
|
||||
Xa
|
||||
A 6
|
||||
Xa
|
||||
A 7
|
||||
Xa
|
||||
A 8
|
||||
Xa
|
||||
M END
|
||||
42
Code/Demos/RDKit/TemplEnum/esters.2.sdf
Executable file
42
Code/Demos/RDKit/TemplEnum/esters.2.sdf
Executable file
@@ -0,0 +1,42 @@
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (3)
|
||||
Lig1
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
6 5 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 0.6988 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (4)
|
||||
Lig2
|
||||
|
||||
$$$$
|
||||
142
Code/Demos/RDKit/TemplEnum/esters.sdf
Executable file
142
Code/Demos/RDKit/TemplEnum/esters.sdf
Executable file
@@ -0,0 +1,142 @@
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
5 4 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (3)
|
||||
Lig1
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
6 5 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 0.6988 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (4)
|
||||
Lig2
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
7 6 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 1.3977 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.0977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 1.3977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 3.4977 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 2.0977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 2.0965 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
3 7 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (5)
|
||||
Lig3
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
7 6 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 0.6988 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
6.0581 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
6 7 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (6)
|
||||
Lig4
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
8 7 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 1.3977 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.0977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 1.3977 0.0000 C 0 0 3 0 0 0 0 0 0 0 0 0
|
||||
2.4249 3.4977 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 2.0977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 2.0965 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
6.0581 1.3977 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
6 7 1 0 0 0 0
|
||||
3 8 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (7)
|
||||
Lig5
|
||||
|
||||
$$$$
|
||||
Structure1
|
||||
csChFnd70/05230312262D
|
||||
|
||||
8 7 0 0 0 0 0 0 0 0999 V2000
|
||||
1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 0.6988 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
6.0581 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
4.8477 2.0965 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 1 0 0 0 0
|
||||
2 3 1 0 0 0 0
|
||||
2 4 2 0 0 0 0
|
||||
1 5 1 0 0 0 0
|
||||
3 6 1 0 0 0 0
|
||||
6 7 1 0 0 0 0
|
||||
6 8 1 0 0 0 0
|
||||
A 5
|
||||
X
|
||||
M END
|
||||
> <ID> (8)
|
||||
Lig6
|
||||
|
||||
$$$$
|
||||
443
Code/Demos/RDKit/TemplEnum/main.cpp
Executable file
443
Code/Demos/RDKit/TemplEnum/main.cpp
Executable file
@@ -0,0 +1,443 @@
|
||||
// $Id: main.cpp 4421 2005-02-09 16:55:05Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2003-2004 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
#include "TemplEnum.h"
|
||||
#include <GraphMol/SmilesParse/SmilesParse.h>
|
||||
#include <GraphMol/SmilesParse/SmilesWrite.h>
|
||||
#include <GraphMol/FileParsers/FileParsers.h>
|
||||
|
||||
using namespace RDKit;
|
||||
using namespace TemplateEnum;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
bool feq(double v1,double v2,double tol=1e-4){
|
||||
return fabs(v1-v2)<=tol;
|
||||
}
|
||||
bool feq(RDGeom::Point3D p1,RDGeom::Point3D p2,double tol=1e-4){
|
||||
return feq(p1.x,p2.x,tol)&&feq(p1.y,p2.y,tol)&&feq(p1.z,p2.z,tol);
|
||||
}
|
||||
|
||||
void test1(){
|
||||
// single attachment point, small list
|
||||
std::cout << " ----------> Test1 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.1.mol",fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==2,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void test2(){
|
||||
// single attachment point, larger list
|
||||
std::cout << " ----------> Test2 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
fileNames.push_back("esters.sdf");
|
||||
fileNames.push_back("esters.sdf");
|
||||
library = enumFromFiles("template.1.mol",fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==6,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms()==13,"");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test3(){
|
||||
// two attachment points, small list
|
||||
std::cout << " ----------> Test3 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.mol",fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==15,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==15,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==16,"");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test4(){
|
||||
// test templates that have repeated attachment points
|
||||
std::cout << " ----------> Test4 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.2.mol",fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==2,"");
|
||||
library[0]->debugMol(std::cout);
|
||||
std::cout << "smi0: " << MolToSmiles(*library[0],0) << std::endl;
|
||||
std::cout << "smi1: " << MolToSmiles(*library[1],0) << std::endl;
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==16,"");
|
||||
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test5(){
|
||||
// test working from SMILES
|
||||
std::cout << " ----------> Test5 " << std::endl;
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC",0,0);
|
||||
CHECK_INVARIANT(m1,"");
|
||||
markAttachmentPoints(m1,'X');
|
||||
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)C",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)CCC",0,0)));
|
||||
prepareSidechains(&sidechains,'X');
|
||||
|
||||
VECT_RWMOL_SPTR_VECT allSideChains;
|
||||
allSideChains.push_back(sidechains);
|
||||
allSideChains.push_back(sidechains);
|
||||
|
||||
RWMOL_SPTR_VECT library;
|
||||
library = enumerateLibrary(m1,allSideChains,false);
|
||||
|
||||
CHECK_INVARIANT(library.size()==9,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[6]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[7]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[8]->getNumAtoms()==16,"");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test6(){
|
||||
// test working from SMILES with no matches
|
||||
std::cout << " ----------> Test6 " << std::endl;
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC",0,0);
|
||||
CHECK_INVARIANT(m1,"");
|
||||
markAttachmentPoints(m1,'X');
|
||||
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)C",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)CCC",0,0)));
|
||||
prepareSidechains(&sidechains,'X');
|
||||
|
||||
VECT_RWMOL_SPTR_VECT allSideChains;
|
||||
allSideChains.push_back(sidechains);
|
||||
allSideChains.push_back(sidechains);
|
||||
|
||||
RWMOL_SPTR_VECT library;
|
||||
library = enumerateLibrary(m1,allSideChains,false);
|
||||
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==6,"");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test7(){
|
||||
// test transforms
|
||||
std::cout << " ----------> Test7 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
RWMOL_SPTR mol;
|
||||
Atom *at1,*at2;
|
||||
int i;
|
||||
std::vector<const char *>fileNames;
|
||||
fileNames.push_back("Ts.1.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
mol = library[0];
|
||||
at1=mol->getAtomWithIdx(0);
|
||||
at2=mol->getAtomWithIdx(4);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(at1->getPos().y-at2->getPos().y==-1.0,"");
|
||||
library.clear();
|
||||
|
||||
// try another orientation of the sidechain molecule:
|
||||
fileNames.clear();
|
||||
fileNames.push_back("Ts.4.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
mol = library[0];
|
||||
std::cout << MolToMolBlock(mol.get());
|
||||
std::cout << std::endl;
|
||||
|
||||
at1=mol->getAtomWithIdx(0);
|
||||
at2=mol->getAtomWithIdx(7);
|
||||
TEST_ASSERT(feq(mol->getAtomWithIdx(7)->getPos(),RDGeom::Point3D(-.5,2.5,0.0)));
|
||||
library.clear();
|
||||
|
||||
|
||||
// now use an SD file that has the same molecule in different
|
||||
// orientations as sidechains:
|
||||
fileNames.clear();
|
||||
fileNames.push_back("Ts.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==8,"");
|
||||
|
||||
for(i=0;i<library.size();i++){
|
||||
std::cout << "------ Mol: " << i << "------" << std::endl;
|
||||
mol = library[i];
|
||||
std::cout << MolToMolBlock(mol.get());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
at1 = library[0]->getAtomWithIdx(i);
|
||||
at2 = library[1]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[2]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[3]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos(),at2->getPos()),"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
// move the attachment point on the template. This should
|
||||
// make no difference.
|
||||
library = enumFromFiles("box.1a.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==8,"");
|
||||
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
at1 = library[0]->getAtomWithIdx(i);
|
||||
|
||||
at2 = library[1]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[2]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[3]->getAtomWithIdx(i);
|
||||
//std::cout << i << "\t" << at1->getPos() << std::endl;
|
||||
//std::cout << "\t" << at2->getPos() << std::endl;
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
// move the attachment point on the template. This should
|
||||
// make no difference.
|
||||
library = enumFromFiles("box.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==20,"");
|
||||
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
at1 = library[0]->getAtomWithIdx(i);
|
||||
|
||||
at2 = library[1]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[2]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
|
||||
at2 = library[3]->getAtomWithIdx(i);
|
||||
CHECK_INVARIANT(feq(at1->getPos().x,at2->getPos().x),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().y,at2->getPos().y),"");
|
||||
CHECK_INVARIANT(feq(at1->getPos().z,at2->getPos().z),"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
|
||||
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void testCoords(){
|
||||
std::cout << " ----------> Test Coords " << std::endl;
|
||||
RWMol *m1 = SmilesToMol("[Xa]C",0,0);
|
||||
CHECK_INVARIANT(m1,"");
|
||||
m1->getAtomWithIdx(1)->setPos(0,0,0);
|
||||
m1->getAtomWithIdx(0)->setPos(0.0,1.5,0.0);
|
||||
|
||||
RWMol *m2 = SmilesToMol("[X]C(C)(C)C",0,0);
|
||||
TEST_ASSERT(m2);
|
||||
m2->getAtomWithIdx(0)->setPos(3.0,1,1);
|
||||
m2->getAtomWithIdx(1)->setPos(1.5,1,1);
|
||||
m2->getAtomWithIdx(2)->setPos(0.0,1,1);
|
||||
m2->getAtomWithIdx(3)->setPos(1.5,2.5,1);
|
||||
m2->getAtomWithIdx(4)->setPos(1.5,1,2.5);
|
||||
|
||||
orientSidechain(m1,m2,0,0);
|
||||
std::cout << "Atoms:" << std::endl;
|
||||
for(int i=0;i<m2->getNumAtoms();i++){
|
||||
std::cout << i << " " << m2->getAtomWithIdx(i)->getPos() << std::endl;
|
||||
}
|
||||
|
||||
TEST_ASSERT(feq(m1->getAtomWithIdx(0)->getPos(),
|
||||
m2->getAtomWithIdx(1)->getPos()));
|
||||
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(0)->getPos(),
|
||||
RDGeom::Point3D(0,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(1)->getPos(),
|
||||
RDGeom::Point3D(0,1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(2)->getPos(),
|
||||
RDGeom::Point3D(0,3.0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(3)->getPos(),
|
||||
RDGeom::Point3D(1.5,1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(4)->getPos(),
|
||||
RDGeom::Point3D(0,1.5,1.5)));
|
||||
|
||||
// ---------------------------------------------------
|
||||
std::cout << "-*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl;
|
||||
m1->getAtomWithIdx(1)->setPos(0,0,0);
|
||||
m1->getAtomWithIdx(0)->setPos(0.0,-1.5,0.0);
|
||||
m2->getAtomWithIdx(0)->setPos(3.0,1,1);
|
||||
m2->getAtomWithIdx(1)->setPos(1.5,1,1);
|
||||
m2->getAtomWithIdx(2)->setPos(0.0,1,1);
|
||||
m2->getAtomWithIdx(3)->setPos(1.5,2.5,1);
|
||||
m2->getAtomWithIdx(4)->setPos(1.5,1,2.5);
|
||||
|
||||
orientSidechain(m1,m2,0,0);
|
||||
std::cout << "Atoms:" << std::endl;
|
||||
for(int i=0;i<m2->getNumAtoms();i++){
|
||||
std::cout << i << " " << m2->getAtomWithIdx(i)->getPos() << std::endl;
|
||||
}
|
||||
TEST_ASSERT(feq(m1->getAtomWithIdx(0)->getPos(),
|
||||
m2->getAtomWithIdx(1)->getPos()));
|
||||
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(0)->getPos(),
|
||||
RDGeom::Point3D(0,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(1)->getPos(),
|
||||
RDGeom::Point3D(0,-1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(2)->getPos(),
|
||||
RDGeom::Point3D(0,-3.0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(3)->getPos(),
|
||||
RDGeom::Point3D(-1.5,-1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(4)->getPos(),
|
||||
RDGeom::Point3D(0,-1.5,1.5)));
|
||||
|
||||
// ---------------------------------------------------
|
||||
std::cout << "-*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl;
|
||||
m1->getAtomWithIdx(1)->setPos(1,0,0);
|
||||
m1->getAtomWithIdx(0)->setPos(1.0,-1.5,0);
|
||||
m2->getAtomWithIdx(0)->setPos(3.0,1,1);
|
||||
m2->getAtomWithIdx(1)->setPos(1.5,1,1);
|
||||
m2->getAtomWithIdx(2)->setPos(0.0,1,1);
|
||||
m2->getAtomWithIdx(3)->setPos(1.5,2.5,1);
|
||||
m2->getAtomWithIdx(4)->setPos(1.5,1,2.5);
|
||||
|
||||
orientSidechain(m1,m2,0,0);
|
||||
std::cout << "Atoms:" << std::endl;
|
||||
for(int i=0;i<m2->getNumAtoms();i++){
|
||||
std::cout << i << " " << m2->getAtomWithIdx(i)->getPos() << std::endl;
|
||||
}
|
||||
TEST_ASSERT(feq(m1->getAtomWithIdx(0)->getPos(),
|
||||
m2->getAtomWithIdx(1)->getPos()));
|
||||
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(0)->getPos(),
|
||||
RDGeom::Point3D(1,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(1)->getPos(),
|
||||
RDGeom::Point3D(1,-1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(2)->getPos(),
|
||||
RDGeom::Point3D(1,-3.0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(3)->getPos(),
|
||||
RDGeom::Point3D(-0.5,-1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(4)->getPos(),
|
||||
RDGeom::Point3D(1,-1.5,1.5)));
|
||||
|
||||
// ---------------------------------------------------
|
||||
std::cout << "-*-*-*-*-*-*-*-*-*-*-*-*-" << std::endl;
|
||||
m1->getAtomWithIdx(1)->setPos(3.0,0,0);
|
||||
m1->getAtomWithIdx(0)->setPos(1.5,0.0,0.0);
|
||||
m2->getAtomWithIdx(0)->setPos(3.0,1,1);
|
||||
m2->getAtomWithIdx(1)->setPos(1.5,1,1);
|
||||
m2->getAtomWithIdx(2)->setPos(0.0,1,1);
|
||||
m2->getAtomWithIdx(3)->setPos(1.5,2.5,1);
|
||||
m2->getAtomWithIdx(4)->setPos(1.5,1,2.5);
|
||||
|
||||
orientSidechain(m1,m2,0,0);
|
||||
std::cout << "Atoms:" << std::endl;
|
||||
for(int i=0;i<m2->getNumAtoms();i++){
|
||||
std::cout << i << " " << m2->getAtomWithIdx(i)->getPos() << std::endl;
|
||||
}
|
||||
TEST_ASSERT(feq(m1->getAtomWithIdx(0)->getPos(),
|
||||
m2->getAtomWithIdx(1)->getPos()));
|
||||
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(0)->getPos(),
|
||||
RDGeom::Point3D(3,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(1)->getPos(),
|
||||
RDGeom::Point3D(1.5,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(2)->getPos(),
|
||||
RDGeom::Point3D(0,0,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(3)->getPos(),
|
||||
RDGeom::Point3D(1.5,1.5,0)));
|
||||
TEST_ASSERT(feq(m2->getAtomWithIdx(4)->getPos(),
|
||||
RDGeom::Point3D(1.5,0,1.5)));
|
||||
|
||||
|
||||
delete m1;
|
||||
delete m2;
|
||||
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
#if 1
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
//test4();
|
||||
test5();
|
||||
test6();
|
||||
#endif
|
||||
test7();
|
||||
testCoords();
|
||||
}
|
||||
42
Code/Demos/RDKit/TemplEnum/simple.cpp
Executable file
42
Code/Demos/RDKit/TemplEnum/simple.cpp
Executable file
@@ -0,0 +1,42 @@
|
||||
// $Id: simple.cpp 4421 2005-02-09 16:55:05Z glandrum $
|
||||
//
|
||||
// Copyright (C) 2004 Rational Discovery LLC
|
||||
// All Rights Reserved
|
||||
//
|
||||
#include "TemplEnum.h"
|
||||
#include <GraphMol/FileParsers/FileParsers.h>
|
||||
|
||||
using namespace RDKit;
|
||||
using namespace TemplateEnum;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
bool feq(double v1,double v2,double tol=1e-4){
|
||||
return fabs(v1-v2)<=tol;
|
||||
}
|
||||
bool feq(RDGeom::Point3D p1,RDGeom::Point3D p2,double tol=1e-4){
|
||||
return feq(p1.x,p2.x,tol)&&feq(p1.y,p2.y,tol)&&feq(p1.z,p2.z,tol);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,const char *argv[]){
|
||||
if(argc<3){
|
||||
std::cerr << " Usage: simple.exe <template.mol> [attach1.sdf, attach2.sdf, ...]" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
std::vector<const char *>fileNames;
|
||||
for(int i=2;i<argc;i++){
|
||||
fileNames.push_back( argv[i] );
|
||||
}
|
||||
RWMOL_SPTR_VECT library=enumFromFiles(argv[1],fileNames);
|
||||
|
||||
std::cerr << "Created: " << library.size() << " compounds." << std::endl;
|
||||
for(int i=0;i<library.size();i++){
|
||||
RWMOL_SPTR mol = library[i];
|
||||
std::cout << MolToMolBlock(mol.get(),false);
|
||||
std::cout << "$$$$" << std::endl;
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
}
|
||||
160
Code/Demos/RDKit/TemplEnum/simpleEnum.vcproj
Normal file
160
Code/Demos/RDKit/TemplEnum/simpleEnum.vcproj
Normal file
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="demo - simpleEnum"
|
||||
ProjectGUID="{F0680DF9-9AC4-4B9A-A95A-BAC39A15FC4F}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),.,$(RDBASE)/code,$(RDBASE)/code/graphmol"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/simpleEnum.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="./testExecs/simpleEnum.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
ProgramDatabaseFile=".\Release/simpleEnum.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/simpleEnum.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\simpleEnum___Win32_Debug"
|
||||
IntermediateDirectory=".\simpleEnum___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),.,$(RDBASE)/code,$(RDBASE)/code/graphmol"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\simpleEnum___Win32_Debug/simpleEnum.pch"
|
||||
AssemblerListingLocation=".\simpleEnum___Win32_Debug/"
|
||||
ObjectFile=".\simpleEnum___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\simpleEnum___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="./testExecs/simpleEnum.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\simpleEnum___Win32_Debug/simpleEnum.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\simpleEnum___Win32_Debug/simpleEnum.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\simple.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TemplEnumTools.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath=".\TemplEnum.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
21
Code/Demos/RDKit/TemplEnum/template.1.mol
Executable file
21
Code/Demos/RDKit/TemplEnum/template.1.mol
Executable file
@@ -0,0 +1,21 @@
|
||||
template.mol
|
||||
ChemDraw05230310522D
|
||||
|
||||
7 7 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.4289 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 2 0
|
||||
2 3 1 0
|
||||
3 4 2 0
|
||||
4 5 1 0
|
||||
5 6 2 0
|
||||
6 1 1 0
|
||||
1 7 1 0
|
||||
A 7
|
||||
Xa
|
||||
M END
|
||||
25
Code/Demos/RDKit/TemplEnum/template.2.mol
Executable file
25
Code/Demos/RDKit/TemplEnum/template.2.mol
Executable file
@@ -0,0 +1,25 @@
|
||||
template.mol
|
||||
ChemDraw05230310522D
|
||||
|
||||
8 8 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.4289 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.4289 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 2 0
|
||||
2 3 1 0
|
||||
3 4 2 0
|
||||
4 5 1 0
|
||||
5 6 2 0
|
||||
6 1 1 0
|
||||
1 7 1 0
|
||||
5 8 1 0
|
||||
A 7
|
||||
Xa
|
||||
A 8
|
||||
Xa
|
||||
M END
|
||||
25
Code/Demos/RDKit/TemplEnum/template.mol
Executable file
25
Code/Demos/RDKit/TemplEnum/template.mol
Executable file
@@ -0,0 +1,25 @@
|
||||
template.mol
|
||||
ChemDraw05230310522D
|
||||
|
||||
8 8 0 0 0 0 0 0 0 0999 V2000
|
||||
-0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 -0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 -0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.7145 0.4125 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
0.0000 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
-1.4289 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1.4289 0.8250 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
1 2 2 0
|
||||
2 3 1 0
|
||||
3 4 2 0
|
||||
4 5 1 0
|
||||
5 6 2 0
|
||||
6 1 1 0
|
||||
1 7 1 0
|
||||
5 8 1 0
|
||||
A 7
|
||||
Xa
|
||||
A 8
|
||||
Xb
|
||||
M END
|
||||
164
Code/Demos/RDKit/TemplEnum/testTemplateEnum.vcproj
Normal file
164
Code/Demos/RDKit/TemplEnum/testTemplateEnum.vcproj
Normal file
@@ -0,0 +1,164 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="testTemplateEnum"
|
||||
ProjectGUID="{C89F425E-5244-4D8D-AEDA-C90537B3D0A9}"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory=".\testExecs\"
|
||||
IntermediateDirectory=".\Release"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
InlineFunctionExpansion="1"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),.,$(RDBASE)/code,$(RDBASE)/code/graphmol"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
EnableFunctionLevelLinking="TRUE"
|
||||
PrecompiledHeaderFile=".\Release/testTemplateEnum.pch"
|
||||
AssemblerListingLocation=".\Release/"
|
||||
ObjectFile=".\Release/"
|
||||
ProgramDataBaseFileName=".\Release/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-$(BOOSTVERSION).lib "
|
||||
OutputFile="./testExecs/testTemplateEnum.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
ProgramDatabaseFile=".\Release/testTemplateEnum.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\Release/testTemplateEnum.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="NDEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory=".\testTemplateEnum___Win32_Debug"
|
||||
IntermediateDirectory=".\testTemplateEnum___Win32_Debug"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="0"
|
||||
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="$(RDBASE)/External/boost/include/$(BOOSTBASE),.,$(RDBASE)/code,$(RDBASE)/code/graphmol"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
PrecompiledHeaderFile=".\testTemplateEnum___Win32_Debug/testTemplateEnum.pch"
|
||||
AssemblerListingLocation=".\testTemplateEnum___Win32_Debug/"
|
||||
ObjectFile=".\testTemplateEnum___Win32_Debug/"
|
||||
ProgramDataBaseFileName=".\testTemplateEnum___Win32_Debug/"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="boost_log-vc71-mt-gd-$(BOOSTVERSION).lib "
|
||||
OutputFile="./testExecs/testTemplateEnum.exe"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="$(RDBASE)\External\boost\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile=".\testTemplateEnum___Win32_Debug/testTemplateEnum.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TypeLibraryName=".\testTemplateEnum___Win32_Debug/testTemplateEnum.tlb"
|
||||
HeaderFileName=""/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
PreprocessorDefinitions="_DEBUG"
|
||||
Culture="1033"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
|
||||
<File
|
||||
RelativePath=".\main.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\TemplEnumTools.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl">
|
||||
<File
|
||||
RelativePath=".\TemplEnum.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user