Open Babel  3.0
isomorphism.h
Go to the documentation of this file.
1 /**********************************************************************
2  isomophism.h - OBIsomorphismMapper class for finding isomorphisms.
3 
4  Copyright (C) 2010 by Tim Vandermeersch
5 
6  This file is part of the Open Babel project.
7  For more information, see <http://openbabel.org/>
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23  **********************************************************************/
24 #ifndef OB_ISOMORPHISM_H
25 #define OB_ISOMORPHISM_H
26 
27 #include <openbabel/bitvec.h>
28 
29 namespace OpenBabel {
30 
31  class OBQuery;
32  class OBMol;
33 
36 
77  class OBAPI OBIsomorphismMapper
78  {
79  public:
84  typedef std::vector< std::pair<unsigned int,unsigned int> > Mapping;
89  typedef std::vector< Mapping > Mappings;
90 
97  virtual ~OBIsomorphismMapper();
98 
107  static OBIsomorphismMapper* GetInstance(OBQuery *query, const std::string &algorithm = std::string("VF2"));
108 
117  virtual void MapFirst(const OBMol *queried, Mapping &map, const OBBitVec &mask = OBBitVec()) = 0;
128  virtual void MapUnique(const OBMol *queried, Mappings &maps, const OBBitVec &mask = OBBitVec()) = 0;
140  virtual void MapAll(const OBMol *queried, Mappings &maps, const OBBitVec &mask = OBBitVec(), std::size_t maxMemory = 3000000) = 0;
141 
148  class Functor
149  {
150  public:
151  virtual ~Functor() {}
159  virtual bool operator()(Mapping &map) = 0;
160  };
169  virtual void MapGeneric(Functor &functor, const OBMol *queried, const OBBitVec &mask = OBBitVec()) = 0;
170 
171 
175  void SetTimeout(unsigned int seconds) { m_timeout = seconds; }
176 
177  protected:
179  unsigned int m_timeout;
180  };
181 
182  inline bool MapsTo(const OBIsomorphismMapper::Mapping &map, unsigned int queryIndex, unsigned int &queriedIndex)
183  {
184  OBIsomorphismMapper::Mapping::const_iterator i;
185  for (i = map.begin(); i != map.end(); ++i)
186  if (i->first == queryIndex) {
187  queriedIndex = i->second;
188  return true;
189  }
190 
191  return false;
192  }
193 
194 
207 
225  OBAPI bool FindAutomorphisms(OBMol *mol, std::vector<OBIsomorphismMapper::Mapping> &aut, const std::vector<unsigned int> &symmetry_classes,
226  const OBBitVec &mask = OBBitVec(), std::size_t maxMemory = 3000000);
235  OBAPI bool FindAutomorphisms(OBMol *mol, std::vector<OBIsomorphismMapper::Mapping> &aut, const OBBitVec &mask = OBBitVec(),
236  std::size_t maxMemory = 3000000);
237 
249  OBAPI void FindAutomorphisms(OBIsomorphismMapper::Functor &functor, OBMol *mol,
250  const std::vector<unsigned int> &symmetry_classes, const OBBitVec &mask = OBBitVec());
251 
366 
368 }
369 
370 #endif
371 
A substructure query.
Definition: query.h:197
Functor base class to be used in combination with MapGeneric.
Definition: isomorphism.h:148
OBIsomorphismMapper::Mappings Automorphisms
A group of automorphic permutations.
Definition: isomorphism.h:206
Molecule Class.
Definition: mol.h:118
A speed-optimized vector of bits.
Definition: bitvec.h:57
bool FindAutomorphisms(OBMol *mol, std::vector< OBIsomorphismMapper::Mapping > &aut, const std::vector< unsigned int > &symmetry_classes, const OBBitVec &mask=OBBitVec(), std::size_t maxMemory=3000000)
void SetTimeout(unsigned int seconds)
Definition: isomorphism.h:175
OBIsomorphismMapper::Mapping Automorphism
A single automorphic permutation.
Definition: isomorphism.h:200
std::vector< std::pair< unsigned int, unsigned int > > Mapping
Definition: isomorphism.h:84
bool MapsTo(const OBIsomorphismMapper::Mapping &map, unsigned int queryIndex, unsigned int &queriedIndex)
Definition: isomorphism.h:182
OBQuery * m_query
The search query.
Definition: isomorphism.h:178
unsigned int m_timeout
The timeout in seconds.
Definition: isomorphism.h:179
Abstract class defining interface for isomorphism (i.e. substructure) searches.
Definition: isomorphism.h:77
Fast and efficient bitstring class.
std::vector< Mapping > Mappings
Definition: isomorphism.h:89
virtual ~Functor()
Definition: isomorphism.h:151
Global namespace for all Open Babel code.
Definition: alias.h:22