~ubuntu-branches/ubuntu/utopic/gdis/utopic

« back to all changes in this revision

Viewing changes to file_gms.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2004-09-13 23:44:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040913234450-wwdqtqfx9k38qhif
Tags: 0.86-1
new upstream release from 2004-08-26

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003 by Andrew Lloyd Rohl
 
3
 
 
4
andrew@power.curtin.edu.au
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
The GNU GPL can also be found at http://www.gnu.org
 
21
*/
 
22
 
 
23
#include <math.h>
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <strings.h>
 
27
#include <ctype.h>
 
28
#include <stdlib.h>
 
29
#include <time.h>
 
30
#include <unistd.h>
 
31
#include <sys/stat.h>
 
32
#include <sys/types.h>
 
33
 
 
34
#ifdef __sun
 
35
#include <sys/dirent.h>
 
36
#else
 
37
#ifdef __WIN32
 
38
#include <dirent.h>
 
39
#else
 
40
#include <sys/dir.h>
 
41
#include <sys/param.h>
 
42
#endif
 
43
#endif
 
44
 
 
45
#include "gdis.h"
 
46
#include "coords.h"
 
47
#include "edit.h"
 
48
#include "file.h"
 
49
#include "parse.h"
 
50
#include "matrix.h"
 
51
#include "interface.h"
 
52
 
 
53
#define BOHR_TO_ANGS 0.52917724928
 
54
#define HARTREE_TO_EV 27.21162
 
55
 
 
56
#define GMS_NGAUSS_TXT "ngauss="
 
57
#define GMS_NUM_P_TXT "npfunc="
 
58
#define GMS_NUM_D_TXT "ndfunc="
 
59
#define GMS_NUM_F_TXT "nffunc="
 
60
#define GMS_DIFFSP_TXT "diffsp=.true."
 
61
#define GMS_DIFFS_TXT "diffs=.true."
 
62
/* TODO: POLAR and split */
 
63
 
 
64
#define GMS_MPLEVEL_TXT "mplevl="
 
65
#define GMS_CITYP_TXT "cityp="
 
66
#define GMS_CCTYP_TXT "cctyp="
 
67
#define GMS_MAXIT_TXT "maxit="
 
68
#define GMS_TOTAL_Q_TXT "icharg="
 
69
#define GMS_MULT_TXT "mult="
 
70
#define GMS_WIDE_OUTPUT_TXT "nprint="
 
71
#define GMS_COORD_TXT "coord=cart"
 
72
 
 
73
#define GMS_TIMLIM_TXT "timlim="
 
74
#define GMS_MWORDS_TXT "mwords="
 
75
 
 
76
#define GMS_NSTEP_TXT "nstep="
 
77
 
 
78
#define GMS_UNITS_TXT "units="
 
79
struct GMS_keyword_pak units[] = {
 
80
{"angs", GMS_ANGS},
 
81
{"bohr", GMS_BOHR},
 
82
{NULL, 0}
 
83
};
 
84
 
 
85
#define GMS_EXETYPE_TXT "exetyp="
 
86
struct GMS_keyword_pak exe_types[] = {
 
87
{"run", GMS_RUN},
 
88
{"check", GMS_CHECK},
 
89
{"debug", GMS_DEBUG},
 
90
{NULL, 0}
 
91
};
 
92
 
 
93
#define GMS_RUNTYPE_TXT "runtyp="
 
94
struct GMS_keyword_pak run_types[] = {
 
95
{"energy",   GMS_ENERGY},
 
96
{"gradient", GMS_GRADIENT},
 
97
{"hessian",  GMS_HESSIAN},
 
98
{"prop",     GMS_PROP},
 
99
{"morokuma", GMS_MOROKUMA},
 
100
{"transitn", GMS_TRANSITN},
 
101
{"ffield",   GMS_FFIELD},
 
102
{"tdhf",     GMS_TDHF},
 
103
{"makefp",   GMS_MAKEFP},
 
104
{"optimize", GMS_OPTIMIZE},
 
105
{"trudge",   GMS_TRUDGE},
 
106
{"sadpoint", GMS_SADPOINT},
 
107
{"irc",      GMS_IRC},
 
108
{"vscf",     GMS_VSCF},
 
109
{"drc",      GMS_DRC},
 
110
{"globop",   GMS_GLOBOP},
 
111
{"gradextr", GMS_GRADEXTR},
 
112
{"surface",  GMS_SURFACE},
 
113
{NULL, 0} 
 
114
};
 
115
 
 
116
#define GMS_SCFTYPE_TXT "scftyp="
 
117
struct GMS_keyword_pak scf_types[] = {
 
118
{"rhf",  GMS_RHF},
 
119
{"uhf",  GMS_UHF}, 
 
120
{"rohf", GMS_ROHF}, 
 
121
{NULL, 0} 
 
122
};
 
123
 
 
124
#define GMS_METHOD_TXT "method="
 
125
struct GMS_keyword_pak method_types[] = {
 
126
{"qa",       GMS_QA}, 
 
127
{"nr",       GMS_NR},
 
128
{"rfo",      GMS_RFO},
 
129
{"schlegel", GMS_SCHLEGEL},
 
130
{NULL, 0} 
 
131
};
 
132
 
 
133
#define GMS_BASIS_TXT "gbasis="
 
134
struct GMS_keyword_pak basis_types[] = {
 
135
{"user defined", GMS_USER},
 
136
{"mndo", GMS_MNDO},
 
137
{"am1",  GMS_AM1},
 
138
{"pm3",  GMS_PM3},
 
139
{"mini", GMS_MINI},
 
140
{"midi", GMS_MIDI},
 
141
{"sto",  GMS_STO},
 
142
{"n21",  GMS_N21},
 
143
{"n31",  GMS_N31},
 
144
{"n311", GMS_N311},
 
145
{"dzv",  GMS_DZV},
 
146
{"dh",   GMS_DH},
 
147
{"tzv",  GMS_TZV},
 
148
{"mc",   GMS_MC},
 
149
{NULL, 0} 
 
150
};
 
151
 
 
152
/* main structures */
 
153
extern struct sysenv_pak sysenv;
 
154
extern struct elem_pak elements[];
 
155
 
 
156
/****************/
 
157
/* file writing */
 
158
/****************/
 
159
 
 
160
void write_keyword(FILE *fp, gchar *keyword, gint id, struct GMS_keyword_pak *values)
 
161
{
 
162
gint i=0;
 
163
while (values[i].label)
 
164
  {
 
165
  if (values[i].id == id)
 
166
    fprintf(fp, "%s%s ", keyword, values[i].label);
 
167
  i++;
 
168
  }
 
169
}
 
170
 
 
171
gint write_gms(gchar *filename, struct model_pak *data)
 
