/src/openbabel/include/openbabel/data.h
Line | Count | Source (jump to first uncovered line) |
1 | | /********************************************************************** |
2 | | data.h - Global data and resource file parsers. |
3 | | |
4 | | Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. |
5 | | Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison |
6 | | |
7 | | This file is part of the Open Babel project. |
8 | | For more information, see <http://openbabel.org/> |
9 | | |
10 | | This program is free software; you can redistribute it and/or modify |
11 | | it under the terms of the GNU General Public License as published by |
12 | | the Free Software Foundation version 2 of the License. |
13 | | |
14 | | This program is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU General Public License for more details. |
18 | | ***********************************************************************/ |
19 | | |
20 | | #ifndef OB_DATA_H |
21 | | #define OB_DATA_H |
22 | | |
23 | | #include <openbabel/babelconfig.h> |
24 | | |
25 | | #include <stdio.h> |
26 | | #include <cstring> |
27 | | #include <fstream> |
28 | | #include <vector> |
29 | | #include <string> |
30 | | #include <cstring> |
31 | | |
32 | | namespace OpenBabel |
33 | | { |
34 | | |
35 | | class OBAtom; |
36 | | class OBMol; |
37 | | |
38 | | /** \class OBGlobalDataBase data.h <openbabel/data.h> |
39 | | \brief Base data table class, handles reading data files |
40 | | |
41 | | Base data table class--reads ASCII data files in various formats |
42 | | -# Checks for the environment variable _envvar (defaults to "BABEL_DATADIR") |
43 | | - Tries the _subdir directory if defined (def. "data") and then the main directory |
44 | | -# Checks for the directory _dir (def. determined by the build environment) |
45 | | - Tries the subdirectory corresponding to this version, then the main directory |
46 | | -# Reverts to the compiled-in default data |
47 | | **/ |
48 | | class OBAPI OBGlobalDataBase |
49 | | { |
50 | | protected: |
51 | | bool _init; //!< Whether the data been read already |
52 | | const char *_dataptr;//!< Default data table if file is unreadable |
53 | | std::string _filename;//!< File to search for |
54 | | std::string _dir; //!< Data directory for file if _envvar fails |
55 | | std::string _subdir; //!< Subdirectory (if using environment variable) |
56 | | std::string _envvar; //!< Environment variable to check first |
57 | | |
58 | | public: |
59 | | //! Constructor |
60 | 10 | OBGlobalDataBase(): _init(false), _dataptr(nullptr) { } |
61 | | //! Destructor |
62 | 2 | virtual ~OBGlobalDataBase() {} |
63 | | //! Read in the data file, falling back as needed |
64 | | void Init(); |
65 | | //! \return the size of the database (for error checking) |
66 | 0 | virtual size_t GetSize() { return 0;} |
67 | | //! Set the directory before calling Init() |
68 | 0 | void SetReadDirectory(char *dir) { _dir = dir; } |
69 | | //! Set the environment variable to use before calling Init() |
70 | 0 | void SetEnvironmentVariable(char *var) { _envvar = var; } |
71 | | //! Specified by particular table classes (parses an individual data line) |
72 | 0 | virtual void ParseLine(const char*) {} |
73 | | }; |
74 | | |
75 | | /** \class OBAtomHOF data.h <openbabel/data.h> |
76 | | \brief helper class for OBAtomicHeatOfFormationTable |
77 | | |
78 | | Stores both theoretical and experimental corrections |
79 | | needed to compute the Enthalpy of formation. In order to |
80 | | use these you need to perform |
81 | | Gaussian G2/G3/G4 or CBS-QB3 calculations. |
82 | | **/ |
83 | | class OBAPI OBAtomHOF |
84 | | { |
85 | | private: |
86 | | std::string _element,_method,_desc,_unit; |
87 | | double _T,_value; |
88 | | int _charge; |
89 | | int _multiplicity; |
90 | | |
91 | | public: |
92 | | /** \brief Initialize Heat of Formation for atom |
93 | | |
94 | | @param element The element string |
95 | | @param charge The formal charge of the particle (if an ion) |
96 | | @param method The method used for determining the value |
97 | | @param desc Description of the value |
98 | | @param T Temperature |
99 | | @param value The value of the property (energy) |
100 | | @param multiplicity The multiplicity of the atomic system |
101 | | @param unit The (energy) unit |
102 | | */ |
103 | | OBAtomHOF(std::string element,int charge, |
104 | | std::string method,std::string desc, |
105 | | double T,double value,int multiplicity, |
106 | | std::string unit) |
107 | 0 | { |
108 | 0 | _element = element; |
109 | 0 | _charge = charge; |
110 | 0 | _method = method; |
111 | 0 | _desc = desc; |
112 | 0 | _T = T; |
113 | 0 | _value = value; |
114 | 0 | _multiplicity = multiplicity; |
115 | 0 | _unit = unit; |
116 | 0 | } |
117 | | |
118 | | /** \brief Destructor */ |
119 | 0 | ~OBAtomHOF() {} |
120 | | /** \brief Return the chemical element */ |
121 | 0 | std::string Element() { return _element; } |
122 | | /** \brief Return the formal charge */ |
123 | 0 | int Charge() { return _charge; } |
124 | | /** \brief Return the method used for the measurement/calculation */ |
125 | 0 | std::string Method() { return _method; } |
126 | | /** \brief Return specification of the measurement/calculation type */ |
127 | 0 | std::string Desc() { return _desc; } |
128 | | /** \brief Return the temperature */ |
129 | 0 | double T() { return _T; } |
130 | | /** \brief Return the (energy) value */ |
131 | 0 | double Value() { return _value; } |
132 | | /** \brief Return the multiplicity */ |
133 | 0 | int Multiplicity() { return _multiplicity; } |
134 | | /** \brief Return the (energy) unit */ |
135 | 0 | std::string Unit() { return _unit; } |
136 | | }; |
137 | | |
138 | | /** \class OBAtomicHeatOfFormationTable data.h <openbabel/data.h> |
139 | | \brief Atomic Heat of Formation Table |
140 | | |
141 | | Contributions of atoms to Enthalpy of Formation calculations performed |
142 | | in Gaussian, using the G2/G3/G4 or CBS-QB3 methods respectively. |
143 | | The energies produced by Gaussian have to be corrected according to their |
144 | | document on Thermochemistry with Gaussian. The data in the file |
145 | | BABEL_DATA/atomization_energies.txt supplies this information based on |
146 | | single atom calculations with Gaussian and the appropriate method and |
147 | | experimental data from Curtiss et al., J. Chem. Phys. 106 (1997) 1063-1079. |
148 | | */ |
149 | | class OBAPI OBAtomicHeatOfFormationTable : public OBGlobalDataBase |
150 | | { |
151 | | std::vector<OBAtomHOF> _atomhof; |
152 | | |
153 | | public: |
154 | | /** \brief Constructor */ |
155 | | OBAtomicHeatOfFormationTable(void); |
156 | | /** \brief Destructor */ |
157 | 0 | ~OBAtomicHeatOfFormationTable() {} |
158 | | |
159 | | //! \return the number of elements in the Atomic Heat Of Formation table |
160 | 0 | size_t GetSize() override { return _atomhof.size(); } |
161 | | |
162 | | /** \brief Read one line in the file and parse it |
163 | | @param Unnamed the line to be parsed |
164 | | */ |
165 | | void ParseLine(const char*) override; |
166 | | /** \brief Extract heat of formation and entropy for an atom |
167 | | @param elem The chemical element we're looking for |
168 | | @param charge At this formal charge |
169 | | @param method The method used for computing/measuring |
170 | | @param T The temperature |
171 | | @param dhof0 The output energy at 0K |
172 | | @param dhof1 The output energy at T |
173 | | @param S0T The entropy at T (it is 0 at 0K) |
174 | | \return 1 if the contribution to the Heat of Formation for this atom |
175 | | is known at temperature T. If 1 the values |
176 | | including all corrections are returned in the dhof variable. |
177 | | */ |
178 | | int GetHeatOfFormation(std::string elem, |
179 | | int charge, |
180 | | std::string method, |
181 | | double T, double *dhof0, |
182 | | double *dhofT,double *S0T); |
183 | | }; |
184 | | |
185 | | // class introduction in data.cpp |
186 | | class OBAPI OBTypeTable : public OBGlobalDataBase |
187 | | { |
188 | | int _linecount; |
189 | | unsigned int _ncols,_nrows; |
190 | | int _from,_to; |
191 | | std::vector<std::string> _colnames; |
192 | | std::vector<std::vector<std::string> > _table; |
193 | | |
194 | | public: |
195 | | |
196 | | OBTypeTable(void); |
197 | 0 | ~OBTypeTable() {} |
198 | | |
199 | | void ParseLine(const char*) override; |
200 | | |
201 | | //! \return the number of atom types in the translation table |
202 | 0 | size_t GetSize() override { return _table.size(); } |
203 | | |
204 | | //! Set the initial atom type to be translated |
205 | | bool SetFromType(const char*); |
206 | | //! Set the destination atom type for translation |
207 | | bool SetToType(const char*); |
208 | | //! Translate atom types |
209 | | bool Translate(char *to, const char *from); // to, from |
210 | | //! Translate atom types |
211 | | //! \return whether the translation was successful |
212 | | bool Translate(std::string &to, const std::string &from); // to, from |
213 | | //! Translate atom types |
214 | | //! \return the translated atom type, or an empty string if not possible |
215 | | std::string Translate(const std::string &from); |
216 | | |
217 | | //! \return the initial atom type to be translated |
218 | | std::string GetFromType(); |
219 | | //! \return the destination atom type for translation |
220 | | std::string GetToType(); |
221 | | }; |
222 | | |
223 | | //! Global OBTypeTable for translating between different atom types |
224 | | //! (e.g., Sybyl <-> MM2) |
225 | | OB_EXTERN OBTypeTable ttab; |
226 | | |
227 | | /** \class OBResidueData data.h <openbabel/data.h> |
228 | | \brief Table of common biomolecule residues (for PDB or other files). |
229 | | |
230 | | Can assign atom types and bond orders for arbitrary residues |
231 | | **/ |
232 | | class OBAPI OBResidueData : public OBGlobalDataBase |
233 | | { |
234 | | int _resnum; |
235 | | std::vector<std::string> _resname; |
236 | | std::vector<std::vector<std::string> > _resatoms; |
237 | | std::vector<std::vector<std::pair<std::string,int> > > _resbonds; |
238 | | |
239 | | //variables used only temporarily for parsing resdata.txt |
240 | | std::vector<std::string> _vatmtmp; |
241 | | std::vector<std::pair<std::string,int> > _vtmp; |
242 | | public: |
243 | | |
244 | | OBResidueData(); |
245 | | void ParseLine(const char*) override; |
246 | | |
247 | | //! \return the number of residues in the table |
248 | 0 | size_t GetSize() override { return _resname.size(); } |
249 | | |
250 | | //! Sets the table to access the residue information for a specified |
251 | | //! residue name |
252 | | //! \return whether this residue name is in the table |
253 | | bool SetResName(const std::string &); |
254 | | //! \return the bond order for the bond specified in the current residue |
255 | | //! \deprecated Easier to use the two-argument form |
256 | | OB_DEPRECATED_MSG("Easier to use the two-argument form") |
257 | | int LookupBO(const std::string &); |
258 | | //! \return the bond order for the bond specified between the two specified |
259 | | //! atom labels |
260 | | int LookupBO(const std::string &, const std::string&); |
261 | | //! Look up the atom type and hybridization for the atom label specified |
262 | | //! in the first argument for the current residue |
263 | | //! \return whether the atom label specified is found in the current residue |
264 | | bool LookupType(const std::string &,std::string&,int&); |
265 | | //! Assign bond orders, atom types and residues for the supplied OBMol |
266 | | //! based on the residue information assigned to atoms |
267 | | bool AssignBonds(OBMol &); |
268 | | }; |
269 | | |
270 | | //! Global OBResidueData biomolecule residue database |
271 | | OB_EXTERN OBResidueData resdat; |
272 | | |
273 | | |
274 | | } // end namespace OpenBabel |
275 | | |
276 | | #endif //DATA_H |
277 | | |
278 | | //! \file data.h |
279 | | //! \brief Global data and resource file parsers. |