RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
CDXMLParser.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2022 Brian P Kelley
3
// All rights reserved.
4
//
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_CDXML_FILEPARSERS_H
12
#define RD_CDXML_FILEPARSERS_H
13
#include <
GraphMol/RWMol.h
>
14
15
#include <
RDGeneral/types.h
>
16
#include <string>
17
#include <vector>
18
19
namespace
RDKit
{
20
class
RWMol
;
21
22
namespace
v2
{
23
namespace
CDXMLParser
{
24
25
enum class
CDXMLFormat
{
26
CDXML
= 0,
27
CDX
= 1,
28
Auto
= 2
29
};
30
31
//! \brief Returns true if the RDKit was build with ChemDraw CDX support
32
RDKIT_FILEPARSERS_EXPORT
bool
hasChemDrawCDXSupport
();
33
34
struct
RDKIT_FILEPARSERS_EXPORT
CDXMLParserParams
{
35
bool
sanitize
=
true
;
36
bool
removeHs
=
true
;
37
CDXMLFormat
format
=
CDXMLFormat::Auto
;
38
bool
parseQueries
=
false
;
39
bool
strictQueryParsing
=
false
;
40
41
CDXMLParserParams
() =
default
;
42
CDXMLParserParams
(
bool
sanitize
,
bool
removeHs
,
CDXMLFormat
format
,
43
bool
parseQueries
=
false
,
bool
strictQueryParsing
=
false
)
44
:
sanitize
(
sanitize
),
45
removeHs
(
removeHs
),
46
format
(
format
),
47
parseQueries
(
parseQueries
),
48
strictQueryParsing
(
strictQueryParsing
) {}
49
};
50
51
//! \brief construct molecules from a CDXML file
52
//! The RDKit is optionally built with the Revvity ChemDraw parser
53
//! If this is available, CDX and CDXML can be read, see CDXMLParserParams
54
//! Note that the CDXML format is large and complex, the RDKit doesn't
55
//! support full functionality, just the base ones required for molecule and
56
//! reaction parsing.
57
//! Note: If the ChemDraw extensions are available, this auto detects between
58
//! CDXML and CDX
59
/*!
60
* \param inStream - string containing the mol block
61
* \param params - parameters controlling the parsing and post-processing
62
*/
63
RDKIT_FILEPARSERS_EXPORT
std::vector<std::unique_ptr<RWMol>>
64
MolsFromCDXMLDataStream
(std::istream &inStream,
65
const
CDXMLParserParams
¶ms =
CDXMLParserParams
());
66
//! \brief construct molecules from a CDXML file
67
//! The RDKit is optionally built with the Revvity ChemDraw parser
68
//! If this is available, CDX and CDXML can be read, see CDXMLParserParams
69
//! Note that the CDXML format is large and complex, the RDKit doesn't
70
//! support full functionality, just the base ones required for molecule and
71
//! reaction parsing.
72
/*!
73
* \param fileName - cdxml fileName
74
* \param params - parameters controlling the parsing and post-processing
75
*/
76
RDKIT_FILEPARSERS_EXPORT
std::vector<std::unique_ptr<RWMol>>
MolsFromCDXMLFile
(
77
const
std::string &filename,
78
const
CDXMLParserParams
¶ms =
CDXMLParserParams
(
true
,
true
,
79
CDXMLFormat::Auto
));
80
81
//! \brief construct molecules from a CDXML block
82
//! The RDKit is optionally built with the Revvity ChemDraw parser
83
//! If this is available, CDX and CDXML can be read, see CDXMLParserParams
84
//! Note that the CDXML format is large and complex, the RDKit doesn't
85
//! support full functionality, just the base ones required for molecule and
86
//! reaction parsing.
87
//! Note: If the ChemDraw extensions are available,
88
//! CDXMLFormat::Auto attempts to see if the input string is CDXML or CDX
89
/*!
90
* \param cdxml - string containing the mol block
91
* \param params - parameters controlling the parsing and post-processing
92
*/
93
RDKIT_FILEPARSERS_EXPORT
std::vector<std::unique_ptr<RWMol>>
MolsFromCDXML
(
94
const
std::string &cdxml,
95
const
CDXMLParserParams
¶ms =
96
CDXMLParserParams
(
true
,
true
,
v2::CDXMLParser::CDXMLFormat::Auto
));
97
98
//! \brief write a CDX or CDXML block from a molecule
99
//! The RDKit is optionally built with the Revvity ChemDraw parser
100
//! If this is available, CDX and CDXML can be written
101
//! Note that the CDXML format is large and complex, the RDKit doesn't
102
//! support full functionality, just the base ones required for molecule and
103
//! reaction parsing.
104
//! Note: If the ChemDraw extensions are unavailable, an exception will be thrown
105
//! please use the support function hasChemDrawCDXSupport() to check
106
//! whether ChemDraw writing support is enabled.
107
//! Note: For CDXML the contents of the std::string are UTF-8
108
//! For CDX they are the binary bytes.
109
/*!
110
* \param mol - Molecule to write
111
* \param format - CDXMLFormat to use, CDX or CDXML (default)
112
*/
113
RDKIT_FILEPARSERS_EXPORT
std::string
MolToCDXMLBlock
(
114
const
RWMol
&mol,
115
CDXMLFormat
format =
CDXMLFormat::CDXML
);
116
}
// namespace CDXMLParser
117
}
// namespace v2
118
119
inline
namespace
v1
{
120
121
//! \brief construct molecules from a CDXML file
122
//! Note that the CDXML format is large and complex, the RDKit doesn't support
123
//! full functionality, just the base ones required for molecule and
124
//! reaction parsing.
125
//! Note: If the ChemDraw extensions are available, this auto detects between
126
//! CDXML and CDX
127
/*!
128
* \param inStream - string containing the mol block
129
* \param sanitize - toggles sanitization and stereochemistry
130
* perception of the molecule
131
* \param removeHs - toggles removal of Hs from the molecule. H removal
132
* is only done if the molecule is sanitized
133
* correctness of the contents.
134
*/
135
inline
std::vector<std::unique_ptr<RWMol>>
CDXMLDataStreamToMols
(
136
std::istream &inStream,
bool
sanitize =
true
,
bool
removeHs =
true
) {
137
v2::CDXMLParser::CDXMLParserParams
params(sanitize, removeHs,
138
v2::CDXMLParser::CDXMLFormat::Auto
);
139
return
v2::CDXMLParser::MolsFromCDXMLDataStream
(inStream, params);
140
}
141
142
//! \brief construct molecules from a CDXML file
143
//! Note that the CDXML format is large and complex, the RDKit doesn't support
144
//! full functionality, just the base ones required for molecule and
145
//! reaction parsing.
146
//! Note: If the ChemDraw extensions are available,
147
//! This function uses the file extension to determine the file type, .cdx or
148
//! .cdxml If not, it defaults to CDXML
149
/*!
150
* \param fileName - cdxml fileName
151
* \param sanitize - toggles sanitization and stereochemistry
152
* perception of the molecule
153
* \param removeHs - toggles removal of Hs from the molecule. H removal
154
* is only done if the molecule is sanitized
155
* correctness of the contents.
156
*/
157
inline
std::vector<std::unique_ptr<RWMol>>
CDXMLFileToMols
(
158
const
std::string &filename,
bool
sanitize =
true
,
bool
removeHs =
true
) {
159
v2::CDXMLParser::CDXMLParserParams
params;
160
params.
sanitize
= sanitize;
161
params.
removeHs
= removeHs;
162
params.
format
=
v2::CDXMLParser::CDXMLFormat::Auto
;
163
return
v2::CDXMLParser::MolsFromCDXMLFile
(filename, params);
164
}
165
166
//! \brief construct molecules from a CDXML block
167
//! Note that the CDXML format is large and complex, the RDKit doesn't support
168
//! full functionality, just the base ones required for molecule and
169
//! reaction parsing.
170
//! Note: to parse CDX files see the CDXParserParams variant of this function
171
/*!
172
* \param cdxml - string containing the mol block
173
* \param sanitize - toggles sanitization and stereochemistry
174
* perception of the molecule
175
* \param removeHs - toggles removal of Hs from the molecule. H removal
176
* is only done if the molecule is sanitized
177
* correctness of the contents.
178
*/
179
inline
std::vector<std::unique_ptr<RWMol>>
CDXMLToMols
(
const
std::string &cdxml,
180
bool
sanitize =
true
,
181
bool
removeHs =
true
) {
182
v2::CDXMLParser::CDXMLParserParams
params;
183
params.
sanitize
= sanitize;
184
params.
removeHs
= removeHs;
185
params.
format
=
v2::CDXMLParser::CDXMLFormat::Auto
;
186
return
v2::CDXMLParser::MolsFromCDXML
(cdxml, params);
187
}
188
}
// namespace v1
189
190
}
// namespace RDKit
191
#endif
// RD_CDXML_FILEPARSERS_H
RWMol.h
Defines the editable molecule class RWMol.
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition
RWMol.h:32
export.h
RDKIT_FILEPARSERS_EXPORT
#define RDKIT_FILEPARSERS_EXPORT
Definition
export.h:221
RDKit::v1
Definition
ReactionParser.h:91
RDKit::v1::CDXMLToMols
std::vector< std::unique_ptr< RWMol > > CDXMLToMols(const std::string &cdxml, bool sanitize=true, bool removeHs=true)
construct molecules from a CDXML block Note that the CDXML format is large and complex,...
Definition
CDXMLParser.h:179
RDKit::v1::CDXMLFileToMols
std::vector< std::unique_ptr< RWMol > > CDXMLFileToMols(const std::string &filename, bool sanitize=true, bool removeHs=true)
construct molecules from a CDXML file Note that the CDXML format is large and complex,...
Definition
CDXMLParser.h:157
RDKit::v1::CDXMLDataStreamToMols
std::vector< std::unique_ptr< RWMol > > CDXMLDataStreamToMols(std::istream &inStream, bool sanitize=true, bool removeHs=true)
construct molecules from a CDXML file Note that the CDXML format is large and complex,...
Definition
CDXMLParser.h:135
RDKit::v2::CDXMLParser
Definition
CDXMLParser.h:23
RDKit::v2::CDXMLParser::CDXMLFormat
CDXMLFormat
Definition
CDXMLParser.h:25
RDKit::v2::CDXMLParser::CDXMLFormat::Auto
@ Auto
Definition
CDXMLParser.h:28
RDKit::v2::CDXMLParser::CDXMLFormat::CDXML
@ CDXML
Definition
CDXMLParser.h:26
RDKit::v2::CDXMLParser::CDXMLFormat::CDX
@ CDX
Definition
CDXMLParser.h:27
RDKit::v2::CDXMLParser::MolsFromCDXMLFile
RDKIT_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXMLFile(const std::string &filename, const CDXMLParserParams ¶ms=CDXMLParserParams(true, true, CDXMLFormat::Auto))
construct molecules from a CDXML file The RDKit is optionally built with the Revvity ChemDraw parser ...
RDKit::v2::CDXMLParser::MolsFromCDXMLDataStream
RDKIT_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXMLDataStream(std::istream &inStream, const CDXMLParserParams ¶ms=CDXMLParserParams())
construct molecules from a CDXML file The RDKit is optionally built with the Revvity ChemDraw parser ...
RDKit::v2::CDXMLParser::MolToCDXMLBlock
RDKIT_FILEPARSERS_EXPORT std::string MolToCDXMLBlock(const RWMol &mol, CDXMLFormat format=CDXMLFormat::CDXML)
write a CDX or CDXML block from a molecule The RDKit is optionally built with the Revvity ChemDraw pa...
RDKit::v2::CDXMLParser::MolsFromCDXML
RDKIT_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXML(const std::string &cdxml, const CDXMLParserParams ¶ms=CDXMLParserParams(true, true, v2::CDXMLParser::CDXMLFormat::Auto))
construct molecules from a CDXML block The RDKit is optionally built with the Revvity ChemDraw parser...
RDKit::v2::CDXMLParser::hasChemDrawCDXSupport
RDKIT_FILEPARSERS_EXPORT bool hasChemDrawCDXSupport()
Returns true if the RDKit was build with ChemDraw CDX support.
RDKit::v2
Definition
ReactionParser.h:71
RDKit
Std stuff.
Definition
Abbreviations.h:19
RDKit::v2::CDXMLParser::CDXMLParserParams
Definition
CDXMLParser.h:34
RDKit::v2::CDXMLParser::CDXMLParserParams::format
CDXMLFormat format
Definition
CDXMLParser.h:37
RDKit::v2::CDXMLParser::CDXMLParserParams::removeHs
bool removeHs
Definition
CDXMLParser.h:36
RDKit::v2::CDXMLParser::CDXMLParserParams::CDXMLParserParams
CDXMLParserParams()=default
RDKit::v2::CDXMLParser::CDXMLParserParams::sanitize
bool sanitize
Definition
CDXMLParser.h:35
RDKit::v2::CDXMLParser::CDXMLParserParams::strictQueryParsing
bool strictQueryParsing
Definition
CDXMLParser.h:39
RDKit::v2::CDXMLParser::CDXMLParserParams::parseQueries
bool parseQueries
Definition
CDXMLParser.h:38
RDKit::v2::CDXMLParser::CDXMLParserParams::CDXMLParserParams
CDXMLParserParams(bool sanitize, bool removeHs, CDXMLFormat format, bool parseQueries=false, bool strictQueryParsing=false)
Definition
CDXMLParser.h:42
types.h
GraphMol
FileParsers
CDXMLParser.h
Generated on
for RDKit by
1.17.0