RDKit
Open-source cheminformatics and machine learning.
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
19namespace RDKit {
20class RWMol;
21
22namespace v2 {
23namespace CDXMLParser {
24
25enum 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
33
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 */
63RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>>
64MolsFromCDXMLDataStream(std::istream &inStream,
65 const CDXMLParserParams &params = 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 */
76RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXMLFile(
77 const std::string &filename,
78 const CDXMLParserParams &params = CDXMLParserParams(true, true,
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 */
93RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXML(
94 const std::string &cdxml,
95 const CDXMLParserParams &params =
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 */
114 const RWMol &mol,
116} // namespace CDXMLParser
117} // namespace v2
118
119inline 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 */
135inline std::vector<std::unique_ptr<RWMol>> CDXMLDataStreamToMols(
136 std::istream &inStream, bool sanitize = true, bool removeHs = true) {
137 v2::CDXMLParser::CDXMLParserParams params(sanitize, removeHs,
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 */
157inline std::vector<std::unique_ptr<RWMol>> CDXMLFileToMols(
158 const std::string &filename, bool sanitize = true, bool removeHs = true) {
160 params.sanitize = sanitize;
161 params.removeHs = removeHs;
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 */
179inline std::vector<std::unique_ptr<RWMol>> CDXMLToMols(const std::string &cdxml,
180 bool sanitize = true,
181 bool removeHs = true) {
183 params.sanitize = sanitize;
184 params.removeHs = removeHs;
186 return v2::CDXMLParser::MolsFromCDXML(cdxml, params);
187}
188} // namespace v1
189
190} // namespace RDKit
191#endif // RD_CDXML_FILEPARSERS_H
Defines the editable molecule class RWMol.
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
#define RDKIT_FILEPARSERS_EXPORT
Definition export.h:221
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,...
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,...
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,...
RDKIT_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXMLFile(const std::string &filename, const CDXMLParserParams &params=CDXMLParserParams(true, true, CDXMLFormat::Auto))
construct molecules from a CDXML file The RDKit is optionally built with the Revvity ChemDraw parser ...
RDKIT_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXMLDataStream(std::istream &inStream, const CDXMLParserParams &params=CDXMLParserParams())
construct molecules from a CDXML file The RDKit is optionally built with the Revvity ChemDraw parser ...
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_FILEPARSERS_EXPORT std::vector< std::unique_ptr< RWMol > > MolsFromCDXML(const std::string &cdxml, const CDXMLParserParams &params=CDXMLParserParams(true, true, v2::CDXMLParser::CDXMLFormat::Auto))
construct molecules from a CDXML block The RDKit is optionally built with the Revvity ChemDraw parser...
RDKIT_FILEPARSERS_EXPORT bool hasChemDrawCDXSupport()
Returns true if the RDKit was build with ChemDraw CDX support.
Std stuff.
CDXMLParserParams(bool sanitize, bool removeHs, CDXMLFormat format, bool parseQueries=false, bool strictQueryParsing=false)
Definition CDXMLParser.h:42