Changeset c30cda
- Timestamp:
- Sep 11, 2008, 1:28:25 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:
- 795a54
- Parents:
- 85bac0
- git-author:
- Frederik Heber <heber@…> (09/09/08 16:42:29)
- git-committer:
- Frederik Heber <heber@…> (09/11/08 13:28:25)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecules.cpp
r85bac0 rc30cda 1156 1156 { 1157 1157 stringstream zeile1, zeile2; 1158 int *DoubleList = (int *) Malloc(Nr*sizeof(int), "PrintPermutationMap: *DoubleList"); 1159 int doubles = 0; 1160 for (int i=0;i<Nr;i++) 1161 DoubleList[i] = 0; 1158 1162 zeile1 << "PermutationMap: "; 1159 1163 zeile2 << " "; 1160 1164 for (int i=0;i<Nr;i++) { 1165 DoubleList[PermutationMap[i]->nr]++; 1161 1166 zeile1 << i << " "; 1162 1167 zeile2 << PermutationMap[i]->nr << " "; 1163 1168 } 1169 for (int i=0;i<Nr;i++) 1170 if (DoubleList[i] > 1) 1171 doubles++; 1172 // *out << "Found " << doubles << " Doubles." << endl; 1173 Free((void **)&DoubleList, "PrintPermutationMap: *DoubleList"); 1164 1174 // *out << zeile1.str() << endl << zeile2.str() << endl; 1165 1175 }; … … 1194 1204 double molecule::MinimiseConstrainedPotential(ofstream *out, atom **&PermutationMap, int startstep, int endstep, bool IsAngstroem) 1195 1205 { 1196 double Potential, OldPotential ;1206 double Potential, OldPotential, OlderPotential; 1197 1207 PermutationMap = (atom **) Malloc(AtomCount*sizeof(atom *), "molecule::MinimiseConstrainedPotential: **PermutationMap"); 1198 1208 DistanceMap **DistanceList = (DistanceMap **) Malloc(AtomCount*sizeof(DistanceMap *), "molecule::MinimiseConstrainedPotential: **DistanceList"); 1199 1209 DistanceMap::iterator *DistanceIterators = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *DistanceIterators"); 1200 1210 int *DoubleList = (int *) Malloc(AtomCount*sizeof(int), "molecule::MinimiseConstrainedPotential: *DoubleList"); 1211 DistanceMap::iterator *StepList = (DistanceMap::iterator *) Malloc(AtomCount*sizeof(DistanceMap::iterator), "molecule::MinimiseConstrainedPotential: *StepList"); 1201 1212 double constants[3]; 1213 int round; 1202 1214 atom *Walker = NULL, *Runner = NULL, *Sprinter = NULL; 1203 DistanceMap::iterator Rider ;1215 DistanceMap::iterator Rider, Strider; 1204 1216 1205 1217 /// Minimise the potential … … 1211 1223 *out << Verbose(1) << "Creating the distance list ... " << endl; 1212 1224 for (int i=AtomCount; i--;) { 1213 DoubleList[i] = 0; // store 's for how many atoms in startstep this atom is a target in endstep1225 DoubleList[i] = 0; // stores for how many atoms in startstep this atom is a target in endstep 1214 1226 DistanceList[i] = new DistanceMap; // is the distance sorted target list per atom 1215 1227 DistanceList[i]->clear(); … … 1229 1241 while (Walker->next != end) { 1230 1242 Walker = Walker->next; 1243 StepList[Walker->nr] = DistanceList[Walker->nr]->begin(); // stores the step to the next iterator that could be a possible next target 1231 1244 PermutationMap[Walker->nr] = DistanceList[Walker->nr]->begin()->second; // always pick target with the smallest distance 1232 1245 DoubleList[DistanceList[Walker->nr]->begin()->second->nr]++; // increase this target's source count (>1? not injective) … … 1253 1266 } while ((DoubleList[NewBase->second->nr] != 0) && (NewBase != DistanceList[Walker->nr]->end())); 1254 1267 if (NewBase != DistanceList[Walker->nr]->end()) { 1255 DoubleList[DistanceIterators[Walker->nr]->second->nr]--; // decrease the old entry in the doubles list1256 DoubleList[NewBase->second->nr]++; // increase the old entry in the doubles list1257 1268 PermutationMap[Walker->nr] = NewBase->second; 1258 1269 Potential = fabs(ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem)); 1259 1270 if (Potential > OldPotential) { // undo 1260 DoubleList[NewBase->second->nr]--; 1271 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second; 1272 } else { // do 1273 DoubleList[DistanceIterators[Walker->nr]->second->nr]--; // decrease the old entry in the doubles list 1274 DoubleList[NewBase->second->nr]++; // increase the old entry in the doubles list 1261 1275 DistanceIterators[Walker->nr] = NewBase; 1262 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second;1263 DoubleList[DistanceIterators[Walker->nr]->second->nr]++;1264 } else {1265 1276 OldPotential = Potential; 1266 1277 *out << Verbose(3) << "Found a new permutation, new potential is " << OldPotential << "." << endl; … … 1277 1288 // argument minimise the constrained potential in this injective PermutationMap 1278 1289 *out << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl; 1290 OldPotential = 1e+10; 1291 round = 0; 1279 1292 do { 1280 Walker = start; 1281 while (Walker->next != end) { // pick one 1282 Walker = Walker->next; 1283 PrintPermutationMap(out, PermutationMap, AtomCount); 1284 Sprinter = DistanceIterators[Walker->nr]->second; // store initial partner 1285 DistanceIterators[Walker->nr]++; // take next farther distance target 1286 if (DistanceIterators[Walker->nr] == DistanceList[Walker->nr]->end()) // stop, before we run through the list and still on 1287 break; 1288 *out << Verbose(2) << "Current Walker: " << *Walker << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[Walker->nr]->second << "." << endl; 1289 Runner = start->next; 1290 while(Runner != end) { // find the other one whose toes we might be stepping on (this target should be used by another already) 1291 if (PermutationMap[Runner->nr] == DistanceIterators[Walker->nr]->second) { 1292 *out << Verbose(2) << "Found the corresponding owner " << *Runner << " to " << *DistanceIterators[Walker->nr]->second << "." << endl; 1293 *out << "Starting round " << ++round << " ... " << endl; 1294 OlderPotential = OldPotential; 1295 do { 1296 Walker = start; 1297 while (Walker->next != end) { // pick one 1298 Walker = Walker->next; 1299 PrintPermutationMap(out, PermutationMap, AtomCount); 1300 Sprinter = DistanceIterators[Walker->nr]->second; // store initial partner 1301 Strider = DistanceIterators[Walker->nr]; //remember old iterator 1302 DistanceIterators[Walker->nr] = StepList[Walker->nr]; 1303 if (DistanceIterators[Walker->nr] == DistanceList[Walker->nr]->end()) {// stop, before we run through the list and still on 1293 1304 break; 1294 1305 } 1295 Runner = Runner->next; 1296 } 1297 if (Runner != end) { // we found one a tripel 1298 // then look in distance list for Sprinter 1299 Rider = DistanceList[Runner->nr]->begin(); 1300 for (; Rider != DistanceList[Runner->nr]->end(); Rider++) 1301 if (Rider->second == Sprinter) 1302 break; 1303 if (Rider != DistanceList[Runner->nr]->end()) { // if we have found one 1304 *out << Verbose(2) << "Current Other: " << *Runner << " with old/next candidate " << *PermutationMap[Runner->nr] << "/" << *Rider->second << "." << endl; 1305 // exchange the second also 1306 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second; // put next farther distance into PermutationMap 1307 PermutationMap[Runner->nr] = Sprinter; // and hand the old target to its respective owner 1308 // calculate the new potential 1309 PrintPermutationMap(out, PermutationMap, AtomCount); 1310 *out << Verbose(2) << "Checking new potential ..." << endl; 1311 Potential = ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem); 1312 if (Potential > OldPotential) { // we made everything worse! Undo ... 1313 *out << Verbose(3) << "Nay, made the potential worse: " << Potential << " vs. " << OldPotential << "!" << endl; 1314 // Undo for Walker 1315 DistanceIterators[Walker->nr]--; // take next farther distance target 1316 PermutationMap[Walker->nr] = Sprinter; 1317 // Undo for Runner (note, we haven't moved the iteration yet, we may use this) 1318 PermutationMap[Runner->nr] = DistanceIterators[Runner->nr]->second; 1319 Potential = OldPotential; 1320 } else { 1321 DistanceIterators[Runner->nr] = Rider; // if successful also move the pointer in the iterator list 1322 *out << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl; 1323 OldPotential = Potential; 1306 //*out << Verbose(2) << "Current Walker: " << *Walker << " with old/next candidate " << *Sprinter << "/" << *DistanceIterators[Walker->nr]->second << "." << endl; 1307 // find source of the new target 1308 Runner = start->next; 1309 while(Runner != end) { // find the source whose toes we might be stepping on (Walker's new target should be in use by another already) 1310 if (PermutationMap[Runner->nr] == DistanceIterators[Walker->nr]->second) { 1311 //*out << Verbose(2) << "Found the corresponding owner " << *Runner << " to " << *PermutationMap[Runner->nr] << "." << endl; 1324 1312 break; 1325 1313 } 1326 if (Potential > constants[2]) { 1327 cerr << "ERROR: The two-step permutation procedure did not maintain injectivity!" << endl; 1314 Runner = Runner->next; 1315 } 1316 if (Runner != end) { // we found the other source 1317 // then look in its distance list for Sprinter 1318 Rider = DistanceList[Runner->nr]->begin(); 1319 for (; Rider != DistanceList[Runner->nr]->end(); Rider++) 1320 if (Rider->second == Sprinter) 1321 break; 1322 if (Rider != DistanceList[Runner->nr]->end()) { // if we have found one 1323 //*out << Verbose(2) << "Current Other: " << *Runner << " with old/next candidate " << *PermutationMap[Runner->nr] << "/" << *Rider->second << "." << endl; 1324 // exchange both 1325 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second; // put next farther distance into PermutationMap 1326 PermutationMap[Runner->nr] = Sprinter; // and hand the old target to its respective owner 1327 PrintPermutationMap(out, PermutationMap, AtomCount); 1328 // calculate the new potential 1329 //*out << Verbose(2) << "Checking new potential ..." << endl; 1330 Potential = ConstrainedPotential(out, PermutationMap, startstep, endstep, constants, IsAngstroem); 1331 if (Potential > OldPotential) { // we made everything worse! Undo ... 1332 //*out << Verbose(3) << "Nay, made the potential worse: " << Potential << " vs. " << OldPotential << "!" << endl; 1333 //*out << Verbose(3) << "Setting " << *Runner << "'s source to " << *DistanceIterators[Runner->nr]->second << "." << endl; 1334 // Undo for Runner (note, we haven't moved the iteration yet, we may use this) 1335 PermutationMap[Runner->nr] = DistanceIterators[Runner->nr]->second; 1336 // Undo for Walker 1337 DistanceIterators[Walker->nr] = Strider; // take next farther distance target 1338 //*out << Verbose(3) << "Setting " << *Walker << "'s source to " << *DistanceIterators[Walker->nr]->second << "." << endl; 1339 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second; 1340 } else { 1341 DistanceIterators[Runner->nr] = Rider; // if successful also move the pointer in the iterator list 1342 *out << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl; 1343 OldPotential = Potential; 1344 } 1345 if (Potential > constants[2]) { 1346 cerr << "ERROR: The two-step permutation procedure did not maintain injectivity!" << endl; 1347 exit(255); 1348 } 1349 //*out << endl; 1350 } else { 1351 cerr << "ERROR: " << *Runner << " was not the owner of " << *Sprinter << "!" << endl; 1328 1352 exit(255); 1329 1353 } 1330 *out << endl; 1354 } else { 1355 PermutationMap[Walker->nr] = DistanceIterators[Walker->nr]->second; // new target has no source! 1331 1356 } 1332 } else { 1333 DistanceIterators[Walker->nr]--; // take old distance target 1334 } 1335 } 1336 } while (Walker->next != end); 1357 StepList[Walker->nr]++; // take next farther distance target 1358 } 1359 } while (Walker->next != end); 1360 } while ((OlderPotential - OldPotential) > 1e-3); 1337 1361 *out << Verbose(1) << "done." << endl; 1338 1362
Note:
See TracChangeset
for help on using the changeset viewer.