/usr/include/rdkit/GraphMol/RankAtoms.h is in librdkit-dev 201309-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | //
// Copyright (C) 2004-2008 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
//! \file RankAtoms.h
/*!
\brief Utility functionality used by atom rankers.
*/
#ifndef _RD_RANKATOMS_H_
#define _RD_RANKATOMS_H_
#include <queue>
#include <vector>
#include <list>
#include <algorithm>
#include <boost/foreach.hpp>
namespace RankAtoms {
typedef std::vector<int> INT_VECT;
typedef std::list<int> INT_LIST;
//! utility function for ranking atoms
void updateInPlayIndices(const INT_VECT &ranks,INT_LIST &indicesInPlay);
//! returns the count of unique items in an std::vector
template <typename T>
unsigned int countClasses(const std::vector<T> &vect){
std::vector<T> sortedVect = vect;
std::sort(sortedVect.begin(),sortedVect.end(),std::less<T>());
typename std::vector<T>::iterator newEnd=std::unique(sortedVect.begin(),sortedVect.end());
return newEnd-sortedVect.begin();
}
//! functor for implementing > on two std::pairs. The first entries are compared.
template <typename T>
struct pairGTFunctor {
bool operator() (const std::pair<T,int> &v1,const std::pair<T,int> &v2){
return v1.first > v2.first;
}
};
//! function for implementing < on two std::pairs. The first entries are compared.
template <typename T>
bool pairLess(const std::pair<T,int> &v1,const std::pair<T,int> &v2){
return v1.first < v2.first;
}
template <typename T>
class argless {
public:
argless(const T& c) : container(c) {};
bool operator() (unsigned int v1,unsigned int v2){
return container[v1]<container[v2];
}
const T &container;
};
//! ranks the entries in a vector
/*!
\param vect the vector to rank
\param res is used to return the ranks of each entry
*/
template <typename T>
void rankVect(const std::vector<T> &vect,INT_VECT &res){
PRECONDITION(res.size()>=vect.size(),"vector size mismatch");
unsigned int nEntries = vect.size();
std::vector< unsigned int > indices(nEntries);
for(unsigned int i=0;i<nEntries;++i) indices[i]=i;
std::sort(indices.begin(),indices.end(),argless< std::vector<T> >(vect) );
int currRank=0;
T lastV = vect[indices[0]];
BOOST_FOREACH(unsigned int idx,indices){
T v = vect[idx];
if(v==lastV){
res[idx] = currRank;
} else {
res[idx] = ++currRank;
lastV = v;
}
}
}
//! finds the relative rankings of the entries in \c vals.
/*!
\param nAtoms the number of points in play
\param vals the values to be ranked
\param indicesInPlay a list containing the indices that
are being considered (only those entries in \c ranks
that appear in \c indicesInPlay will be modified)
\param ranks the current ranks of entries, this is updated
with new ranks
*/
template <typename T>
void sortAndRankVect(unsigned int nAtoms,
const std::vector<T> &vals,
const INT_LIST &indicesInPlay,
INT_VECT &ranks) {
// --------------
//
// start by getting the internal ranking of the values passed in
//
// --------------
INT_VECT newRanks(vals.size());
rankVect(vals,newRanks);
// --------------
//
// At the end of this operation, ranks will contain the ranks
// of atoms that are no longer active (-1 for active atoms).
//
// --------------
BOOST_FOREACH(int idx,indicesInPlay){
ranks[idx] = -1;
}
INT_VECT idxVect;
idxVect.assign(indicesInPlay.begin(),indicesInPlay.end());
// -------------
//
// Loop over all the new ranks. We'll know that we're done
// when currNewRank > maxNewRank
//
// -------------
int currNewRank= *(std::min_element(newRanks.begin(),newRanks.end()));
int maxNewRank = *(std::max_element(newRanks.begin(),newRanks.end()));
while(currNewRank<=maxNewRank){
//
// If this rank is already present in ranks, increment
// this rank and all new ranks that are higher:
//
while(std::find(ranks.begin(),ranks.end(),currNewRank)!=ranks.end()){
BOOST_FOREACH(int &rank,newRanks){
if(rank>=currNewRank)
++rank;
}
// increment both the current rank *and* the maximum new rank
++currNewRank;
++maxNewRank;
}
//
// now grab all entries with this new rank and copy them into
// the ranks list
//
INT_VECT::iterator ivIt=std::find(newRanks.begin(),newRanks.end(),currNewRank);
while(ivIt!=newRanks.end()){
int offset=ivIt-newRanks.begin();
int idx = idxVect[offset];
ranks[idx] = currNewRank;
++ivIt;
ivIt=std::find(ivIt,newRanks.end(),currNewRank);
}
++currNewRank;
}
}
template <typename T>
void sortAndRankVect2(const std::vector<std::vector<T> > &vals,
const INT_LIST &indicesInPlay,
INT_VECT &ranks) {
// --------------
//
// start by getting the internal ranking of the values passed in
//
// --------------
INT_VECT newRanks(vals.size());
rankVect(vals,newRanks);
// --------------
//
// At the end of this operation, ranks will contain the ranks
// of atoms that are no longer active (-1 for active atoms).
//
// --------------
BOOST_FOREACH(int idx,indicesInPlay){
ranks[idx] = newRanks[idx];
}
return;
INT_VECT idxVect;
idxVect.assign(indicesInPlay.begin(),indicesInPlay.end());
// -------------
//
// Loop over all the new ranks. We'll know that we're done
// when currNewRank > maxNewRank
//
// -------------
int currNewRank= *(std::min_element(newRanks.begin(),newRanks.end()));
int maxNewRank = *(std::max_element(newRanks.begin(),newRanks.end()));
while(currNewRank<=maxNewRank){
//
// If this rank is already present in ranks, increment
// this rank and all new ranks that are higher:
//
while(std::find(ranks.begin(),ranks.end(),currNewRank)!=ranks.end()){
BOOST_FOREACH(int &rank,newRanks){
if(rank>=currNewRank)
++rank;
}
// increment both the current rank *and* the maximum new rank
++currNewRank;
++maxNewRank;
}
//
// now grab all entries with this new rank and copy them into
// the ranks list
//
INT_VECT::iterator ivIt=std::find(newRanks.begin(),newRanks.end(),currNewRank);
while(ivIt!=newRanks.end()){
int offset=ivIt-newRanks.begin();
int idx = idxVect[offset];
ranks[idx] = currNewRank;
++ivIt;
ivIt=std::find(ivIt,newRanks.end(),currNewRank);
}
++currNewRank;
}
}
}
#endif
|