RDKit
Open-source cheminformatics and machine learning.
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
20namespace RDKit {
21class ROMol;
22class 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 */
31enum class SubsetMethod {
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 */
45 bool sanitize =
46 false; /**< perform sanitization automatically on the subset */
48 false; /**< clear all computed props on the subsetted molecule */
49 bool copyAsQuery = false; /**< Return the subset as a query */
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
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
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
92std::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
98std::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 */
122RDKIT_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
126RDKIT_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
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
Std stuff.
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())
SubsetMethod
Subsetting Methods for copyMolSubset.
Definition Subset.h:31
std::map< unsigned int, unsigned int > bondMapping
Definition Subset.h:67
boost::dynamic_bitset selectedBonds
Definition Subset.h:63
boost::dynamic_bitset selectedAtoms
Definition Subset.h:62
std::map< unsigned int, unsigned int > atomMapping
Definition Subset.h:65
Subsetting Options for copyMolSubset.
Definition Subset.h:44
SubsetMethod method
Definition Subset.h:55
unsigned int conformerIdx
Definition Subset.h:52
bool clearComputedProps
Definition Subset.h:47