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 namespace RDKit {
36 class ROMol;
37 // NOTE: before replacing the defn of PATH_TYPE: be aware that
38 // we do occasionally use reverse iterators on these things, so
39 // replacing with a slist would probably be a bad idea.
40 typedef std::vector<int> PATH_TYPE;
41 typedef std::list<PATH_TYPE> PATH_LIST;
42 typedef PATH_LIST::const_iterator PATH_LIST_CI;
43 
44 typedef std::map<int, PATH_LIST> INT_PATH_LIST_MAP;
45 typedef INT_PATH_LIST_MAP::const_iterator INT_PATH_LIST_MAP_CI;
46 typedef INT_PATH_LIST_MAP::iterator INT_PATH_LIST_MAP_I;
47 
48 // --- --- --- --- --- --- --- --- --- --- --- --- ---
49 //
50 //
51 // --- --- --- --- --- --- --- --- --- --- --- --- ---
52 
53 //! \brief find all bond subgraphs in a range of sizes
54 /*!
55  * \param mol - the molecule to be considered
56  * \param lowerLen - the minimum subgraph size to find
57  * \param upperLen - the maximum subgraph size to find
58  * \param useHs - if set, hydrogens in the graph will be considered
59  * eligible to be in paths. NOTE: this will not add
60  * Hs to the graph.
61  * \param rootedAtAtom - if non-negative, only subgraphs that start at
62  * this atom will be returned.
63  *
64  * The result is a map from subgraph size -> list of paths
65  * (i.e. list of list of bond indices)
66 */
67 INT_PATH_LIST_MAP findAllSubgraphsOfLengthsMtoN(const ROMol &mol,
68  unsigned int lowerLen,
69  unsigned int upperLen,
70  bool useHs = false,
71  int rootedAtAtom = -1);
72 
73 //! \brief find all bond subgraphs of a particular size
74 /*!
75  * \param mol - the molecule to be considered
76  * \param targetLen - the length of the subgraphs to be returned
77  * \param useHs - if set, hydrogens in the graph will be considered
78  * eligible to be in paths. NOTE: this will not add
79  * Hs to the graph.
80  * \param rootedAtAtom - if non-negative, only subgraphs that start at
81  * this atom will be returned.
82  *
83  *
84  * The result is a list of paths (i.e. list of list of bond indices)
85 */
86 PATH_LIST findAllSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen,
87  bool useHs = false, int rootedAtAtom = -1);
88 
89 //! \brief find unique bond subgraphs of a particular size
90 /*!
91  * \param mol - the molecule to be considered
92  * \param targetLen - the length of the subgraphs to be returned
93  * \param useHs - if set, hydrogens in the graph will be considered
94  * eligible to be in paths. NOTE: this will not add
95  * Hs to the graph.
96  * \param useBO - if set, bond orders will be considered when uniquifying
97  * the paths
98  * \param rootedAtAtom - if non-negative, only subgraphs that start at
99  * this atom will be returned.
100  *
101  * The result is a list of paths (i.e. list of list of bond indices)
102 */
103 PATH_LIST findUniqueSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen,
104  bool useHs = false, bool useBO = true,
105  int rootedAtAtom = -1);
106 //! \brief find all paths of a particular size
107 /*!
108  * \param mol - the molecule to be considered
109  * \param targetLen - the length of the paths to be returned
110  * \param useBonds - if set, the path indices will be bond indices,
111  * not atom indices
112  * \param useHs - if set, hydrogens in the graph will be considered
113  * eligible to be in paths. NOTE: this will not add
114  * Hs to the graph.
115  * \param rootedAtAtom - if non-negative, only subgraphs that start at
116  * this atom will be returned.
117  *
118  * The result is a list of paths (i.e. list of list of bond indices)
119 */
120 PATH_LIST findAllPathsOfLengthN(const ROMol &mol, unsigned int targetLen,
121  bool useBonds = true, bool useHs = false,
122  int rootedAtAtom = -1);
123 INT_PATH_LIST_MAP findAllPathsOfLengthsMtoN(
124  const ROMol &mol, unsigned int lowerLen, unsigned int upperLen,
125  bool useBonds = true, bool useHs = false, 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,
140  bool useHs = false);
141 }
142 
143 #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:46
PATH_LIST::const_iterator PATH_LIST_CI
Definition: Subgraphs.h:42
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
std::map< int, PATH_LIST > INT_PATH_LIST_MAP
Definition: Subgraphs.h:44
INT_PATH_LIST_MAP::const_iterator INT_PATH_LIST_MAP_CI
Definition: Subgraphs.h:45
std::list< PATH_TYPE > PATH_LIST
Definition: Subgraphs.h:41
Std stuff.
Definition: Atom.h:29
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:36