psi::extrema::coord_base Class Reference

First level of abstract coordinate classes. More...

#include <coord_base.h>

Inheritance diagram for psi::extrema::coord_base:

psi::extrema::coord_base_carts psi::extrema::math_tools psi::extrema::internals psi::extrema::deloc psi::extrema::zmat

Protected Member Functions

 coord_base ()
 Coord_base constructor.
 ~coord_base ()
 Destructor. Memory is freed and io is stopped.
void mem_alloc ()
 Allocates memory.
void parse_input ()
 Parses input for info common to all coordinate types.
void print_Hi ()
 prints inverse of hessian matrix.
void print_H ()
 prints hessian matrix.
virtual void read_opt ()
 Reads from opt.dat().
virtual void write_opt ()
 Writes to opt.dat().
void update_Hi ()
 Updates inverse hessian.
void grad_test ()
 Tests for convergence of cartesian gradients.
virtual void initial_Hi ()=0
 Derived classes must provide a inverse Hessian guess function.
void H_test ()
 Computes hessian and its eigenvalues.

Protected Attributes

int iteration
int num_coords
int grad_max
int print_lvl
int do_deriv
int do_opt
int angle_abort
double * coords
double * grads
double * atomic_nums
double ** Hi
double * coords_old
double * grads_old
double ** Hi_old
double * coord_write
char * update
char ** felement

Detailed Description

First level of abstract coordinate classes.

The coord_base class contains data and functions common to all coordinate types. All coordinate types derive from this class. Member data includes generic coordinates and gradients, cartesians and cartesian gradients, a generic Hessian, information form previous iterations ("old" variables), and basic user suppied parameters. Generic functions for coordinate data manipulations are members of this class.

"generic" variables hold values and no information regarding coordinates to which they correspond. Classes deriving from this class determine the actual coordinate type and are responsible for proper handling of these variables.

Definition at line 80 of file coord_base.h.


Constructor & Destructor Documentation

coord_base::coord_base (  )  [protected]

Coord_base constructor.

Parses input

Definition at line 27 of file coord_base.cc.

References atomic_nums, chkpt_rd_zvals(), and parse_input().

00027                          : coord_base_carts(), math_tools() {
00028 
00029     coord_base::parse_input();
00030 
00031     atomic_nums = chkpt_rd_zvals();
00032     
00033     return; 
00034 }


Member Function Documentation

void coord_base::mem_alloc (  )  [protected]

Allocates memory.

Must be called once number of optimized coordinates is determined.

Reimplemented in psi::extrema::internals.

Definition at line 46 of file coord_base.cc.

References coord_write, coords, coords_old, grads, grads_old, Hi, Hi_old, init_array(), init_matrix(), and num_coords.

Referenced by psi::extrema::internals::mem_alloc().

void coord_base::read_opt (  )  [protected, virtual]

Reads from opt.dat().

Reads previous coordinates, gradients, and hessian inverse from opt.dat.

Definition at line 73 of file coord_base_io.cc.

References coords_old, ffile_noexit(), grads_old, Hi_old, ip_count(), ip_data(), ip_exist(), iteration, and num_coords.

Referenced by psi::extrema::zmat::optimize().

00073                             {
00074 
00075         FILE *opt_ptr;
00076 
00077         int i, j, error;
00078 
00079         ffile_noexit(&opt_ptr,"opt.dat",2);
00080         if( opt_ptr != NULL ) {      
00081             
00082             ip_done();
00083             ip_set_uppercase(1);
00084             ip_initialize(opt_ptr,outfile);
00085             ip_cwk_add(":OPT_INFO");
00086 
00087             ip_data("ITERATION","%d",&iteration,0);
00088             ++iteration;
00089       
00090             /*read old coordinate vector*/
00091             error = 0;
00092             error += !ip_exist("COORD",0);  
00093             ip_count("COORD",&num_coords,0);
00094           
00095             for (i=0;i<num_coords;++i) 
00096                 error += ip_data("COORD","%lf",&coords_old[i],1,i);
00097                 
00098             if(error != 0)
00099                 punt("Problem reading old coordinate values from opt.dat");
00100   
00101             /*read old gradient vector*/
00102             error += !ip_exist("GRAD",0);
00103 
00104             for (i=0;i<num_coords;++i) {
00105                 error += ip_data("GRAD","%lf",&grads_old[i],1,i);
00106             } 
00107 
00108             if(error != 0)
00109                 punt("Problem reading old gradient from opt.dat");
00110             
00111             /*read hmat, the inverse of the hessian*/
00112             error += (!ip_exist("HINV",0));
00113             
00114             for (i=0;i<num_coords;++i) {
00115                 for (j=0;j<num_coords;++j) {
00116                     error += ip_data("HINV","%lf", &Hi_old[i][j], 2, i, j);
00117                 }
00118             }
00119             
00120             fclose(opt_ptr);
00121       
00122             if(error != 0)
00123                 punt("Problem reading old hessian from opt.dat");
00124         }
00125         else iteration=1;
00126 
00127         fprintf(outfile,"\n\n  Beginning iteration: %d\n",iteration);
00128 
00129         return;
00130 }

