Changeset 730d7a for src/Fragmentation/fragmentation_helpers.cpp
- Timestamp:
- Oct 25, 2011, 12:08:03 PM (13 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:
- 851be8
- Parents:
- 75363b
- git-author:
- Frederik Heber <heber@…> (10/20/11 10:34:17)
- git-committer:
- Frederik Heber <heber@…> (10/25/11 12:08:03)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/fragmentation_helpers.cpp
r75363b r730d7a 29 29 #include "Bond/bond.hpp" 30 30 #include "Element/element.hpp" 31 #include "Fragmentation/AdaptivityMap.hpp" 31 32 #include "Fragmentation/Graph.hpp" 32 33 #include "Fragmentation/KeySet.hpp" … … 37 38 using namespace std; 38 39 39 /** Inserts a (\a No, \a value) pair into the list, overwriting present one.40 * Note if values are equal, No will decided on which is first41 * \param *out output stream for debugging42 * \param &AdaptiveCriteriaList list to insert into43 * \param &IndexedKeySetList list to find key set for a given index \a No44 * \param FragOrder current bond order of fragment45 * \param No index of keyset46 * \param value energy value47 */48 void InsertIntoAdaptiveCriteriaList(std::map<int, pair<double,int> > *AdaptiveCriteriaList, std::map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value)49 {50 map<int,KeySet>::iterator marker = IndexKeySetList.find(No); // find keyset to Frag No.51 if (marker != IndexKeySetList.end()) { // if found52 Value *= 1 + MYEPSILON*(*((*marker).second.begin())); // in case of equal energies this makes them not equal without changing anything actually53 // as the smallest number in each set has always been the root (we use global id to keep the doubles away), seek smallest and insert into AtomMask54 pair <map<int, pair<double,int> >::iterator, bool> InsertedElement = AdaptiveCriteriaList->insert( make_pair(*((*marker).second.begin()), pair<double,int>( fabs(Value), FragOrder) ));55 map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first;56 if (!InsertedElement.second) { // this root is already present57 if ((*PresentItem).second.second < FragOrder) // if order there is lower, update entry with higher-order term58 //if ((*PresentItem).second.first < (*runner).first) // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase)59 { // if value is smaller, update value and order60 (*PresentItem).second.first = fabs(Value);61 (*PresentItem).second.second = FragOrder;62 DoLog(2) && (Log() << Verbose(2) << "Updated element (" << (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);63 } else {64 DoLog(2) && (Log() << Verbose(2) << "Did not update element " << (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl);65 }66 } else {67 DoLog(2) && (Log() << Verbose(2) << "Inserted element (" << (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);68 }69 } else {70 DoLog(1) && (Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl);71 }72 };73 74 /** Counts lines in file.75 * Note we are scanning lines from current position, not from beginning.76 * \param InputFile file to be scanned.77 */78 int CountLinesinFile(std::ifstream &InputFile)79 {80 char *buffer = new char[MAXSTRINGSIZE];81 int lines=0;82 83 int PositionMarker = InputFile.tellg(); // not needed as Inputfile is copied, given by value, not by ref84 // count the number of lines, i.e. the number of fragments85 InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines86 InputFile.getline(buffer, MAXSTRINGSIZE);87 while(!InputFile.eof()) {88 InputFile.getline(buffer, MAXSTRINGSIZE);89 lines++;90 }91 InputFile.seekg(PositionMarker, ios::beg);92 delete[](buffer);93 return lines;94 };95 40 96 41 97 /** Scans the adaptive order file and insert (index, value) into map.98 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)99 * \param &IndexedKeySetList list to find key set for a given index \a No100 * \return adaptive criteria list from file101 */102 std::map<int, std::pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, std::map<int,KeySet> &IndexKeySetList)103 {104 map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >;105 int No = 0, FragOrder = 0;106 double Value = 0.;107 char buffer[MAXSTRINGSIZE];108 string filename = path + ENERGYPERFRAGMENT;109 ifstream InputFile(filename.c_str());110 111 if (InputFile.fail()) {112 DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);113 return AdaptiveCriteriaList;114 }115 116 if (CountLinesinFile(InputFile) > 0) {117 // each line represents a fragment root (Atom::Nr) id and its energy contribution118 InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines119 InputFile.getline(buffer, MAXSTRINGSIZE);120 while(!InputFile.eof()) {121 InputFile.getline(buffer, MAXSTRINGSIZE);122 if (strlen(buffer) > 2) {123 //Log() << Verbose(2) << "Scanning: " << buffer << endl;124 stringstream line(buffer);125 line >> FragOrder;126 line >> ws >> No;127 line >> ws >> Value; // skip time entry128 line >> ws >> Value;129 No -= 1; // indices start at 1 in file, not 0130 //Log() << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;131 132 // clean the list of those entries that have been superceded by higher order terms already133 InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, IndexKeySetList, FragOrder, No, Value);134 }135 }136 // close and done137 InputFile.close();138 InputFile.clear();139 }140 141 return AdaptiveCriteriaList;142 };143 144 /** Maps adaptive criteria list back onto (Value, (Root Nr., Order))145 * (i.e. sorted by value to pick the highest ones)146 * \param *out output stream for debugging147 * \param &AdaptiveCriteriaList list to insert into148 * \param *mol molecule with atoms149 * \return remapped list150 */151 std::map<double, std::pair<int,int> > * ReMapAdaptiveCriteriaListToValue(std::map<int, std::pair<double,int> > *AdaptiveCriteriaList, molecule *mol)152 {153 atom *Walker = NULL;154 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;155 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);156 for(map<int, pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {157 Walker = mol->FindAtom((*runner).first);158 if (Walker != NULL) {159 //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order160 if (!Walker->MaxOrder) {161 DoLog(2) && (Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl);162 FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );163 } else {164 DoLog(2) && (Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl);165 }166 } else {167 DoeLog(0) && (eLog()<< Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl);168 performCriticalExit();169 }170 }171 return FinalRootCandidates;172 };173 42 174 43 /** Marks all candidate sites for update if below adaptive threshold.
Note:
See TracChangeset
for help on using the changeset viewer.