| [0b990d] | 1 | // | 
|---|
|  | 2 | // cartcoor.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 <chemistry/molecule/molecule.h> | 
|---|
|  | 33 | #include <chemistry/molecule/coor.h> | 
|---|
|  | 34 | #include <chemistry/molecule/simple.h> | 
|---|
|  | 35 |  | 
|---|
|  | 36 | using namespace std; | 
|---|
|  | 37 | using namespace sc; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 40 | // members of CartMolecularCoor | 
|---|
|  | 41 |  | 
|---|
|  | 42 | static ClassDesc CartMolecularCoor_cd( | 
|---|
|  | 43 | typeid(CartMolecularCoor),"CartMolecularCoor",1,"public MolecularCoor", | 
|---|
|  | 44 | 0, create<CartMolecularCoor>, create<CartMolecularCoor>); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | CartMolecularCoor::CartMolecularCoor(Ref<Molecule>&mol): | 
|---|
|  | 47 | MolecularCoor(mol) | 
|---|
|  | 48 | { | 
|---|
|  | 49 | init(); | 
|---|
|  | 50 | } | 
|---|
|  | 51 |  | 
|---|
|  | 52 | CartMolecularCoor::CartMolecularCoor(const Ref<KeyVal>& keyval): | 
|---|
|  | 53 | MolecularCoor(keyval) | 
|---|
|  | 54 | { | 
|---|
|  | 55 | init(); | 
|---|
|  | 56 | } | 
|---|
|  | 57 |  | 
|---|
|  | 58 | CartMolecularCoor::CartMolecularCoor(StateIn& s): | 
|---|
|  | 59 | MolecularCoor(s) | 
|---|
|  | 60 | { | 
|---|
|  | 61 | dim_ << SavableState::restore_state(s); | 
|---|
|  | 62 | } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | void | 
|---|
|  | 65 | CartMolecularCoor::init() | 
|---|
|  | 66 | { | 
|---|
|  | 67 | // compute needed dimensions | 
|---|
|  | 68 | dim_ = dnatom3_; | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | CartMolecularCoor::~CartMolecularCoor() | 
|---|
|  | 72 | { | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | void | 
|---|
|  | 76 | CartMolecularCoor::save_data_state(StateOut&s) | 
|---|
|  | 77 | { | 
|---|
|  | 78 | MolecularCoor::save_data_state(s); | 
|---|
|  | 79 |  | 
|---|
|  | 80 | SavableState::save_state(dim_.pointer(),s); | 
|---|
|  | 81 | } | 
|---|
|  | 82 |  | 
|---|
|  | 83 | RefSCDimension | 
|---|
|  | 84 | CartMolecularCoor::dim() | 
|---|
|  | 85 | { | 
|---|
|  | 86 | return dim_; | 
|---|
|  | 87 | } | 
|---|
|  | 88 |  | 
|---|
|  | 89 |  | 
|---|
|  | 90 | // presumably this will actually be passed the new cartesian coords in | 
|---|
|  | 91 | // new_internal, so do almost nothing | 
|---|
|  | 92 | int | 
|---|
|  | 93 | CartMolecularCoor::to_cartesian(const Ref<Molecule>&mol, | 
|---|
|  | 94 | const RefSCVector&new_internal) | 
|---|
|  | 95 | { | 
|---|
|  | 96 | // get a reference to Molecule for convenience | 
|---|
|  | 97 | Molecule& molecule = *(mol.pointer()); | 
|---|
|  | 98 |  | 
|---|
|  | 99 | // update the geometry | 
|---|
|  | 100 | for(int i=0; i < dim_.n(); i++) { | 
|---|
|  | 101 | molecule.r(i/3,i%3) = new_internal(i); | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | return 0; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | // again, the coordinates we want to use are cartesian, so just copy | 
|---|
|  | 108 | // the cartesian coords into internal | 
|---|
|  | 109 | int | 
|---|
|  | 110 | CartMolecularCoor::to_internal(RefSCVector&internal) | 
|---|
|  | 111 | { | 
|---|
|  | 112 | // get a reference to Molecule for convenience | 
|---|
|  | 113 | Molecule& molecule = *(molecule_.pointer()); | 
|---|
|  | 114 |  | 
|---|
|  | 115 | int n = dim_.n(); | 
|---|
|  | 116 | for (int i=0; i < n; i++) { | 
|---|
|  | 117 | internal(i) = molecule.r(i/3,i%3); | 
|---|
|  | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 | return 0; | 
|---|
|  | 121 | } | 
|---|
|  | 122 |  | 
|---|
|  | 123 | int | 
|---|
|  | 124 | CartMolecularCoor::to_cartesian(RefSCVector&gradient,RefSCVector&internal) | 
|---|
|  | 125 | { | 
|---|
|  | 126 | gradient->assign(internal.pointer()); | 
|---|
|  | 127 | return 0; | 
|---|
|  | 128 | } | 
|---|
|  | 129 |  | 
|---|
|  | 130 | // converts the gradient in cartesian coordinates to internal coordinates | 
|---|
|  | 131 | int | 
|---|
|  | 132 | CartMolecularCoor::to_internal(RefSCVector&internal,RefSCVector&gradient) | 
|---|
|  | 133 | { | 
|---|
|  | 134 | internal->assign(gradient.pointer()); | 
|---|
|  | 135 | return 0; | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | int | 
|---|
|  | 139 | CartMolecularCoor::to_cartesian(RefSymmSCMatrix&cart,RefSymmSCMatrix&internal) | 
|---|
|  | 140 | { | 
|---|
|  | 141 | cart->assign(internal.pointer()); | 
|---|
|  | 142 | return 0; | 
|---|
|  | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 | int | 
|---|
|  | 146 | CartMolecularCoor::to_internal(RefSymmSCMatrix&internal,RefSymmSCMatrix&cart) | 
|---|
|  | 147 | { | 
|---|
|  | 148 | internal->assign(cart.pointer()); | 
|---|
|  | 149 | return 0; | 
|---|
|  | 150 | } | 
|---|
|  | 151 |  | 
|---|
|  | 152 | void | 
|---|
|  | 153 | CartMolecularCoor::print(ostream& os) const | 
|---|
|  | 154 | { | 
|---|
|  | 155 | molecule_->print(os); | 
|---|
|  | 156 | } | 
|---|
|  | 157 |  | 
|---|
|  | 158 | void | 
|---|
|  | 159 | CartMolecularCoor::print_simples(ostream& os) const | 
|---|
|  | 160 | { | 
|---|
|  | 161 | } | 
|---|
|  | 162 |  | 
|---|
|  | 163 | void | 
|---|
|  | 164 | CartMolecularCoor::guess_hessian(RefSymmSCMatrix&hessian) | 
|---|
|  | 165 | { | 
|---|
|  | 166 | SymmMolecularCoor imcoor(molecule_); | 
|---|
|  | 167 | RefSymmSCMatrix ihessian(imcoor.dim(),matrixkit_); | 
|---|
|  | 168 | imcoor.guess_hessian(ihessian); | 
|---|
|  | 169 | imcoor.to_cartesian(hessian,ihessian); | 
|---|
|  | 170 |  | 
|---|
|  | 171 | RefSCMatrix evecs(hessian.dim(),hessian.dim(),matrixkit_); | 
|---|
|  | 172 | RefDiagSCMatrix evals(hessian.dim(),matrixkit_); | 
|---|
|  | 173 |  | 
|---|
|  | 174 | hessian.diagonalize(evals,evecs); | 
|---|
|  | 175 | hessian.assign(0.0); | 
|---|
|  | 176 |  | 
|---|
|  | 177 | // get rid of the 3 translations and 3 rotations | 
|---|
|  | 178 | for (int i=0; i < evals.n(); i++) { | 
|---|
|  | 179 | if (fabs(evals.get_element(i)) < 1.0e-6) { | 
|---|
|  | 180 | for (int j=0; j < evals.n(); j++) | 
|---|
|  | 181 | evecs.set_element(j,i,0.0); | 
|---|
|  | 182 | evals.set_element(i,0.0); | 
|---|
|  | 183 | } | 
|---|
|  | 184 | } | 
|---|
|  | 185 |  | 
|---|
|  | 186 | hessian.accumulate_transform(evecs,evals); | 
|---|
|  | 187 | } | 
|---|
|  | 188 |  | 
|---|
|  | 189 | RefSymmSCMatrix | 
|---|
|  | 190 | CartMolecularCoor::inverse_hessian(RefSymmSCMatrix& hessian) | 
|---|
|  | 191 | { | 
|---|
|  | 192 | return hessian.gi(); | 
|---|
|  | 193 | } | 
|---|
|  | 194 |  | 
|---|
|  | 195 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 196 |  | 
|---|
|  | 197 | // Local Variables: | 
|---|
|  | 198 | // mode: c++ | 
|---|
|  | 199 | // c-file-style: "ETS" | 
|---|
|  | 200 | // End: | 
|---|