Changeset 06f41f3 for src/Graph/CheckAgainstAdjacencyFile.cpp
- Timestamp:
- Dec 3, 2012, 9:49:30 AM (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, Candidate_v1.7.0, Candidate_v1.7.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:
- 9511c7
- Parents:
- b78dfd
- git-author:
- Frederik Heber <heber@…> (09/19/12 13:55:43)
- git-committer:
- Frederik Heber <heber@…> (12/03/12 09:49:30)
- File:
-
- 1 edited
-
src/Graph/CheckAgainstAdjacencyFile.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/CheckAgainstAdjacencyFile.cpp
rb78dfd r06f41f3 56 56 */ 57 57 CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile(std::istream &File) : 58 status(true),59 58 NonMatchNumber(0) 60 59 { 61 ParseInExternalMap(File); 60 bool status = ParseInInternalMap(File); 61 if (!status) // remove map if failed to parse 62 InternalAtomBondMap.clear(); 62 63 } 63 64 64 65 CheckAgainstAdjacencyFile::~CheckAgainstAdjacencyFile() 65 { 66 ExternalAtomBondMap.clear(); 67 InternalAtomBondMap.clear(); 68 } 66 {} 69 67 70 68 /** Parses the bond partners of each atom from an external file into \a AtomBondMap. … … 73 71 * @return true - everything ok, false - error while parsing 74 72 */ 75 bool CheckAgainstAdjacencyFile::ParseIn ExternalMap(std::istream &File)73 bool CheckAgainstAdjacencyFile::ParseInInternalMap(std::istream &File) 76 74 { 77 75 if (File.fail()) { … … 80 78 } 81 79 82 ExternalAtomBondMap.clear();80 InternalAtomBondMap.clear(); 83 81 char buffer[MAXSTRINGSIZE]; 84 82 int tmp; … … 93 91 if (AtomNr > 0) { 94 92 const atom *Walker = World::getInstance().getAtom(AtomById(AtomNr-1)); 95 ASSERT(Walker != NULL,96 "CheckAgainstAdjacencyFile::ParseInExternalMap() - there is no atom with id "+toString(AtomNr-1)+".");97 93 if (Walker == NULL) 98 94 return false; 95 const atomId_t WalkerId = Walker->getId(); 99 96 // parse bond partner ids associated to AtomNr 100 97 while (line >> ws >> tmp) { 101 LOG(3, "INFO: Recognized bond partner " << tmp-1 );102 ExternalAtomBondMap.insert( std::make_pair(Walker->getId(), tmp-1) );98 LOG(3, "INFO: Recognized bond partner " << tmp-1 << " for " << WalkerId << "."); 99 InternalAtomBondMap.insert( std::make_pair(WalkerId, tmp-1) ); 103 100 } 104 101 } else { … … 114 111 /** Fills the InternalAtomBondMap from the atoms given by the two iterators. 115 112 * 116 * @param AtomMapBegin iterator pointing to begin of map (think of World's SelectionIterator) 117 * @param AtomMapEnd iterator pointing past end of map (think of World's SelectionIterator) 118 */ 119 void CheckAgainstAdjacencyFile::CreateInternalMap(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd) 120 { 121 InternalAtomBondMap.clear(); 113 * @param atomids set of atomic ids to check (must be global ids, i.e. from atom::getId()) 114 */ 115 void CheckAgainstAdjacencyFile::CreateExternalMap(const atomids_t &atomids) 116 { 117 ExternalAtomBondMap.clear(); 122 118 // go through each atom in the list 123 for (World::AtomSet::const_iterator iter = AtomMapBegin; iter != AtomMapEnd; ++iter) { 124 const atom *Walker = iter->second; 125 const atomId_t WalkerId = Walker->getId(); 119 for (atomids_t::const_iterator iter = atomids.begin(); iter != atomids.end(); ++iter) { 120 const atomId_t WalkerId = *iter; 126 121 ASSERT(WalkerId != (size_t)-1, 127 "CheckAgainstAdjacencyFile::CreateInternalMap() - Walker has no id."); 122 "CheckAgainstAdjacencyFile::CreateExternalMap() - Walker has no id."); 123 const atom *Walker = World::getInstance().getAtom(AtomById(WalkerId)); 124 ASSERT( Walker != NULL, 125 "CheckAgainstAdjacencyFile::CreateExternalMap() - Walker id "+toString(*iter) 126 +" is not associated to any of World's atoms."); 128 127 const BondList& ListOfBonds = Walker->getListOfBonds(); 129 128 // go through each of its bonds … … 133 132 const atomId_t id = (*Runner)->GetOtherAtom(Walker)->getId(); 134 133 ASSERT(id != (size_t)-1, 135 "CheckAgainstAdjacencyFile::Create InternalMap() - OtherAtom has not id.");136 InternalAtomBondMap.insert( std::make_pair(WalkerId, id) );134 "CheckAgainstAdjacencyFile::CreateExternalMap() - OtherAtom has not id."); 135 ExternalAtomBondMap.insert( std::make_pair(WalkerId, id) ); 137 136 } 138 137 } … … 142 141 * \return true - structure is equal, false - not equivalence 143 142 */ 144 bool CheckAgainstAdjacencyFile::operator()(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd) 145 { 146 LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... "); 147 148 bool status = true; 149 150 if (InternalAtomBondMap.empty()) 151 CreateInternalMap(AtomMapBegin, AtomMapEnd); 152 153 status = status && CompareInternalExternalMap(); 154 143 bool CheckAgainstAdjacencyFile::operator()(const atomids_t &atomids) 144 { 145 LOG(0, "STATUS: Looking at bond structure of given ids and comparing against stored in adjacency file... "); 146 147 // parse in external map 148 CreateExternalMap(atomids); 149 150 bool status = CompareInternalExternalMap(); 155 151 if (status) { // if equal we parse the KeySetFile 156 152 LOG(0, "STATUS: Equal."); … … 182 178 } 183 179 184 /** Counts the number of mismatching items in each set. 185 * 186 * @param firstset first set 187 * @param secondset second set 188 * @return number of items that don't match between first and second set 180 /** Counts the number of items in the second set not present in the first set. 181 * 182 * \note We assume that the sets are sorted. 183 * 184 * @param firstset check set 185 * @param secondset reference set 186 * @return number of items in the first set that are missing in the second 189 187 */ 190 188 template <class T> 191 size_t getMis matchingItems(const T &firstset, const T &secondset)189 size_t getMissingItems(const T &firstset, const T &secondset) 192 190 { 193 191 size_t Mismatch = 0; 194 192 typename T::const_iterator firstiter = firstset.begin(); 195 193 typename T::const_iterator seconditer = secondset.begin(); 196 for (; (firstiter != firstset.end()) && (seconditer != secondset.end()); 197 ++firstiter, ++seconditer) { 198 if (*firstiter != *seconditer) 199 ++Mismatch; 194 for (; (firstiter != firstset.end()) && (seconditer != secondset.end());) { 195 if (*firstiter > *seconditer) 196 ++seconditer; 197 else { 198 if (*firstiter < *seconditer) 199 ++Mismatch; 200 ++firstiter; 201 } 200 202 } 201 203 return Mismatch; … … 209 211 { 210 212 NonMatchNumber = 0; 211 // check whether sizes match212 if (ExternalAtomBondMap.size() != InternalAtomBondMap.size()) {213 NonMatchNumber = abs((int)ExternalAtomBondMap.size() - (int)InternalAtomBondMap.size());214 LOG(2, "INFO: " << NonMatchNumber << " entries don't match.");215 return false;216 }217 213 // extract keys and check whether they match 218 214 const AtomBondRange Intrange(InternalAtomBondMap.begin(), InternalAtomBondMap.end()); … … 225 221 226 222 // check for same amount of keys 227 if (InternalKeys.size() != ExternalKeys.size()) { 228 NonMatchNumber = abs((int)ExternalKeys.size() - (int)InternalKeys.size()); 229 LOG(2, "INFO: Number of keys don't match: " 230 << InternalKeys.size() << " != " << ExternalKeys.size()); 231 return false; 232 } 233 234 // check items against one another 235 NonMatchNumber = getMismatchingItems(InternalKeys, ExternalKeys); 223 if (ExternalKeys.size() > InternalKeys.size()) { 224 NonMatchNumber = (int)ExternalKeys.size() - (int)InternalKeys.size(); 225 LOG(2, "INFO: Number of external keys exceeds internal one by " << NonMatchNumber << "."); 226 return false; 227 } 228 229 // check which keys are missing in the internal set 230 NonMatchNumber = getMissingItems(ExternalKeys, InternalKeys); 236 231 237 232 if (NonMatchNumber != 0) { … … 241 236 242 237 // now check each map per key 243 for (KeysSet::const_iterator keyIter = InternalKeys.begin();244 keyIter != InternalKeys.end();238 for (KeysSet::const_iterator keyIter = ExternalKeys.begin(); 239 keyIter != ExternalKeys.end(); 245 240 ++keyIter) { 246 241 // std::cout << "Current key is " << *keyIter << std::endl; … … 249 244 ValuesSet InternalValues( getValues(IntRange) ); 250 245 ValuesSet ExternalValues( getValues(ExtRange) ); 246 // throw out all values not present in ExternalKeys 247 ValuesSet ExternalValues_temp( ExternalValues ); 248 for(KeysSet::const_iterator iter = ExternalKeys.begin(); 249 iter != ExternalKeys.end(); ++iter) 250 ExternalValues_temp.erase(*iter); 251 // all remaining values must be masked out 252 for (ValuesSet::const_iterator iter = ExternalValues_temp.begin(); 253 iter != ExternalValues_temp.end(); ++iter) 254 ExternalValues.erase(*iter); 251 255 // std::cout << "InternalValues: " << InternalValues << std::endl; 252 256 // std::cout << "ExternalValues: " << ExternalValues << std::endl; 253 NonMatchNumber += getMis matchingItems(InternalValues, ExternalValues);257 NonMatchNumber += getMissingItems(ExternalValues, InternalValues); 254 258 } 255 259 if (NonMatchNumber != 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
