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 bond or if the magnitude of the coordinates
29 are too large)*/
30 unsigned int precision = 6; /**< precision of coordinates (only available in
31 V3000)*/
32};
33
34// \brief generates an MDL mol block for a molecule
35/*!
36 * \param mol - the molecule in question
37 * \param MolWriterParams - parmeter struct with write options
38 * \param confId - selects the conformer to be used
39 * (default=-1 - find first in mol)
40 */
42 const ROMol &mol, const MolWriterParams &params, int confId = -1);
43
44// \brief generates an MDL mol block for a molecule
45/*!
46 * \param mol - the molecule in question
47 * \param includeStereo - toggles inclusion of stereochemistry information
48 * (default=true)
49 * \param confId - selects the conformer to be used
50 * (default=-1 - find first in mol)
51 * \param kekulize - triggers kekulization
52 * of the molecule before it is written (default=true)
53 * \param forceV3000 - force generation a V3000 mol block (happens
54 * automatically with more than 999 atoms or
55 * bonds)(default=false)
56 */
57inline std::string MolToMolBlock(const ROMol &mol, bool includeStereo = true,
58 int confId = -1, bool kekulize = true,
59 bool forceV3000 = false) {
60 MolWriterParams params{includeStereo, kekulize, forceV3000};
61 return MolToMolBlock(mol, params, confId);
62}
63
64// \brief generates an MDL v3000 mol block for a molecule
65/*!
66 * \param mol - the molecule in question
67 * \param MolWriterParams - parameter struct with write options
68 * \param confId - selects the conformer to be used
69 * (default=-1 - find first in mol)
70 */
71inline std::string MolToV3KMolBlock(const ROMol &mol,
72 const MolWriterParams &params,
73 int confId = -1) {
74 // have to set forceV300, prefer copy over mutable params argument
76 v3KParams.forceV3000 = true;
77 return MolToMolBlock(mol, v3KParams, confId);
78}
79
80// \brief generates an MDL v3000 mol block for a molecule
81/*!
82 * \param mol - the molecule in question
83 * \param includeStereo - toggles inclusion of stereochemistry information
84 * \param confId - selects the conformer to be used
85 * (default=-1 - find first in mol)
86 * \param kekulize - triggers kekulization of the molecule before it is
87 * - written
88 */
89inline std::string MolToV3KMolBlock(const ROMol &mol, bool includeStereo = true,
90 int confId = -1, bool kekulize = true) {
91 MolWriterParams params{includeStereo, kekulize, true};
92 return MolToMolBlock(mol, params, confId);
93}
94
95// \brief generates an MDL v2000 mol block for a molecule
96/*!
97 * \param mol - the molecule in question
98 * \param MolWriterParams - parameter struct with write options
99 * \param confId - selects the conformer to be used
100 * (default=-1 - find first in mol)
101 *
102 * \note This function will throw a ValueError exception if the molecule has
103 * more than 999 atoms, bonds, or SGroups.
104 */
106 const ROMol &mol, const MolWriterParams &params = MolWriterParams(),
107 int confId = -1);
108
109// \brief Writes a molecule to an MDL mol file
110/*!
111 * \param mol - the molecule in question
112 * \param fName - the name of the file to use
113 * \param MolWriterParams - parameter struct with write options
114 * \param confId - selects the conformer to be used
115 */
117 const std::string &fName,
118 const MolWriterParams &params,
119 int confId = -1);
120
121// \brief Writes a molecule to an MDL mol file
122/*!
123 * \param mol - the molecule in question
124 * \param fName - the name of the file to use
125 * \param includeStereo - toggles inclusion of stereochemistry information
126 * \param confId - selects the conformer to be used
127 * \param kekulize - triggers kekulization of the molecule before it is
128 * written
129 * \param forceV3000 - force generation a V3000 mol block (happens
130 * automatically with
131 * more than 999 atoms or bonds)
132 */
133inline void MolToMolFile(const ROMol &mol, const std::string &fName,
134 bool includeStereo = true, int confId = -1,
135 bool kekulize = true, bool forceV3000 = false) {
136 MolWriterParams params{includeStereo, kekulize, forceV3000};
137 MolToMolFile(mol, fName, params, confId);
138}
139
140// \brief Writes a molecule to an MDL V3000 mol file
141/*!
142 * \param mol - the molecule in question
143 * \param fName - the name of the file to use
144 * \param MolWriterParams - parameter struct with write options
145 * \param confId - selects the conformer to be used
146 */
147inline void MolToV3KMolFile(const ROMol &mol, const std::string &fName,
148 const MolWriterParams &params, int confId = -1) {
149 // have to set forceV300, prefer copy over mutable params argument
151 v3KParams.forceV3000 = true;
152 MolToMolFile(mol, fName, v3KParams, confId);
153}
154
155// \brief Writes a molecule to an MDL V3000 mol file
156/*!
157 * \param mol - the molecule in question
158 * \param fName - the name of the file to use
159 * \param includeStereo - toggles inclusion of stereochemistry information
160 * \param confId - selects the conformer to be used
161 * \param kekulize - triggers kekulization of the molecule before it is
162 * written
163 */
164inline void MolToV3KMolFile(const ROMol &mol, const std::string &fName,
165 bool includeStereo = true, int confId = -1,
166 bool kekulize = true) {
167 MolWriterParams params{includeStereo, kekulize, true};
168 MolToMolFile(mol, fName, params, confId);
169}
170
172 int confId = -1,
173 bool kekulize = true);
174
176 const std::string &fName,
177 int confId = -1,
178 bool kekulize = true);
179
180// \brief Writes a molecule to an XYZ block
181/*!
182 * \param mol - the molecule in question
183 * \param confId - selects which conformation to output
184 * \param precision - precision of the coordinates
185 */
187 int confId = -1,
188 unsigned int precision = 6);
189
190// \brief Writes a molecule to an XYZ block
191/*!
192 * \param mol - the molecule in question
193 * \param fName - the file to write to
194 * \param confId - selects which conformation to output
195 * \param precision - precision of the coordinates
196 */
198 const std::string &fName,
199 int confId = -1,
200 unsigned int precision = 6);
201
203 const ROMol &mol, const std::string &partialChargeProp = "_GasteigerCharge",
204 bool writeFirstConfTwice = false);
206 const ROMol &mol, const std::string &fName,
207 const std::string &partialChargeProp = "_GasteigerCharge",
208 bool writeFirstConfTwice = false);
209
210// \brief generates an PDB block for a molecule
211/*!
212 * \param mol - the molecule in question
213 * \param confId - selects the conformer to be used
214 * \param flavor - controls what gets written:
215 * flavor & 1 : Write MODEL/ENDMDL lines around each record
216 * flavor & 2 : Don't write single CONECT records
217 * flavor & 4 : Write CONECT records in both directions
218 * flavor & 8 : Don't use multiple CONECTs to encode bond order
219 * flavor & 16 : Write MASTER record
220 * flavor & 32 : Write TER record
221 */
223 int confId = -1,
224 unsigned int flavor = 0);
225// \brief Writes a molecule to an MDL mol file
226/*!
227 * \param mol - the molecule in question
228 * \param fName - the name of the file to use
229 * \param confId - selects the conformer to be used
230 * \param flavor - controls what gets written:
231 * flavor & 1 : Write MODEL/ENDMDL lines around each record
232 * flavor & 2 : Don't write single CONECT records
233 * flavor & 4 : Write CONECT records in both directions
234 * flavor & 8 : Don't use multiple CONECTs to encode bond order
235 * flavor & 16 : Write MASTER record
236 * flavor & 32 : Write TER record
237 */
239 const std::string &fname,
240 int confId = -1,
241 unsigned int flavor = 0);
242
243} // namespace RDKit
244
245#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:71
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)