~ubuntu-branches/ubuntu/intrepid/psicode/intrepid

« back to all changes in this revision

Viewing changes to src/bin/optking/grad_save.cc

  • 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
/*** ENERGY_SAVE.CC Rollin King, 2002 ***/
 
2
// function executes if optinfo.mode == MODE_ENERGY_SAVE
 
3
 
 
4
#if HAVE_CMATH
 
5
# include <cmath>
 
6
#else
 
7
# include <math.h>
 
8
#endif
 
9
 
 
10
extern "C" {
 
11
#include <stdio.h>
 
12
#include <libchkpt/chkpt.h>
 
13
#include <stdlib.h>
 
14
#include <string.h>
 
15
#include <ctype.h>
 
16
#include <libciomr/libciomr.h>
 
17
#include <libipv1/ip_lib.h>
 
18
#include <libpsio/psio.h>
 
19
#include <physconst.h>
 
20
#include <psifiles.h>
 
21
}
 
22
 
 
23
#define EXTERN
 
24
#include "opt.h"
 
25
#undef EXTERN
 
26
#include "cartesians.h"
 
27
#include "internals.h"
 
28
 
 
29
void grad_save(cartesians &carts) {
 
30
  int i,j,dim_carts,total_num_disps;
 
31
  double energy, *micro_e, *micro_grad, *grad, **ggrad, **refgrad, **rref;
 
32
 
 
33
  dim_carts = 3*optinfo.natom;
 
34
 
 
35
  fprintf(outfile,"Saving gradient and energy.\n");
 
36
 
 
37
  open_PSIF();
 
38
  psio_read_entry(PSIF_OPTKING, "OPT: Current disp_num",
 
39
      (char *) &(optinfo.disp_num), sizeof(int));
 
40
  psio_read_entry(PSIF_OPTKING, "OPT: Total num. of disp.",
 
41
      (char *) &(total_num_disps), sizeof(int));
 
42
 
 
43
  micro_e = new double[total_num_disps];
 
44
  micro_grad = new double [total_num_disps*3*carts.get_natom()*sizeof(double)];
 
45
  psio_read_entry(PSIF_OPTKING, "OPT: Displaced gradients",
 
46
      (char *) &(micro_grad[0]), total_num_disps*3*carts.get_natom()*sizeof(double));
 
47
 
 
48
  /*
 
49
  fprintf(outfile,"gradients\n");
 
50
  for (i=0; i<total_num_disps*3*carts.get_natom(); ++i)
 
51
    fprintf(outfile,"%15.10lf\n",micro_grad[i]);
 
52
    */
 
53
 
 
54
  psio_read_entry(PSIF_OPTKING, "OPT: Displaced energies",
 
55
      (char *) &(micro_e[0]), total_num_disps*sizeof(double));
 
56
  close_PSIF();
 
57
 
 
58
  chkpt_init(PSIO_OPEN_OLD);
 
59
  grad = chkpt_rd_grad();
 
60
  rref = chkpt_rd_rref();
 
61
  energy = chkpt_rd_etot();
 
62
  chkpt_close();
 
63
 
 
64
  // Rotate the gradient back to the reference frame in which all geometries were generated and stores
 
65
  int natoms = carts.get_natom();
 
66
  ggrad = block_matrix(natoms,3);
 
67
  int atomxyz=0;
 
68
  for(int atom=0; atom<natoms; atom++)
 
69
    for(int xyz=0; xyz<3; xyz++,atomxyz++)
 
70
      ggrad[atom][xyz] = grad[atomxyz];
 
71
  delete[] grad;
 
72
  refgrad = block_matrix(carts.get_natom(),3);
 
73
  mmult(ggrad,0,rref,0,refgrad,0,carts.get_natom(),3,3,0);
 
74
  free_block(rref);
 
75
  free_block(ggrad);
 
76
 
 
77
  micro_e[optinfo.disp_num] = energy;
 
78
  for (i=0; i<dim_carts; ++i) {
 
79
    int atom = i/3;
 
80
    int xyz = i%3;
 
81
    micro_grad[3*carts.get_natom()*(optinfo.disp_num)+i] = refgrad[atom][xyz];
 
82
  }
 
83
 
 
84
  open_PSIF();
 
85
  psio_write_entry(PSIF_OPTKING,"OPT: Displaced energies",
 
86
      (char *) &(micro_e[0]), total_num_disps*sizeof(double));
 
87
  psio_write_entry(PSIF_OPTKING, "OPT: Displaced gradients",
 
88
      (char *) &(micro_grad[0]), total_num_disps*3*carts.get_natom()*sizeof(double));
 
89
  close_PSIF();
 
90
 
 
91
  delete [] micro_e; delete [] micro_grad;
 
92
 
 
93
  // increment disp_num
 
94
  open_PSIF();
 
95
  optinfo.disp_num += 1;
 
96
  psio_write_entry(PSIF_OPTKING, "OPT: Current disp_num",
 
97
      (char *) &(optinfo.disp_num), sizeof(int));
 
98
  close_PSIF();
 
99
 
 
100
  return ;
 
101
}
 
102