172
{
 
173
gdouble x[3];
 
174
GSList *list;
 
175
struct core_pak *core;
 
176
FILE *fp;
 
177
 
 
178
/* checks */
 
179
g_return_val_if_fail(data != NULL, 1);
 
180
g_return_val_if_fail(filename != NULL, 2);
 
181
 
 
182
/* open the file */
 
183
fp = fopen(filename,"wt");
 
184
if (!fp)
 
185
  return(3);
 
186
  
 
187
/* print control keywords */
 
188
fprintf(fp, " $contrl coord=unique ");
 
189
write_keyword(fp, GMS_EXETYPE_TXT, data->gamess.exe_type, exe_types);
 
190
write_keyword(fp, GMS_SCFTYPE_TXT, data->gamess.scf_type, scf_types);
 
191
write_keyword(fp, GMS_RUNTYPE_TXT, data->gamess.run_type, run_types);
 
192
write_keyword(fp, GMS_UNITS_TXT, data->gamess.units, units);
 
193
fprintf(fp, "\n");
 
194
 
 
195
/* TODO: electron correlation stuff */
 
196
fprintf(fp, "%s%d ", GMS_MAXIT_TXT, (gint) data->gamess.maxit);
 
197
if (data->gamess.total_charge != 0)
 
198
  fprintf(fp, "%s%d ", GMS_TOTAL_Q_TXT, (gint) data->gamess.total_charge);
 
199
if (data->gamess.multiplicity > 1)
 
200
  fprintf(fp, "%s%d ", GMS_MULT_TXT, (gint) data->gamess.multiplicity);
 
201
if (data->gamess.wide_output)
 
202
  fprintf(fp, "%s6 ", GMS_WIDE_OUTPUT_TXT);
 
203
fprintf(fp, "$end\n");
 
204
 
 
205
/* print size and memory */
 
206
fprintf(fp, " $system %s%d %s%d $end\n", GMS_TIMLIM_TXT, (gint) data->gamess.time_limit, GMS_MWORDS_TXT, (gint) data->gamess.mwords);
 
207
 
 
208
/* print optimiser data */
 
209
if (data->gamess.run_type >= GMS_OPTIMIZE)
 
210
 {
 
211
  fprintf(fp, " $statpt %s%d ", GMS_NSTEP_TXT, (gint) data->gamess.nstep);
 
212
  write_keyword(fp, GMS_METHOD_TXT, data->gamess.opt_type, method_types);
 
213
  fprintf(fp, "$end\n");
 
214
  }
 
215
 
 
216
/* print basis set if one of the standard ones */
 
217
if (data->gamess.basis != GMS_USER)
 
218
  {
 
219
  fprintf(fp, " $basis ");
 
220
  write_keyword(fp, GMS_BASIS_TXT, data->gamess.basis, basis_types);
 
221
  if (data->gamess.ngauss)
 
222
    fprintf(fp, "%s%d ", GMS_NGAUSS_TXT, data->gamess.ngauss);
 
223
  if (data->gamess.num_p)
 
224
    fprintf(fp, "%s%d ", GMS_NUM_P_TXT, (gint) data->gamess.num_p);
 
225
  if (data->gamess.num_d)
 
226
    fprintf(fp, "%s%d ", GMS_NUM_D_TXT, (gint) data->gamess.num_d);
 
227
  if (data->gamess.num_f)
 
228
    fprintf(fp, "%s%d ", GMS_NUM_F_TXT, (gint) data->gamess.num_f);
 
229
  if (data->gamess.have_heavy_diffuse)
 
230
    fprintf(fp, "%s ", GMS_DIFFSP_TXT);
 
231
  if (data->gamess.have_hydrogen_diffuse)
 
232
    fprintf(fp, "%s ", GMS_DIFFS_TXT);
 
233
  fprintf(fp, "$end\n");
 
234
  }
 
235
  
 
236
/* print data */
 
237
fprintf(fp, " $data\n");
 
238
/* print data header */
 
239
fprintf(fp, "%s\n", data->gamess.title);
 
240
/* print symmetry */
 
241
fprintf(fp, "c1\n");
 
242
 
 
243
for (list=data->cores ; list ; list=g_slist_next(list))
 
244
  {
 
245
  core = (struct core_pak *) list->data;
 
246
  if (core->status & DELETED)
 
247
    continue;
 
248
 
 
249
/* everything is cartesian after latmat mult */
 
250
  ARR3SET(x, core->x);
 
251
  vecmat(data->latmat, x);
 
252
  if (data->gamess.units == GMS_ANGS)
 
253
    fprintf(fp,"%-7s  %d  %14.9f  %14.9f  %14.9f\n",
 
254
              elements[core->atom_code].symbol, elements[core->atom_code].number, x[0], x[1], x[2]);
 
255
  else
 
256
    fprintf(fp,"%-7s  %d  %14.9f  %14.9f  %14.9f\n",
 
257
              elements[core->atom_code].symbol, elements[core->atom_code].number, x[0]/BOHR_TO_ANGS, x[1]/BOHR_TO_ANGS, x[2]/BOHR_TO_ANGS);
 
258
  }
 
259
fprintf(fp, " $end\n");
 
260
 
 
261
fclose(fp);
 
262
return(0);
 
263
}
 
264
 
 
265
gchar *get_next_keyword(FILE *fp, gchar *line, gint newline, gint *ret)
 
266
{
 
267
static int i;
 
268
int num_tokens;
 
269
static gchar **buff;
 
270
gchar *keyword;
 
271
 
 
272
if (newline)
 
273
  {
 
274
  buff = tokenize(line, &num_tokens);
 
275
  i = 0;
 
276
  }
 
277
while (buff[i] == NULL)
 
278
  {
 
279
  /* TODO skip comment lines? */
 
280
  if (fgetline(fp, line))
 
281
    {
 
282
    *ret = 2;
 
283
    return(NULL);
 
284
    }
 
285
  else
 
286
    {
 
287
    /* TODO free array of pointers */
 
288
    /* g_strfreev(buff); */
 
289
    buff = tokenize(line, &num_tokens);
 
290
    i = 0;
 
291
    }
 
292
  }
 
293
  *ret = 0;
 
294
  keyword = buff[i];
 
295
  i++;
 
296
  return(keyword);
 
297
}
 
298
 
 
299
GSList *get_gamess_keywords(FILE *fp, gchar *line, gint *ret)
 
300
{
 
301
gchar *keyword;
 
302
GSList *keywords=NULL;
 
303
 
 
304
keyword = get_next_keyword(fp, line, TRUE, ret);
 
305
while ((g_ascii_strncasecmp(keyword, "$end", 4) != 0) && (*ret == 0))
 
306
  {
 
307
  keywords = g_slist_append(keywords, keyword);
 
308
  keyword = get_next_keyword(fp, line, FALSE, ret);
 
309
  }
 
310
if (g_ascii_strncasecmp(keyword, "$end", 4) == 0)
 
311
  g_free(keyword);
 
312
return(keywords);
 
313
}
 
