2
Copyright (C) 2003 by Andrew Lloyd Rohl
4
andrew@power.curtin.edu.au
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.
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.
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.
20
The GNU GPL can also be found at http://www.gnu.org
32
#include <sys/types.h>
35
#include <sys/dirent.h>
41
#include <sys/param.h>
51
#include "interface.h"
53
#define BOHR_TO_ANGS 0.52917724928
54
#define HARTREE_TO_EV 27.21162
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 */
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"
73
#define GMS_TIMLIM_TXT "timlim="
74
#define GMS_MWORDS_TXT "mwords="
76
#define GMS_NSTEP_TXT "nstep="
78
#define GMS_UNITS_TXT "units="
79
struct GMS_keyword_pak units[] = {
85
#define GMS_EXETYPE_TXT "exetyp="
86
struct GMS_keyword_pak exe_types[] = {
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},
99
{"morokuma", GMS_MOROKUMA},
100
{"transitn", GMS_TRANSITN},
101
{"ffield", GMS_FFIELD},
103
{"makefp", GMS_MAKEFP},
104
{"optimize", GMS_OPTIMIZE},
105
{"trudge", GMS_TRUDGE},
106
{"sadpoint", GMS_SADPOINT},
110
{"globop", GMS_GLOBOP},
111
{"gradextr", GMS_GRADEXTR},
112
{"surface", GMS_SURFACE},
116
#define GMS_SCFTYPE_TXT "scftyp="
117
struct GMS_keyword_pak scf_types[] = {
124
#define GMS_METHOD_TXT "method="
125
struct GMS_keyword_pak method_types[] = {
129
{"schlegel", GMS_SCHLEGEL},
133
#define GMS_BASIS_TXT "gbasis="
134
struct GMS_keyword_pak basis_types[] = {
135
{"user defined", GMS_USER},
152
/* main structures */
153
extern struct sysenv_pak sysenv;
154
extern struct elem_pak elements[];
160
void write_keyword(FILE *fp, gchar *keyword, gint id, struct GMS_keyword_pak *values)
163
while (values[i].label)
165
if (values[i].id == id)
166
fprintf(fp, "%s%s ", keyword, values[i].label);
171
gint write_gms(gchar *filename, struct model_pak *data)
175
struct core_pak *core;
179
g_return_val_if_fail(data != NULL, 1);
180
g_return_val_if_fail(filename != NULL, 2);
183
fp = fopen(filename,"wt");
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);
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");
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);
208
/* print optimiser data */
209
if (data->gamess.run_type >= GMS_OPTIMIZE)
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");
216
/* print basis set if one of the standard ones */
217
if (data->gamess.basis != GMS_USER)
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");
237
fprintf(fp, " $data\n");
238
/* print data header */
239
fprintf(fp, "%s\n", data->gamess.title);
243
for (list=data->cores ; list ; list=g_slist_next(list))
245
core = (struct core_pak *) list->data;
246
if (core->status & DELETED)
249
/* everything is cartesian after latmat mult */
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]);
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);
259
fprintf(fp, " $end\n");
265
gchar *get_next_keyword(FILE *fp, gchar *line, gint newline, gint *ret)
274
buff = tokenize(line, &num_tokens);
277
while (buff[i] == NULL)
279
/* TODO skip comment lines? */
280
if (fgetline(fp, line))
287
/* TODO free array of pointers */
288
/* g_strfreev(buff); */
289
buff = tokenize(line, &num_tokens);
299
GSList *get_gamess_keywords(FILE *fp, gchar *line, gint *ret)
302
GSList *keywords=NULL;
304
keyword = get_next_keyword(fp, line, TRUE, ret);
305
while ((g_ascii_strncasecmp(keyword, "$end", 4) != 0) && (*ret == 0))
307
keywords = g_slist_append(keywords, keyword);
308
keyword = get_next_keyword(fp, line, FALSE, ret);
310
if (g_ascii_strncasecmp(keyword, "$end", 4) == 0)
315
gint read_keyword(gchar *value, struct GMS_keyword_pak *values, gint *id)
317
gint i=0, found=FALSE;
318
while (values[i].label)
320
if (g_ascii_strcasecmp(values[i].label, value) == 0)
333
gint get_data(FILE *fp, struct model_pak *data, gint have_basis)
335
gchar **buff, line[LINELEN];
337
struct core_pak *core;
339
if (fgetline(fp, line))
341
show_text(ERROR, "unexpected end of file reading title\n");
344
data->gamess.title = g_strdup(g_strstrip(line));
345
if (fgetline(fp, line))
347
show_text(ERROR, "unexpected end of file reading symmetry\n");
350
if (g_ascii_strncasecmp(line, "c1", 2) != 0)
352
/* TODO handle symmetry! */
353
show_text(ERROR, "only C1 symmetry understood at present\n");
356
if (fgetline(fp, line))
358
show_text(ERROR, "unexpected end of file reading coordinates\n");
361
while (g_ascii_strncasecmp(line, " $end", 5) != 0)
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)
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));
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;
378
data->cores = g_slist_append(data->cores, core);
382
data->gamess.basis = GMS_USER;
383
while (fgetline(fp, line) == 0)
385
buff = tokenize(line, &num_tokens);
389
/* TODO should read the basis rather than skipping it!!!! */
392
if (fgetline(fp, line))
394
show_text(ERROR, "unexpected end of file reading coordinates\n");
401
gint get_basis(gchar *keyword, struct model_pak *data)
405
if (g_ascii_strncasecmp(GMS_BASIS_TXT, keyword, len=strlen(GMS_BASIS_TXT)) == 0)
407
if (read_keyword(&keyword[len], basis_types, (gint *) &data->gamess.basis) > 0)
409
show_text(ERROR, " unknown basis ");
410
show_text(ERROR, &keyword[len]);
411
show_text(ERROR, " ");
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;
430
show_text(ERROR, " unknown keyword ");
431
show_text(ERROR, keyword);
432
show_text(ERROR, " ");
438
gint get_control(gchar *keyword, struct model_pak *data)
442
if (g_ascii_strncasecmp(GMS_UNITS_TXT, keyword, len=strlen(GMS_UNITS_TXT)) == 0)
444
if (read_keyword(&keyword[len], units, (gint *) &data->gamess.units) > 0)
446
show_text(ERROR, " unknown units ");
447
show_text(ERROR, &keyword[len]);
448
show_text(ERROR, " ");
453
if (g_ascii_strncasecmp(GMS_EXETYPE_TXT, keyword, len=strlen(GMS_EXETYPE_TXT)) == 0)
455
if (read_keyword(&keyword[len], exe_types, (gint *) &data->gamess.exe_type) > 0)
457
show_text(ERROR, " unknown exetyp ");
458
show_text(ERROR, &keyword[len]);
459
show_text(ERROR, " ");
465
if (g_ascii_strncasecmp(GMS_RUNTYPE_TXT, keyword, len=strlen(GMS_RUNTYPE_TXT)) == 0)
467
if (read_keyword(&keyword[len], run_types, (gint *) &data->gamess.run_type) > 0)
469
show_text(ERROR, " unknown runtyp ");
470
show_text(ERROR, &keyword[len]);
471
show_text(ERROR, " ");
477
if (g_ascii_strncasecmp(GMS_SCFTYPE_TXT, keyword, len=strlen(GMS_SCFTYPE_TXT)) == 0)
479
if (read_keyword(&keyword[len], scf_types, (gint *) &data->gamess.scf_type) > 0)
481
show_text(ERROR, " unknown scftyp ");
482
show_text(ERROR, &keyword[len]);
483
show_text(ERROR, " ");
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 */
501
show_text(ERROR, " unknown keyword ");
502
show_text(ERROR, keyword);
503
show_text(ERROR, " ");
509
gint get_system(gchar *keyword, struct model_pak *data)
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]));
519
show_text(ERROR, " unknown keyword ");
520
show_text(ERROR, keyword);
521
show_text(ERROR, " ");
527
gint get_statpt(gchar *keyword, struct model_pak *data)
531
if (g_ascii_strncasecmp(GMS_METHOD_TXT, keyword, len=strlen(GMS_METHOD_TXT)) == 0)
533
if (read_keyword(&keyword[len], method_types, (gint *) &data->gamess.opt_type) > 0)
535
show_text(ERROR, " unknown method ");
536
show_text(ERROR, &keyword[len]);
537
show_text(ERROR, " ");
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]);
546
show_text(ERROR, " unknown keyword ");
547
show_text(ERROR, keyword);
548
show_text(ERROR, " ");
555
gint get_next_group(FILE *fp, struct model_pak *data, gint *have_basis)
557
gchar line[LINELEN], *lc_line, *keyword;
559
GSList *keywords = NULL, *list;
561
if (fgetline(fp, line))
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)
568
ret = get_data(fp, data, *have_basis);
570
else if (g_ascii_strncasecmp(lc_line, " $basis", 7) == 0)
573
keywords = get_gamess_keywords(fp, lc_line+7, &ret);
574
for (list=keywords; list ; list=g_slist_next(list))
576
keyword = (gchar *) list->data;
577
ret = get_basis(keyword, data);
580
else if (g_ascii_strncasecmp(lc_line, " $contrl", 8) == 0)
582
keywords = get_gamess_keywords(fp, lc_line+8, &ret);
583
for (list=keywords; list ; list=g_slist_next(list))
585
keyword = (gchar *) list->data;
586
ret = get_control(keyword, data);
589
else if (g_ascii_strncasecmp(lc_line, " $system", 8) == 0)
591
keywords = get_gamess_keywords(fp, lc_line+8, &ret);
592
for (list=keywords; list ; list=g_slist_next(list))
594
keyword = (gchar *) list->data;
595
ret = get_system(keyword, data);
598
else if (g_ascii_strncasecmp(lc_line, " $statpt", 8) == 0)
600
keywords = get_gamess_keywords(fp, lc_line+8, &ret);
601
for (list=keywords; list ; list=g_slist_next(list))
603
keyword = (gchar *) list->data;
604
ret = get_statpt(keyword, data);
609
/* TODO - Unknown keyword, just pass through */
611
free_slist(keywords);
616
gint read_gms(gchar *filename, struct model_pak *data)
619
gchar line[LINELEN], *name;
620
gint have_basis = FALSE;
622
fp = fopen(filename, "rt");
625
sprintf(line, "Unable to open file %s\n", filename);
626
show_text(ERROR, line);
631
name = g_path_get_basename(filename);
632
sprintf(line, "Opening %s: \n", name);
634
show_text(STANDARD, line);
637
while (get_next_group(fp, data, &have_basis));
639
show_text(STANDARD, "\n");
641
strcpy(data->filename, filename);
642
g_free(data->basename);
643
data->basename = strdup_basename(filename);
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)
655
gchar **buff, line[LINELEN];
658
struct core_pak *core;
662
/* ignore first num_skip lines */
663
for (i=0 ; i<num_skip; i++)
664
if (fgetline(fp, line))
666
show_text(ERROR, "unexpected end of file reading coordinates\n");
670
data->construct_pbc = FALSE;
671
data->fractional = FALSE;
673
/* get 1st line of coords */
674
if (fgetline(fp, line))
676
show_text(ERROR, "unexpected end of file reading coordinates\n");
679
buff = tokenize(line, &num_tokens);
681
while (num_tokens > 4)
685
core = (struct core_pak *) clist->data;
686
clist = g_slist_next(clist);
690
core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, data);
691
data->cores = g_slist_append(data->cores, core);
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));
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));
709
if (fgetline(fp, line))
711
show_text(ERROR, "unexpected end of file reading coordinates\n");
714
buff = tokenize(line, &num_tokens);
718
/* search for energy */
719
while (!fgetline(fp, line))
721
if (g_ascii_strncasecmp(line, " FINAL", 6) == 0)
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));
727
data->gamess.energy = str_to_float(*(buff+4));
728
data->gamess.have_energy = TRUE;
735
if (data->gamess.MP_level > 0)
737
while (!fgetline(fp, line))
739
if (g_strrstr(line ,"E(MP2)") != NULL)
741
buff = tokenize(line, &num_tokens);
742
data->gamess.energy = str_to_float(*(buff+1));
743
data->gamess.have_energy = TRUE;
750
/* search for gradient and read any properties */
751
while (!fgetline(fp, line))
753
if (g_ascii_strncasecmp(line, " NET CHARGES:", 13) == 0)
756
/* skip forward four lines */
758
if (fgetline(fp, line))
760
show_text(ERROR, "unexpected end of file reading fitted charges\n");
763
while (clist != NULL)
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));
770
clist = g_slist_next(clist);
771
if (fgetline(fp, line))
773
show_text(ERROR, "unexpected end of file reading fitted charges\n");
778
if (g_ascii_strncasecmp(line, " MAXIMUM GRADIENT", 26) == 0)
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;
786
/* check next line to see if converged */
787
if (fgetline(fp, line))
789
show_text(ERROR, "unexpected end of file reading equilibrium status\n");
792
if (g_ascii_strncasecmp(line, "1 ***** EQUILIBRIUM GEOMETRY LOCATED *****", 46) == 0)
793
data->gamess.converged = TRUE;
798
title = g_string_new("");
799
if (data->gamess.have_energy)
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);
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);
814
/*******************************/
815
/* GAMESS output frame reading */
816
/*******************************/
817
gint read_gms_out_frame(FILE *fp, struct model_pak *data)
819
/* replace all data */
820
return(read_gms_out_block(fp, data, 2, FALSE));
823
/********************************/
824
/* Read in a GAMESS output file */
825
/********************************/
826
gint read_gms_out(gchar *filename, struct model_pak *data)
828
gint flag, frame, num_tokens, len, i, index;
829
gchar **buff, line[LINELEN], *keyword, *option;
832
fp = fopen(filename, "rt");
835
sprintf(line, "Unable to open file %s\n", filename);
836
show_text(ERROR, line);
843
/* read in BASIS OPTIONS */
844
while (!fgetline(fp, line))
846
if (g_ascii_strncasecmp(line, " BASIS OPTIONS", 18) == 0)
849
if (fgetline(fp, line))
851
show_text(ERROR, "unexpected end of file reading basis options\n");
854
if (fgetline(fp, line))
856
show_text(ERROR, "unexpected end of file reading basis options\n");
859
/* get first line of options i.e. basis set */
860
buff = tokenize(line, &num_tokens);
861
/* GBASIS=STO IGAUSS= 3 POLAR=NONE */
863
if (g_ascii_strncasecmp(keyword, GMS_BASIS_TXT, len = strlen(GMS_BASIS_TXT)) == 0)
865
if (read_keyword(&keyword[len], basis_types, (gint *) &data->gamess.basis) > 0)
867
sprintf(line, "invalid basis %s\n", &keyword[len]);
868
show_text(ERROR, line);
872
data->gamess.ngauss = (gint) str_to_float(*(buff+2));
875
/* get 2nd line of options i.e. NDFUNC and DIFFSP */
876
if (fgetline(fp, line))
878
show_text(ERROR, "unexpected end of file reading basis options\n");
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;
887
data->gamess.have_heavy_diffuse = TRUE;
890
/* get 3rd line of options i.e. MULT and ICHARG */
891
if (fgetline(fp, line))
893
show_text(ERROR, "unexpected end of file reading basis options\n");
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;
902
data->gamess.have_hydrogen_diffuse = TRUE;
905
/* TODO f functions */
913
/* no basis present so set to user defined and rewind file */
914
data->gamess.basis = GMS_USER;
919
/* read in RUN TITLE */
920
while (!fgetline(fp, line))
922
if (g_ascii_strncasecmp(line, " RUN TITLE", 14) == 0)
924
if (fgetline(fp, line))
926
show_text(ERROR, "unexpected end of file reading title\n");
929
if (fgetline(fp, line))
931
show_text(ERROR, "unexpected end of file reading title\n");
934
data->gamess.title = g_strdup(g_strstrip(line));
942
show_text(ERROR, "RUN TITLE not found\n");
947
/* read in $CONTRL OPTIONS */
948
while (!fgetline(fp, line))
950
if (g_ascii_strncasecmp(line, " $CONTRL OPTIONS", 20) == 0)
953
if (fgetline(fp, line))
954
/* skip line of dashes */
956
show_text(ERROR, "unexpected end of file reading contrl options\n");
961
if (fgetline(fp, line))
963
show_text(ERROR, "unexpected end of file reading contrl options\n");
966
/* is the line the blank line signalling end of control options? */
967
if (strlen(g_strchug(line)) == 0)
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 */
973
while (index+15 <= strlen(line))
975
option = g_strndup(line+index, 15);
976
/* split into pair */
977
buff = g_strsplit(option, "=", 2);
979
/* remove whitespace */
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)
985
if (read_keyword(buff[1], scf_types, (gint *) &data->gamess.scf_type) > 0)
987
sprintf(line, "invalid scf type %s\n", buff[1]);
988
show_text(ERROR, line);
992
else if (g_ascii_strncasecmp(buff[0], GMS_RUNTYPE_TXT, strlen(GMS_RUNTYPE_TXT) - 1) == 0)
994
if (read_keyword(buff[1], run_types, (gint *) &data->gamess.run_type) > 0)
996
sprintf(line, "invalid run type %s\n", buff[1]);
997
show_text(ERROR, line);
1001
else if (g_ascii_strncasecmp(buff[0], GMS_EXETYPE_TXT, strlen(GMS_EXETYPE_TXT) - 1) == 0)
1003
if (read_keyword(buff[1], exe_types, (gint *) &data->gamess.exe_type) > 0)
1005
sprintf(line, "invalid execution type %s\n", buff[1]);
1006
show_text(ERROR, line);
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;
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;
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);
1041
/* don't return... prep_model() needs to be called to avoid crashing */
1042
show_text(WARNING, "$CONTRL OPTIONS not found\n");
1046
/* read in $SYSTEM OPTIONS */
1047
while (!fgetline(fp, line))
1049
if (g_ascii_strncasecmp(line, " $SYSTEM OPTIONS", 20) == 0)
1051
if (fgetline(fp, line))
1053
show_text(ERROR, "unexpected end of file reading system options\n");
1056
if (fgetline(fp, line))
1058
show_text(ERROR, "unexpected end of file reading system options\n");
1061
buff = tokenize(line, &num_tokens);
1062
data->gamess.mwords = (gint) (str_to_float(*(buff+2))/1000000);
1067
if (fgetline(fp, line))
1069
show_text(ERROR, "unexpected end of file reading system options\n");
1073
buff = tokenize(line, &num_tokens);
1074
data->gamess.time_limit = (gint) (str_to_float(*(buff+1))/60.0);
1083
/* don't return... prep_model() needs to be called to avoid crashing */
1084
show_text(WARNING, "$SYSTEM OPTIONS not found\n");
1088
/* anything else to find ? */
1089
while (!fgetline(fp, line))
1091
if (g_ascii_strncasecmp(line, " GRADIENT OF THE ENERGY", 47) == 0)
1093
if (fgetline(fp, line))
1095
show_text(ERROR, "unexpected end of file reading gradient\n");
1098
while (g_ascii_strncasecmp(line, " MAXIMUM GRADIENT", 35) != 0)
1100
if (fgetline(fp, line))
1102
show_text(ERROR, "unexpected end of file reading gradient\n");
1106
buff = tokenize(line, &num_tokens);
1107
data->gamess.max_grad = str_to_float(*(buff+3));
1108
data->gamess.have_max_grad = TRUE;
1110
if (fgetline(fp, line))
1112
show_text(ERROR, "unexpected end of file reading gradient\n");
1115
buff = tokenize(line, &num_tokens);
1116
data->gamess.rms_grad = str_to_float(*(buff+3));
1117
data->gamess.have_rms_grad = TRUE;
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))
1128
if (g_ascii_strncasecmp(line, " ATOM ATOMIC COORDINATES (BOHR)", 57) == 0)
1130
read_gms_out_block(fp, data, 1, TRUE);
1139
/* get optimisation parameters */
1140
while (!fgetline(fp, line))
1142
if (g_ascii_strncasecmp(line, " STATIONARY POINT LOCATION RUN", 39) == 0)
1146
if (fgetline(fp, line))
1148
show_text(ERROR, "unexpected end of file reading optimizer options\n");
1152
if (data->gamess.exe_type == GMS_CHECK)
1153
if (fgetline(fp, line))
1155
show_text(ERROR, "unexpected end of file reading optimizer options\n");
1158
buff = tokenize(line, &num_tokens);
1159
if (read_keyword(&(*(buff+1))[1], method_types, (gint *) &data->gamess.opt_type) > 0)
1161
sprintf(line, "invalid method %s\n",&(*(buff+1))[1]);
1162
show_text(ERROR, line);
1167
if (fgetline(fp, line))
1169
show_text(ERROR, "unexpected end of file reading optimizer options\n");
1172
if (fgetline(fp, line))
1174
show_text(ERROR, "unexpected end of file reading optimizer options\n");
1177
buff = tokenize(line, &num_tokens);
1178
data->gamess.nstep = str_to_float(*(buff+2));
1186
show_text(ERROR, "optimizer options not found\n");
1189
/* Are there any coordinates from a minimisation? */
1191
while (!fgetline(fp, line) && !data->gamess.converged)
1194
if (g_ascii_strncasecmp(line, " COORDINATES OF ALL ATOMS ARE", 29) == 0)
1196
/* go through all frames to count them */
1197
add_frame_offset(fp, data);
1198
read_gms_out_block(fp, data, 2, FALSE);
1209
/* set frame if don't want last? */
1210
strcpy(data->filename, filename);
1211
g_free(data->basename);
1212
data->basename = strdup_basename(filename);
1214
data->num_frames = data->cur_frame = frame;