1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**********************************************************************
Copyright (C) 2001-2008 by Geoffrey R. Hutchison
Some portions Copyright (C) 2004 by Chris Morley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#include <openbabel/babelconfig.h>
#include <openbabel/obmolecformat.h>
#include <openbabel/generic.h>
#ifndef BUFF_SIZE
#define BUFF_SIZE 32768
#endif
#include <sstream>
using namespace std;
namespace OpenBabel
{
// The ".out" format:
// Detect GAMESS, GAMESS-UK, Q-Chem, PWSCF, Gaussian, or MOPAC output files
// also detect ORCA output files now --- added 14.03.2014 by D.Lenk
class OutputFormat : public OBMoleculeFormat
{
public:
//Register this format type ID
OutputFormat()
{
OBConversion::RegisterFormat("out", this);
OBConversion::RegisterFormat("output", this);
OBConversion::RegisterFormat("log", this);
OBConversion::RegisterFormat("dat", this);
}
virtual const char* Description() //required
{
return
"Generic Output file format\n"
"Automatically detect and read computational chemistry output files\n\n"
"This format can be used to read ADF, Gaussian, GAMESS, PWSCF, Q-Chem,\n"
"MOPAC, ORCA etc. output files by automatically detecting the file type.\n\n"
"Read Options e.g. -as\n"
" s Output single bonds only\n"
" b Disable bonding entirely\n\n";
};
virtual const char* SpecificationURL()
{return "http://openbabel.org/wiki/Output";}; //optional
//Flags() can return be any the following combined by | or be omitted if none apply
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY
virtual unsigned int Flags()
{
return READONEONLY | NOTWRITABLE;
};
//*** This section identical for most OBMol conversions ***
////////////////////////////////////////////////////
/// The "API" interface functions
virtual bool ReadMolecule(OBBase* pOb, OBConversion* pConv);
};
//***
//Make an instance of the format class
OutputFormat theOutputFormat;
/////////////////////////////////////////////////////////////////
bool OutputFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
// so we want to read through the file until we can figure out
// what program actually created it
// if we get to the end, emit a warning
istream &ifs = *pConv->GetInStream();
char buffer[BUFF_SIZE];
OBFormat *pFormat = nullptr;
std::string formatName;
// the detection strings are from the Chemical MIME project
// http://chemical-mime.sourceforge.net/chemical-mime-data.html
while (ifs.getline(buffer,BUFF_SIZE)) {
if (strstr(buffer, "GAMESS execution script") != nullptr ||
strstr(buffer, "PC GAMESS") != nullptr ||
strstr(buffer, "GAMESS VERSION") != nullptr) {
// GAMESS output
formatName = "gamout";
break;
} else if (strstr(buffer, "=== G A M E S S - U K === ") != nullptr) {
// GAMESS-UK output
formatName = "gukout";
break;
} else if (strstr(buffer, "Gaussian, Inc") != nullptr) {
// Gaussian output
formatName = "g03";
break;
} else if (strstr(buffer, "GENERAL UTILITY LATTICE PROGRAM") != nullptr) {
// GULP output -- not currently supported
break;
} else if (strstr(buffer, "MOPAC") != nullptr) {
// MOPAC output
formatName = "mopout";
break;
} else if (strstr(buffer, "Program PWSCF") != nullptr) {
// PWSCF
formatName = "pwscf";
break;
} else if (strstr(buffer, "Welcome to Q-Chem") != nullptr) {
// Q-Chem output
formatName = "qcout";
break;
} else if (strstr(buffer, "Amsterdam Density Functional") != nullptr) {
// ADF output
// Determine the kind of ADF output
while (ifs.getline(buffer, BUFF_SIZE)) {
if (strstr(buffer, "| A D F |") != nullptr) {
formatName = "adfout";
break;
} else if (strstr(buffer, "| B A N D |") != nullptr) {
formatName = "adfband";
break;
} else if (strstr(buffer, "| D F T B |") != nullptr) {
formatName = "adfdftb";
break;
} else if (strstr(buffer, "DFTB Engine") != nullptr) {
// "| D F T B |" is no longer printed in ADF 2018
// Hopefully, "DFTB Engine" will work fine...
formatName = "adfdftb";
break;
}
}
break;
} else if (strstr(buffer, "Northwest Computational Chemistry") != nullptr) {
// NWChem output
formatName = "nwo";
break;
} else if (strstr(buffer, "MPQC: Massively Parallel Quantum Chemistry") != nullptr) {
// MPQC output
formatName = "mpqc";
break;
} else if (strstr(buffer, "PROGRAM SYSTEM MOLPRO") != nullptr) {
// MOLPRO output
formatName = "mpo";
break;
} else if (strstr(buffer, "Schrodinger, Inc.") != nullptr &&
strstr(buffer, "Jaguar") != nullptr) {
// Jaguar
formatName = "jout";
break;
} else if (strstr(buffer, "ABINIT") != nullptr) {
// Abinit
formatName = "abinit";
break;
} else if (strstr(buffer, "ACES2") != nullptr) {
// ACESII
formatName = "acesout";
break;
} else if (strstr(buffer, "CRYSTAL06") != nullptr ||
strstr(buffer, "CRYSTAL09") != nullptr) {
// CRYSTAL09
formatName = "c09out";
break;
} else if (strstr(buffer, "* O R C A *") != nullptr) {
// ORCA
formatName = "orca";
break;
} else if (strstr(buffer, "WELCOME TO SIESTA") != nullptr) {
// SIESTA
formatName = "siesta";
break;
}
}
// if we assigned something above, let's try to find it
if (formatName.length())
pFormat = pConv->FindFormat(formatName);
if (pFormat) {
ifs.seekg (0, ios::beg); // reset the stream to the beginning
ifs.clear();
bool success = pFormat->ReadMolecule(pOb, pConv);
// Tag the molecule with the format (e.g., if a program wants to know the kind of "out" or "log" file)
// We have to do this *after* ReadMolecule returns, or the data might be cleared
if (pOb) {
OBPairData *dp = new OBPairData;
dp->SetAttribute("File Format");
dp->SetValue(formatName);
dp->SetOrigin(fileformatInput);
pOb->SetData(dp);
}
return success;
}
obErrorLog.ThrowError(__FUNCTION__,
"Problems reading an output file: Could not determine the format of this file. Please report it to the openbabel-discuss @ lists.sourceforge.net mailing list.", obError);
return(false); // we couldn't figure out the format
}
} //namespace OpenBabel