314
 
 
315
gint read_keyword(gchar *value, struct GMS_keyword_pak *values, gint *id)
 
316
{
 
317
gint i=0, found=FALSE;
 
318
while (values[i].label)
 
319
  {
 
320
  if (g_ascii_strcasecmp(values[i].label, value) == 0)
 
321
    {
 
322
    *id = values[i].id;
 
323
    found=TRUE;
 
324
    }
 
325
  i++;
 
326
  }
 
327
  if (found)
 
328
    return(0);
 
329
  else
 
330
    return(1);
 
331
}
 
332
 
 
333
gint get_data(FILE *fp, struct model_pak *data, gint have_basis)
 
334
{
 
335
gchar **buff, line[LINELEN];
 
336
gint num_tokens;
 
337
struct core_pak *core;
 
338
 
 
339
if (fgetline(fp, line))
 
340
  {
 
341
  show_text(ERROR, "unexpected end of file reading title\n");
 
342
  return(2);
 
343
  }
 
344
data->gamess.title = g_strdup(g_strstrip(line));
 
345
if (fgetline(fp, line))
 
346
  {
 
347
  show_text(ERROR, "unexpected end of file reading symmetry\n");
 
348
  return(2);
 
349
  }
 
350
if (g_ascii_strncasecmp(line, "c1", 2) != 0)
 
351
  {
 
352
  /* TODO handle symmetry! */
 
353
  show_text(ERROR, "only C1 symmetry understood at present\n");
 
354
  return(2);
 
355
  }
 
356
if (fgetline(fp, line))
 
357
  {
 
358
  show_text(ERROR, "unexpected end of file reading coordinates\n");
 
359
  return(2);
 
360
  }
 
361
while (g_ascii_strncasecmp(line, " $end", 5) != 0)
 
362
  {
 
363
  buff = tokenize(line, &num_tokens);
 
364
  /* TODO Store GAMESS label and use in .inp files */
 
365
  core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, data);
 
366
  if (data->gamess.units == GMS_ANGS)
 
367
    {
 
368
    core->x[0] = str_to_float(*(buff+2));
 
369
    core->x[1] = str_to_float(*(buff+3));
 
370
    core->x[2] = str_to_float(*(buff+4));
 
371
    }
 
372
  else
 
373
    {
 
374
    core->x[0] = str_to_float(*(buff+2)) * BOHR_TO_ANGS;
 
375
    core->x[1] = str_to_float(*(buff+3)) * BOHR_TO_ANGS;
 
376
    core->x[2] = str_to_float(*(buff+4)) * BOHR_TO_ANGS;
 
377
    }
 
378
  data->cores = g_slist_append(data->cores, core);
 
379
  g_strfreev(buff);
 
380
  if (!have_basis)
 
381
    {
 
382
    data->gamess.basis = GMS_USER;
 
383
    while (fgetline(fp, line) == 0)
 
384
      {
 
385
      buff = tokenize(line, &num_tokens);
 
386
      g_strfreev(buff);
 
387
      if (buff == 0)
 
388
        break;
 
389
        /* TODO should read the basis rather than skipping it!!!! */
 
390
      }
 
391
    }
 
392
  if (fgetline(fp, line))
 
393
    {
 
394
    show_text(ERROR, "unexpected end of file reading coordinates\n");
 
395
    return(2);
 
396
    }
 
397
  }
 
398
  return(0);
 
399
}
 
400
 
 
401
gint get_basis(gchar *keyword, struct model_pak *data)
 
402
{
 
403
gint len;
 
404
 
 
405
if (g_ascii_strncasecmp(GMS_BASIS_TXT, keyword, len=strlen(GMS_BASIS_TXT)) == 0)
 
406
  {
 
407
  if (read_keyword(&keyword[len], basis_types, (gint *) &data->gamess.basis) > 0)
 
408
    {
 
409
    show_text(ERROR, " unknown basis ");
 
410
    show_text(ERROR, &keyword[len]);
 
411
    show_text(ERROR, " ");
 
412
    return(1);
 
413
    }
 
414
  return(0);
 
415
  }
 
416
else if (g_ascii_strncasecmp(keyword, GMS_NGAUSS_TXT, len=strlen(GMS_NGAUSS_TXT)) == 0)
 
417
  data->gamess.ngauss = (gint) (str_to_float(&keyword[len]));
 
418
else if (g_ascii_strncasecmp(keyword, GMS_NUM_P_TXT, len=strlen(GMS_NUM_P_TXT)) == 0)
 
419
  data->gamess.num_p = str_to_float(&keyword[len]);
 
420
else if (g_ascii_strncasecmp(keyword, GMS_NUM_D_TXT, len=strlen(GMS_NUM_D_TXT)) == 0)
 
421
  data->gamess.num_d = str_to_float(&keyword[len]);
 
422
else if (g_ascii_strncasecmp(keyword, GMS_NUM_F_TXT, len=strlen(GMS_NUM_F_TXT)) == 0)
 
423
  data->gamess.num_f = str_to_float(&keyword[len]);
 
424
else if (g_ascii_strncasecmp(keyword, GMS_DIFFSP_TXT, len=strlen(GMS_DIFFSP_TXT)) == 0)
 
425
  data->gamess.have_heavy_diffuse = TRUE;
 
426
else if (g_ascii_strncasecmp(keyword, GMS_DIFFS_TXT, len=strlen(GMS_DIFFS_TXT)) == 0)
 
427
  data->gamess.have_hydrogen_diffuse = TRUE;
 
428
else 
 
429
  {
 
430
  show_text(ERROR, " unknown keyword ");
 
431
  show_text(ERROR, keyword);
 
432
  show_text(ERROR, " ");
 
433
  return(1);
 
434
  }
 
435
return(0);
 
436
}
 
437
 
 
438
gint get_control(gchar *keyword, struct model_pak *data)
 
