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 #include <RDGeneral/export.h>
29 #ifndef _RD_SUBGRAPHS_H_
30 #define _RD_SUBGRAPHS_H_
31 
32 #include <vector>
33 #include <list>
34 #include <map>
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 */
69  unsigned int lowerLen,
70  unsigned int upperLen,
71  bool useHs = false,
72  int rootedAtAtom = -1);
73 
74 //! \brief find all bond subgraphs of a particular size
75 /*!
76  * \param mol - the molecule to be considered
77  * \param targetLen - the length of the subgraphs to be returned
78  * \param useHs - if set, hydrogens in the graph will be considered
79  * eligible to be in paths. NOTE: this will not add
80  * Hs to the graph.
81  * \param rootedAtAtom - if non-negative, only subgraphs that start at
82  * this atom will be returned.
83  *
84  *
85  * The result is a list of paths (i.e. list of list of bond indices)
86 */
87 RDKIT_SUBGRAPHS_EXPORT PATH_LIST findAllSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen,
88  bool useHs = false, int rootedAtAtom = -1);
89 
90 //! \brief find unique bond subgraphs of a particular size
91 /*!
92  * \param mol - the molecule to be considered
93  * \param targetLen - the length of the subgraphs to be returned
94  * \param useHs - if set, hydrogens in the graph will be considered
95  * eligible to be in paths. NOTE: this will not add
96  * Hs to the graph.
97  * \param useBO - if set, bond orders will be considered when uniquifying
98  * the paths
99  * \param rootedAtAtom - if non-negative, only subgraphs that start at
100  * this atom will be returned.
101  *
102  * The result is a list of paths (i.e. list of list of bond indices)
103 */
104 RDKIT_SUBGRAPHS_EXPORT PATH_LIST findUniqueSubgraphsOfLengthN(const ROMol &mol, unsigned int targetLen,
105  bool useHs = false, bool useBO = true,
106  int rootedAtAtom = -1);
107 //! \brief find all paths of a particular size
108 /*!
109  * \param mol - the molecule to be considered
110  * \param targetLen - the length of the paths to be returned
111  * \param useBonds - if set, the path indices will be bond indices,
112  * not atom indices
113  * \param useHs - if set, hydrogens in the graph will be considered
114  * eligible to be in paths. NOTE: this will not add
115  * Hs to the graph.
116  * \param rootedAtAtom - if non-negative, only subgraphs that start at
117  * this atom will be returned.
118  *
119  * The result is a list of paths (i.e. list of list of bond indices)
120 */
121 RDKIT_SUBGRAPHS_EXPORT PATH_LIST findAllPathsOfLengthN(const ROMol &mol, unsigned int targetLen,
122  bool useBonds = true, bool useHs = false,
123  int rootedAtAtom = -1);
125  const ROMol &mol, unsigned int lowerLen, unsigned int upperLen,
126  bool useBonds = true, bool useHs = false, int rootedAtAtom = -1);
127 
128 //! \brief find bond subgraphs of a particular radius around an atom
129 /*!
130  * \param mol - the molecule to be considered
131  * \param radius - the radius of the subgraphs to be considered
132  * \param rootedAtAtom - the atom to consider
133  * \param useHs - if set, hydrogens in the graph will be considered
134  * eligible to be in paths. NOTE: this will not add
135  * Hs to the graph.
136  *
137  * The result is a path (a vector of bond indices)
138 */
139 RDKIT_SUBGRAPHS_EXPORT PATH_TYPE findAtomEnvironmentOfRadiusN(const ROMol &mol, unsigned int radius,
140  unsigned int rootedAtAtom,
141  bool useHs = false);
142 }
143 
144 #endif
RDKIT_SUBGRAPHS_EXPORT 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::iterator INT_PATH_LIST_MAP_I
Definition: Subgraphs.h:47
RDKIT_SUBGRAPHS_EXPORT 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::const_iterator PATH_LIST_CI
Definition: Subgraphs.h:43
#define RDKIT_SUBGRAPHS_EXPORT
Definition: export.h:619
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
Std stuff.
Definition: Atom.h:30
RDKIT_SUBGRAPHS_EXPORT 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
RDKIT_SUBGRAPHS_EXPORT INT_PATH_LIST_MAP findAllPathsOfLengthsMtoN(const ROMol &mol, unsigned int lowerLen, unsigned int upperLen, bool useBonds=true, bool useHs=false, int rootedAtAtom=-1)
RDKIT_SUBGRAPHS_EXPORT 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
RDKIT_SUBGRAPHS_EXPORT 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