void coord_base::write_opt (  )  [protected, virtual]

Writes to opt.dat().

Writes coordinates, gradients, and hessian inverse to opt.dat.

Definition at line 141 of file coord_base_io.cc.

References coord_write, ffile(), grads, Hi, iteration, and num_coords.

Referenced by psi::extrema::zmat::optimize().

00141                              {
00142 
00143     int place, i, r;
00144     
00145     FILE *opt_ptr;
00146 
00147     ip_done();
00148     ffile(&opt_ptr,"opt.dat",0);
00149     ip_set_uppercase(1);
00150     ip_initialize(opt_ptr,outfile);
00151     
00152     fprintf(opt_ptr,"opt_info: (\n\n");
00153 
00154     /* write number of coords */
00155     fprintf(opt_ptr,"  num_coords = %d\n\n",num_coords);    
00156     
00157     /*write iteration number*/
00158     fprintf(opt_ptr,"  iteration = %d\n\n",iteration);
00159     
00160     /*write coordinate vector*/
00161     place = 0;
00162     fprintf(opt_ptr,"  coord = ( ");
00163     for (i=0;i<num_coords;++i) {
00164         if( place==8 ) {
00165             place = 0;
00166             fprintf(opt_ptr,"\n            ");
00167         }
00168         fprintf(opt_ptr,"%lf  ",coord_write[i]);
00169         ++place;
00170     }
00171     fprintf(opt_ptr,")\n\n");
00172 
00173     /*write gradient vector*/
00174     place = 0;
00175     fprintf(opt_ptr,"  grad = ( ");
00176     for (i=0;i<num_coords;++i) {
00177         if( place==8 ) {
00178             place = 0;
00179             fprintf(opt_ptr,"\n            ");
00180         }
00181         fprintf(opt_ptr,"%.20lf  ",grads[i]);
00182         ++place;
00183     }
00184     fprintf(opt_ptr,")\n\n");
00185     
00186     /*write Hessian one row at a time*/
00187     place=0;
00188     fprintf(opt_ptr,"  hinv = ( ");
00189     for(r=0;r<num_coords;++r) {
00190         if( place==0 )
00191             fprintf(opt_ptr,"\n         ( ");
00192         for (i=0;i<num_coords;++i) {
00193             if( place==8 ) {
00194                 place = 0;
00195                 fprintf(opt_ptr,"\n           ");
00196             }
00197             fprintf(opt_ptr,"%lf  ",Hi[r][i]);
00198             ++place;
00199         }
00200         fprintf(opt_ptr,")\n         ");
00201         place = 0;
00202     }
00203     fprintf(opt_ptr,")\n\n");
00204     
00205     fprintf(opt_ptr,"          )\n");
00206     
00207     fclose(opt_ptr);
00208     return;
00209 }

void coord_base::update_Hi (  )  [protected]

Updates inverse hessian.

Interface for math_tools update functions.

Definition at line 68 of file coord_base.cc.

References coords, coords_old, grads, grads_old, Hi, Hi_old, init_array(), num_coords, print_lvl, print_mat(), RIDICULOUS_PRINT, update, psi::extrema::math_tools::update_bfgs(), and psi::extrema::math_tools::update_ms().

Referenced by psi::extrema::zmat::optimize(), and psi::extrema::deloc::optimize().

00068                              {
00069 
00070     int i;
00071     double *coord_dif, *grad_dif;
00072     coord_dif = init_array(num_coords);
00073     grad_dif = init_array(num_coords);
00074     for(i=0;i<num_coords;++i) {
00075         coord_dif[i] = coords[i] - coords_old[i];
00076         grad_dif[i] = grads[i] - grads_old[i];
00077     }
00078 
00079     if(print_lvl >= RIDICULOUS_PRINT) {
00080         fprintf(outfile,"\n  Hi matrix from previous itertation:\n");
00081         print_mat(Hi_old,num_coords,num_coords,outfile);
00082         fprintf(outfile,"\n  Coordinate differences:\n");
00083         for(i=0;i<num_coords;++i)
00084             fprintf(outfile,"  %lf - %lf = %lf\n",
00085                     coords[i],coords_old[i],coord_dif[i]);
00086         fprintf(outfile,"\n  Gradient differences:\n");
00087         for(i=0;i<num_coords;++i) 
00088             fprintf(outfile,"  %lf - %lf = %lf\n",
00089                     grads[i],grads_old[i],grad_dif[i]);
00090     }
00091 
00092     if(!strcmp(update,"MS")) {
00093         fprintf(outfile,"\n  Performing ms update of inverse hessian\n");
00094         Hi = math_tools :: update_ms(num_coords, coord_dif, grad_dif, Hi_old);
00095     }
00096     else { 
00097         fprintf(outfile,"\n  Performing bfgs update of inverse hessian\n");
00098         Hi = math_tools ::update_bfgs(num_coords, coord_dif, grad_dif, Hi_old);
00099     }
00100 
00101     free(coord_dif);
00102     free(grad_dif);
00103 
00104     return;
00105 }


