| 1 | //
 | 
|---|
| 2 | // redund.cc
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
 | 
|---|
| 5 | //
 | 
|---|
| 6 | // Author: Edward Seidl <seidl@janed.com>
 | 
|---|
| 7 | // Maintainer: LPS
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // This file is part of the SC Toolkit.
 | 
|---|
| 10 | //
 | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
 | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by
 | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
 | 
|---|
| 14 | // any later version.
 | 
|---|
| 15 | //
 | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
 | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 19 | // GNU Library General Public License for more details.
 | 
|---|
| 20 | //
 | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License
 | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
 | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
|---|
| 24 | //
 | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
 | 
|---|
| 26 | //
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include <math.h>
 | 
|---|
| 29 | 
 | 
|---|
| 30 | #include <util/state/stateio.h>
 | 
|---|
| 31 | #include <math/scmat/matrix.h>
 | 
|---|
| 32 | #include <math/scmat/local.h>
 | 
|---|
| 33 | #include <chemistry/molecule/molecule.h>
 | 
|---|
| 34 | #include <chemistry/molecule/coor.h>
 | 
|---|
| 35 | #include <chemistry/molecule/simple.h>
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include <util/container/bitarray.h>
 | 
|---|
| 38 | 
 | 
|---|
| 39 | using namespace sc;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | ///////////////////////////////////////////////////////////////////////////
 | 
|---|
| 42 | // members of RedundMolecularCoor
 | 
|---|
| 43 | 
 | 
|---|
| 44 | static ClassDesc RedundMolecularCoor_cd(
 | 
|---|
| 45 |   typeid(RedundMolecularCoor),"RedundMolecularCoor",1,"public IntMolecularCoor",
 | 
|---|
| 46 |   0, create<RedundMolecularCoor>, create<RedundMolecularCoor>);
 | 
|---|
| 47 | 
 | 
|---|
| 48 | RedundMolecularCoor::RedundMolecularCoor(Ref<Molecule>&mol):
 | 
|---|
| 49 |   IntMolecularCoor(mol)
 | 
|---|
| 50 | {
 | 
|---|
| 51 |   init();
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | RedundMolecularCoor::RedundMolecularCoor(const Ref<KeyVal>& keyval):
 | 
|---|
| 55 |   IntMolecularCoor(keyval)
 | 
|---|
| 56 | {
 | 
|---|
| 57 |   init();
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | RedundMolecularCoor::RedundMolecularCoor(StateIn& s):
 | 
|---|
| 61 |   IntMolecularCoor(s)
 | 
|---|
| 62 | {
 | 
|---|
| 63 | }
 | 
|---|
| 64 | 
 | 
|---|
| 65 | RedundMolecularCoor::~RedundMolecularCoor()
 | 
|---|
| 66 | {
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | void
 | 
|---|
| 70 | RedundMolecularCoor::save_data_state(StateOut&s)
 | 
|---|
| 71 | {
 | 
|---|
| 72 |   IntMolecularCoor::save_data_state(s);
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | void
 | 
|---|
| 76 | RedundMolecularCoor::form_coordinates(int keep_variable)
 | 
|---|
| 77 | {
 | 
|---|
| 78 |   if (!keep_variable) variable_ = all_;
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   if (form_print_simples_) print_simples(ExEnv::out0());
 | 
|---|
| 81 |   if (form_print_variable_) print_variable(ExEnv::out0());
 | 
|---|
| 82 |   if (form_print_constant_) print_constant(ExEnv::out0());
 | 
|---|
| 83 | }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | void
 | 
|---|
| 86 | RedundMolecularCoor::guess_hessian(RefSymmSCMatrix&hessian)
 | 
|---|
| 87 | {
 | 
|---|
| 88 |   variable_->guess_hessian(molecule_,hessian);
 | 
|---|
| 89 | }
 | 
|---|
| 90 | 
 | 
|---|
| 91 | RefSymmSCMatrix
 | 
|---|
| 92 | RedundMolecularCoor::inverse_hessian(RefSymmSCMatrix& hessian)
 | 
|---|
| 93 | {
 | 
|---|
| 94 |   RefSCDimension dredun = hessian.dim();
 | 
|---|
| 95 |   
 | 
|---|
| 96 |   // form bmat for variable coordinates (ie all the simples)
 | 
|---|
| 97 |   RefSCMatrix bmat(dredun,dnatom3_,matrixkit_);
 | 
|---|
| 98 |   variable_->bmat(molecule_,bmat);
 | 
|---|
| 99 |   
 | 
|---|
| 100 |   // and form G = (B*B+)
 | 
|---|
| 101 |   RefSymmSCMatrix bmbt(dredun,matrixkit_);
 | 
|---|
| 102 |   bmbt.assign(0.0);
 | 
|---|
| 103 |   bmbt.accumulate_symmetric_product(bmat);
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   // free bmat, and allocate storage for the projection matrix p
 | 
|---|
| 106 |   bmat = 0;
 | 
|---|
| 107 | 
 | 
|---|
| 108 |   RefSCMatrix p(dredun,dredun,matrixkit_);
 | 
|---|
| 109 |   p.assign(0.0);
 | 
|---|
| 110 | 
 | 
|---|
| 111 |   // form p = G- * G
 | 
|---|
| 112 |   for (int i=0; i < dredun->n(); i++)
 | 
|---|
| 113 |     p.set_element(i,i,1.0);
 | 
|---|
| 114 |   p = bmbt * p;
 | 
|---|
| 115 |   p = bmbt.gi()*p;
 | 
|---|
| 116 |   
 | 
|---|
| 117 |   // accumulate (p*hessian*p).gi() into bmbt
 | 
|---|
| 118 |   bmbt.assign(0.0);
 | 
|---|
| 119 |   bmbt.accumulate_transform(p,hessian);
 | 
|---|
| 120 |   bmbt = bmbt.gi();
 | 
|---|
| 121 |   
 | 
|---|
| 122 |   // finally return hinv = p*(p*h*p)-*p
 | 
|---|
| 123 |   RefSymmSCMatrix thess = hessian.clone();
 | 
|---|
| 124 |   thess.assign(0.0);
 | 
|---|
| 125 |   thess.accumulate_transform(p,bmbt);
 | 
|---|
| 126 |   return thess;
 | 
|---|
| 127 | }
 | 
|---|
| 128 | 
 | 
|---|
| 129 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 130 | 
 | 
|---|
| 131 | // Local Variables:
 | 
|---|
| 132 | // mode: c++
 | 
|---|
| 133 | // c-file-style: "ETS"
 | 
|---|
| 134 | // End:
 | 
|---|