439
{
 
440
gint len;
 
441
 
 
442
if (g_ascii_strncasecmp(GMS_UNITS_TXT, keyword, len=strlen(GMS_UNITS_TXT)) == 0)
 
443
  {
 
444
  if (read_keyword(&keyword[len], units, (gint *) &data->gamess.units) > 0)
 
445
    {
 
446
    show_text(ERROR, " unknown units ");
 
447
    show_text(ERROR, &keyword[len]);
 
448
    show_text(ERROR, " ");
 
449
    return(1);
 
450
    }
 
451
  return(0);
 
452
  }
 
453
if (g_ascii_strncasecmp(GMS_EXETYPE_TXT, keyword, len=strlen(GMS_EXETYPE_TXT)) == 0)
 
454
  {
 
455
  if (read_keyword(&keyword[len], exe_types, (gint *) &data->gamess.exe_type) > 0)
 
456
    {
 
457
    show_text(ERROR, " unknown exetyp ");
 
458
    show_text(ERROR, &keyword[len]);
 
459
    show_text(ERROR, " ");
 
460
    return(1);
 
461
    }
 
462
  return(0);
 
463
  }
 
464
 
 
465
if (g_ascii_strncasecmp(GMS_RUNTYPE_TXT, keyword, len=strlen(GMS_RUNTYPE_TXT)) == 0)
 
466
  {
 
467
  if (read_keyword(&keyword[len], run_types, (gint *) &data->gamess.run_type) > 0)
 
468
    {
 
469
    show_text(ERROR, " unknown runtyp ");
 
470
    show_text(ERROR, &keyword[len]);
 
471
    show_text(ERROR, " ");
 
472
    return(1);
 
473
    }
 
474
  return(0);
 
475
  }
 
476
 
 
477
if (g_ascii_strncasecmp(GMS_SCFTYPE_TXT, keyword, len=strlen(GMS_SCFTYPE_TXT)) == 0)
 
478
  {
 
479
  if (read_keyword(&keyword[len], scf_types, (gint *) &data->gamess.scf_type) > 0)
 
480
    {
 
481
    show_text(ERROR, " unknown scftyp ");
 
482
    show_text(ERROR, &keyword[len]);
 
483
    show_text(ERROR, " ");
 
484
    return(1);
 
485
    }
 
486
  return(0);
 
487
  }
 
488
 
 
489
else if (g_ascii_strncasecmp(keyword, GMS_MAXIT_TXT, len=strlen(GMS_MAXIT_TXT)) == 0)
 
490
  data->gamess.maxit = (gint) (str_to_float(&keyword[len]));
 
491
else if (g_ascii_strncasecmp(keyword, GMS_TOTAL_Q_TXT, len=strlen(GMS_TOTAL_Q_TXT)) == 0)
 
492
  data->gamess.total_charge = (gint) (str_to_float(&keyword[len]));
 
493
else if (g_ascii_strncasecmp(keyword, GMS_MULT_TXT, len=strlen(GMS_MULT_TXT)) == 0)
 
494
  data->gamess.multiplicity = (gint) (str_to_float(&keyword[len]));
 
495
else if (g_ascii_strncasecmp(keyword, GMS_WIDE_OUTPUT_TXT, len=strlen(GMS_WIDE_OUTPUT_TXT)) == 0)
 
496
  data->gamess.wide_output = (((gint) (str_to_float(&keyword[len]))) == 6);
 
497
else if (g_ascii_strncasecmp(keyword, GMS_COORD_TXT, len=strlen(GMS_COORD_TXT)) == 0)
 
498
  ; /* TODO handle different coordinate types */
 
499
else 
 
500
  {
 
501
  show_text(ERROR, " unknown keyword ");
 
502
  show_text(ERROR, keyword);
 
503
  show_text(ERROR, " ");
 
504
  return(1);
 
505
  }
 
506
return(0);
 
507
}
 
508
 
 
509
gint get_system(gchar *keyword, struct model_pak *data)
 
510
{
 
511
int len;
 
512
 
 
513
if (g_ascii_strncasecmp(keyword, GMS_TIMLIM_TXT, len=strlen(GMS_TIMLIM_TXT)) == 0)
 
514
  data->gamess.time_limit = (gint) (str_to_float(&keyword[len]));
 
515
else if (g_ascii_strncasecmp(keyword, GMS_MWORDS_TXT, len=strlen(GMS_MWORDS_TXT)) == 0)
 
516
  data->gamess.mwords = (gint) (str_to_float(&keyword[len]));
 
517
else 
 
518
  {
 
519
  show_text(ERROR, " unknown keyword ");
 
520
  show_text(ERROR, keyword);
 
521
  show_text(ERROR, " ");
 
522
  return(1);
 
523
  }
 
524
return(0);
 
525
}
 
526
 
 
527
gint get_statpt(gchar *keyword, struct model_pak *data)
 
528
{
 
529
int len;
 
530
 
 
531
if (g_ascii_strncasecmp(GMS_METHOD_TXT, keyword, len=strlen(GMS_METHOD_TXT)) == 0)
 
532
  {
 
533
  if (read_keyword(&keyword[len], method_types, (gint *) &data->gamess.opt_type) > 0)
 
534
    {
 
535
    show_text(ERROR, " unknown method ");
 
536
    show_text(ERROR, &keyword[len]);
 
537
    show_text(ERROR, " ");
 
538
    return(1);
 
539
    }
 
540
  return(0);
 
541
  }
 
542
else if (g_ascii_strncasecmp(keyword, GMS_NSTEP_TXT, len=strlen(GMS_NSTEP_TXT)) == 0)
 
543
  data->gamess.nstep = str_to_float(&keyword[len]);
 
544
else
 
545
  {
 
546
  show_text(ERROR, " unknown keyword ");
 
547
  show_text(ERROR, keyword);
 
548
  show_text(ERROR, " ");
 
549
  return(1);
 
550
  }
 
551
return(0);
 
552
}
 
553
 
 
554
 
 
555
gint get_next_group(FILE *fp, struct model_pak *data, gint *have_basis)
 
556
{
 
557
gchar line[LINELEN], *lc_line, *keyword;
 
558
gint ret;
 
559
GSList *keywords = NULL, *list;
 
560
 
 
561
if (fgetline(fp, line))
 
562
  return(FALSE);
 
563
if (g_ascii_strncasecmp(line, " $", 2) != 0)
 
564
  return(TRUE); /* TODO not a valid keyword so for the moment skip but could store */    
 
565
lc_line = g_ascii_strdown(line, -1);
 
566
if (g_ascii_strncasecmp(lc_line, " $data", 6) == 0)
 
567
  {
 
568
  ret = get_data(fp, data, *have_basis);
 
569
  }
 
570
else if (g_ascii_strncasecmp(lc_line, " $basis", 7) == 0)
 
571
  {
 
572
  *have_basis = TRUE;
 
573
  keywords = get_gamess_keywords(fp, lc_line+7, &ret);
 
574
  for (list=keywords; list ; list=g_slist_next(list))
 
575
    {
 
576
    keyword = (gchar *) list->data;
 
577
    ret = get_basis(keyword, data);  
 
578
    }
 
579
  }
 
580
else if (g_ascii_strncasecmp(lc_line, " $contrl", 8) == 0)
 
581
  {
 
582
  keywords = get_gamess_keywords(fp, lc_line+8, &ret);
 
583
  for (list=keywords; list ; list=g_slist_next(list))
 
584
    {
 
585
    keyword = (gchar *) list->data;
 
586
    ret = get_control(keyword, data);  
 
587
    }
 
588
  }
 
589
else if (g_ascii_strncasecmp(lc_line, " $system", 8) == 0)
 
590
  {
 
591
  keywords = get_gamess_keywords(fp, lc_line+8, &ret);
 
592
  for (list=keywords; list ; list=g_slist_next(list))
 
593
    {
 
594
    keyword = (gchar *) list->data;
 
595
    ret = get_system(keyword, data);  
 
596
    }
 
597
  }
 
598
else if (g_ascii_strncasecmp(lc_line, " $statpt", 8) == 0)
 
599
  {
 
600
  keywords = get_gamess_keywords(fp, lc_line+8, &ret);
 
601
  for (list=keywords; list ; list=g_slist_next(list))
 
602
    {
 
603
    keyword = (gchar *) list->data;
 
604
    ret = get_statpt(keyword, data);  
 
605
    }
 
606
  }
 
607
else
 
608
  {
 
609
  /* TODO - Unknown keyword, just pass through */
 
610
  }
 
611
free_slist(keywords);
 
612
g_free(lc_line);
 
613
return(TRUE);
 
614
}
 
