File: compfg.c

package info (click to toggle)
ghemical 0.82-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,448 kB
  • ctags: 18,571
  • sloc: ansic: 68,828; cpp: 51,774; fortran: 35,324; sh: 2,505; makefile: 475; perl: 70
file content (509 lines) | stat: -rw-r--r-- 13,168 bytes parent folder | download | duplicates (2)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/* compfg.f -- translated by f2c (version 19991025).
   You must link the resulting object file with the libraries:
	-lf2c -lm   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    integer nvar, loc[720]	/* was [2][360] */, idumy;
    doublereal dumy[360];
} geovar_;

#define geovar_1 geovar_

struct {
    integer ndep, locpar[360], idepfn[360], locdep[360];
} geosym_;

#define geosym_1 geosym_

struct {
    doublereal geo[360]	/* was [3][120] */, xcoord[360]	/* was [3][120] */;
} geom_;

#define geom_1 geom_

struct {
    doublereal atheat;
} atheat_;

#define atheat_1 atheat_

struct {
    doublereal wj[214770], wk[214770];
} wmatrx_;

#define wmatrx_1 wmatrx_

struct {
    doublereal enuclr;
} enuclr_;

#define enuclr_1 enuclr_

struct {
    integer nztype[107], mtype[30], ltype;
} natype_;

#define natype_1 natype_

struct {
    doublereal elect;
} elect_;

#define elect_1 elect_

struct {
    doublereal rxyz[45150], xdumy[84450];
} scrach_;

#define scrach_1 scrach_

struct {
    doublereal h__[45150];
} hmatrx_;

#define hmatrx_1 hmatrx_

struct {
    integer natoms, labels[120], na[120], nb[120], nc[120];
} geokst_;

#define geokst_1 geokst_

struct {
    doublereal errfn[360], aicorr[360];
} errfn_;

#define errfn_1 errfn_

struct {
    doublereal c__[90000], eigs[300], cbeta[90000], eigb[300];
} vector_;

#define vector_1 vector_

struct {
    integer last;
} last_;

#define last_1 last_

struct {
    integer numcal;
} numcal_;

#define numcal_1 numcal_

struct {
    doublereal emin;
    logical limscf;
} scftyp_;

#define scftyp_1 scftyp_

struct {
    doublereal htype[4];
    integer nhco[80]	/* was [4][20] */, nnhco, itype;
} molmec_;

#define molmec_1 molmec_

struct {
    integer numat, nat[120], nfirst[120], nmidle[120], nlast[120], norbs, 
	    nelecs, nalpha, nbeta, nclose, nopen, ndumy;
    doublereal fract;
} molkst_;

#define molkst_1 molkst_

struct {
    logical iseps, useps, upda;
} iseps_;

#define iseps_1 iseps_

struct {
    char keywrd[241];
} keywrd_;

#define keywrd_1 keywrd_

/* Table of constant values */

static integer c__1 = 1;
static logical c_true = TRUE_;

