1 // SEARCH.H : conformational search classes. 2 3 // Copyright (C) 1998 Tommi Hassinen. 4 5 // This package is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 10 // This package is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 15 // You should have received a copy of the GNU General Public License 16 // along with this package; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 19 /*################################################################################################*/ 20 21 #ifndef SEARCH_H 22 #define SEARCH_H 23 24 class random_search; // DO WE NEED TO RANDOMIZE THE RANDOM NUMBER GENERATOR SOMEWAY??? 25 class systematic_search; // DO WE NEED TO RANDOMIZE THE RANDOM NUMBER GENERATOR SOMEWAY??? 26 class monte_carlo_search; // DO WE NEED TO RANDOMIZE THE RANDOM NUMBER GENERATOR SOMEWAY??? 27 28 class transition_state_search; 29 30 #define UPDATEFRQ 25 31 32 /*################################################################################################*/ 33 34 #include "engine.h" 35 #include "eng1_qm.h" 36 #include "conjgrad.h" 37 #include "geomopt.h" 38 #include "intcrd.h" 39 40 /*################################################################################################*/ 41 42 /// A random conformational search (intcrd based). 43 44 class random_search 45 { 46 protected: 47 48 model * mdl; i32s molnum; 49 i32s in_crdset; i32s out_crdset; 50 51 i32s cycles; 52 i32s optsteps; 53 54 intcrd * ic; 55 56 engine * eng; 57 geomopt * go; 58 59 i32s counter1; 60 i32s counter2; 61 62 f64 min_energy; 63 64 public: 65 66 random_search(model *, i32s, i32s, i32s, i32s, i32s); 67 ~random_search(void); 68 GetMinEnergy(void)69 f64 GetMinEnergy(void) { return min_energy; } 70 71 // the search is split in small steps to make it "look nice" in graphic environment. 72 // you should just keep callig TakeStep() until it returns a negative value... 73 74 i32s TakeStep(void); 75 76 public: 77 78 int last_step; 79 float last_E; 80 }; 81 82 /*################################################################################################*/ 83 84 /// A systematic conformational search (intcrd based). 85 86 class systematic_search 87 { 88 protected: 89 90 model * mdl; i32s molnum; 91 i32s in_crdset; i32s out_crdset; 92 93 i32s divisions; 94 i32s optsteps; 95 96 intcrd * ic; 97 98 engine * eng; 99 geomopt * go; 100 101 i32s nvar; 102 i32s * counter1; 103 i32s counter2; 104 105 f64 min_energy; 106 107 public: 108 109 systematic_search(model *, i32s, i32s, i32s, i32s, i32s); 110 ~systematic_search(void); 111 GetMinEnergy(void)112 f64 GetMinEnergy(void) { return min_energy; } 113 114 // the search is split in small steps to make it "look nice" in graphic environment. 115 // you should just keep callig TakeStep() until it returns a negative value... 116 117 i32s TakeStep(void); 118 }; 119 120 /*################################################################################################*/ 121 122 /** A monte carlo search (intcrd based). both for conformational search and for collecting 123 a set of probable states for a molecule. 124 */ 125 126 class monte_carlo_search 127 { 128 protected: 129 130 model * mdl; i32s molnum; 131 i32s in_crdset; i32s out_crdset; 132 133 i32s n_init_steps; 134 i32s n_simul_steps; 135 i32s optsteps; 136 137 intcrd * ic; 138 139 engine * eng; 140 geomopt * go; 141 142 i32s counter1; 143 i32s counter2; 144 145 i32s nvar; 146 f64 * curr_ic1; 147 f64 * curr_ic2; 148 f64 curr_energy; 149 150 f64 min_energy; 151 152 public: 153 154 monte_carlo_search(model *, i32s, i32s, i32s, i32s, i32s, i32s); 155 ~monte_carlo_search(void); 156 GetMinEnergy(void)157 f64 GetMinEnergy(void) { return min_energy; } 158 159 // the search is split in small steps to make it "look nice" in graphic environment. 160 // you should just keep callig TakeStep() until it returns a negative value... 161 162 i32s TakeStep(void); 163 }; 164 165 /*################################################################################################*/ 166 /*################################################################################################*/ 167 /*################################################################################################*/ 168 169 /** A transition state search for QM methods. 170 This is NOT a "gradient extremal" method, but works roughly the same way. 171 Simple energy constraints are added to drive the reactants/products towards each other. 172 */ 173 174 class transition_state_search 175 { 176 protected: 177 178 model * mdl; 179 180 setup1_qm * suQM; 181 eng1_qm * engQM; 182 183 bool init_failed; 184 185 f64 deltae; 186 f64 * target[2]; 187 188 f64 energy1[2]; // energy with constraints 189 f64 energy2[2]; // energy without constraints 190 191 f64 fc[2]; 192 193 f64 t_ene[2]; 194 f64 last_de[2]; 195 196 f64 p[2]; // progress ; actually a "reaction coordinate" for sorting the structures. 197 bool ready[2]; 198 199 public: 200 201 vector<i32u> patoms; // this is for calculating the final reaction coordinates. 202 vector<bond *> rbonds; // this is for graphics only... 203 vector<bond *> pbonds; // this is for graphics only... 204 205 public: 206 207 transition_state_search(model *, f64, f64); 208 ~transition_state_search(void); 209 InitFailed(void)210 bool InitFailed(void) { return init_failed; } 211 212 void Run(i32s *); 213 void UpdateTargets(bool *); 214 GetE(i32s p1)215 f64 GetE(i32s p1) { return energy2[p1]; } GetP(i32s p1)216 f64 GetP(i32s p1) { return p[p1]; } 217 GetR(i32s p1)218 bool GetR(i32s p1) { return ready[p1]; } 219 220 protected: 221 222 void SetTarget(i32s, i32s); 223 }; 224 225 /*################################################################################################*/ 226 227 /** This class finds stationary states by minimizing forces in a structure. 228 Used as a final stage in the transition state search. 229 */ 230 231 class stationary_state_search : public conjugate_gradient 232 { 233 protected: 234 235 engine * eng; 236 237 f64 * my_d1; 238 239 public: 240 241 stationary_state_search(engine *, i32s, f64, f64); 242 ~stationary_state_search(void); 243 244 f64 GetValue(void); // virtual 245 246 // no GetGradient() function defined here; just use the default numerical one... 247 // no GetGradient() function defined here; just use the default numerical one... 248 // no GetGradient() function defined here; just use the default numerical one... 249 }; 250 251 /*################################################################################################*/ 252 253 #endif // SEARCH_H 254 255 // eof 256