Changeset 4e855e for src


Ignore:
Timestamp:
Feb 4, 2011, 6:56:38 PM (14 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:
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)
Message:

BondGraph::LoadBondLengthTable() now accepts istream instead of const char *.

  • This has been quite a lot of work because the matrix parsing is involved.
  • Hence, the fix is not really clean, this should get fixed as soon as we deal with the BondGraph implementation.
  • This fixes ticket #130.
Location:
src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/CommandAction/BondLengthTableAction.cpp

    rfd3788 r4e855e  
    4545  DoLog(0) && (Log() << Verbose(0) << "Using " << params.BondGraphFileName << " as bond length table." << endl);
    4646  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));
    5460    } 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);
    5664      return Action::failure;
    5765    }
    5866  } 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);
    6069    return Action::failure;
    6170  }
     
    6372
    6473Action::state_ptr CommandBondLengthTableAction::performUndo(Action::state_ptr _state) {
    65 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
     74  CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get());
    6675
    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));
    7281}
    7382
    7483Action::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));
    7691}
    7792
  • src/Actions/CommandAction/BondLengthTableAction.def

    rfd3788 r4e855e  
    88// all includes and forward declarations necessary for non-integral types below
    99
     10#include "bondgraph.hpp"
    1011
    1112// i.e. there is an integer with variable name Z that can be found in
     
    1819#define paramreferences (BondGraphFileName)
    1920
    20 #undef statetypes
    21 #undef statereferences
     21#define statetypes (BondGraph)
     22#define statereferences (OldBG)
    2223
    2324// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/FragmentationAction/DepthFirstSearchAction.cpp

    rfd3788 r4e855e  
    5252  std::deque<bond *> *BackEdgeStack = NULL;
    5353  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);
    5559  Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
    5660  if (Subgraphs != NULL) {
  • src/bondgraph.cpp

    rfd3788 r4e855e  
    5757 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
    5858 * 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
    6160 * \return true - success in parsing file, false - failed to parse the file
    6261 */
    63 bool BondGraph::LoadBondLengthTable(const string &filename)
     62bool BondGraph::LoadBondLengthTable(std::istream &input)
    6463{
    6564  Info FunctionInfo(__func__);
     
    7574
    7675  // 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))) {
    7877    DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
    7978  } else {
    8079    DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
     80    status = false;
    8181  }
    8282
     
    129129double BondGraph::GetBondLength(int firstZ, int secondZ)
    130130{
    131   if (BondLengthMatrix == NULL)
     131  std::cout << "Request for length between " << firstZ << " and " << secondZ << ": ";
     132  if (BondLengthMatrix == NULL) {
     133    std::cout << "-1." << std::endl;
    132134    return( -1. );
    133   else
     135  } else {
     136    std::cout << BondLengthMatrix->Matrix[0][firstZ][secondZ] << std::endl;
    134137    return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
     138  }
    135139};
    136140
  • src/bondgraph.hpp

    rfd3788 r4e855e  
    3636  BondGraph(bool IsA);
    3737  ~BondGraph();
    38   bool LoadBondLengthTable(const string &filename);
     38  bool LoadBondLengthTable(std::istream &input);
    3939  bool ConstructBondGraph(molecule * const mol);
    4040  double GetBondLength(int firstelement, int secondelement);
  • src/builder_init.cpp

    rfd3788 r4e855e  
    1919
    2020#include "CodePatterns/MemDebug.hpp"
     21
     22#include <iostream>
    2123
    2224#include "bondgraph.hpp"
     
    107109    World::getInstance().getConfig()->BG = new BondGraph(World::getInstance().getConfig()->GetIsAngstroem());
    108110    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))) {
    110113        DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
    111114      } else {
    112115        DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
    113116      }
     117      input.close();
    114118    }
    115119  }
  • src/molecule_dynamics.cpp

    rfd3788 r4e855e  
    574574{
    575575  Info FunctionInfo(__func__);
    576   ifstream input(file);
    577576  string token;
    578577  stringstream item;
     
    582581
    583582  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();
    586588    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
    624621  // correct velocities (rather momenta) so that center of mass remains motionless
    625622  Velocity = atoms.totalMomentumAtStep(MDSteps+1);
  • src/molecule_graph.cpp

    rfd3788 r4e855e  
    174174        for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) {
    175175          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;
    177177          if (List != NULL) {
    178178            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    179179              Walker = dynamic_cast<atom*>(*Runner);
    180180              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;
    182182              // 3c. check for possible bond between each atom in this and every one in the 27 cells
    183183              for (n[0] = -1; n[0] <= 1; n[0]++)
     
    185185                  for (n[2] = -1; n[2] <= 1; n[2]++) {
    186186                    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;
    188187                    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;
    189189                      for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
    190190                        if ((*OtherRunner)->nr > Walker->nr) {
    191191                          OtherWalker = dynamic_cast<atom*>(*OtherRunner);
    192192                          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;
    194193                          (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
    195194                          const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
     195                          Log() << Verbose(1) << "Checking distance " << distance << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
    196196                          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;
    198198                          if (OtherWalker->father->nr > Walker->father->nr) {
    199199                            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;
    201201                              AddBond(Walker->father, OtherWalker->father, 1); // also increases molecule::BondCount
    202202                            } else {
    203 //                              Log() << Verbose(1) << "Not Adding: distance too great." << endl;
     203                              Log() << Verbose(1) << "Not Adding: distance too great." << endl;
    204204                            }
    205205                          } else {
    206 //                            Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl;
     206                            Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl;
    207207                          }
    208208                        }
  • src/parser.cpp

    rfd3788 r4e855e  
    2222
    2323#include <cstring>
     24#include <iomanip>
    2425
    2526#include "Helpers/helpers.hpp"
     
    158159 *    -# allocate matrix
    159160 *    -# loop over found column and row counts and parse in each entry
    160  * \param *name directory with files
     161 * \param &input input stream
    161162 * \param skiplines number of inital lines to skip
    162163 * \param skiplines number of inital columns to skip
     
    164165 * \return parsing successful
    165166 */
    166 bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr)
    167 {
    168   ifstream input;
     167bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr)
     168{
    169169  stringstream line;
    170170  string token;
    171171  char filename[1023];
    172172
    173   input.open(name, ios::in);
    174173  //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);
    177176    //performCriticalExit();
    178177    return false;
     
    190189  for(int k=skipcolumns;k--;)
    191190    line >> Header[MatrixNr];
    192   //Log() << Verbose(0) << line.str() << endl;
     191  Log() << Verbose(0) << line.str() << endl;
    193192  ColumnCounter[MatrixNr]=0;
    194193  while ( getline(line,token, '\t') ) {
     
    196195      ColumnCounter[MatrixNr]++;
    197196  }
    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;
    200199  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);
    202201    performCriticalExit();
    203202  }
     
    207206  while (!input.eof()) {
    208207    input.getline(filename, 1023);
    209     //Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
     208    Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
    210209    RowCounter[MatrixNr]++; // then line was not last MeanForce
    211210    if (strncmp(filename,"MeanForce", 9) == 0) {
     
    213212    }
    214213  }
    215   //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
     214  Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl;
    216215  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);
    218217    performCriticalExit();
    219218  }
     
    233232      input.getline(Header[MatrixNr], 1023);    // skip header
    234233    line.str(Header[MatrixNr]);
     234    Log() << Verbose(0) << "Header: " << line.str() << endl;
    235235    for(int k=skipcolumns;k--;)  // skip columns in header too
    236236      line >> filename;
     
    245245      input.getline(filename, 1023);
    246246      stringstream lines(filename);
    247       //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
     247      Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
    248248      for(int k=skipcolumns;k--;)
    249249        lines >> filename;
    250250      for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
    251251        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;
    253253      }
    254254      if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL)
     
    261261    DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl);
    262262  }
    263   input.close();
    264263  return true;
    265264};
     
    327326    file.str(" ");
    328327    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();
    330331      return false;
     332    }
     333    input.close();
    331334    delete[](FragmentNumber);
    332335  }
     
    628631    strncat(filename, prefix, 1023-strlen(filename));
    629632    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();
    631636  }
    632637  return status;
     
    764769    strncat(filename, prefix, 1023-strlen(filename));
    765770    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();
    767774  }
    768775 
     
    992999    strncat(filename, prefix, 1023-strlen(filename));
    9931000    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();
    9951004  }
    9961005
  • src/parser.hpp

    rfd3788 r4e855e  
    8686 
    8787  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);
    8989  virtual bool ParseFragmentMatrix(const char *name, const char *prefix, string suffix, int skiplines, int skipcolumns);
    9090  bool AllocateMatrix(char **GivenHeader, int MCounter, int *RCounter, int *CCounter);
  • src/unittests/AnalysisBondsUnitTest.cpp

    rfd3788 r4e855e  
    9292  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 );
    9393
    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;
    9896  test << ".\tH\tHe\tLi\tBe\tB\tC\n";
    9997  test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
     
    103101  test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
    104102  test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
    105   test.close();
    106103  BG = new BondGraph(true);
    107104  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    108105
    109   CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
     106  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) );
    110107  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    111108  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
     
    119116{
    120117  // remove the file
    121   remove(filename->c_str());
    122   delete(filename);
    123118  delete(BG);
    124119
  • src/unittests/BondGraphUnitTest.cpp

    rfd3788 r4e855e  
    9292  CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
    9393
    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
    10095  test << ".\tH\tHe\tLi\tBe\tB\tC\n";
    10196  test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
     
    105100  test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
    106101  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());
    108105  BG = new BondGraph(true);
    109106  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
     
    114111{
    115112  // remove the file
    116   remove(filename->c_str());
    117   delete(filename);
    118   delete(dummyname);
    119113  delete(BG);
    120114
     
    139133void BondGraphTest::LoadTableTest()
    140134{
    141   CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
     135  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) );
    142136  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    143137  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
     
    152146  molecule::iterator Runner = TestMolecule->begin();
    153147  Runner++;
    154   CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
     148  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(test) );
    155149  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    156150  CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) );
     
    165159  //atom *Runner = TestMolecule->end->previous;
    166160  //CPPUNIT_ASSERT( TestMolecule->end != Walker );
    167   CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
     161  CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(dummy) );
    168162  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
    169163
  • src/unittests/BondGraphUnitTest.hpp

    rfd3788 r4e855e  
    4949
    5050      BondGraph *BG;
    51       string *filename;
    52       string *dummyname;
     51      std::stringstream dummy;
     52      std::stringstream test;
    5353};
    5454
Note: See TracChangeset for help on using the changeset viewer.