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} // namespace CDXMLParser
90} // namespace v2
91
92inline namespace v1 {
93
94//! \brief construct molecules from a CDXML file
95//! Note that the CDXML format is large and complex, the RDKit doesn't support
96//! full functionality, just the base ones required for molecule and
97//! reaction parsing.
98//! Note: If the ChemDraw extensions are available, this auto detects between
99//! CDXML and CDX
100/*!
101 * \param inStream - string containing the mol block
102 * \param sanitize - toggles sanitization and stereochemistry
103 * perception of the molecule
104 * \param removeHs - toggles removal of Hs from the molecule. H removal
105 * is only done if the molecule is sanitized
106 * correctness of the contents.
107 */
108inline std::vector<std::unique_ptr<RWMol>> CDXMLDataStreamToMols(
109 std::istream &inStream, bool sanitize = true, bool removeHs = true) {
110 v2::CDXMLParser::CDXMLParserParams params(sanitize, removeHs,
112 return v2::CDXMLParser::MolsFromCDXMLDataStream(inStream, params);
113}
114
115//! \brief construct molecules from a CDXML file
116//! Note that the CDXML format is large and complex, the RDKit doesn't support
117//! full functionality, just the base ones required for molecule and
118//! reaction parsing.
119//! Note: If the ChemDraw extensions are available,
120//! This function uses the file extension to determine the file type, .cdx or
121//! .cdxml If not, it defaults to CDXML
122/*!
123 * \param fileName - cdxml fileName
124 * \param sanitize - toggles sanitization and stereochemistry
125 * perception of the molecule
126 * \param removeHs - toggles removal of Hs from the molecule. H removal
127 * is only done if the molecule is sanitized
128 * correctness of the contents.
129 */
130inline std::vector<std::unique_ptr<RWMol>> CDXMLFileToMols(
131 const std::string &filename, bool sanitize = true, bool removeHs = true) {
133 params.sanitize = sanitize;
134 params.removeHs = removeHs;
136 return v2::CDXMLParser::MolsFromCDXMLFile(filename, params);
137}
138
139//! \brief construct molecules from a CDXML block
140//! Note that the CDXML format is large and complex, the RDKit doesn't support
141//! full functionality, just the base ones required for molecule and
142//! reaction parsing.
143//! Note: to parse CDX files see the CDXParserParams variant of this function
144/*!
145 * \param cdxml - string containing the mol block
146 * \param sanitize - toggles sanitization and stereochemistry
147 * perception of the molecule
148 * \param removeHs - toggles removal of Hs from the molecule. H removal
149 * is only done if the molecule is sanitized
150 * correctness of the contents.
151 */
152inline std::vector<std::unique_ptr<RWMol>> CDXMLToMols(const std::string &cdxml,
153 bool sanitize = true,
154 bool removeHs = true) {
156 params.sanitize = sanitize;
157 params.removeHs = removeHs;
159 return v2::CDXMLParser::MolsFromCDXML(cdxml, params);
160}
161} // namespace v1
162
163} // namespace RDKit
164#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::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