Field Documentation

int psi::extrema::coord_base::iteration [protected]

current iteration

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::deloc::deloc(), psi::extrema::zmat::optimize(), psi::extrema::deloc::optimize(), read_opt(), and write_opt().

int psi::extrema::coord_base::num_coords [protected]

number of coordinates which are actually optimized

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::deloc::deloc(), H_test(), psi::extrema::internals::mem_alloc(), mem_alloc(), psi::extrema::zmat::newton_step(), print_H(), print_Hi(), read_opt(), update_Hi(), write_opt(), psi::extrema::zmat::zmat(), ~coord_base(), and psi::extrema::internals::~internals().

int psi::extrema::coord_base::grad_max [protected]

max allowable gradient is 10^-(grad_max)

Definition at line 84 of file coord_base.h.

Referenced by grad_test(), and parse_input().

int psi::extrema::coord_base::print_lvl [protected]

print level

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::internals::back_transform(), psi::extrema::internals::compute_A(), psi::extrema::internals::compute_G(), psi::extrema::deloc::deloc(), psi::extrema::zmat::grad_trans(), H_test(), psi::extrema::zmat::newton_step(), psi::extrema::zmat::optimize(), psi::extrema::deloc::optimize(), parse_input(), psi::extrema::internals::print_B(), and update_Hi().

int psi::extrema::coord_base::do_deriv [protected]

are we doing derivatives

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::deloc::deloc(), and parse_input().

int psi::extrema::coord_base::do_opt [protected]

are we doing optimization

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::deloc::deloc(), and parse_input().

int psi::extrema::coord_base::angle_abort [protected]

die if bad angle

Definition at line 84 of file coord_base.h.

Referenced by psi::extrema::zmat::newton_step(), parse_input(), and psi::extrema::zmat::zmat().

double* psi::extrema::coord_base::coords [protected]

generic coordinate array

Definition at line 92 of file coord_base.h.

Referenced by psi::extrema::deloc::deloc(), mem_alloc(), psi::extrema::zmat::newton_step(), update_Hi(), psi::extrema::zmat::zmat(), and ~coord_base().

double * psi::extrema::coord_base::grads [protected]

generic gradient array

Definition at line 92 of file coord_base.h.

Referenced by psi::extrema::zmat::grad_trans(), mem_alloc(), psi::extrema::zmat::newton_step(), psi::extrema::deloc::optimize(), update_Hi(), write_opt(), and ~coord_base().

double * psi::extrema::coord_base::atomic_nums [protected]

atomic numbers

Definition at line 92 of file coord_base.h.

Referenced by coord_base(), and ~coord_base().

double ** psi::extrema::coord_base::Hi [protected]

generic inverse hessian matrix

Definition at line 92 of file coord_base.h.

Referenced by H_test(), psi::extrema::zmat::initial_Hi(), mem_alloc(), psi::extrema::zmat::newton_step(), print_H(), print_Hi(), update_Hi(), write_opt(), and ~coord_base().

double * psi::extrema::coord_base::coords_old [protected]

generic coordinates from previous iteration

Definition at line 92 of file coord_base.h.

Referenced by mem_alloc(), read_opt(), update_Hi(), and ~coord_base().

double * psi::extrema::coord_base::grads_old [protected]

generic gradients from previous iteration

Definition at line 92 of file coord_base.h.

Referenced by mem_alloc(), read_opt(), update_Hi(), and ~coord_base().

double ** psi::extrema::coord_base::Hi_old [protected]

generic hessian inverse

Definition at line 92 of file coord_base.h.

Referenced by mem_alloc(), read_opt(), update_Hi(), and ~coord_base().

double * psi::extrema::coord_base::coord_write [protected]

holds coordinate values prior to optimization step until opt.dat is written

Definition at line 92 of file coord_base.h.

Referenced by mem_alloc(), psi::extrema::zmat::newton_step(), write_opt(), and ~coord_base().

char* psi::extrema::coord_base::update [protected]

Note:
"generic" variables hold values and no information regarding coordinates to which they correspond. Classes deriving from this class determine the actual coordinate type and are responsible for proper handling of these variables the hessian inverse update method

Definition at line 107 of file coord_base.h.

Referenced by parse_input(), and update_Hi().

char ** psi::extrema::coord_base::felement [protected]

the full list of element names (including dummy atoms)

Definition at line 107 of file coord_base.h.

Referenced by psi::extrema::zmat::compute_B(), psi::extrema::deloc::deloc(), psi::extrema::zmat::print_c_grads(), psi::extrema::zmat::print_carts(), psi::extrema::zmat::print_internals(), psi::extrema::zmat::write_chkpt(), psi::extrema::zmat::zmat(), and ~coord_base().


The documentation for this class was generated from the following files:
Generated on Wed Feb 13 16:36:15 2008 for PSI by  doxygen 1.5.4