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