Changeset 5b0581
- Timestamp:
- Jun 18, 2012, 10:53:29 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, 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:
- ca331c
- Parents:
- 27cfde
- git-author:
- Frederik Heber <heber@…> (06/14/12 12:44:55)
- git-committer:
- Frederik Heber <heber@…> (06/18/12 10:53:29)
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TremoloParser.cpp
r27cfde r5b0581 187 187 } 188 188 189 struct usedFieldsWeakComparator 190 { 191 /** Special comparator regards "neighbors=4" and "neighbors=2" as equal 192 * 193 * \note This one is used for making usedFields unique, i.e. throwing out the "smaller" 194 * neighbors. 195 */ 196 bool operator()(const std::string &a, const std::string &b) const 197 { 198 // only compare up to first equality sign 199 return (a.substr(0, a.find_first_of('=')) == b.substr(0, b.find_first_of('='))); 200 } 201 }; 202 203 struct usedFieldsSpecialOrderer 204 { 205 /** Special string comparator that regards "neighbors=4" < "neighbors=2" as true and 206 * the other way round as false. 207 * 208 * Here, we implement the operator "\a < \b" in a special way to allow the 209 * above. 210 * 211 * \note This one is used for sorting usedFields in preparation for making it unique. 212 */ 213 bool operator()(const std::string &a, const std::string &b) const 214 { 215 // only compare up to first equality sign 216 size_t a_equality = a.find_first_of('='); 217 size_t b_equality = b.find_first_of('='); 218 // if key before equality is not equal, return whether it is smaller or not 219 if (a.substr(0, a_equality) != b.substr(0, b_equality)) { 220 return a.substr(0, a_equality) < b.substr(0, b_equality); 221 } else { // now we know that the key before equality is the same in either string 222 // if one of them has no equality, the one with equality must go before 223 if ((a_equality != std::string::npos) && (b_equality == std::string::npos)) 224 return true; 225 if ((a_equality == std::string::npos) && (b_equality != std::string::npos)) 226 return false; 227 // if both don't have equality (and the token before is equal), it is not "<" but "==" 228 if ((a_equality == std::string::npos) && (b_equality == std::string::npos)) 229 return false; 230 // if now both have equality sign, the larger value after it, must come first 231 return a.substr(a_equality, std::string::npos) > b.substr(b_equality, std::string::npos); 232 } 233 } 234 }; 235 189 236 /** Helper function to make \given fields unique while preserving the order of first appearance. 190 237 * … … 200 247 // std::unique only removes if predecessor is equal, not over whole range, hence do it manually 201 248 usedFields_t temp_fields(fields); 202 std::sort(temp_fields.begin(), temp_fields.end()); 249 usedFieldsSpecialOrderer SpecialOrderer; 250 usedFieldsWeakComparator WeakComparator; 251 std::sort(temp_fields.begin(), temp_fields.end(), SpecialOrderer); 203 252 usedFields_t::iterator it = 204 std::unique(temp_fields.begin(), temp_fields.end() ); // skips all duplicates in the vector253 std::unique(temp_fields.begin(), temp_fields.end(), WeakComparator); 205 254 temp_fields.erase(it, temp_fields.end()); 206 255 usedFields_t usedfields(fields); -
tests/regression/Makefile.am
r27cfde r5b0581 135 135 $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-load-multiply.at \ 136 136 $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-save.at \ 137 $(srcdir)/Parser/Tremolo/testsuite-parser-tremolo-save-unique_usedfields.at \ 137 138 $(srcdir)/Parser/Tremolo-Exttypes/testsuite-parser-tremolo-save-selected-atoms-as-exttypes.at \ 138 139 $(srcdir)/Parser/Tremolo-Potentials/testsuite-parser-tremolo-potentials.at \ -
tests/regression/Parser/testsuite-parser.at
r27cfde r5b0581 50 50 m4_include([Parser/Tremolo/testsuite-parser-tremolo-load-multiply.at]) 51 51 m4_include([Parser/Tremolo/testsuite-parser-tremolo-save.at]) 52 m4_include([Parser/Tremolo/testsuite-parser-tremolo-save-unique_usedfields.at]) 52 53 53 54 # parsing tremolo with .potentials
Note:
See TracChangeset
for help on using the changeset viewer.