Changeset 390248 for src/moleculelist.cpp
- Timestamp:
- Jul 24, 2008, 2:00:19 PM (16 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 958457
- Parents:
- c685eb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/moleculelist.cpp
rc685eb r390248 133 133 }; 134 134 135 /** Calculates necessary hydrogen correction due to unwanted interaction between saturated ones. 136 * If for a pair of two hydrogen atoms a and b, at least is a saturated one, and a and b are not 137 * bonded to the same atom, then we add for this pair a correction term constructed from a Morse 138 * potential function fit to QM calculations with respecting to the interatomic hydrogen distance. 139 * \param *out output stream for debugging 140 * \param *path path to file 141 */ 142 bool MoleculeListClass::AddHydrogenCorrection(ofstream *out, char *path) 143 { 144 atom *Walker = NULL; 145 atom *Runner = NULL; 146 double ***FitConstant = NULL, **correction = NULL; 147 int a,b; 148 ofstream output; 149 ifstream input; 150 string line; 151 stringstream zeile; 152 double distance; 153 char ParsedLine[1023]; 154 double tmp; 155 char *FragmentNumber = NULL; 156 157 cout << Verbose(1) << "Saving hydrogen saturation correction ... "; 158 // 0. parse in fit constant files that should have the same dimension as the final energy files 159 // 0a. find dimension of matrices with constants 160 line = path; 161 line.append("/"); 162 line += FRAGMENTPREFIX; 163 line += "1"; 164 line += FITCONSTANTSUFFIX; 165 input.open(line.c_str()); 166 if (input == NULL) { 167 cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl; 168 return false; 169 } 170 a=0; 171 b=-1; // we overcount by one 172 while (!input.eof()) { 173 input.getline(ParsedLine, 1023); 174 zeile.str(ParsedLine); 175 int i=0; 176 while (!zeile.eof()) { 177 zeile >> distance; 178 i++; 179 } 180 if (i > a) 181 a = i; 182 b++; 183 } 184 cout << "I recognized " << a << " columns and " << b << " rows, "; 185 input.close(); 186 187 // 0b. allocate memory for constants 188 FitConstant = (double ***) Malloc(sizeof(double **)*3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 189 for (int k=0;k<3;k++) { 190 FitConstant[k] = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 191 for (int i=a;i--;) { 192 FitConstant[k][i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 193 } 194 } 195 // 0c. parse in constants 196 for (int i=0;i<3;i++) { 197 line = path; 198 line.append("/"); 199 line += FRAGMENTPREFIX; 200 sprintf(ParsedLine, "%d", i+1); 201 line += ParsedLine; 202 line += FITCONSTANTSUFFIX; 203 input.open(line.c_str()); 204 if (input == NULL) { 205 cerr << endl << "Unable to open " << line << ", is the directory correct?" << endl; 206 return false; 207 } 208 int k = 0,l; 209 while ((!input.eof()) && (k < b)) { 210 input.getline(ParsedLine, 1023); 211 //cout << "Current Line: " << ParsedLine << endl; 212 zeile.str(ParsedLine); 213 zeile.clear(); 214 l = 0; 215 while ((!zeile.eof()) && (l < a)) { 216 zeile >> FitConstant[i][l][k]; 217 //cout << FitConstant[i][l][k] << "\t"; 218 l++; 219 } 220 //cout << endl; 221 k++; 222 } 223 input.close(); 224 } 225 for(int k=0;k<3;k++) { 226 cout << "Constants " << k << ":" << endl; 227 for (int j=0;j<b;j++) { 228 for (int i=0;i<a;i++) { 229 cout << FitConstant[k][i][j] << "\t"; 230 } 231 cout << endl; 232 } 233 cout << endl; 234 } 235 236 // 0d. allocate final correction matrix 237 correction = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **correction"); 238 for (int i=a;i--;) 239 correction[i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *correction[]"); 240 241 // 1a. go through every molecule in the list 242 for(int i=NumberOfMolecules;i--;) { 243 // 1b. zero final correction matrix 244 for (int k=a;k--;) 245 for (int j=b;j--;) 246 correction[k][j] = 0.; 247 // 2. take every hydrogen that is a saturated one 248 Walker = ListOfMolecules[i]->start; 249 while (Walker->next != ListOfMolecules[i]->end) { 250 Walker = Walker->next; 251 //cout << Verbose(1) << "Walker: " << *Walker << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0] << "." << endl; 252 if ((Walker->type->Z == 1) && ((Walker->father == NULL) || (Walker->father->type->Z != 1))) { // if it's a hydrogen 253 Runner = ListOfMolecules[i]->start; 254 while (Runner->next != ListOfMolecules[i]->end) { 255 Runner = Runner->next; 256 //cout << Verbose(2) << "Runner: " << *Runner << " with first bond " << *ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0] << "." << endl; 257 // 3. take every other hydrogen that is the not the first and not bound to same bonding partner 258 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (ListOfMolecules[i]->ListOfBondsPerAtom[Runner->nr][0]->GetOtherAtom(Runner) != ListOfMolecules[i]->ListOfBondsPerAtom[Walker->nr][0]->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!) 259 // 4. evaluate the morse potential for each matrix component and add up 260 distance = sqrt(Runner->x.Distance(&Walker->x)); 261 //cout << "Fragment " << i << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl; 262 for(int k=0;k<a;k++) { 263 for (int j=0;j<b;j++) { 264 switch(k) { 265 case 1: 266 case 7: 267 case 11: 268 tmp = pow(FitConstant[0][k][j] * ( 1. - exp(-FitConstant[1][k][j] * (distance - FitConstant[2][k][j]) ) ),2); 269 break; 270 default: 271 tmp = FitConstant[0][k][j] * pow( distance, FitConstant[1][k][j]) + FitConstant[2][k][j]; 272 }; 273 correction[k][j] -= tmp; // ground state is actually lower (disturbed by additional interaction) 274 //cout << tmp << "\t"; 275 } 276 //cout << endl; 277 } 278 //cout << endl; 279 } 280 } 281 } 282 } 283 // 5. write final matrix to file 284 line = path; 285 line.append("/"); 286 line += FRAGMENTPREFIX; 287 FragmentNumber = FixedDigitNumber(NumberOfMolecules, i); 288 line += FragmentNumber; 289 delete(FragmentNumber); 290 line += HCORRECTIONSUFFIX; 291 output.open(line.c_str()); 292 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 293 for (int j=0;j<b;j++) { 294 for(int i=0;i<a;i++) 295 output << correction[i][j] << "\t"; 296 output << endl; 297 } 298 output.close(); 299 } 300 line = path; 301 line.append("/"); 302 line += HCORRECTIONSUFFIX; 303 output.open(line.c_str()); 304 output << "Time\t\tTotal\t\tKinetic\t\tNonLocal\tCorrelation\tExchange\tPseudo\t\tHartree\t\t-Gauss\t\tEwald\t\tIonKin\t\tETotal" << endl; 305 for (int j=0;j<b;j++) { 306 for(int i=0;i<a;i++) 307 output << 0 << "\t"; 308 output << endl; 309 } 310 output.close(); 311 // 6. free memory of parsed matrices 312 FitConstant = (double ***) Malloc(sizeof(double **)*a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant"); 313 for (int k=0;k<3;k++) { 314 FitConstant[k] = (double **) Malloc(sizeof(double *)*a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]"); 315 for (int i=a;i--;) { 316 FitConstant[k][i] = (double *) Malloc(sizeof(double)*b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]"); 317 } 318 } 319 cout << "done." << endl; 320 return true; 321 }; 135 322 136 323 /** Store force indices, i.e. the connection between the nuclear index in the total molecule config and the respective atom in fragment config. … … 224 411 outputFragment.open(FragmentName, ios::out); 225 412 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as XYZ ..."; 226 if ( intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment))413 if ((intermediateResult = ListOfMolecules[i]->OutputXYZ(&outputFragment))) 227 414 *out << " done." << endl; 228 415 else … … 263 450 configuration->SetDefaultPath(FragmentName); 264 451 *out << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter-1 << " as config ..."; 265 if ( intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i]))452 if ((intermediateResult = configuration->Save(&outputFragment, ListOfMolecules[i]->elemente, ListOfMolecules[i]))) 266 453 *out << " done." << endl; 267 454 else
Note:
See TracChangeset
for help on using the changeset viewer.