source: src/Bond/AdjacencyMatcher/AdjacencyMatcher.cpp@ c66ae6

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
Last change on this file since c66ae6 was c66ae6, checked in by Frederik Heber <heber@…>, 9 years ago

TESTFIX: Added AdjacencyMatcher to correctly compare .adj files in save-adjacency regression test.

  • GuiChecks sees a different (but still valid) ordering in the .adj file in the save-adjacency regression test.
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2015 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * AdjacencyMatcher.cpp
25 *
26 * Created on: Jul 19, 2015
27 * Author: heber
28 *
29 *
30 * This is mostly copy&pasted from AdjacencyMatcher.cpp
31 */
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include "CodePatterns/MemDebug.hpp"
39
40#include <boost/exception/all.hpp>
41#include <boost/filesystem/operations.hpp>
42#include <boost/filesystem/path.hpp>
43#include <boost/tokenizer.hpp>
44
45#include <algorithm>
46#include <fstream>
47#include <iostream>
48#include <iterator>
49#include <map>
50#include <set>
51#include <sstream>
52#include <string>
53
54#include "Adjacency.hpp"
55
56#include "CodePatterns/toString.hpp"
57
58typedef std::set<detail::Adjacency> adjacencies_t;
59
60using namespace detail;
61
62namespace bf = boost::filesystem;
63
64typedef boost::error_info<
65 struct tag_IllegalTesselationFileContent_LineNumber,
66 int> IllegalTesselationFileContent_LineNumber;
67
68typedef boost::error_info<
69 struct tag_IllegalTesselationFileContent_Entries,
70 int> IllegalTesselationFileContent_Entries;
71
72typedef boost::error_info<
73 struct tag_IllegalTesselationFileContent_Line,
74 int> IllegalTesselationFileContent_Line;
75
76//!> Exception for illegal lines encountered in adjacencies files
77struct IllegalTesselationFileContentException:
78 virtual boost::exception, virtual std::exception { };
79
80Adjacency::index_t toIndex(const std::string &_element)
81{
82 Adjacency::index_t index;
83 std::stringstream tokenstring(_element);
84 tokenstring >> index;
85 return index;
86}
87
88template <class T>
89std::ostream& operator<<(
90 std::ostream &_ost,
91 const std::set<T> &elements)
92{
93 for( const T elem : elements)
94 _ost << elem << std::endl;
95 return _ost;
96}
97
98/** Parses a adjacencies file into a vector of Adjacencys.
99 *
100 * \param _filename name of file to parse
101 * \return adjacencies_t structure filled with adjacency index triples
102 */
103const adjacencies_t parseFile(const boost::filesystem::path &_filename)
104{
105 adjacencies_t adjacencies;
106
107 std::ifstream infile(_filename.string().c_str());
108 boost::char_separator<char> sep(" \t");
109
110 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
111 std::string line;
112 while (!infile.eof()) {
113 std::getline(infile, line);
114 tokenizer tokens(line, sep);
115 Adjacency::indices_t indices;
116 const int entries = std::distance( tokens.begin(), tokens.end() );
117 // check for empty lines
118 if (entries == 0)
119 continue;
120 std::transform(
121 tokens.begin(),
122 tokens.end(),
123 std::back_inserter(indices),
124 toIndex);
125 adjacencies.insert(Adjacency(indices));
126 }
127 infile.close();
128
129 return adjacencies;
130}
131
132int main(int argc, char **argv) {
133
134 /// check arguments and give usage
135 if (argc <= 2) {
136 std::cerr << "Usage: " << argv[0] << " <list of files>\n";
137 std::cerr << "At least two adjacencies files need to be specified that contain\n";
138 std::cerr << "each three indices per line.\n";
139
140 return 255;
141 }
142
143 /// read in files and parse into structures
144 typedef std::multimap<adjacencies_t, std::string> adjacencies_filename_t;
145 //!> contains all adjacencies parsed from files
146 adjacencies_filename_t adjacencyfiles;
147 for (int i=1; i<argc;++i) {
148 const bf::path filename(argv[i]);
149 if (bf::exists(filename)) {
150 try {
151 adjacencies_t adjacencies = parseFile(filename);
152 adjacencyfiles.insert(
153 std::make_pair(adjacencies, filename.string()) );
154 } catch (IllegalTesselationFileContentException &e) {
155 std::cerr << "Illegal line at "
156 << *boost::get_error_info<IllegalTesselationFileContent_LineNumber>(e)
157 << " encountered with "
158 << *boost::get_error_info<IllegalTesselationFileContent_Entries>(e)
159 << " entries in "
160 << filename.string()
161 << ", aborting.\n";
162 return 5;
163 }
164 } else {
165 std::cerr << "The following file does not exist "
166 << filename.string() << ", aborting.\n";
167 return 5;
168 }
169 }
170
171 /// make comparison for equivalence
172 assert( adjacencyfiles.size() >= 2 );
173 adjacencies_filename_t::const_iterator advancer = adjacencyfiles.begin();
174 adjacencies_filename_t::const_iterator iter = advancer++;
175
176 bool AllEqual = true;
177 while( advancer != adjacencyfiles.end() ) {
178// std::cout << "Comparing " << *advancer << " with " << *iter << std::endl;
179 if (advancer->first == iter->first) {
180 std::cout << "MATCH: "
181 << advancer->second << " and " << iter->second
182 << std::endl;
183 } else {
184 std::cout << advancer->first << " and " << iter->first
185 << " don't match.\n";
186 AllEqual = false;
187 }
188 iter = advancer++;
189 }
190
191 // exit (convert bool to int)
192 return (AllEqual ? 0 : 1);
193}
Note: See TracBrowser for help on using the repository browser.