/* Subroutine */ int compfg_(xparam, int__, escf, fulscf, grad, lgrad)
doublereal *xparam;
logical *int__;
doublereal *escf;
logical *fulscf;
doublereal *grad;
logical *lgrad;
{
    /* Initialized data */

    static integer icalcn = 0;

    /* System generated locals */
    integer i__1, i__2;
    doublereal d__1;
    alist al__1;

    /* Builtin functions */
    integer i_indx(), s_wsfe(), do_fio(), e_wsfe(), f_rew();
    double sin();

    /* Local variables */
    extern /* Subroutine */ int btoc_(), iter_();
    static integer i__, j, k, l;
    extern /* Subroutine */ int dihed_();
    static logical aider, debug;
#define w ((doublereal *)&wmatrx_1)
    static doublereal angle;
    static logical large, force;
    static doublereal delta[2400];
    extern /* Subroutine */ int hcore_(), mecip_();
    static doublereal coord[360]	/* was [3][120] */;
    extern /* Subroutine */ int deriv_(), timer_();
    static logical times, print;
    static doublereal degree[3];
    static logical usedci, analyt;
    static doublereal xparef[360], deltap[64];
    extern /* Subroutine */ int setupg_(), gmetry_();
    static integer indeps;
    extern /* Subroutine */ int initsv_(), consts_(), symtry_();

    /* Fortran I/O blocks */
    static cilist io___17 = { 0, 6, 0, "(' INTERNAL COORDS',/100(/,3F12.6))", 
	    0 };
    static cilist io___19 = { 0, 6, 0, "(' CARTESIAN COORDS',/100(/,3F16.9))",
	     0 };
    static cilist io___22 = { 0, 6, 0, "(/10X,' HEAT OF FORMATION',G30.17)", 
	    0 };
    static cilist io___23 = { 0, 6, 0, "(' GRADIENT       ',8F8.2,(/10F8.2))",
	     0 };


/* COMDECK SIZES */
/* *********************************************************************** */
/*   THIS FILE CONTAINS ALL THE ARRAY SIZES FOR USE IN MOPAC. */

/*     THERE ARE ONLY 5 PARAMETERS THAT THE PROGRAMMER NEED SET: */
/*     MAXHEV = MAXIMUM NUMBER OF HEAVY ATOMS (HEAVY: NON-HYDROGEN ATOMS) */
/*     MAXLIT = MAXIMUM NUMBER OF HYDROGEN ATOMS. */
/*     MAXTIM = DEFAULT TIME FOR A JOB. (SECONDS) */
/*     MAXDMP = DEFAULT TIME FOR AUTOMATIC RESTART FILE GENERATION (SECS) */
/*     ISYBYL = 1 IF MOPAC IS TO BE USED IN THE SYBYL PACKAGE, =0 OTHERWISE */
/*     SEE ALSO NMECI, NPULAY AND MESP AT THE END OF THIS FILE */


/* *********************************************************************** */

/*   THE FOLLOWING CODE DOES NOT NEED TO BE ALTERED BY THE PROGRAMMER */

/* *********************************************************************** */

/*    ALL OTHER PARAMETERS ARE DERIVED FUNCTIONS OF THESE TWO PARAMETERS */

/*      NAME                   DEFINITION */
/*     NUMATM         MAXIMUM NUMBER OF ATOMS ALLOWED. */
/*     MAXORB         MAXIMUM NUMBER OF ORBITALS ALLOWED. */
/*     MAXPAR         MAXIMUM NUMBER OF PARAMETERS FOR OPTIMISATION. */
/*     N2ELEC         MAXIMUM NUMBER OF TWO ELECTRON INTEGRALS ALLOWED. */
/*     MPACK          AREA OF LOWER HALF TRIANGLE OF DENSITY MATRIX. */
/*     MORB2          SQUARE OF THE MAXIMUM NUMBER OF ORBITALS ALLOWED. */
/*     MAXHES         AREA OF HESSIAN MATRIX */
/*     MAXALL         LARGER THAN MAXORB OR MAXPAR. */
/* *********************************************************************** */

/* *********************************************************************** */
/* DECK MOPAC */
/* COSMO change A. Klamt */
/* end of COSMO change */
/* *********************************************************************** */

/*   COMPFG CALCULATES (A) THE HEAT OF FORMATION OF THE SYSTEM, AND */
/*                     (B) THE GRADIENTS, IF LGRAD IS .TRUE. */

/*   ON INPUT  XPARAM = ARRAY OF PARAMETERS TO BE USED IN INTERNAL COORDS */
/*             LGRAD  = .TRUE. IF GRADIENTS ARE NEEDED, .FALSE. OTHERWISE */
/*             INT    = .TRUE. IF HEAT OF FORMATION IS TO BE CALCULATED */
/*             FULSCF = .TRUE. IF FULL SCF TO BE DONE, .FALSE. OTHERWISE. */

/*   ON OUTPUT ESCF  = HEAT OF FORMATION. */
/*             GRAD   = ARRAY OF GRADIENTS, IF LGRAD = .TRUE. */

/* *********************************************************************** */
    /* Parameter adjustments */
    --grad;
    --xparam;

    /* Function Body */
/*                 MNDO     AM1      PM3      MINDO/ */
    if (icalcn != numcal_1.numcal) {
	icalcn = numcal_1.numcal;
	molmec_1.htype[0] = 6.1737;
	molmec_1.htype[1] = 3.3191;
	molmec_1.htype[2] = 7.1853;
	molmec_1.htype[3] = 1.7712;
	natype_1.ltype = 0;
	i__1 = molkst_1.numat;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    if (molkst_1.nat[i__ - 1] < 99) {
		i__2 = natype_1.ltype;
		for (j = 1; j <= i__2; ++j) {
/* L10: */
		    if (molkst_1.nat[i__ - 1] == natype_1.mtype[j - 1]) {
			goto L20;
		    }
		}
		++natype_1.ltype;
		natype_1.mtype[natype_1.ltype - 1] = molkst_1.nat[i__ - 1];
		natype_1.nztype[molkst_1.nat[i__ - 1] - 1] = natype_1.ltype;

/*       LTYPE = NUMBER OF TYPES OF REAL ATOM PRESENT */
/*       MTYPE = TYPES OF REAL ATOMS PRESENT */
		j = natype_1.ltype;
L20:
		;
	    }
/* L30: */
	}
	aider = i_indx(keywrd_1.keywrd, "AIDER", (ftnlen)241, (ftnlen)5) != 0;
	times = i_indx(keywrd_1.keywrd, "TIMES", (ftnlen)241, (ftnlen)5) != 0;
	analyt = i_indx(keywrd_1.keywrd, "ANALYT", (ftnlen)241, (ftnlen)6) != 
		0;
	if (*int__ && analyt) {
	    setupg_();
	}
	degree[0] = 1.;
	if (i_indx(keywrd_1.keywrd, " XYZ", (ftnlen)241, (ftnlen)4) != 0) {
	    degree[1] = 1.;
	} else {
	    degree[1] = 57.295779531334603;
	}
	degree[2] = degree[1];
	usedci = molkst_1.nclose != molkst_1.nopen && molkst_1.fract != 2. && 
		molkst_1.fract != 0. || i_indx(keywrd_1.keywrd, "C.I.", (
		ftnlen)241, (ftnlen)4) != 0;
	force = i_indx(keywrd_1.keywrd, "FORCE", (ftnlen)241, (ftnlen)5) != 0;
	large = i_indx(keywrd_1.keywrd, "LARGE", (ftnlen)241, (ftnlen)5) != 0;
	print = i_indx(keywrd_1.keywrd, "COMPFG", (ftnlen)241, (ftnlen)6) != 
		0;
	debug = i_indx(keywrd_1.keywrd, "DEBUG", (ftnlen)241, (ftnlen)5) != 0 
		&& print;
	scftyp_1.emin = 0.;
	i__1 = geovar_1.nvar;
	for (i__ = 1; i__ <= i__1; ++i__) {
/* L40: */
	    xparef[i__ - 1] = xparam[i__];
	}
    }

