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 MolWriterParams &params,
42 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,
58 bool includeStereo = true,
59 int confId = -1,
60 bool kekulize = true,
61 bool forceV3000 = false) {
62 MolWriterParams params{includeStereo, kekulize, forceV3000};
63 return MolToMolBlock(mol, params, confId);
64}
65
66// \brief generates an MDL v3000 mol block for a molecule
67/*!
68 * \param mol - the molecule in question
69 * \param MolWriterParams - parameter struct with write options
70 * \param confId - selects the conformer to be used
71 * (default=-1 - find first in mol)
72 */
73inline std::string MolToV3KMolBlock(const ROMol &mol,
74 const MolWriterParams &params,
75 int confId = -1) {
76 // have to set forceV300, prefer copy over mutable params argument
78 v3KParams.forceV3000 = true;
79 return MolToMolBlock(mol, v3KParams, confId);
80}
81
82// \brief generates an MDL v3000 mol block for a molecule
83/*!
84 * \param mol - the molecule in question
85 * \param includeStereo - toggles inclusion of stereochemistry information
86 * \param confId - selects the conformer to be used
87 * (default=-1 - find first in mol)
88 * \param kekulize - triggers kekulization of the molecule before it is
89 * - written
90 */
91inline std::string MolToV3KMolBlock(const ROMol &mol, bool includeStereo = true,
92 int confId = -1, bool kekulize = true) {
93 MolWriterParams params{includeStereo, kekulize, true};
94 return MolToMolBlock(mol, params, confId);
95}
96
97// \brief Writes a molecule to an MDL mol file
98/*!
99 * \param mol - the molecule in question
100 * \param fName - the name of the file to use
101 * \param MolWriterParams - parameter struct with write options
102 * \param confId - selects the conformer to be used
103 */
105 const std::string &fName,
106 const MolWriterParams &params,
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 includeStereo - toggles inclusion of stereochemistry information
114 * \param confId - selects the conformer to be used
115 * \param kekulize - triggers kekulization of the molecule before it is
116 * written
117 * \param forceV3000 - force generation a V3000 mol block (happens
118 * automatically with
119 * more than 999 atoms or bonds)
120 */
121inline void MolToMolFile(
122 const ROMol &mol, const std::string &fName, bool includeStereo = true,
123 int confId = -1, bool kekulize = true, bool forceV3000 = false) {
124 MolWriterParams params{includeStereo, kekulize, forceV3000};
125 MolToMolFile(mol, fName, params, confId);
126}
127
128// \brief Writes a molecule to an MDL V3000 mol file
129/*!
130 * \param mol - the molecule in question
131 * \param fName - the name of the file to use
132 * \param MolWriterParams - parameter struct with write options
133 * \param confId - selects the conformer to be used
134 */
135inline void MolToV3KMolFile(const ROMol &mol,
136 const std::string &fName,
137 const MolWriterParams &params,
138 int confId = -1) {
139 // have to set forceV300, prefer copy over mutable params argument
141 v3KParams.forceV3000 = true;
142 MolToMolFile(mol, fName, v3KParams, confId);
143}
144
145// \brief Writes a molecule to an MDL V3000 mol file
146/*!
147 * \param mol - the molecule in question
148 * \param fName - the name of the file to use
149 * \param includeStereo - toggles inclusion of stereochemistry information
150 * \param confId - selects the conformer to be used
151 * \param kekulize - triggers kekulization of the molecule before it is
152 * written
153 */
154inline void MolToV3KMolFile(const ROMol &mol, const std::string &fName,
155 bool includeStereo = true, int confId = -1,
156 bool kekulize = true) {
157 MolWriterParams params{includeStereo, kekulize, true};
158 MolToMolFile(mol, fName, params, confId);
159}
160
162 int confId = -1,
163 bool kekulize = true);
164
166 const std::string &fName,
167 int confId = -1,
168 bool kekulize = true);
169
170// \brief Writes a molecule to an XYZ block
171/*!
172 * \param mol - the molecule in question
173 * \param confId - selects which conformation to output
174 * \param precision - precision of the coordinates
175 */
177 int confId = -1,
178 unsigned int precision = 6);
179
180// \brief Writes a molecule to an XYZ block
181/*!
182 * \param mol - the molecule in question
183 * \param fName - the file to write to
184 * \param confId - selects which conformation to output
185 * \param precision - precision of the coordinates
186 */
188 const std::string &fName,
189 int confId = -1,
190 unsigned int precision = 6);
191
193 const ROMol &mol, const std::string &partialChargeProp = "_GasteigerCharge",
194 bool writeFirstConfTwice = false);
196 const ROMol &mol, const std::string &fName,
197 const std::string &partialChargeProp = "_GasteigerCharge",
198 bool writeFirstConfTwice = false);
199
200// \brief generates an PDB block for a molecule
201/*!
202 * \param mol - the molecule in question
203 * \param confId - selects the conformer to be used
204 * \param flavor - controls what gets written:
205 * flavor & 1 : Write MODEL/ENDMDL lines around each record
206 * flavor & 2 : Don't write single CONECT records
207 * flavor & 4 : Write CONECT records in both directions
208 * flavor & 8 : Don't use multiple CONECTs to encode bond order
209 * flavor & 16 : Write MASTER record
210 * flavor & 32 : Write TER record
211 */
213 int confId = -1,
214 unsigned int flavor = 0);
215// \brief Writes a molecule to an MDL mol file
216/*!
217 * \param mol - the molecule in question
218 * \param fName - the name of the file to use
219 * \param confId - selects the conformer to be used
220 * \param flavor - controls what gets written:
221 * flavor & 1 : Write MODEL/ENDMDL lines around each record
222 * flavor & 2 : Don't write single CONECT records
223 * flavor & 4 : Write CONECT records in both directions
224 * flavor & 8 : Don't use multiple CONECTs to encode bond order
225 * flavor & 16 : Write MASTER record
226 * flavor & 32 : Write TER record
227 */
229 const std::string &fname,
230 int confId = -1,
231 unsigned int flavor = 0);
232
233} // namespace RDKit
234
235#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:73
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)