615
 
 
616
gint read_gms(gchar *filename, struct model_pak *data)
 
617
{
 
618
FILE *fp;
 
619
gchar line[LINELEN], *name;
 
620
gint have_basis = FALSE;
 
621
 
 
622
fp = fopen(filename, "rt");
 
623
if (!fp)
 
624
  {
 
625
  sprintf(line, "Unable to open file %s\n", filename);
 
626
  show_text(ERROR, line);
 
627
  return(1);
 
628
  }
 
629
else
 
630
  {
 
631
  name = g_path_get_basename(filename);
 
632
  sprintf(line, "Opening %s: \n", name);
 
633
  g_free(name);
 
634
  show_text(STANDARD, line);
 
635
  }
 
636
 
 
637
while (get_next_group(fp, data, &have_basis));
 
638
 
 
639
show_text(STANDARD, "\n");
 
640
 
 
641
strcpy(data->filename, filename);
 
642
g_free(data->basename);
 
643
data->basename = strdup_basename(filename);
 
644
prep_model(data);
 
645
return(0);
 
646
}
 
647
 
 
648
/*******************************************/
 
649
/* read single GAMESS output configuration */
 
650
/*******************************************/
 
651
#define DEBUG_READ_GMS_OUT 1
 
652
gint read_gms_out_block(FILE *fp, struct model_pak *data, gint num_skip, gint bohr)
 
653
{
 
654
gint i, num_tokens;
 
655
gchar **buff, line[LINELEN];
 
656
GString *title;
 
657
GSList *clist;
 
658
struct core_pak *core;
 
659
 
 
660
clist = data->cores;
 
661
 
 
662
/* ignore first num_skip lines */
 
663
for (i=0 ; i<num_skip; i++)
 
664
  if (fgetline(fp, line))
 
665
    {
 
666
    show_text(ERROR, "unexpected end of file reading coordinates\n");
 
667
    return(11);
 
668
    }
 
669
 
 
670
data->construct_pbc = FALSE;
 
671
data->fractional = FALSE;
 
672
 
 
673
/* get 1st line of coords */
 
674
if (fgetline(fp, line))
 
675
    {
 
676
    show_text(ERROR, "unexpected end of file reading coordinates\n");
 
677
    return(11);
 
678
    }
 
679
buff = tokenize(line, &num_tokens);
 
680
 
 
681
while (num_tokens > 4)
 
682
  {
 
683
  if (clist)
 
684
    {
 
685
    core = (struct core_pak *) clist->data;
 
686
    clist = g_slist_next(clist);
 
687
    }
 
688
  else
 
689
    {
 
690
    core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, data);
 
691
    data->cores = g_slist_append(data->cores, core);
 
692
    }
 
693
 
 
694
  if (bohr)
 
695
    {
 
696
    core->x[0] = BOHR_TO_ANGS*str_to_float(*(buff+2));
 
697
    core->x[1] = BOHR_TO_ANGS*str_to_float(*(buff+3));
 
698
    core->x[2] = BOHR_TO_ANGS*str_to_float(*(buff+4));
 
699
    }
 
700
  else
 
701
    {
 
702
    core->x[0] = str_to_float(*(buff+2));
 
703
    core->x[1] = str_to_float(*(buff+3));
 
704
    core->x[2] = str_to_float(*(buff+4));
 
705
    }
 
706
 
 
707
/* get next line */
 
708
  g_strfreev(buff);
 
709
  if (fgetline(fp, line))
 
710
    {
 
711
    show_text(ERROR, "unexpected end of file reading coordinates\n");
 
712
    return(11);
 
713
    }
 
714
  buff = tokenize(line, &num_tokens);
 
715
  }
 
716
g_strfreev(buff);
 
717
  
 
718
/* search for energy */
 
719
while (!fgetline(fp, line))
 
720
  {
 
721
  if (g_ascii_strncasecmp(line, " FINAL", 6) == 0)
 
722
    {
 
723
    buff = tokenize(line, &num_tokens);
 
724
    if (g_ascii_strncasecmp(*(buff+1), "ENERGY", 6) == 0)
 
725
      data->gamess.energy = str_to_float(*(buff+3));
 
726
    else
 
727
      data->gamess.energy = str_to_float(*(buff+4));
 
728
    data->gamess.have_energy = TRUE;
 
729
    g_strfreev(buff);
 
730
    break;
 
731
    }
 
732
  }
 
733
 
 
734
/* update for MP? */
 
735
if (data->gamess.MP_level > 0)
 
736
  {
 
737
  while (!fgetline(fp, line))
 
738
    {
 
739
    if (g_strrstr(line ,"E(MP2)") != NULL)
 
740
      {
 
741
      buff = tokenize(line, &num_tokens);
 
742
      data->gamess.energy = str_to_float(*(buff+1));
 
743
      data->gamess.have_energy = TRUE;
 
744
      g_strfreev(buff);
 
745
      break;
 
746
      }
 
747
    }
 
748
  }
 
749
 
 
750
/* search for gradient and read any properties */
 
751
while (!fgetline(fp, line))
 
