RDKit
Open-source cheminformatics and machine learning.
Subgraphs.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2008 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 
11 /*! \file Subgraphs.h
12 
13  \brief functionality for finding subgraphs and paths in molecules
14 
15  Difference between _subgraphs_ and _paths_ :
16  Subgraphs are potentially branched, whereas paths (in our
17  terminology at least) cannot be. So, the following graph:
18 \verbatim
19  C--0--C--1--C--3--C
20  |
21  2
22  |
23  C
24 \endverbatim
25  has 3 _subgraphs_ of length 3: (0,1,2),(0,1,3),(2,1,3)
26  but only 2 _paths_ of length 3: (0,1,3),(2,1,3)
27 */
28 #ifndef _RD_SUBGRAPHS_H_
29 #define _RD_SUBGRAPHS_H_
30 
31 #include <vector>
32 #include <list>
33 #include <map>
34 
35 
36 namespace RDKit{
37  class ROMol;
38  // NOTE: before replacing the defn of PATH_TYPE: be aware that
39  // we do occasionally use reverse iterators on these things, so
40  // replacing with a slist would probably be a bad idea.
41  typedef std::vector<int> PATH_TYPE;
42  typedef std::list< PATH_TYPE > PATH_LIST;
43  typedef PATH_LIST::const_iterator PATH_LIST_CI;
44 
45  typedef std::map<int, PATH_LIST> INT_PATH_LIST_MAP;
46  typedef INT_PATH_LIST_MAP::const_iterator INT_PATH_LIST_MAP_CI;
47  typedef INT_PATH_LIST_MAP::iterator INT_PATH_LIST_MAP_I;
48 
49  // --- --- --- --- --- --- --- --- --- --- --- --- ---
50  //
51  //
52  // --- --- --- --- --- --- --- --- --- --- --- --- ---
53 
54  //! \brief find all bond subgraphs in a range of sizes
55  /*!
56  * \param mol - the molecule to be considered
57  * \param lowerLen - the minimum subgraph size to find
58  * \param upperLen - the maximum subgraph size to find
59  * \param useHs - if set, hydrogens in the graph will be considered
60  * eligible to be in paths. NOTE: this will not add
61  * Hs to the graph.
62  * \param rootedAtAtom - if non-negative, only subgraphs that start at
63  * this atom will be returned.
64  *
65  * The result is a map from subgraph size -> list of paths
66  * (i.e. list of list of bond indices)
67  */
68  INT_PATH_LIST_MAP findAllSubgraphsOfLengthsMtoN(const ROMol &mol, unsigned int lowerLen,
69  unsigned int upperLen, bool useHs=false,
70  int rootedAtAtom=-1);
71 
72  //! \brief find all bond subgraphs of a particular size
73  /*!
74  * \param mol - the molecule to be considered
75  * \param targetLen - the length of the subgraphs to be returned
76  * \param useHs - if set, hydrogens in the graph will be considered
77  * eligible to be in paths. NOTE: this will not add
78  * Hs to the graph.
79  * \param rootedAtAtom - if non-negative, only subgraphs that start at
80  * this atom will be returned.
81  *
82  *
83  * The result is a list of paths (i.e. list of list of bond indices)
84  */
85  PATH_LIST findAllSubgraphsOfLengthN(const ROMol &mol,unsigned int targetLen,
86  bool useHs=false,int rootedAtAtom=-1);
87 
88  //! \brief find unique bond subgraphs of a particular size
89  /*!
90  * \param mol - the molecule to be considered
91  * \param targetLen - the length of the subgraphs to be returned
92  * \param useHs - if set, hydrogens in the graph will be considered
93  * eligible to be in paths. NOTE: this will not add
94  * Hs to the graph.
95  * \param useBO - if set, bond orders will be considered when uniquifying
96  * the paths
97  * \param rootedAtAtom - if non-negative, only subgraphs that start at
98  * this atom will be returned.
99  *
100  * The result is a list of paths (i.e. list of list of bond indices)
101  */
102  PATH_LIST findUniqueSubgraphsOfLengthN(const ROMol &mol,unsigned int targetLen,
103  bool useHs=false,bool useBO=true,
104  int rootedAtAtom=-1);
105  //! \brief find all paths of a particular size
106  /*!
107  * \param mol - the molecule to be considered
108  * \param targetLen - the length of the paths to be returned
109  * \param useBonds - if set, the path indices will be bond indices,
110  * not atom indices
111  * \param useHs - if set, hydrogens in the graph will be considered
112  * eligible to be in paths. NOTE: this will not add
113  * Hs to the graph.
114  * \param rootedAtAtom - if non-negative, only subgraphs that start at
115  * this atom will be returned.
116  *
117  * The result is a list of paths (i.e. list of list of bond indices)
118  */
119  PATH_LIST findAllPathsOfLengthN(const ROMol &mol,unsigned int targetLen,
120  bool useBonds=true,bool useHs=false,
121  int rootedAtAtom=-1);
122  INT_PATH_LIST_MAP findAllPathsOfLengthsMtoN(const ROMol &mol,unsigned int lowerLen,
123  unsigned int upperLen,
124  bool useBonds=true,bool useHs=false,
125  int rootedAtAtom=-1);
126 
127  //! \brief find bond subgraphs of a particular radius around an atom
128  /*!
129  * \param mol - the molecule to be considered
130  * \param radius - the radius of the subgraphs to be considered
131  * \param rootedAtAtom - the atom to consider
132  * \param useHs - if set, hydrogens in the graph will be considered
133  * eligible to be in paths. NOTE: this will not add
134  * Hs to the graph.
135  *
136  * The result is a path (a vector of bond indices)
137  */
138  PATH_TYPE findAtomEnvironmentOfRadiusN(const ROMol &mol,unsigned int radius,
139  unsigned int rootedAtAtom,bool useHs=false);
140 
141 }
142 
143 
144 #endif
PATH_TYPE findAtomEnvironmentOfRadiusN(const ROMol &mol, unsigned int radius, unsigned int rootedAtAtom, bool useHs=false)
find bond subgraphs of a particular radius around an atom
PATH_LIST findAllPathsOfLengthN(const ROMol &mol, unsigned int targetLen, bool useBonds=true, bool useHs=false, int rootedAtAtom=-1)
find all paths of a particular size
PATH_LIST findUniqueSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen, bool useHs=false, bool useBO=true, int rootedAtAtom=-1)
find unique bond subgraphs of a particular size
INT_PATH_LIST_MAP::iterator INT_PATH_LIST_MAP_I
Definition: Subgraphs.h:47
PATH_LIST::const_iterator PATH_LIST_CI
Definition: Subgraphs.h:43
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
std::map< int, PATH_LIST > INT_PATH_LIST_MAP
Definition: Subgraphs.h:45
INT_PATH_LIST_MAP::const_iterator INT_PATH_LIST_MAP_CI
Definition: Subgraphs.h:46
std::list< PATH_TYPE > PATH_LIST
Definition: Subgraphs.h:42
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
INT_PATH_LIST_MAP findAllPathsOfLengthsMtoN(const ROMol &mol, unsigned int lowerLen, unsigned int upperLen, bool useBonds=true, bool useHs=false, int rootedAtAtom=-1)
PATH_LIST findAllSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen, bool useHs=false, int rootedAtAtom=-1)
find all bond subgraphs of a particular size
INT_PATH_LIST_MAP findAllSubgraphsOfLengthsMtoN(const ROMol &mol, unsigned int lowerLen, unsigned int upperLen, bool useHs=false, int rootedAtAtom=-1)
find all bond subgraphs in a range of sizes
std::vector< int > PATH_TYPE
Definition: Subgraphs.h:37