~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/bin/detcas/step.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <stdio.h>
 
3
#include <libipv1/ip_lib.h>
 
4
#include <libciomr/libciomr.h>
 
5
#include <libchkpt/chkpt.h>
 
6
#include <libqt/qt.h>
 
7
#include <math.h>
 
8
#include "globaldefs.h"
 
9
#include "globals.h"
 
10
 
 
11
#define MO_HESS_MIN 1.0E-2
 
12
 
 
13
 
 
14
/*
 
15
** calc_orb_step()
 
16
**
 
17
** This function calculates the step in theta space for the orbitals
 
18
** given the orbital gradient and an approximate orbital Hessian
 
19
**
 
20
** C. David Sherrill
 
21
** April 1998
 
22
*/
 
23
void calc_orb_step(int npairs, double *grad, double *hess_diag, double *theta)
 
24
{
 
25
 
 
26
  int pair;
 
27
  double numer, denom;
 
28
 
 
29
  for (pair=0; pair<npairs; pair++) {
 
30
    numer = grad[pair];
 
31
    denom = hess_diag[pair];
 
32
    if (denom < 0.0) {
 
33
      fprintf(outfile, "Warning: MO Hessian denominator negative\n");
 
34
      denom = -denom;
 
35
    }
 
36
    if (denom < MO_HESS_MIN) {
 
37
      fprintf(outfile, "Warning: MO Hessian denominator too small\n");
 
38
      denom = MO_HESS_MIN;
 
39
    } 
 
40
    theta[pair] =  - numer / denom;
 
41
  }
 
42
 
 
43
}
 
44
 
 
45
 
 
46
/*
 
47
** print_step
 
48
**
 
49
** This function prints out the information for a given orbital iteration
 
50
*/
 
51
int print_step(int npairs, int steptype)
 
52
{
 
53
  FILE *sumfile;
 
54
  char sumfile_name[] = "file14.dat";
 
55
  int i, entries, iter, *nind;
 
56
  double *rmsgrad, *scaled_rmsgrad, *energies, energy;
 
57
  char **comments;
 
58
 
 
59
  /* open ascii file, get number of entries already in it */
 
60
 
 
61
  sumfile = fopen(sumfile_name, "r");
 
62
  if (sumfile == NULL) { /* the file doesn't exist yet */
 
63
    entries = 0;
 
64
    if (Params.print_lvl)
 
65
      fprintf(outfile, "\nPreparing new file %s\n", sumfile_name);
 
66
  }
 
67
  else {
 
68
    if (fscanf(sumfile, "%d", &entries) != 1) {
 
69
      fprintf(outfile,"(print_step): Trouble reading num entries in file %s\n",
 
70
        sumfile_name);
 
71
      fclose(sumfile);
 
72
      return;
 
73
    }
 
74
  }
 
75
 
 
76
  rmsgrad = init_array(entries+1);
 
77
  scaled_rmsgrad = init_array(entries+1);
 
78
  energies= init_array(entries+1);
 
79
  nind = init_int_array(entries+1);
 
80
  comments = (char **) malloc ((entries+1) * sizeof (char *));
 
81
  for (i=0; i<entries+1; i++) {
 
82
    comments[i] = (char *) malloc (MAX_COMMENT * sizeof(char));
 
83
  }
 
84
 
 
85
  for (i=0; i<entries; i++) {
 
86
    fscanf(sumfile, "%d %d %lf %lf %lf %s", &iter, &(nind[i]), 
 
87
           &(scaled_rmsgrad[i]), &(rmsgrad[i]), &(energies[i]), comments[i]);
 
88
  }
 
89
 
 
90
  chkpt_init(PSIO_OPEN_OLD);
 
91
  energy = chkpt_rd_etot();
 
92
  chkpt_close();
 
93
 
 
94
  scaled_rmsgrad[entries] = CalcInfo.scaled_mo_grad_rms;
 
95
  rmsgrad[entries] = CalcInfo.mo_grad_rms;
 
96
  energies[entries] = energy;
 
97
  nind[entries] = npairs;
 
98
 
 
99
  if (steptype == 0) 
 
100
    strcpy(comments[entries], "CONV");
 
101
  else if (steptype == 1)
 
102
    strcpy(comments[entries], "NR");
 
103
  else if (steptype == 2)
 
104
    strcpy(comments[entries], "DIIS"); 
 
105
  else {
 
106
    fprintf(outfile, "(print_step): Unrecognized steptype %d\n", steptype);
 
107
    strcpy(comments[entries], "?");
 
108
  }
 
109
 
 
110
  if (entries) fclose(sumfile);
 
111
 
 
112
  /* now open file for writing, write out old info plus new */
 
113
  if ((sumfile = fopen("file14.dat", "w")) == NULL) {
 
114
    fprintf(outfile, "(print_step): Unable to open file %s\n", sumfile_name);
 
115
  }
 
116
  else {
 
117
    entries++;
 
118
    fprintf(sumfile, "%5d\n", entries);
 
119
    for (i=0; i<entries; i++) {
 
120
      fprintf(sumfile, "%5d %5d %14.9lf %14.9lf %20.12lf %9s\n", i+1, nind[i], 
 
121
              scaled_rmsgrad[i], rmsgrad[i], energies[i], comments[i]);
 
122
    }
 
123
    fclose(sumfile);
 
124
  }
 
125
 
 
126
  free(scaled_rmsgrad);
 
127
  free(rmsgrad);
 
128
  free(energies);
 
129
  free(nind);
 
130
  for (i=0; i<entries; i++)
 
131
    free(comments[i]);
 
132
  free(comments);
 
133
 
 
134
}
 
135