/* SET UP COORDINATES FOR CURRENT CALCULATION */

/*       PLACE THE NEW VALUES OF THE VARIABLES IN THE ARRAY GEO. */
/*       MAKE CHANGES IN THE GEOMETRY. */
    i__1 = geovar_1.nvar;
    for (i__ = 1; i__ <= i__1; ++i__) {
	k = geovar_1.loc[(i__ << 1) - 2];
	l = geovar_1.loc[(i__ << 1) - 1];
/* L50: */
	geom_1.geo[l + k * 3 - 4] = xparam[i__];
    }
/*      IMPOSE THE SYMMETRY CONDITIONS + COMPUTE THE DEPENDENT-PARAMETERS */
    if (geosym_1.ndep != 0) {
	symtry_();
    }
/*      NOW COMPUTE THE ATOMIC COORDINATES. */
    if (debug) {
	if (large) {
	    k = geokst_1.natoms;
	} else {
	    k = min(5,geokst_1.natoms);
	}
	s_wsfe(&io___17);
	i__1 = k;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    for (j = 1; j <= 3; ++j) {
		d__1 = geom_1.geo[j + i__ * 3 - 4] * degree[j - 1];
		do_fio(&c__1, (char *)&d__1, (ftnlen)sizeof(doublereal));
	    }
	}
	e_wsfe();
    }
    gmetry_(geom_1.geo, coord);
    if (debug) {
	if (large) {
	    k = molkst_1.numat;
	} else {
	    k = min(5,molkst_1.numat);
	}
	s_wsfe(&io___19);
	i__1 = k;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    for (j = 1; j <= 3; ++j) {
		do_fio(&c__1, (char *)&coord[j + i__ * 3 - 4], (ftnlen)sizeof(
			doublereal));
	    }
	}
	e_wsfe();
    }
    if (*int__ && analyt) {
	al__1.aerr = 0;
	al__1.aunit = 2;
	f_rew(&al__1);
    }
/* COSMO change A. Klamt */
/*     IF (.NOT. USEPS) THEN */
    if (! iseps_1.iseps) {
/* end of COSMO change */
	if (times) {
	    timer_("BEFORE HCORE", (ftnlen)12);
	}
	if (*int__) {
	    hcore_(coord, hmatrx_1.h__, w, wmatrx_1.wj, wmatrx_1.wk, &
		    enuclr_1.enuclr);
	}
	if (times) {
	    timer_("AFTER HCORE", (ftnlen)11);
	}

/* COMPUTE THE HEAT OF FORMATION. */

	if (molkst_1.norbs > 0 && molkst_1.nelecs > 0) {
	    if (times) {
		timer_("BEFORE ITER", (ftnlen)11);
	    }
	    if (*int__) {
		iter_(hmatrx_1.h__, w, wmatrx_1.wj, wmatrx_1.wk, &
			elect_1.elect, fulscf, &c_true);
	    }
	    if (times) {
		timer_("AFTER ITER", (ftnlen)10);
	    }
	} else {
	    elect_1.elect = 0.;
	}
	*escf = (elect_1.elect + enuclr_1.enuclr) * 23.061 + atheat_1.atheat;
	if (*escf < scftyp_1.emin || scftyp_1.emin == 0.) {
	    scftyp_1.emin = *escf;
	}
	i__1 = molmec_1.nnhco;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    dihed_(coord, &molmec_1.nhco[(i__ << 2) - 4], &molmec_1.nhco[(i__ 
		    << 2) - 3], &molmec_1.nhco[(i__ << 2) - 2], &
		    molmec_1.nhco[(i__ << 2) - 1], &angle);
/* Computing 2nd power */
	    d__1 = sin(angle);
	    *escf += molmec_1.htype[molmec_1.itype - 1] * (d__1 * d__1);
/* L60: */
	}
