Chemical Data Processing Library C++ API - Version 1.1.1
ReactionSubstructureSearch.hpp
Go to the documentation of this file.
1 /*
2  * ReactionSubstructureSearch.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CHEM_REACTIONSUBSTRUCTURESEARCH_HPP
30 #define CDPL_CHEM_REACTIONSUBSTRUCTURESEARCH_HPP
31 
32 #include <vector>
33 #include <deque>
34 #include <set>
35 #include <utility>
36 #include <cstddef>
37 
38 #include <boost/iterator/indirect_iterator.hpp>
39 
40 #include "CDPL/Chem/APIPrefix.hpp"
43 #include "CDPL/Util/BitSet.hpp"
45 
46 
47 namespace CDPL
48 {
49 
50  namespace Chem
51  {
52 
53  class Reaction;
54  class MolecularGraph;
55  class Atom;
56  class Bond;
57 
62  {
63 
64  typedef std::vector<AtomBondMapping*> ABMappingList;
65 
66  public:
70  typedef boost::indirect_iterator<ABMappingList::iterator, AtomBondMapping> MappingIterator;
71 
75  typedef boost::indirect_iterator<ABMappingList::const_iterator, const AtomBondMapping> ConstMappingIterator;
76 
81 
87 
94 
99  void setQuery(const Reaction& query);
100 
113  bool mappingExists(const Reaction& target);
114 
129  bool findMappings(const Reaction& target);
130 
135  std::size_t getNumMappings() const;
136 
143  AtomBondMapping& getMapping(std::size_t idx);
144 
151  const AtomBondMapping& getMapping(std::size_t idx) const;
152 
158 
164 
170 
176 
182 
188 
194 
200 
212  void uniqueMappingsOnly(bool unique);
213 
219  bool uniqueMappingsOnly() const;
220 
231  void setMaxNumMappings(std::size_t max_num_mappings);
232 
238  std::size_t getMaxNumMappings() const;
239 
251  void setEnabledReactionRoles(unsigned int roles);
252 
259  unsigned int getEnabledReactionRoles() const;
260 
261  private:
262  typedef std::pair<std::size_t, std::size_t> IndexOffsetPair;
263 
265 
267 
268  bool init(const Reaction&);
269 
270  void initQueryData();
271  void initTargetData();
272 
273  bool findEquivAtoms();
274  bool findEquivBonds();
275 
276  bool mapAtoms();
277 
278  std::size_t nextQueryAtom() const;
279  bool nextTargetAtom(std::size_t, unsigned int, std::size_t&, std::size_t&) const;
280 
281  bool atomMappingAllowed(std::size_t, std::size_t) const;
282 
283  bool mapBonds(const Atom*, const Atom*, const IndexOffsetPair&);
284  bool mapAtoms(std::size_t);
285  bool mapAtoms(std::size_t, std::size_t);
286 
287  bool mappingFound();
288 
289  bool hasPostMappingMatchExprs() const;
290  bool foundMappingMatches(const AtomBondMapping*) const;
291 
292  bool foundMappingUnique();
293 
294  void freeAtomBondMappings();
295  void freeAtomBondMapping();
296 
297  AtomBondMapping* createAtomBondMapping();
298 
299  class ABMappingMask
300  {
301 
302  public:
303  void initAtomMask(std::size_t);
304  void initBondMask(std::size_t);
305 
306  void setAtomBit(std::size_t);
307  void resetAtomBit(std::size_t);
308 
309  bool testAtomBit(std::size_t) const;
310 
311  void setBondBit(std::size_t);
312  void resetBondMask();
313 
314  bool operator<(const ABMappingMask&) const;
315  bool operator>(const ABMappingMask&) const;
316 
317  private:
318  Util::BitSet atomMask;
319  Util::BitSet bondMask;
320  };
321 
322  typedef MatchExpression<Reaction>::SharedPointer ReactionMatchExprPtr;
323 
324  typedef std::vector<Util::BitSet> BitMatrix;
325  typedef std::vector<const Atom*> AtomMappingTable;
326  typedef std::vector<std::size_t> BondMappingTable;
327  typedef std::deque<std::size_t> AtomQueue;
328  typedef std::set<ABMappingMask> UniqueMappingList;
329  typedef std::vector<const Atom*> AtomList;
330  typedef std::vector<const Bond*> BondList;
331  typedef std::vector<std::size_t> IndexList;
332  typedef std::vector<MatchExpression<Atom, MolecularGraph>::SharedPointer> AtomMatchExprTable;
333  typedef std::vector<MatchExpression<Bond, MolecularGraph>::SharedPointer> BondMatchExprTable;
334  typedef std::vector<IndexOffsetPair> IndexOffsetTable;
335  typedef Util::ObjectStack<AtomBondMapping> MappingCache;
336 
337  const Reaction* query;
338  const Reaction* target;
339  AtomList queryAtoms;
340  BondList queryBonds;
341  AtomList targetAtoms;
342  BondList targetBonds;
343  IndexOffsetTable queryABIndexOffsets;
344  IndexOffsetTable targetABIndexOffsets;
345  BitMatrix atomEquivMatrix;
346  BitMatrix bondEquivMatrix;
347  AtomQueue termQueryAtoms;
348  AtomMappingTable queryAtomMapping;
349  BondMappingTable queryBondMapping;
350  Util::BitSet queryMappingMask;
351  ABMappingMask targetMappingMask;
352  ABMappingList foundMappings;
353  UniqueMappingList uniqueMappings;
354  AtomMatchExprTable atomMatchExprTable;
355  BondMatchExprTable bondMatchExprTable;
356  ReactionMatchExprPtr rxnMatchExpression;
357  IndexList postMappingMatchAtoms;
358  IndexList postMappingMatchBonds;
359  MappingCache mappingCache;
360  bool queryChanged;
361  bool initQueryMappingData;
362  bool uniqueMatches;
363  bool saveMappings;
364  unsigned int enabledRxnRoles;
365  std::size_t numQueryAtoms;
366  std::size_t numQueryBonds;
367  std::size_t numTargetAtoms;
368  std::size_t numTargetBonds;
369  std::size_t maxNumMappings;
370  };
371  } // namespace Chem
372 } // namespace CDPL
373 
374 #endif // CDPL_CHEM_REACTIONSUBSTRUCTURESEARCH_HPP
CDPL::Chem::ReactionSubstructureSearch::begin
MappingIterator begin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
ObjectStack.hpp
Definition of the class CDPL::Util::ObjectStack.
CDPL::Chem::ReactionSubstructureSearch::setQuery
void setQuery(const Reaction &query)
Allows to specify a new query reaction pattern.
CDPL::Chem::ReactionSubstructureSearch::~ReactionSubstructureSearch
~ReactionSubstructureSearch()
Destructor.
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::ReactionSubstructureSearch::MappingIterator
boost::indirect_iterator< ABMappingList::iterator, AtomBondMapping > MappingIterator
A mutable random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: ReactionSubstructureSearch.hpp:70
CDPL::Chem::ReactionSubstructureSearch::getNumMappings
std::size_t getNumMappings() const
Returns the number of atom/bond mappings that were recorded in the last call to findMappings().
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::ReactionSubstructureSearch::uniqueMappingsOnly
bool uniqueMappingsOnly() const
Tells whether duplicate atom/bond mappings are discarded.
CDPL::Chem::ReactionSubstructureSearch::begin
ConstMappingIterator begin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::ReactionSubstructureSearch::end
ConstMappingIterator end() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::ReactionSubstructureSearch::ReactionSubstructureSearch
ReactionSubstructureSearch()
Constructs and initializes a ReactionSubstructureSearch instance.
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
CDPL::Chem::ReactionSubstructureSearch::getMaxNumMappings
std::size_t getMaxNumMappings() const
Returns the specified limit on the number of stored atom/bond mappings.
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::ReactionSubstructureSearch::ConstMappingIterator
boost::indirect_iterator< ABMappingList::const_iterator, const AtomBondMapping > ConstMappingIterator
A constant random access iterator used to iterate over the stored atom/bond mapping objects.
Definition: ReactionSubstructureSearch.hpp:75
CDPL::Chem::ReactionSubstructureSearch::ReactionSubstructureSearch
ReactionSubstructureSearch(const Reaction &query)
Constructs and initializes a ReactionSubstructureSearch instance for the specified query reaction pat...
CDPL::Chem::ReactionSubstructureSearch
ReactionSubstructureSearch.
Definition: ReactionSubstructureSearch.hpp:62
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
CDPL::Chem::ReactionSubstructureSearch::getEnabledReactionRoles
unsigned int getEnabledReactionRoles() const
Tells which reaction component roles are considered in the search for matching reaction substructures...
CDPL::Util::operator<
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
CDPL::Chem::ReactionSubstructureSearch::end
MappingIterator end()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
CDPL::Chem::ReactionSubstructureSearch::uniqueMappingsOnly
void uniqueMappingsOnly(bool unique)
Allows to specify whether or not to store only unique atom/bond mappings.
CDPL::Chem::ReactionSubstructureSearch::getMappingsBegin
ConstMappingIterator getMappingsBegin() const
Returns a constant iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::ReactionSubstructureSearch::getMappingsEnd
MappingIterator getMappingsEnd()
Returns a mutable iterator pointing to the end of the stored atom/bond mapping objects.
AtomBondMapping.hpp
Definition of the class CDPL::Chem::AtomBondMapping.
CDPL::Chem::ReactionSubstructureSearch::findMappings
bool findMappings(const Reaction &target)
Searches for all possible atom/bond between the query reaction pattern and the specified target react...
CDPL::Chem::ReactionSubstructureSearch::getMappingsBegin
MappingIterator getMappingsBegin()
Returns a mutable iterator pointing to the beginning of the stored atom/bond mapping objects.
CDPL::Chem::MatchExpression
A generic boolean expression interface for the implementation of query/target object equivalence test...
Definition: MatchExpression.hpp:75
CDPL::Chem::ReactionSubstructureSearch::setEnabledReactionRoles
void setEnabledReactionRoles(unsigned int roles)
Allows the reaction role specific exclusion of query and target components from the search for matchi...
MatchExpression.hpp
Definition of the class CDPL::Chem::MatchExpression.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Reaction
Reaction.
Definition: Reaction.hpp:52
CDPL::Chem::ReactionSubstructureSearch::mappingExists
bool mappingExists(const Reaction &target)
Tells whether the query reaction pattern matches the specified target reaction.
CDPL::Chem::AtomBondMapping
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
CDPL::Util::ObjectStack< AtomBondMapping >
CDPL::Util::operator>
bool operator>(const Array< ValueType > &array1, const Array< ValueType > &array2)
Greater than comparison operator.
CDPL::Chem::ReactionSubstructureSearch::getMapping
AtomBondMapping & getMapping(std::size_t idx)
Returns a non-const reference to the stored atom/bond mapping object at index idx.
CDPL::Chem::ReactionSubstructureSearch::getMapping
const AtomBondMapping & getMapping(std::size_t idx) const
Returns a const reference to the stored atom/bond mapping object at index idx.
CDPL::Chem::ReactionSubstructureSearch::setMaxNumMappings
void setMaxNumMappings(std::size_t max_num_mappings)
Allows to specify a limit on the number of stored atom/bond mappings.
CDPL::Chem::ReactionSubstructureSearch::getMappingsEnd
ConstMappingIterator getMappingsEnd() const
Returns a constant iterator pointing to the end of the stored atom/bond mapping objects.