- Timestamp:
- Feb 4, 2011, 6:56:38 PM (14 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:
- febef3
- Parents:
- fd3788
- git-author:
- Frederik Heber <heber@…> (02/04/11 18:54:12)
- git-committer:
- Frederik Heber <heber@…> (02/04/11 18:56:38)
- Location:
- src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/CommandAction/BondLengthTableAction.cpp
rfd3788 r4e855e 45 45 DoLog(0) && (Log() << Verbose(0) << "Using " << params.BondGraphFileName << " as bond length table." << endl); 46 46 config *configuration = World::getInstance().getConfig(); 47 if (configuration->BG == NULL) { 48 configuration->BG = new BondGraph(configuration->GetIsAngstroem()); 49 if ((!params.BondGraphFileName.empty()) 50 && boost::filesystem::exists(params.BondGraphFileName) 51 && (configuration->BG->LoadBondLengthTable(params.BondGraphFileName.string()))) { 52 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl); 53 return Action::success; 47 BondGraph *OldBG; 48 if (configuration->BG != NULL) { 49 OldBG = configuration->BG; 50 DoLog(0) && (Log() << Verbose(0) << "There is a bond length table already present." << endl); 51 } 52 configuration->BG = new BondGraph(configuration->GetIsAngstroem()); 53 if ((!params.BondGraphFileName.empty()) 54 && boost::filesystem::exists(params.BondGraphFileName)) { 55 std::ifstream input(params.BondGraphFileName.string().c_str()); 56 if ((input.good()) && (configuration->BG->LoadBondLengthTable(input))) { 57 DoLog(0) && (Log() << Verbose(0) << "Bond length table parsed successfully." << endl); 58 input.close(); 59 return Action::state_ptr(new CommandBondLengthTableState(*OldBG, params)); 54 60 } else { 55 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl); 61 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table parsing failed." << endl); 62 input.close(); 63 configuration->BG = new BondGraph(*OldBG); 56 64 return Action::failure; 57 65 } 58 66 } else { 59 DoLog(0) && (Log() << Verbose(0) << "Bond length table already present." << endl); 67 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl); 68 configuration->BG = new BondGraph(*OldBG); 60 69 return Action::failure; 61 70 } … … 63 72 64 73 Action::state_ptr CommandBondLengthTableAction::performUndo(Action::state_ptr _state) { 65 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());74 CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get()); 66 75 67 return Action::failure;68 // string newName = state->mol->getName();69 // state->mol->setName(state->lastName);70 // 71 // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));76 config *configuration = World::getInstance().getConfig(); 77 BondGraph *OldBG = new BondGraph(*configuration->BG); 78 configuration->BG = new BondGraph(state->OldBG); 79 80 return Action::state_ptr(new CommandBondLengthTableState(*OldBG,params)); 72 81 } 73 82 74 83 Action::state_ptr CommandBondLengthTableAction::performRedo(Action::state_ptr _state){ 75 return Action::failure; 84 CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get()); 85 86 config *configuration = World::getInstance().getConfig(); 87 BondGraph *OldBG = new BondGraph(*configuration->BG); 88 configuration->BG = new BondGraph(state->OldBG); 89 90 return Action::state_ptr(new CommandBondLengthTableState(*OldBG,params)); 76 91 } 77 92 -
src/Actions/CommandAction/BondLengthTableAction.def
rfd3788 r4e855e 8 8 // all includes and forward declarations necessary for non-integral types below 9 9 10 #include "bondgraph.hpp" 10 11 11 12 // i.e. there is an integer with variable name Z that can be found in … … 18 19 #define paramreferences (BondGraphFileName) 19 20 20 # undef statetypes21 # undef statereferences21 #define statetypes (BondGraph) 22 #define statereferences (OldBG) 22 23 23 24 // some defines for all the names, you may use ACTION, STATE and PARAMS -
src/Actions/FragmentationAction/DepthFirstSearchAction.cpp
rfd3788 r4e855e 52 52 std::deque<bond *> *BackEdgeStack = NULL; 53 53 std::deque<bond *> *LocalBackEdgeStack = NULL; 54 mol->CreateAdjacencyList(params.distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); 54 BondGraph *BG = World::getInstance().getConfig()->BG; 55 if (BG != NULL) 56 mol->CreateAdjacencyList(params.distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::BondLengthMatrixMinMaxDistance, BG); 57 else 58 mol->CreateAdjacencyList(params.distance, World::getInstance().getConfig()->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, BG); 55 59 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack); 56 60 if (Subgraphs != NULL) { -
src/bondgraph.cpp
rfd3788 r4e855e 57 57 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(), 58 58 * but only if parsing is successful. Otherwise variable is left as NULL. 59 * \param *out output stream for debugging 60 * \param filename file with bond lengths to parse 59 * \param &input input stream to parse table from 61 60 * \return true - success in parsing file, false - failed to parse the file 62 61 */ 63 bool BondGraph::LoadBondLengthTable( const string &filename)62 bool BondGraph::LoadBondLengthTable(std::istream &input) 64 63 { 65 64 Info FunctionInfo(__func__); … … 75 74 76 75 // parse in matrix 77 if (( status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0))) {76 if ((input.good()) && (status = TempContainer->ParseMatrix(input, 0, 1, 0))) { 78 77 DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl); 79 78 } else { 80 79 DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl); 80 status = false; 81 81 } 82 82 … … 129 129 double BondGraph::GetBondLength(int firstZ, int secondZ) 130 130 { 131 if (BondLengthMatrix == NULL) 131 std::cout << "Request for length between " << firstZ << " and " << secondZ << ": "; 132 if (BondLengthMatrix == NULL) { 133 std::cout << "-1." << std::endl; 132 134 return( -1. ); 133 else 135 } else { 136 std::cout << BondLengthMatrix->Matrix[0][firstZ][secondZ] << std::endl; 134 137 return (BondLengthMatrix->Matrix[0][firstZ][secondZ]); 138 } 135 139 }; 136 140 -
src/bondgraph.hpp
rfd3788 r4e855e 36 36 BondGraph(bool IsA); 37 37 ~BondGraph(); 38 bool LoadBondLengthTable( const string &filename);38 bool LoadBondLengthTable(std::istream &input); 39 39 bool ConstructBondGraph(molecule * const mol); 40 40 double GetBondLength(int firstelement, int secondelement); -
src/builder_init.cpp
rfd3788 r4e855e 19 19 20 20 #include "CodePatterns/MemDebug.hpp" 21 22 #include <iostream> 21 23 22 24 #include "bondgraph.hpp" … … 107 109 World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem()); 108 110 if (boost::filesystem::exists(BondGraphFileName)) { 109 if (World::getInstance().getConfig()->BG->LoadBondLengthTable(BondGraphFileName)) { 111 std::ifstream input(BondGraphFileName.c_str()); 112 if ((input.good()) && (World::getInstance().getConfig()->BG->LoadBondLengthTable(input))) { 110 113 DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl); 111 114 } else { 112 115 DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl); 113 116 } 117 input.close(); 114 118 } 115 119 } -
src/molecule_dynamics.cpp
rfd3788 r4e855e 574 574 { 575 575 Info FunctionInfo(__func__); 576 ifstream input(file);577 576 string token; 578 577 stringstream item; … … 582 581 583 582 const int AtomCount = getAtomCount(); 584 // check file 585 if (input == NULL) { 583 // parse file into ForceMatrix 584 std::ifstream input(file); 585 if ((input.good()) && (!Force.ParseMatrix(input, 0,0,0))) { 586 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl); 587 performCriticalExit(); 586 588 return false; 587 } else { 588 // parse file into ForceMatrix 589 if (!Force.ParseMatrix(file, 0,0,0)) { 590 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl); 591 performCriticalExit(); 592 return false; 593 } 594 if (Force.RowCounter[0] != AtomCount) { 595 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount() << "." << endl); 596 performCriticalExit(); 597 return false; 598 } 599 // correct Forces 600 Velocity.Zero(); 601 for(int i=0;i<AtomCount;i++) 602 for(int d=0;d<NDIM;d++) { 603 Velocity[d] += Force.Matrix[0][i][d+offset]; 604 } 605 for(int i=0;i<AtomCount;i++) 606 for(int d=0;d<NDIM;d++) { 607 Force.Matrix[0][i][d+offset] -= Velocity[d]/static_cast<double>(AtomCount); 608 } 609 // solve a constrained potential if we are meant to 610 if (configuration.DoConstrainedMD) { 611 // calculate forces and potential 612 atom **PermutationMap = NULL; 613 ConstrainedPotentialEnergy = MinimiseConstrainedPotential(PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem()); 614 EvaluateConstrainedForces(configuration.DoConstrainedMD, 0, PermutationMap, &Force); 615 delete[](PermutationMap); 616 } 617 618 // and perform Verlet integration for each atom with position, velocity and force vector 619 // check size of vectors 620 for_each(atoms.begin(), 621 atoms.end(), 622 boost::bind(&atom::VelocityVerletUpdate,_1,MDSteps+1, &configuration, &Force, (const size_t) 0)); 623 } 589 } 590 input.close(); 591 if (Force.RowCounter[0] != AtomCount) { 592 DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << getAtomCount() << "." << endl); 593 performCriticalExit(); 594 return false; 595 } 596 // correct Forces 597 Velocity.Zero(); 598 for(int i=0;i<AtomCount;i++) 599 for(int d=0;d<NDIM;d++) { 600 Velocity[d] += Force.Matrix[0][i][d+offset]; 601 } 602 for(int i=0;i<AtomCount;i++) 603 for(int d=0;d<NDIM;d++) { 604 Force.Matrix[0][i][d+offset] -= Velocity[d]/static_cast<double>(AtomCount); 605 } 606 // solve a constrained potential if we are meant to 607 if (configuration.DoConstrainedMD) { 608 // calculate forces and potential 609 atom **PermutationMap = NULL; 610 ConstrainedPotentialEnergy = MinimiseConstrainedPotential(PermutationMap,configuration.DoConstrainedMD, 0, configuration.GetIsAngstroem()); 611 EvaluateConstrainedForces(configuration.DoConstrainedMD, 0, PermutationMap, &Force); 612 delete[](PermutationMap); 613 } 614 615 // and perform Verlet integration for each atom with position, velocity and force vector 616 // check size of vectors 617 for_each(atoms.begin(), 618 atoms.end(), 619 boost::bind(&atom::VelocityVerletUpdate,_1,MDSteps+1, &configuration, &Force, (const size_t) 0)); 620 624 621 // correct velocities (rather momenta) so that center of mass remains motionless 625 622 Velocity = atoms.totalMomentumAtStep(MDSteps+1); -
src/molecule_graph.cpp
rfd3788 r4e855e 174 174 for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) { 175 175 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 176 //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;176 Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl; 177 177 if (List != NULL) { 178 178 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 179 179 Walker = dynamic_cast<atom*>(*Runner); 180 180 ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode"); 181 //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;181 Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl; 182 182 // 3c. check for possible bond between each atom in this and every one in the 27 cells 183 183 for (n[0] = -1; n[0] <= 1; n[0]++) … … 185 185 for (n[2] = -1; n[2] <= 1; n[2]++) { 186 186 const LinkedCell::LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n); 187 // Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;188 187 if (OtherList != NULL) { 188 Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl; 189 189 for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) { 190 190 if ((*OtherRunner)->nr > Walker->nr) { 191 191 OtherWalker = dynamic_cast<atom*>(*OtherRunner); 192 192 ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode"); 193 //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;194 193 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); 195 194 const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition()); 195 Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 196 196 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance); 197 //Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl;197 Log() << Verbose(1) << "MinDistance is " << MinDistance << " and MaxDistance is " << MaxDistance << "." << endl; 198 198 if (OtherWalker->father->nr > Walker->father->nr) { 199 199 if (status) { // create bond if distance is smaller 200 //Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;200 Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl; 201 201 AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount 202 202 } else { 203 //Log() << Verbose(1) << "Not Adding: distance too great." << endl;203 Log() << Verbose(1) << "Not Adding: distance too great." << endl; 204 204 } 205 205 } else { 206 //Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl;206 Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl; 207 207 } 208 208 } -
src/parser.cpp
rfd3788 r4e855e 22 22 23 23 #include <cstring> 24 #include <iomanip> 24 25 25 26 #include "Helpers/helpers.hpp" … … 158 159 * -# allocate matrix 159 160 * -# loop over found column and row counts and parse in each entry 160 * \param *name directory with files161 * \param &input input stream 161 162 * \param skiplines number of inital lines to skip 162 163 * \param skiplines number of inital columns to skip … … 164 165 * \return parsing successful 165 166 */ 166 bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr) 167 { 168 ifstream input; 167 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr) 168 { 169 169 stringstream line; 170 170 string token; 171 171 char filename[1023]; 172 172 173 input.open(name, ios::in);174 173 //Log() << Verbose(1) << "Opening " << name << " ... " << input << endl; 175 if (input == NULL) {176 DoeLog(1) && (eLog()<< Verbose(1) << endl << "MatrixContainer::ParseMatrix: Unable to open " << name << ", is the directory correct?" << endl);174 if (input.bad()) { 175 DoeLog(1) && (eLog()<< Verbose(1) << endl << "MatrixContainer::ParseMatrix: Unable to parse istream." << endl); 177 176 //performCriticalExit(); 178 177 return false; … … 190 189 for(int k=skipcolumns;k--;) 191 190 line >> Header[MatrixNr]; 192 //Log() << Verbose(0) << line.str() << endl;191 Log() << Verbose(0) << line.str() << endl; 193 192 ColumnCounter[MatrixNr]=0; 194 193 while ( getline(line,token, '\t') ) { … … 196 195 ColumnCounter[MatrixNr]++; 197 196 } 198 //Log() << Verbose(0) << line.str() << endl;199 //Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;197 Log() << Verbose(0) << line.str() << endl; 198 Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl; 200 199 if (ColumnCounter[MatrixNr] == 0) { 201 DoeLog(0) && (eLog()<< Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);200 DoeLog(0) && (eLog()<< Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from ostream." << endl); 202 201 performCriticalExit(); 203 202 } … … 207 206 while (!input.eof()) { 208 207 input.getline(filename, 1023); 209 //Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;208 Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl; 210 209 RowCounter[MatrixNr]++; // then line was not last MeanForce 211 210 if (strncmp(filename,"MeanForce", 9) == 0) { … … 213 212 } 214 213 } 215 //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;214 Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl; 216 215 if (RowCounter[MatrixNr] == 0) { 217 DoeLog(0) && (eLog()<< Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);216 DoeLog(0) && (eLog()<< Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl); 218 217 performCriticalExit(); 219 218 } … … 233 232 input.getline(Header[MatrixNr], 1023); // skip header 234 233 line.str(Header[MatrixNr]); 234 Log() << Verbose(0) << "Header: " << line.str() << endl; 235 235 for(int k=skipcolumns;k--;) // skip columns in header too 236 236 line >> filename; … … 245 245 input.getline(filename, 1023); 246 246 stringstream lines(filename); 247 //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;247 Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl; 248 248 for(int k=skipcolumns;k--;) 249 249 lines >> filename; 250 250 for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) { 251 251 lines >> Matrix[MatrixNr][j][k]; 252 //Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl;252 Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl; 253 253 } 254 254 if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL) … … 261 261 DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl); 262 262 } 263 input.close();264 263 return true; 265 264 }; … … 327 326 file.str(" "); 328 327 file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix; 329 if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i)) 328 std::ifstream input(file.str().c_str()); 329 if (!ParseMatrix(input, skiplines, skipcolumns, i)) { 330 input.close(); 330 331 return false; 332 } 333 input.close(); 331 334 delete[](FragmentNumber); 332 335 } … … 628 631 strncat(filename, prefix, 1023-strlen(filename)); 629 632 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 630 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 633 std::ifstream input(filename); 634 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 635 input.close(); 631 636 } 632 637 return status; … … 764 769 strncat(filename, prefix, 1023-strlen(filename)); 765 770 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 766 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 771 std::ifstream input(filename); 772 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 773 input.close(); 767 774 } 768 775 … … 992 999 strncat(filename, prefix, 1023-strlen(filename)); 993 1000 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 994 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 1001 std::ifstream input(filename); 1002 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 1003 input.close(); 995 1004 } 996 1005 -
src/parser.hpp
rfd3788 r4e855e 86 86 87 87 bool InitialiseIndices(class MatrixContainer *Matrix = NULL); 88 bool ParseMatrix( const char *name, int skiplines, int skipcolumns, int MatrixNr);88 bool ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr); 89 89 virtual bool ParseFragmentMatrix(const char *name, const char *prefix, string suffix, int skiplines, int skipcolumns); 90 90 bool AllocateMatrix(char **GivenHeader, int MCounter, int *RCounter, int *CCounter); -
src/unittests/AnalysisBondsUnitTest.cpp
rfd3788 r4e855e 92 92 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 ); 93 93 94 // create a small file with table 95 filename = new string("test.dat"); 96 CPPUNIT_ASSERT(filename != NULL && "could not create string"); 97 ofstream test(filename->c_str()); 94 // create stream with table 95 std::stringstream test; 98 96 test << ".\tH\tHe\tLi\tBe\tB\tC\n"; 99 97 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n"; … … 103 101 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n"; 104 102 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n"; 105 test.close();106 103 BG = new BondGraph(true); 107 104 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); 108 105 109 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable( *filename) );106 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) ); 110 107 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) ); 111 108 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) ); … … 119 116 { 120 117 // remove the file 121 remove(filename->c_str());122 delete(filename);123 118 delete(BG); 124 119 -
src/unittests/BondGraphUnitTest.cpp
rfd3788 r4e855e 92 92 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); 93 93 94 // create a small file with table 95 dummyname = new string("dummy.dat"); 96 CPPUNIT_ASSERT(dummyname != NULL && "could not create string"); 97 filename = new string("test.dat"); 98 CPPUNIT_ASSERT(filename != NULL && "could not create string"); 99 ofstream test(filename->c_str()); 94 // create stream with table 100 95 test << ".\tH\tHe\tLi\tBe\tB\tC\n"; 101 96 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n"; … … 105 100 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n"; 106 101 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n"; 107 test.close(); 102 // created bad stream (i.e. non-present file) 103 dummy.setstate(ios::eofbit); 104 CPPUNIT_ASSERT(dummy.eof()); 108 105 BG = new BondGraph(true); 109 106 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); … … 114 111 { 115 112 // remove the file 116 remove(filename->c_str());117 delete(filename);118 delete(dummyname);119 113 delete(BG); 120 114 … … 139 133 void BondGraphTest::LoadTableTest() 140 134 { 141 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable( *filename) );135 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) ); 142 136 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) ); 143 137 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) ); … … 152 146 molecule::iterator Runner = TestMolecule->begin(); 153 147 Runner++; 154 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable( *filename) );148 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) ); 155 149 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) ); 156 150 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) ); … … 165 159 //atom *Runner = TestMolecule->end->previous; 166 160 //CPPUNIT_ASSERT( TestMolecule->end != Walker ); 167 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable( *dummyname) );161 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(dummy) ); 168 162 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) ); 169 163 -
src/unittests/BondGraphUnitTest.hpp
rfd3788 r4e855e 49 49 50 50 BondGraph *BG; 51 st ring *filename;52 st ring *dummyname;51 std::stringstream dummy; 52 std::stringstream test; 53 53 }; 54 54
Note:
See TracChangeset
for help on using the changeset viewer.