Ignore:
Timestamp:
Oct 25, 2011, 12:08:03 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

New class AdaptivityMap and moved some functions from fragmentation_helpers into it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/fragmentation_helpers.cpp

    r75363b r730d7a  
    2929#include "Bond/bond.hpp"
    3030#include "Element/element.hpp"
     31#include "Fragmentation/AdaptivityMap.hpp"
    3132#include "Fragmentation/Graph.hpp"
    3233#include "Fragmentation/KeySet.hpp"
     
    3738using namespace std;
    3839
    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 first
    41  * \param *out output stream for debugging
    42  * \param &AdaptiveCriteriaList list to insert into
    43  * \param &IndexedKeySetList list to find key set for a given index \a No
    44  * \param FragOrder current bond order of fragment
    45  * \param No index of keyset
    46  * \param value energy value
    47  */
    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 found
    52     Value *= 1 + MYEPSILON*(*((*marker).second.begin()));     // in case of equal energies this makes them not equal without changing anything actually
    53     // 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 AtomMask
    54     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 present
    57       if ((*PresentItem).second.second < FragOrder)  // if order there is lower, update entry with higher-order term
    58         //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 order
    60         (*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 ref
    84   // count the number of lines, i.e. the number of fragments
    85   InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
    86   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 };
    9540
    9641
    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 No
    100  * \return adaptive criteria list from file
    101  */
    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 contribution
    118     InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
    119     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 entry
    128         line >> ws >> Value;
    129         No -= 1;  // indices start at 1 in file, not 0
    130         //Log() << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;
    131 
    132         // clean the list of those entries that have been superceded by higher order terms already
    133         InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, IndexKeySetList, FragOrder, No, Value);
    134       }
    135     }
    136     // close and done
    137     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 debugging
    147  * \param &AdaptiveCriteriaList list to insert into
    148  * \param *mol molecule with atoms
    149  * \return remapped list
    150  */
    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 order
    160       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 };
    17342
    17443/** Marks all candidate sites for update if below adaptive threshold.
Note: See TracChangeset for help on using the changeset viewer.