752
  {
 
753
  if (g_ascii_strncasecmp(line, " NET CHARGES:", 13) == 0)
 
754
    {
 
755
    clist = data->cores;
 
756
    /* skip forward four lines */
 
757
    for (i=0 ; i<4; i++)
 
758
      if (fgetline(fp, line))
 
759
        {
 
760
        show_text(ERROR, "unexpected end of file reading fitted charges\n");
 
761
        return(11);
 
762
        }
 
763
    while (clist != NULL)
 
764
      {
 
765
      buff = tokenize(line, &num_tokens);
 
766
      core = (struct core_pak *) clist->data;
 
767
      core->lookup_charge = FALSE;
 
768
      core->charge = str_to_float(*(buff+1));
 
769
      g_strfreev(buff);
 
770
      clist = g_slist_next(clist);
 
771
      if (fgetline(fp, line))
 
772
        {
 
773
        show_text(ERROR, "unexpected end of file reading fitted charges\n");
 
774
        return(11);
 
775
        }
 
776
      }
 
777
    }
 
778
  if (g_ascii_strncasecmp(line, "          MAXIMUM GRADIENT", 26) == 0)
 
779
    {
 
780
    buff = tokenize(line, &num_tokens);
 
781
    data->gamess.max_grad = str_to_float(*(buff+3));
 
782
    data->gamess.have_max_grad = TRUE;
 
783
    data->gamess.rms_grad = str_to_float(*(buff+7));
 
784
    data->gamess.have_rms_grad = TRUE;
 
785
    g_strfreev(buff);
 
786
    /* check next line to see if converged */
 
787
    if (fgetline(fp, line))
 
788
      {
 
789
      show_text(ERROR, "unexpected end of file reading equilibrium status\n");
 
790
      return(11);
 
791
      }
 
792
    if (g_ascii_strncasecmp(line, "1     ***** EQUILIBRIUM GEOMETRY LOCATED *****", 46) == 0)
 
793
      data->gamess.converged = TRUE;
 
794
    break;
 
795
    }
 
796
  }
 
797
g_free(data->title);
 
798
title = g_string_new("");
 
799
if (data->gamess.have_energy)
 
800
  {
 
801
  g_string_append_printf(title, "E");
 
802
  if (data->gamess.MP_level > 0)
 
803
    g_string_append_printf(title, "(MP%d)", data->gamess.MP_level);
 
804
  g_string_append_printf(title, " = %.5f H", data->gamess.energy);
 
805
  }
 
806
if (data->gamess.have_rms_grad)
 
807
  g_string_append_printf(title, ", grad = %.5f", data->gamess.rms_grad);
 
808
data->title = g_strdup(title->str);
 
809
g_string_free(title, TRUE);
 
810
 
 
811
return(0);
 
812
}
 
813
 
 
814
/*******************************/
 
815
/* GAMESS output frame reading */
 
816
/*******************************/
 
817
gint read_gms_out_frame(FILE *fp, struct model_pak *data)
 
818
{
 
819
/* replace all data */
 
820
return(read_gms_out_block(fp, data, 2, FALSE));
 
821
}
 
822
 
 
823
/********************************/
 
824
/* Read in a GAMESS output file */
 
825
/********************************/
 
826
gint read_gms_out(gchar *filename, struct model_pak *data)
 
