RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
Subset.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2025 Hussein Faara, Brian Kelley and other RDKit contributors
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
#ifndef RD_SUBSET_H
11
#define RD_SUBSET_H
12
#include <map>
13
14
#include <
RDGeneral/export.h
>
15
#include <boost/dynamic_bitset.hpp>
16
17
#include <memory>
18
#include <vector>
19
20
namespace
RDKit
{
21
class
ROMol
;
22
class
RWMol
;
23
24
//! Subsetting Methods for copyMolSubset
25
/*
26
* These control what the path structures mean in copyMolSubset
27
*
28
* NOTE: when the atoms and bonds are fully specified, the subset method is
29
* ignored.
30
*/
31
enum class
SubsetMethod
{
32
BONDS_BETWEEN_ATOMS
=
33
0,
//<! extract the specified atoms and the bonds between them
34
BONDS
= 1
//<! extract the specified bonds and their attached atoms
35
};
36
37
//! Subsetting Options for copyMolSubset
38
/*
39
* These control what is copied over from the original molecule
40
*
41
* NOTE: when the atoms and bonds are fully specified, the subset method is
42
* ignored.
43
*/
44
struct
RDKIT_GRAPHMOL_EXPORT
SubsetOptions
{
45
bool
sanitize
=
46
false
;
/**< perform sanitization automatically on the subset */
47
bool
clearComputedProps
=
48
false
;
/**< clear all computed props on the subsetted molecule */
49
bool
copyAsQuery
=
false
;
/**< Return the subset as a query */
50
bool
copyCoordinates
=
51
true
;
/**< *Copy the active coordinates from the molecule */
52
unsigned
int
conformerIdx
=
53
-1u;
/**< What conformer idx to use for the coordinates default is -1 */
54
55
SubsetMethod
method
=
56
SubsetMethod::BONDS_BETWEEN_ATOMS
;
/**< Subsetting method to use. *Note*
57
* if atoms and bonds are fully
58
* specified the method is ignored.*/
59
};
60
61
struct
RDKIT_GRAPHMOL_EXPORT
SubsetInfo
{
62
boost::dynamic_bitset<>
selectedAtoms
;
/**< atoms selected in the subset */
63
boost::dynamic_bitset<>
selectedBonds
;
/**< bonds selected in the subset */
64
std::map<unsigned int, unsigned int>
65
atomMapping
;
/**< mapping of original atom indices to new ones */
66
std::map<unsigned int, unsigned int>
67
bondMapping
;
/**< mapping of original bond indices to new ones */
68
};
69
70
//!
71
/*
72
* Extract a subgraph from an ROMol. Bonds, atoms, substance groups and
73
* stereo groups are only extracted to the subgraph if all participant entities
74
* are contained within the given atoms and bonds.
75
*
76
* \param mol - starting mol
77
* \param atoms - atoms to extract
78
* \param bonds - bonds to extract
79
* \param subsetInfo - optional subsetInfo to record the atoms and bonds used
80
* \param options - subset options, note the method is ignored since all the
81
* atoms and bonds are specified
82
*
83
*
84
* NOTE: Bookmarks are currently copied, StereoGroups that are not entirely
85
* included in the subset are not copied.
86
*
87
* NOTE: when using this method the SubsetOptions.method is ignored
88
* for resolving the atoms and bonds to use to subset
89
*/
90
91
RDKIT_GRAPHMOL_EXPORT
92
std::unique_ptr<RDKit::RWMol>
copyMolSubset
(
93
const
RDKit::ROMol
&mol,
const
std::vector<unsigned int> &atoms,
94
const
std::vector<unsigned int> &bonds,
95
const
SubsetOptions
&options =
SubsetOptions
());
96
97
RDKIT_GRAPHMOL_EXPORT
98
std::unique_ptr<RDKit::RWMol>
copyMolSubset
(
99
const
RDKit::ROMol
&mol,
const
std::vector<unsigned int> &atoms,
100
const
std::vector<unsigned int> &bonds,
SubsetInfo
&subsetInfo,
101
const
SubsetOptions
&options =
SubsetOptions
());
102
103
//!
104
/*
105
* Extract a subgraph from an ROMol. Bonds, substance groups and
106
* stereo groups are only extracted to the subgraph if all participant entities
107
* are selected by the `path` parameter.
108
*
109
* \param mol - starting mol
110
* \param path - the indices of atoms or bonds to extract. If an index falls
111
* outside of the acceptable indices, it is ignored.
112
* use SubsetMethod::BONDS to indicate a bond path and
113
* SubsetMethod::BONDS_BETWEEN_ATOMS to indicate an atom path
114
* and any bond that includes both atoms in the path
115
* \param subsetInfo - optional subsetInfo to record the atoms and bonds used
116
* \param option - optional SubsetOptions to control how the subset is created
117
*
118
* NOTE: Bookmarks are currently copied, StereoGroups that are not entirely
119
* included in the subset are not copied.
120
*
121
*/
122
RDKIT_GRAPHMOL_EXPORT
std::unique_ptr<RDKit::RWMol>
copyMolSubset
(
123
const
RDKit::ROMol
&mol,
const
std::vector<unsigned int> &path,
124
const
SubsetOptions
&options =
SubsetOptions
());
125
126
RDKIT_GRAPHMOL_EXPORT
std::unique_ptr<RDKit::RWMol>
copyMolSubset
(
127
const
RDKit::ROMol
&mol,
const
std::vector<unsigned int> &path,
128
SubsetInfo
&subsetInfo,
const
SubsetOptions
&options =
SubsetOptions
());
129
130
}
// namespace RDKit
131
#endif
RDKit::ROMol
Definition
ROMol.h:344
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition
RWMol.h:32
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition
export.h:321
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::copyMolSubset
RDKIT_GRAPHMOL_EXPORT std::unique_ptr< RDKit::RWMol > copyMolSubset(const RDKit::ROMol &mol, const std::vector< unsigned int > &atoms, const std::vector< unsigned int > &bonds, const SubsetOptions &options=SubsetOptions())
RDKit::SubsetMethod
SubsetMethod
Subsetting Methods for copyMolSubset.
Definition
Subset.h:31
RDKit::SubsetMethod::BONDS
@ BONDS
Definition
Subset.h:34
RDKit::SubsetMethod::BONDS_BETWEEN_ATOMS
@ BONDS_BETWEEN_ATOMS
Definition
Subset.h:32
RDKit::SubsetInfo
Definition
Subset.h:61
RDKit::SubsetInfo::bondMapping
std::map< unsigned int, unsigned int > bondMapping
Definition
Subset.h:67
RDKit::SubsetInfo::selectedBonds
boost::dynamic_bitset selectedBonds
Definition
Subset.h:63
RDKit::SubsetInfo::selectedAtoms
boost::dynamic_bitset selectedAtoms
Definition
Subset.h:62
RDKit::SubsetInfo::atomMapping
std::map< unsigned int, unsigned int > atomMapping
Definition
Subset.h:65
RDKit::SubsetOptions
Subsetting Options for copyMolSubset.
Definition
Subset.h:44
RDKit::SubsetOptions::copyAsQuery
bool copyAsQuery
Definition
Subset.h:49
RDKit::SubsetOptions::method
SubsetMethod method
Definition
Subset.h:55
RDKit::SubsetOptions::sanitize
bool sanitize
Definition
Subset.h:45
RDKit::SubsetOptions::copyCoordinates
bool copyCoordinates
Definition
Subset.h:50
RDKit::SubsetOptions::conformerIdx
unsigned int conformerIdx
Definition
Subset.h:52
RDKit::SubsetOptions::clearComputedProps
bool clearComputedProps
Definition
Subset.h:47
GraphMol
Subset.h
Generated on
for RDKit by
1.17.0