RDKit: CDXMLParser.h Source File

| 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 {
22 namespace CDXMLParser {
23
24 enum 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
31 RDKIT_FILEPARSERS_EXPORT bool hasChemDrawCDXSupport();
32
33 struct RDKIT_FILEPARSERS_EXPORT CDXMLParserParams {
34 bool sanitize = true;
35 bool removeHs = true;
36 CDXMLFormat format = CDXMLFormat::Auto;
37
38 CDXMLParserParams() = default;
39 CDXMLParserParams(bool sanitize, bool removeHs, CDXMLFormat format)
40 : sanitize(sanitize), removeHs(removeHs), format(format) {}
41};
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 */
55 RDKIT_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 */
68 RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXMLFile(
69 const std::string &filename,
70 const CDXMLParserParams &params = CDXMLParserParams(true, true,
71 CDXMLFormat::Auto));
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 */
85 RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXML(
86 const std::string &cdxml,
87 const CDXMLParserParams &params =
88 CDXMLParserParams(true, true, v2::CDXMLParser::CDXMLFormat::Auto));
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 */
108 inline std::vector<std::unique_ptr<RWMol>> CDXMLDataStreamToMols(
109 std::istream &inStream, bool sanitize = true, bool removeHs = true) {
110 v2::CDXMLParser::CDXMLParserParams params(sanitize, removeHs,
111 v2::CDXMLParser::CDXMLFormat::Auto);
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 */
130 inline std::vector<std::unique_ptr<RWMol>> CDXMLFileToMols(
131 const std::string &filename, bool sanitize = true, bool removeHs = true) {
132 v2::CDXMLParser::CDXMLParserParams params;
133 params.sanitize = sanitize;
134 params.removeHs = removeHs;
135 params.format = v2::CDXMLParser::CDXMLFormat::Auto;
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 */
152 inline std::vector<std::unique_ptr<RWMol>> CDXMLToMols(const std::string &cdxml,
153 bool sanitize = true,
154 bool removeHs = true) {
155 v2::CDXMLParser::CDXMLParserParams params;
156 params.sanitize = sanitize;
157 params.removeHs = removeHs;
158 params.format = v2::CDXMLParser::CDXMLFormat::Auto;
159 return v2::CDXMLParser::MolsFromCDXML(cdxml, params);
160}
161} // namespace v1
162
163} // namespace RDKit
164#endif // RD_CDXML_FILEPARSERS_H
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:177
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:152
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:130
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:108
RDKit::v2::CDXMLParser
Definition CDXMLParser.h:22
RDKit::v2::CDXMLParser::CDXMLFormat
CDXMLFormat
Definition CDXMLParser.h:24
RDKit::v2::CDXMLParser::CDXMLFormat::Auto
@ Auto
Definition CDXMLParser.h:27
RDKit::v2::CDXMLParser::CDXMLFormat::CDXML
@ CDXML
Definition CDXMLParser.h:25
RDKit::v2::CDXMLParser::CDXMLFormat::CDX
@ CDX
Definition CDXMLParser.h:26
RDKit::v2::CDXMLParser::MolsFromCDXMLFile
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::v2::CDXMLParser::MolsFromCDXMLDataStream
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::v2::CDXMLParser::MolsFromCDXML
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::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:33
RDKit::v2::CDXMLParser::CDXMLParserParams::format
CDXMLFormat format
Definition CDXMLParser.h:36
RDKit::v2::CDXMLParser::CDXMLParserParams::removeHs
bool removeHs
Definition CDXMLParser.h:35
RDKit::v2::CDXMLParser::CDXMLParserParams::CDXMLParserParams
CDXMLParserParams()=default
RDKit::v2::CDXMLParser::CDXMLParserParams::sanitize
bool sanitize
Definition CDXMLParser.h:34
RDKit::v2::CDXMLParser::CDXMLParserParams::CDXMLParserParams
CDXMLParserParams(bool sanitize, bool removeHs, CDXMLFormat format)
Definition CDXMLParser.h:39
types.h