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 <iostream>
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
43
44//! \brief construct molecules from a CDXML file
45//! The RDKit is optionally built with the Revvity ChemDraw parser
46//! If this is available, CDX and CDXML can be read, see CDXMLParserParams
47//! Note that the CDXML format is large and complex, the RDKit doesn't
48//! support full functionality, just the base ones required for molecule and
49//! reaction parsing.
50//! Note: If the ChemDraw extensions are available, this auto detects between
51//! CDXML and CDX
52/*!
53 * \param inStream - string containing the mol block
54 * \param params - parameters controlling the parsing and post-processing
55 */
56RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>>
57MolsFromCDXMLDataStream(std::istream &inStream,
58 const CDXMLParserParams &params = CDXMLParserParams());
59//! \brief construct molecules from a CDXML file
60//! The RDKit is optionally built with the Revvity ChemDraw parser
61//! If this is available, CDX and CDXML can be read, see CDXMLParserParams
62//! Note that the CDXML format is large and complex, the RDKit doesn't
63//! support full functionality, just the base ones required for molecule and
64//! reaction parsing.
65/*!
66 * \param fileName - cdxml fileName
67 * \param params - parameters controlling the parsing and post-processing
68 */
69RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXMLFile(
70 const std::string &filename,
71 const CDXMLParserParams &params = CDXMLParserParams(true, true, 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 */
85RDKIT_FILEPARSERS_EXPORT std::vector<std::unique_ptr<RWMol>> MolsFromCDXML(
86 const std::string &cdxml,
88} // namespace CDXMLParser
89} // namespace v2
90
91inline namespace v1 {
92
93//! \brief construct molecules from a CDXML file
94//! Note that the CDXML format is large and complex, the RDKit doesn't support
95//! full functionality, just the base ones required for molecule and
96//! reaction parsing.
97//! Note: If the ChemDraw extensions are available, this auto detects between
98//! CDXML and CDX
99/*!
100 * \param inStream - string containing the mol block
101 * \param sanitize - toggles sanitization and stereochemistry
102 * perception of the molecule
103 * \param removeHs - toggles removal of Hs from the molecule. H removal
104 * is only done if the molecule is sanitized
105 * correctness of the contents.
106 */
107inline std::vector<std::unique_ptr<RWMol>> CDXMLDataStreamToMols(
108 std::istream &inStream, bool sanitize = true, bool removeHs = true) {
110 sanitize, removeHs, v2::CDXMLParser::CDXMLFormat::Auto);
111 return v2::CDXMLParser::MolsFromCDXMLDataStream(inStream, params);
112}
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,
119//! This function uses the file extension to determine the file type, .cdx or .cdxml
120//! If not, it defaults to CDXML
121/*!
122 * \param fileName - cdxml fileName
123 * \param sanitize - toggles sanitization and stereochemistry
124 * perception of the molecule
125 * \param removeHs - toggles removal of Hs from the molecule. H removal
126 * is only done if the molecule is sanitized
127 * correctness of the contents.
128 */
129inline std::vector<std::unique_ptr<RWMol>> CDXMLFileToMols(
130 const std::string &filename, bool sanitize = true, bool removeHs = true) {
132 params.sanitize = sanitize;
133 params.removeHs = removeHs;
135 return v2::CDXMLParser::MolsFromCDXMLFile(filename, params);
136}
137
138//! \brief construct molecules from a CDXML block
139//! Note that the CDXML format is large and complex, the RDKit doesn't support
140//! full functionality, just the base ones required for molecule and
141//! reaction parsing.
142//! Note: to parse CDX files see the CDXParserParams variant of this function
143/*!
144 * \param cdxml - string containing the mol block
145 * \param sanitize - toggles sanitization and stereochemistry
146 * perception of the molecule
147 * \param removeHs - toggles removal of Hs from the molecule. H removal
148 * is only done if the molecule is sanitized
149 * correctness of the contents.
150 */
151inline std::vector<std::unique_ptr<RWMol>> CDXMLToMols(const std::string &cdxml,
152 bool sanitize = true,
153 bool removeHs = true) {
155 params.sanitize = sanitize;
156 params.removeHs = removeHs;
158 return v2::CDXMLParser::MolsFromCDXML(cdxml, params);
159}
160} // namespace v1
161
162} // namespace RDKit
163#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:40