RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
FileWriters.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2024 Greg Landrum and other RDKit contributors
3//
4// @@ All Rights Reserved @@
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_FILEWRITERS_H
12#define RD_FILEWRITERS_H
13
14#include <RDGeneral/types.h>
15#include <GraphMol/RDKitBase.h>
16#include <string>
17#include <iostream>
18
19namespace RDKit {
20
22 bool includeStereo = true; /**< toggles inclusion of stereochemistry
23 information*/
24 bool kekulize = true; /**< triggers kekulization of the molecule before
25 it is written*/
26 bool forceV3000 = false; /**< force generation a V3000 mol block (happens
27 automatically with more than 999 atoms or
28 bonds)*/
29 unsigned int precision = 6; /**< precision of coordinates (only available in
30 V3000)*/
31};
32
33// \brief generates an MDL mol block for a molecule
34/*!
35 * \param mol - the molecule in question
36 * \param MolWriterParams - parmeter struct with write options
37 * \param confId - selects the conformer to be used
38 * (default=-1 - find first in mol)
39 */
41 const ROMol &mol, const MolWriterParams &params, int confId = -1);
42
43// \brief generates an MDL mol block for a molecule
44/*!
45 * \param mol - the molecule in question
46 * \param includeStereo - toggles inclusion of stereochemistry information
47 * (default=true)
48 * \param confId - selects the conformer to be used
49 * (default=-1 - find first in mol)
50 * \param kekulize - triggers kekulization
51 * of the molecule before it is written (default=true)
52 * \param forceV3000 - force generation a V3000 mol block (happens
53 * automatically with more than 999 atoms or
54 * bonds)(default=false)
55 */
56inline std::string MolToMolBlock(const ROMol &mol, bool includeStereo = true,
57 int confId = -1, bool kekulize = true,
58 bool forceV3000 = false) {
59 MolWriterParams params{includeStereo, kekulize, forceV3000};
60 return MolToMolBlock(mol, params, confId);
61}
62
63// \brief generates an MDL v3000 mol block for a molecule
64/*!
65 * \param mol - the molecule in question
66 * \param MolWriterParams - parameter struct with write options
67 * \param confId - selects the conformer to be used
68 * (default=-1 - find first in mol)
69 */
70inline std::string MolToV3KMolBlock(const ROMol &mol,
71 const MolWriterParams &params,
72 int confId = -1) {
73 // have to set forceV300, prefer copy over mutable params argument
75 v3KParams.forceV3000 = true;
76 return MolToMolBlock(mol, v3KParams, confId);
77}
78
79// \brief generates an MDL v3000 mol block for a molecule
80/*!
81 * \param mol - the molecule in question
82 * \param includeStereo - toggles inclusion of stereochemistry information
83 * \param confId - selects the conformer to be used
84 * (default=-1 - find first in mol)
85 * \param kekulize - triggers kekulization of the molecule before it is
86 * - written
87 */
88inline std::string MolToV3KMolBlock(const ROMol &mol, bool includeStereo = true,
89 int confId = -1, bool kekulize = true) {
90 MolWriterParams params{includeStereo, kekulize, true};
91 return MolToMolBlock(mol, params, confId);
92}
93
94// \brief generates an MDL v2000 mol block for a molecule
95/*!
96 * \param mol - the molecule in question
97 * \param MolWriterParams - parameter struct with write options
98 * \param confId - selects the conformer to be used
99 * (default=-1 - find first in mol)
100 *
101 * \note This function will throw a ValueError exception if the molecule has
102 * more than 999 atoms, bonds, or SGroups.
103 */
105 const ROMol &mol, const MolWriterParams &params = MolWriterParams(),
106 int confId = -1);
107
108// \brief Writes a molecule to an MDL mol file
109/*!
110 * \param mol - the molecule in question
111 * \param fName - the name of the file to use
112 * \param MolWriterParams - parameter struct with write options
113 * \param confId - selects the conformer to be used
114 */
116 const std::string &fName,
117 const MolWriterParams &params,
118 int confId = -1);
119
120// \brief Writes a molecule to an MDL mol file
121/*!
122 * \param mol - the molecule in question
123 * \param fName - the name of the file to use
124 * \param includeStereo - toggles inclusion of stereochemistry information
125 * \param confId - selects the conformer to be used
126 * \param kekulize - triggers kekulization of the molecule before it is
127 * written
128 * \param forceV3000 - force generation a V3000 mol block (happens
129 * automatically with
130 * more than 999 atoms or bonds)
131 */
132inline void MolToMolFile(const ROMol &mol, const std::string &fName,
133 bool includeStereo = true, int confId = -1,
134 bool kekulize = true, bool forceV3000 = false) {
135 MolWriterParams params{includeStereo, kekulize, forceV3000};
136 MolToMolFile(mol, fName, params, confId);
137}
138
139// \brief Writes a molecule to an MDL V3000 mol file
140/*!
141 * \param mol - the molecule in question
142 * \param fName - the name of the file to use
143 * \param MolWriterParams - parameter struct with write options
144 * \param confId - selects the conformer to be used
145 */
146inline void MolToV3KMolFile(const ROMol &mol, const std::string &fName,
147 const MolWriterParams &params, int confId = -1) {
148 // have to set forceV300, prefer copy over mutable params argument
150 v3KParams.forceV3000 = true;
151 MolToMolFile(mol, fName, v3KParams, confId);
152}
153
154// \brief Writes a molecule to an MDL V3000 mol file
155/*!
156 * \param mol - the molecule in question
157 * \param fName - the name of the file to use
158 * \param includeStereo - toggles inclusion of stereochemistry information
159 * \param confId - selects the conformer to be used
160 * \param kekulize - triggers kekulization of the molecule before it is
161 * written
162 */
163inline void MolToV3KMolFile(const ROMol &mol, const std::string &fName,
164 bool includeStereo = true, int confId = -1,
165 bool kekulize = true) {
166 MolWriterParams params{includeStereo, kekulize, true};
167 MolToMolFile(mol, fName, params, confId);
168}
169
171 int confId = -1,
172 bool kekulize = true);
173
175 const std::string &fName,
176 int confId = -1,
177 bool kekulize = true);
178
179// \brief Writes a molecule to an XYZ block
180/*!
181 * \param mol - the molecule in question
182 * \param confId - selects which conformation to output
183 * \param precision - precision of the coordinates
184 */
186 int confId = -1,
187 unsigned int precision = 6);
188
189// \brief Writes a molecule to an XYZ block
190/*!
191 * \param mol - the molecule in question
192 * \param fName - the file to write to
193 * \param confId - selects which conformation to output
194 * \param precision - precision of the coordinates
195 */
197 const std::string &fName,
198 int confId = -1,
199 unsigned int precision = 6);
200
202 const ROMol &mol, const std::string &partialChargeProp = "_GasteigerCharge",
203 bool writeFirstConfTwice = false);
205 const ROMol &mol, const std::string &fName,
206 const std::string &partialChargeProp = "_GasteigerCharge",
207 bool writeFirstConfTwice = false);
208
209// \brief generates an PDB block for a molecule
210/*!
211 * \param mol - the molecule in question
212 * \param confId - selects the conformer to be used
213 * \param flavor - controls what gets written:
214 * flavor & 1 : Write MODEL/ENDMDL lines around each record
215 * flavor & 2 : Don't write single CONECT records
216 * flavor & 4 : Write CONECT records in both directions
217 * flavor & 8 : Don't use multiple CONECTs to encode bond order
218 * flavor & 16 : Write MASTER record
219 * flavor & 32 : Write TER record
220 */
222 int confId = -1,
223 unsigned int flavor = 0);
224// \brief Writes a molecule to an MDL mol file
225/*!
226 * \param mol - the molecule in question
227 * \param fName - the name of the file to use
228 * \param confId - selects the conformer to be used
229 * \param flavor - controls what gets written:
230 * flavor & 1 : Write MODEL/ENDMDL lines around each record
231 * flavor & 2 : Don't write single CONECT records
232 * flavor & 4 : Write CONECT records in both directions
233 * flavor & 8 : Don't use multiple CONECTs to encode bond order
234 * flavor & 16 : Write MASTER record
235 * flavor & 32 : Write TER record
236 */
238 const std::string &fname,
239 int confId = -1,
240 unsigned int flavor = 0);
241
242} // namespace RDKit
243
244#endif
pulls in the core RDKit functionality
#define RDKIT_FILEPARSERS_EXPORT
Definition export.h:161
Std stuff.
RDKIT_FILEPARSERS_EXPORT std::string MolToPDBBlock(const ROMol &mol, int confId=-1, unsigned int flavor=0)
bool rdvalue_is(const RDValue_cast_t)
RDKIT_FILEPARSERS_EXPORT void MolToMolFile(const ROMol &mol, const std::string &fName, const MolWriterParams &params, int confId=-1)
RDKIT_FILEPARSERS_EXPORT std::string MolToTPLText(const ROMol &mol, const std::string &partialChargeProp="_GasteigerCharge", bool writeFirstConfTwice=false)
RDKIT_FILEPARSERS_EXPORT void MolToPDBFile(const ROMol &mol, const std::string &fname, int confId=-1, unsigned int flavor=0)
RDKIT_FILEPARSERS_EXPORT void MolToCMLFile(const ROMol &mol, const std::string &fName, int confId=-1, bool kekulize=true)
RDKIT_FILEPARSERS_EXPORT std::string MolToXYZBlock(const ROMol &mol, int confId=-1, unsigned int precision=6)
std::string MolToV3KMolBlock(const ROMol &mol, const MolWriterParams &params, int confId=-1)
Definition FileWriters.h:70
RDKIT_FILEPARSERS_EXPORT std::string MolToCMLBlock(const ROMol &mol, int confId=-1, bool kekulize=true)
RDKIT_FILEPARSERS_EXPORT void MolToXYZFile(const ROMol &mol, const std::string &fName, int confId=-1, unsigned int precision=6)
RDKIT_FILEPARSERS_EXPORT std::string MolToMolBlock(const ROMol &mol, const MolWriterParams &params, int confId=-1)
RDKIT_FILEPARSERS_EXPORT void MolToTPLFile(const ROMol &mol, const std::string &fName, const std::string &partialChargeProp="_GasteigerCharge", bool writeFirstConfTwice=false)
void MolToV3KMolFile(const ROMol &mol, const std::string &fName, const MolWriterParams &params, int confId=-1)
RDKIT_FILEPARSERS_EXPORT std::string MolToV2KMolBlock(const ROMol &mol, const MolWriterParams &params=MolWriterParams(), int confId=-1)