/* COSMO change A. Klamt 18.7.91 */
    }
    if (iseps_1.iseps) {
	indeps = i_indx(keywrd_1.keywrd, "EPS=", (ftnlen)241, (ftnlen)4);
	initsv_(&indeps);
/* The following routine constructs the dielectric screening surface */
	consts_(coord);
/* The following routine constructs dielectric response matrix CCMAT */
	btoc_(coord);
/* A. Klamt 18.7.91 */
	iseps_1.useps = TRUE_;
	if (times) {
	    timer_("BEFORE HCORE", (ftnlen)12);
	}
	if (*int__) {
	    hcore_(coord, hmatrx_1.h__, w, wmatrx_1.wj, wmatrx_1.wk, &
		    enuclr_1.enuclr);
	}
	if (times) {
	    timer_("AFTER HCORE", (ftnlen)11);
	}

/* COMPUTE THE HEAT OF FORMATION. */

	if (molkst_1.norbs > 0 && molkst_1.nelecs > 0) {
	    if (times) {
		timer_("BEFORE ITER", (ftnlen)11);
	    }
	    if (*int__) {
		iter_(hmatrx_1.h__, w, wmatrx_1.wj, wmatrx_1.wk, &
			elect_1.elect, fulscf, &c_true);
	    }
	    if (times) {
		timer_("AFTER ITER", (ftnlen)10);
	    }
	} else {
	    elect_1.elect = 0.;
	}
	*escf = (elect_1.elect + enuclr_1.enuclr) * 23.061 + atheat_1.atheat;
	if (*escf < scftyp_1.emin || scftyp_1.emin == 0.) {
	    scftyp_1.emin = *escf;
	}
	i__1 = molmec_1.nnhco;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    dihed_(coord, &molmec_1.nhco[(i__ << 2) - 4], &molmec_1.nhco[(i__ 
		    << 2) - 3], &molmec_1.nhco[(i__ << 2) - 2], &
		    molmec_1.nhco[(i__ << 2) - 1], &angle);
/* Computing 2nd power */
	    d__1 = sin(angle);
	    *escf += molmec_1.htype[molmec_1.itype - 1] * (d__1 * d__1);
/* L61: */
	}
    }
/* end of COSMO change */

/* FIND DERIVATIVES IF DESIRED */

    if (*lgrad) {
	if (times) {
	    timer_("BEFORE DERIV", (ftnlen)12);
	}
	deriv_(geom_1.geo, &grad[1]);
	if (times) {
	    timer_("AFTER DERIV", (ftnlen)11);
	}
    }
    if (aider) {

/*  ADD IN AB INITIO CORRECTION */

	i__1 = geovar_1.nvar;
	for (i__ = 1; i__ <= i__1; ++i__) {
/* L70: */
	    *escf += (xparam[i__] - xparef[i__ - 1]) * errfn_1.aicorr[i__ - 1]
		    ;
	}
    }
    if (*int__ && print) {
	s_wsfe(&io___22);
	do_fio(&c__1, (char *)&(*escf), (ftnlen)sizeof(doublereal));
	e_wsfe();
    }
    if (print && *lgrad) {
	s_wsfe(&io___23);
	i__1 = geovar_1.nvar;
	for (i__ = 1; i__ <= i__1; ++i__) {
	    do_fio(&c__1, (char *)&grad[i__], (ftnlen)sizeof(doublereal));
	}
	e_wsfe();
    }

/* REFORM DENSITY MATRIX, IF A C.I. DONE AND EITHER THE LAST SCF OR A */
/* FORCE CALCULATION */

    if (usedci && (last_1.last == 1 || force)) {
	mecip_(vector_1.c__, &molkst_1.norbs, deltap, delta);
    }
    return 0;
} /* compfg_ */

#undef w