827
{
 
828
gint flag, frame, num_tokens, len, i, index;
 
829
gchar **buff, line[LINELEN], *keyword, *option;
 
830
FILE *fp;
 
831
 
 
832
fp = fopen(filename, "rt");
 
833
if (!fp)
 
834
  {
 
835
  sprintf(line, "Unable to open file %s\n", filename);
 
836
  show_text(ERROR, line);
 
837
  return(1);
 
838
  }
 
839
 
 
840
data->periodic = 0;
 
841
flag=frame=0;
 
842
 
 
843
/* read in BASIS OPTIONS */
 
844
while (!fgetline(fp, line))
 
845
  {
 
846
  if (g_ascii_strncasecmp(line, "     BASIS OPTIONS", 18) == 0)
 
847
    {
 
848
    /* skip line */
 
849
    if (fgetline(fp, line))
 
850
      {
 
851
      show_text(ERROR, "unexpected end of file reading basis options\n");
 
852
      return(2);
 
853
      }
 
854
    if (fgetline(fp, line))
 
855
      {
 
856
      show_text(ERROR, "unexpected end of file reading basis options\n");
 
857
      return(2);
 
858
      }
 
859
    /* get first line of options i.e. basis set */
 
860
    buff = tokenize(line, &num_tokens); 
 
861
    /* GBASIS=STO          IGAUSS=       3      POLAR=NONE */
 
862
    keyword = *(buff+0);
 
863
    if (g_ascii_strncasecmp(keyword, GMS_BASIS_TXT, len = strlen(GMS_BASIS_TXT)) == 0)
 
864
      {
 
865
      if (read_keyword(&keyword[len], basis_types, (gint *) &data->gamess.basis) > 0)
 
866
        {
 
867
        sprintf(line, "invalid basis %s\n", &keyword[len]);
 
868
        show_text(ERROR, line);
 
869
        return(3);
 
870
        }
 
871
      }
 
872
    data->gamess.ngauss = (gint) str_to_float(*(buff+2));
 
873
    g_strfreev(buff);
 
874
    
 
875
    /* get 2nd line of options i.e. NDFUNC and DIFFSP */
 
876
    if (fgetline(fp, line))
 
877
      {
 
878
      show_text(ERROR, "unexpected end of file reading basis options\n");
 
879
      return(2);
 
880
      }
 
881
    buff = tokenize(line, &num_tokens);
 
882
    /* NDFUNC=       0     DIFFSP=       F */
 
883
    data->gamess.num_d = str_to_float(*(buff+1));
 
884
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
 
885
      data->gamess.have_heavy_diffuse = FALSE;
 
886
    else
 
887
      data->gamess.have_heavy_diffuse = TRUE;
 
888
    g_strfreev(buff);
 
889
      
 
890
    /* get 3rd line of options i.e. MULT and ICHARG */
 
891
    if (fgetline(fp, line))
 
892
      {
 
893
      show_text(ERROR, "unexpected end of file reading basis options\n");
 
894
      return(2);
 
895
      }
 
896
    buff = tokenize(line, &num_tokens);
 
897
    /* NPFUNC=       0      DIFFS=       F */
 
898
    data->gamess.num_p = (gint) str_to_float(*(buff+1));
 
899
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
 
900
      data->gamess.have_hydrogen_diffuse = FALSE;
 
901
    else
 
902
      data->gamess.have_hydrogen_diffuse = TRUE;
 
903
    g_strfreev(buff);
 
904
      
 
905
    /* TODO f functions */
 
906
        flag++;
 
907
        break;
 
908
        }
 
909
  }
 
910
 
 
911
if (!flag)
 
912
  {
 
913
   /* no basis present so set to user defined and rewind file */
 
914
   data->gamess.basis = GMS_USER;
 
915
   rewind(fp);
 
916
  }
 
917
flag=0;
 
918
 
 
919
/* read in RUN TITLE */
 
920
while (!fgetline(fp, line))
 
921
  {
 
922
  if (g_ascii_strncasecmp(line, "     RUN TITLE", 14) == 0)
 
923
    {
 
924
    if (fgetline(fp, line))
 
925
      {
 
926
      show_text(ERROR, "unexpected end of file reading title\n");
 
927
      return(2);
 
928
      }
 
929
    if (fgetline(fp, line))
 
930
      {
 
931
      show_text(ERROR, "unexpected end of file reading title\n");
 
932
      return(2);
 
933
      }
 
934
    data->gamess.title = g_strdup(g_strstrip(line));
 
935
    flag++;
 
936
    break;
 
937
    }
 
938
  }
 
939
 
 
940
if (!flag)
 
941
  {
 
942
   show_text(ERROR, "RUN TITLE not found\n");
 
943
   return(2);
 
944
  }
 
945
flag=0;
 
946
 
 
947
/* read in $CONTRL OPTIONS */
 
948
while (!fgetline(fp, line))
 
949
  {
 
950
  if (g_ascii_strncasecmp(line, "     $CONTRL OPTIONS", 20) == 0)
 
951
    {
 
952
    flag++;
 
953
    if (fgetline(fp, line))
 
954
      /* skip line of dashes */
 
955
      {
 
956
      show_text(ERROR, "unexpected end of file reading contrl options\n");
 
957
      return(3);
 
958
      }
 
959
    while (TRUE)
 
960
      {
 
961
      if (fgetline(fp, line))
 
962
        {
 
963
        show_text(ERROR, "unexpected end of file reading contrl options\n");
 
964
        return(3);
 
965
        }
 
966
      /* is the line the blank line signalling end of control options? */
 
967
      if (strlen(g_strchug(line)) == 0)
 
968
        break;
 
969
      /* break up line into option pairs */
 
970
      /* each pair takes 15 characters with 5 characters between them */
 
971
      /* note that we have already removed the single space in front of the lines with the g_strchug */
 
972
      index = 0;
 
973
      while (index+15 <= strlen(line))
 
974
        {
 
975
        option = g_strndup(line+index, 15);
 
976
        /* split into pair */
 
977
        buff = g_strsplit(option, "=", 2);
 
978
        g_free(option);
 
979
        /* remove whitespace */
 
980
        g_strstrip(buff[0]);
 
981
        g_strstrip(buff[1]);
 
982
        /* the compare strings end in = which we have stripped off so compare on strlen-1 */
 
983
        if (g_ascii_strncasecmp(buff[0], GMS_SCFTYPE_TXT, strlen(GMS_SCFTYPE_TXT) - 1) == 0)
 
984
          {
 
985
          if (read_keyword(buff[1], scf_types, (gint *) &data->gamess.scf_type) > 0)
 
986
            {
 
987
            sprintf(line, "invalid scf type %s\n", buff[1]);
 
988
            show_text(ERROR, line);
 
989
            return(3);
 
990
            }
 
991
          }
 
992
        else if (g_ascii_strncasecmp(buff[0], GMS_RUNTYPE_TXT, strlen(GMS_RUNTYPE_TXT) - 1) == 0)
 
993
          {
 
994
          if (read_keyword(buff[1], run_types, (gint *) &data->gamess.run_type) > 0)
 
995
            {
 
996
            sprintf(line, "invalid run type %s\n", buff[1]);
 
997
            show_text(ERROR, line);
 
998
            return(3);
 
999
            }
 
1000
          }
 
1001
        else if (g_ascii_strncasecmp(buff[0], GMS_EXETYPE_TXT, strlen(GMS_EXETYPE_TXT) - 1) == 0)
 
1002
          {
 
1003
          if (read_keyword(buff[1], exe_types, (gint *) &data->gamess.exe_type) > 0)
 
1004
            {
 
1005
            sprintf(line, "invalid execution type %s\n", buff[1]);
 
1006
            show_text(ERROR, line);
 
1007
            return(3);
 
1008
            }
 
1009
          }
 
1010
        else if (g_ascii_strncasecmp(buff[0], GMS_MPLEVEL_TXT, strlen(GMS_MPLEVEL_TXT) - 1) == 0)
 
1011
                data->gamess.MP_level = (gint) str_to_float(buff[1]);
 
1012
        else if (g_ascii_strncasecmp(buff[0], GMS_CITYP_TXT, strlen(GMS_CITYP_TXT) - 1) == 0)
 
1013
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
 
1014
            data->gamess.have_CI = FALSE;
 
1015
          else
 
1016
            data->gamess.have_CI = TRUE;
 
1017
        else if (g_ascii_strncasecmp(buff[0], GMS_CCTYP_TXT, strlen(GMS_CCTYP_TXT) - 1) == 0)
 
1018
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
 
1019
            data->gamess.have_CC = FALSE;
 
1020
          else
 
1021
            data->gamess.have_CC = TRUE;
 
1022
        else if (g_ascii_strncasecmp(buff[0], GMS_TOTAL_Q_TXT, strlen(GMS_TOTAL_Q_TXT) - 1) == 0)
 
1023
          data->gamess.total_charge = (gint) str_to_float(buff[1]);
 
1024
        else if (g_ascii_strncasecmp(buff[0], GMS_MULT_TXT, strlen(GMS_MULT_TXT) - 1) == 0)
 
1025
          data->gamess.multiplicity = (gint) str_to_float(buff[1]);
 
1026
        else if (g_ascii_strncasecmp(buff[0], GMS_MAXIT_TXT, strlen(GMS_MAXIT_TXT) - 1) == 0)
 
1027
          data->gamess.maxit = ((gint) str_to_float(buff[1]));
 
1028
        else if (g_ascii_strncasecmp(buff[0], GMS_WIDE_OUTPUT_TXT, strlen(GMS_WIDE_OUTPUT_TXT) - 1) == 0)   
 
1029
         data->gamess.wide_output = ((gint) str_to_float(buff[1]) == 6);
 
1030
 
 
1031
        g_strfreev(buff);
 
1032
        index += 20;
 
1033
        }
 
1034
      }
 
1035
      break;
 
1036
    }
 
1037
  }
 
1038
 
 
1039
if (!flag)
 
1040
  {
 
1041
/* don't return... prep_model() needs to be called to avoid crashing */
 
1042
   show_text(WARNING, "$CONTRL OPTIONS not found\n");
 
1043
  }
 
1044
flag=0;
 
1045
 
 
1046
/* read in $SYSTEM OPTIONS */
 
1047
while (!fgetline(fp, line))
 
1048
  {
 
1049
  if (g_ascii_strncasecmp(line, "     $SYSTEM OPTIONS", 20) == 0)
 
1050
    {
 
1051
    if (fgetline(fp, line))
 
1052
      {
 
1053
      show_text(ERROR, "unexpected end of file reading system options\n");
 
1054
      return(4);
 
1055
      }
 
1056
    if (fgetline(fp, line))
 
1057
      {
 
1058
      show_text(ERROR, "unexpected end of file reading system options\n");
 
1059
      return(4);
 
1060
      }
 
1061
    buff = tokenize(line, &num_tokens);
 
1062
    data->gamess.mwords = (gint) (str_to_float(*(buff+2))/1000000);
 
1063
    g_strfreev(buff);
 
1064
    
 
1065
    for (i=0; i<4; i++)
 
1066
      {
 
1067
      if (fgetline(fp, line))
 
1068
        {
 
1069
        show_text(ERROR, "unexpected end of file reading system options\n");
 
1070
        return(4);
 
1071
        }
 
1072
      }
 
1073
    buff = tokenize(line, &num_tokens);
 
1074
    data->gamess.time_limit = (gint) (str_to_float(*(buff+1))/60.0);
 
1075
    g_strfreev(buff);
 
1076
    flag++;
 
1077
    break;
 
1078
    }
 
1079
  }
 
1080
 
 
1081
if (!flag)
 
1082
  {
 
1083
/* don't return... prep_model() needs to be called to avoid crashing */
 
1084
   show_text(WARNING, "$SYSTEM OPTIONS not found\n");
 
1085
  }
 
1086
flag=0;
 
1087
 
 
1088
/* anything else to find ? */
 
1089
while (!fgetline(fp, line))
 
1090
  {
 
1091
  if (g_ascii_strncasecmp(line, "                         GRADIENT OF THE ENERGY", 47) == 0)
 
1092
    {
 
1093
    if (fgetline(fp, line))
 
1094
      {
 
1095
      show_text(ERROR, "unexpected end of file reading gradient\n");
 
1096
      return(5);
 
1097
      }
 
1098
    while (g_ascii_strncasecmp(line, "                   MAXIMUM GRADIENT", 35) != 0) 
 
1099
      {
 
1100
      if (fgetline(fp, line))
 
1101
        {
 
1102
        show_text(ERROR, "unexpected end of file reading gradient\n");
 
1103
        return(5);
 
1104
        }
 
1105
      }
 
1106
      buff = tokenize(line, &num_tokens);
 
1107
      data->gamess.max_grad = str_to_float(*(buff+3));
 
1108
      data->gamess.have_max_grad = TRUE;
 
1109
      g_strfreev(buff);
 
1110
      if (fgetline(fp, line))
 
1111
        {
 
1112
        show_text(ERROR, "unexpected end of file reading gradient\n");
 
1113
        return(5);
 
1114
        }
 
1115
      buff = tokenize(line, &num_tokens);
 
1116
      data->gamess.rms_grad = str_to_float(*(buff+3));
 
1117
      data->gamess.have_rms_grad = TRUE;
 
1118
      g_strfreev(buff);
 
1119
    }
 
1120
  }
 
1121
 
 
1122
rewind(fp);
 
1123
 
 
1124
/* Read the input coordinates - single frame has different format to multiframe */
 
1125
if (data->gamess.run_type < GMS_OPTIMIZE) { /* is it a single frame job? */
 
1126
  while (!fgetline(fp, line))
 
1127
    {
 
1128
    if (g_ascii_strncasecmp(line, " ATOM      ATOMIC                      COORDINATES (BOHR)", 57) == 0)
 
1129
      {
 
1130
          read_gms_out_block(fp, data, 1, TRUE);
 
1131
          flag++;
 
1132
          break;
 
1133
      }
 
1134
        }
 
1135
  }
 
1136
 
 
1137
else
 
1138
  {
 
1139
  /* get optimisation parameters */
 
1140
  while (!fgetline(fp, line))
 
1141
    {
 
1142
    if (g_ascii_strncasecmp(line, "          STATIONARY POINT LOCATION RUN", 39) == 0)
 
1143
      {
 
1144
      for (i=0; i<7; i++)
 
1145
        {
 
1146
        if (fgetline(fp, line))
 
1147
          {
 
1148
          show_text(ERROR, "unexpected end of file reading optimizer options\n");
 
1149
          return(5);
 
1150
          }
 
1151
        }
 
1152
      if (data->gamess.exe_type == GMS_CHECK)
 
1153
        if (fgetline(fp, line))
 
1154
          {
 
1155
          show_text(ERROR, "unexpected end of file reading optimizer options\n");
 
1156
          return(5);
 
1157
          }
 
1158
      buff = tokenize(line, &num_tokens);
 
1159
      if (read_keyword(&(*(buff+1))[1], method_types, (gint *) &data->gamess.opt_type) > 0)
 
1160
        {
 
1161
        sprintf(line, "invalid method %s\n",&(*(buff+1))[1]);
 
1162
        show_text(ERROR, line);
 
1163
        return(5);
 
1164
        }
 
1165
      g_strfreev(buff);
 
1166
      flag++;
 
1167
      if (fgetline(fp, line))
 
1168
        {
 
1169
        show_text(ERROR, "unexpected end of file reading optimizer options\n");
 
1170
        return(5);
 
1171
        }
 
1172
      if (fgetline(fp, line))
 
1173
        {
 
1174
        show_text(ERROR, "unexpected end of file reading optimizer options\n");
 
1175
        return(5);
 
1176
        }
 
1177
      buff = tokenize(line, &num_tokens);
 
1178
      data->gamess.nstep = str_to_float(*(buff+2));
 
1179
      g_strfreev(buff);
 
1180
      flag++;
 
1181
      break;
 
1182
      }
 
1183
    }
 
1184
  if (!flag)
 
1185
    {
 
1186
    show_text(ERROR, "optimizer options not found\n");
 
1187
    return(5);
 
1188
    }
 
1189
  /* Are there any coordinates from a minimisation? */
 
1190
  flag=0;
 
1191
  while (!fgetline(fp, line) && !data->gamess.converged)
 
1192
    {
 
1193
    /* coordinates */
 
1194
    if (g_ascii_strncasecmp(line, " COORDINATES OF ALL ATOMS ARE", 29) == 0)
 
1195
      {
 
1196
      /* go through all frames to count them */
 
1197
      add_frame_offset(fp, data);
 
1198
      read_gms_out_block(fp, data, 2, FALSE);
 
1199
      flag++;
 
1200
      frame++;
 
1201
      }
 
1202
    }
 
1203
  }
 
1204
 
 
1205
/* done */
 
1206
 
 
1207
if (flag)
 
1208
  {
 
1209
  /* set frame if don't want last? */
 
1210
  strcpy(data->filename, filename);
 
1211
  g_free(data->basename);
 
1212
  data->basename = strdup_basename(filename);
 
1213
 
 
1214
  data->num_frames = data->cur_frame = frame;
 
1215
  data->cur_frame--;
 
1216
  
 
1217
  prep_model(data);
 
1218
  }
 
1219
else
 
1220
  return(2);
 
1221
 
 
1222
return(0);
 
1223
}
 
1224