RDKit: Abbreviations.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
Abbreviations.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 Greg Landrum and T5 Informatics GmbH
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#include <RDGeneral/export.h>
11#ifndef RD_ABBREVIATIONS_H
12#define RD_ABBREVIATIONS_H
13#include <GraphMol/Substruct/SubstructMatch.h>
14#include <utility>
15#include <vector>
16#include <string>
17#include <memory>
18
19 namespace RDKit {
20class ROMol;
21class RWMol;
22
23 namespace Abbreviations {
24 struct RDKIT_ABBREVIATIONS_EXPORT AbbreviationDefinition {
25 std::string label;
26 std::string displayLabel;
27 std::string displayLabelW;
28 std::string smarts;
29 std::shared_ptr<ROMol> mol; //!< optional
30 std::vector<unsigned int> extraAttachAtoms; //!< optional
31 bool includesXBonds = true; //! whether or not the abbreviation definition
32 //! includes bonds to non-abbreviation atoms
33 bool operator==(const AbbreviationDefinition &other) const {
34 return label == other.label && displayLabel == other.displayLabel &&
35 displayLabelW == other.displayLabelW && smarts == other.smarts;
36 }
37 bool operator!=(const AbbreviationDefinition &other) const {
38 return !(*this == other);
39 }
40};
41 struct RDKIT_ABBREVIATIONS_EXPORT AbbreviationMatch {
42 MatchVectType match;
43 AbbreviationDefinition abbrev;
44 AbbreviationMatch(std::vector<std::pair<int, int>> matchArg,
45 AbbreviationDefinition abbrevArg)
46 : match(std::move(matchArg)), abbrev(std::move(abbrevArg)) {}
47 AbbreviationMatch() : match(), abbrev() {}
48 bool operator==(const AbbreviationMatch &other) const {
49 return abbrev == other.abbrev && match == other.match;
50 }
51 bool operator!=(const AbbreviationMatch &other) const {
52 return !(*this == other);
53 }
54};
55 namespace common_properties {
56 RDKIT_ABBREVIATIONS_EXPORT extern const std::string numDummies;
57 RDKIT_ABBREVIATIONS_EXPORT extern const std::string origAtomMapping;
58 RDKIT_ABBREVIATIONS_EXPORT extern const std::string origBondMapping;
59} // namespace common_properties
60 namespace Utils {
61//! returns the default set of abbreviation definitions
62 RDKIT_ABBREVIATIONS_EXPORT std::vector<AbbreviationDefinition>
63getDefaultAbbreviations();
64//! returns the default set of linker definitions
65 RDKIT_ABBREVIATIONS_EXPORT std::vector<AbbreviationDefinition>
66getDefaultLinkers();
67
68//! parses a string describing abbreviation matches and returns the result
69/*
70
71\param text the data to be parsed, see below for the format
72\param removeExtraDummies controls whether or not dummy atoms beyond atom 0 are
73 removed. Set this to true to create abbreviations for linkers
74\param allowConnectionToDummies allows abbreviations to directly connect to
75 abbreviations. set this to true for linkers
76
77Format of the text data:
78 A series of lines, each of which contains:
79
80 label SMARTS displayLabel displayLabelW
81
82 the "displayLabel" and "displayLabelW" fields are optional.
83 where label is the label used for the abbreviation,
84 SMARTS is the SMARTS definition of the abbreviation.
85 displayLabel is used in drawings to render the abbreviations.
86 displayLabelW is the display label if a bond comes in from the right
87
88 Use dummies to indicate attachment points. The assumption is that the first
89 atom is a dummy (one will be added if this is not true) and that the second
90 atom is the surrogate for the rest of the group.
91
92*/
93 RDKIT_ABBREVIATIONS_EXPORT std::vector<AbbreviationDefinition>
94parseAbbreviations(const std::string &text, bool removeExtraDummies = false,
95 bool allowConnectionToDummies = false);
96//! \brief equivalent to calling \c parseAbbreviations(text,true,true)
97 inline std::vector<AbbreviationDefinition> parseLinkers(
98 const std::string &text) {
99 return parseAbbreviations(text, true, true);
100};
101} // namespace Utils
102
103//! returns all matches for the abbreviations across the molecule
104/*!
105
106 \param abbrevs the abbreviations to look for. This list is used in order.
107 \param maxCoverage any abbreviation that covers than more than this fraction
108 of the molecule's atoms (not counting dummies) will not be returned.
109*/
110 RDKIT_ABBREVIATIONS_EXPORT std::vector<AbbreviationMatch>
111findApplicableAbbreviationMatches(
112 const ROMol &mol, const std::vector<AbbreviationDefinition> &abbrevs,
113 double maxCoverage = 0.4);
114//! applies the abbreviation matches to a molecule, modifying it in place.
115//! the modified molecule is not sanitized
116 RDKIT_ABBREVIATIONS_EXPORT void applyMatches(
117 RWMol &mol, const std::vector<AbbreviationMatch> &matches);
118//! creates "SUP" SubstanceGroups on the molecule describing the abbreviation
119 RDKIT_ABBREVIATIONS_EXPORT void labelMatches(
120 RWMol &mol, const std::vector<AbbreviationMatch> &matches);
121//! convenience function for finding and applying abbreviations
122//! the modified molecule is not sanitized
123 RDKIT_ABBREVIATIONS_EXPORT void condenseMolAbbreviations(
124 RWMol &mol, const std::vector<AbbreviationDefinition> &abbrevs,
125 double maxCoverage = 0.4, bool sanitize = true);
126//! convenience function for finding and labeling abbreviations as SUP
127//! SubstanceGroups
128 RDKIT_ABBREVIATIONS_EXPORT void labelMolAbbreviations(
129 RWMol &mol, const std::vector<AbbreviationDefinition> &abbrevs,
130 double maxCoverage = 0.4);
131//! collapses abbreviation (i.e. "SUP") substance groups
132//! the modified molecule is not sanitized
133 RDKIT_ABBREVIATIONS_EXPORT void condenseAbbreviationSubstanceGroups(RWMol &mol);
134
135} // namespace Abbreviations
136} // namespace RDKit
137#endif
SubstructMatch.h
RDKit::ROMol
Definition ROMol.h:199
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
export.h
RDKIT_ABBREVIATIONS_EXPORT
#define RDKIT_ABBREVIATIONS_EXPORT
Definition export.h:9
RDKit::Abbreviations::Utils
Definition Abbreviations.h:60
RDKit::Abbreviations::Utils::parseLinkers
std::vector< AbbreviationDefinition > parseLinkers(const std::string &text)
equivalent to calling parseAbbreviations(text,true,true)
Definition Abbreviations.h:97
RDKit::Abbreviations::Utils::getDefaultLinkers
RDKIT_ABBREVIATIONS_EXPORT std::vector< AbbreviationDefinition > getDefaultLinkers()
returns the default set of linker definitions
RDKit::Abbreviations::Utils::parseAbbreviations
RDKIT_ABBREVIATIONS_EXPORT std::vector< AbbreviationDefinition > parseAbbreviations(const std::string &text, bool removeExtraDummies=false, bool allowConnectionToDummies=false)
parses a string describing abbreviation matches and returns the result
RDKit::Abbreviations::Utils::getDefaultAbbreviations
RDKIT_ABBREVIATIONS_EXPORT std::vector< AbbreviationDefinition > getDefaultAbbreviations()
returns the default set of abbreviation definitions
RDKit::Abbreviations::common_properties
Definition Abbreviations.h:55
RDKit::Abbreviations::common_properties::origAtomMapping
RDKIT_ABBREVIATIONS_EXPORT const std::string origAtomMapping
RDKit::Abbreviations::common_properties::origBondMapping
RDKIT_ABBREVIATIONS_EXPORT const std::string origBondMapping
RDKit::Abbreviations::common_properties::numDummies
RDKIT_ABBREVIATIONS_EXPORT const std::string numDummies
RDKit::Abbreviations
Definition Abbreviations.h:23
RDKit::Abbreviations::applyMatches
RDKIT_ABBREVIATIONS_EXPORT void applyMatches(RWMol &mol, const std::vector< AbbreviationMatch > &matches)
RDKit::Abbreviations::condenseAbbreviationSubstanceGroups
RDKIT_ABBREVIATIONS_EXPORT void condenseAbbreviationSubstanceGroups(RWMol &mol)
RDKit::Abbreviations::labelMolAbbreviations
RDKIT_ABBREVIATIONS_EXPORT void labelMolAbbreviations(RWMol &mol, const std::vector< AbbreviationDefinition > &abbrevs, double maxCoverage=0.4)
RDKit::Abbreviations::condenseMolAbbreviations
RDKIT_ABBREVIATIONS_EXPORT void condenseMolAbbreviations(RWMol &mol, const std::vector< AbbreviationDefinition > &abbrevs, double maxCoverage=0.4, bool sanitize=true)
RDKit::Abbreviations::labelMatches
RDKIT_ABBREVIATIONS_EXPORT void labelMatches(RWMol &mol, const std::vector< AbbreviationMatch > &matches)
creates "SUP" SubstanceGroups on the molecule describing the abbreviation
RDKit::Abbreviations::findApplicableAbbreviationMatches
RDKIT_ABBREVIATIONS_EXPORT std::vector< AbbreviationMatch > findApplicableAbbreviationMatches(const ROMol &mol, const std::vector< AbbreviationDefinition > &abbrevs, double maxCoverage=0.4)
returns all matches for the abbreviations across the molecule
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::MatchVectType
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
Definition FragFPGenerator.h:24
RDKit::Abbreviations::AbbreviationDefinition
Definition Abbreviations.h:24
RDKit::Abbreviations::AbbreviationDefinition::extraAttachAtoms
std::vector< unsigned int > extraAttachAtoms
optional
Definition Abbreviations.h:30
RDKit::Abbreviations::AbbreviationDefinition::operator==
bool operator==(const AbbreviationDefinition &other) const
Definition Abbreviations.h:33
RDKit::Abbreviations::AbbreviationDefinition::includesXBonds
bool includesXBonds
Definition Abbreviations.h:31
RDKit::Abbreviations::AbbreviationDefinition::mol
std::shared_ptr< ROMol > mol
optional
Definition Abbreviations.h:29
RDKit::Abbreviations::AbbreviationDefinition::label
std::string label
Definition Abbreviations.h:25
RDKit::Abbreviations::AbbreviationDefinition::operator!=
bool operator!=(const AbbreviationDefinition &other) const
Definition Abbreviations.h:37
RDKit::Abbreviations::AbbreviationDefinition::smarts
std::string smarts
Definition Abbreviations.h:28
RDKit::Abbreviations::AbbreviationDefinition::displayLabel
std::string displayLabel
Definition Abbreviations.h:26
RDKit::Abbreviations::AbbreviationDefinition::displayLabelW
std::string displayLabelW
Definition Abbreviations.h:27
RDKit::Abbreviations::AbbreviationMatch::AbbreviationMatch
AbbreviationMatch(std::vector< std::pair< int, int > > matchArg, AbbreviationDefinition abbrevArg)
Definition Abbreviations.h:44
RDKit::Abbreviations::AbbreviationMatch::operator!=
bool operator!=(const AbbreviationMatch &other) const
Definition Abbreviations.h:51
RDKit::Abbreviations::AbbreviationMatch::AbbreviationMatch
AbbreviationMatch()
Definition Abbreviations.h:47
RDKit::Abbreviations::AbbreviationMatch::match
MatchVectType match
Definition Abbreviations.h:42
RDKit::Abbreviations::AbbreviationMatch::abbrev
AbbreviationDefinition abbrev
Definition Abbreviations.h:43
RDKit::Abbreviations::AbbreviationMatch::operator==
bool operator==(const AbbreviationMatch &other) const
Definition Abbreviations.h:48