Changeset 7cdf58 for src


Ignore:
Timestamp:
Apr 8, 2013, 11:56:08 AM (12 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:
830b3e
Parents:
c39675
git-author:
Frederik Heber <heber@…> (03/03/13 21:19:22)
git-committer:
Frederik Heber <heber@…> (04/08/13 11:56:08)
Message:

ExportGraph_ToFiles now uses one-by-one procedure to store fragments.

Location:
src/Fragmentation/Exporters
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.cpp

    rc39675 r7cdf58  
    7171{}
    7272
     73/** Returns a string with \a i prefixed with 0s to match order of total number of molecules in digits.
     74 * \param FragmentNumber total number of fragments to determine necessary number of digits
     75 * \param digits number to create with 0 prefixed
     76 * \return allocated(!) char array with number in digits, ten base.
     77 */
     78static char *FixedDigitNumber(const int FragmentNumber, const int digits)
     79{
     80  char *returnstring;
     81  int number = FragmentNumber;
     82  int order = 0;
     83  while (number != 0) { // determine number of digits needed
     84    number = (int)floor(((double)number / 10.));
     85    order++;
     86    //LOG(0, "Number is " << number << ", order is " << order << ".");
     87  }
     88  // allocate string
     89  returnstring = new char[order + 2];
     90  // terminate  and fill string array from end backward
     91  returnstring[order] = '\0';
     92  number = digits;
     93  for (int i=order;i--;) {
     94    returnstring[i] = '0' + (char)(number % 10);
     95    number = (int)floor(((double)number / 10.));
     96  }
     97  //LOG(0, returnstring);
     98  return returnstring;
     99};
     100
    73101/** Actual implementation of the export to files function.
    74102 */
    75103void ExportGraph_ToFiles::operator()()
    76104{
    77   ExportGraph::operator()();
     105  LOG(1, "INFO: Writing " << TotalGraph.size() << " possible bond fragmentation configs");
     106  size_t FragmentCounter = 0;
     107  char *FragmentNumber = NULL;
     108  string filename(prefix);
     109  filename += FORCESFILE;
     110  std::ofstream ForcesFile(filename.c_str());
     111  SortIndex_t SortIndex;
    78112
    79113  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
    80   LOG(1, "Writing " << BondFragments.ListOfMolecules.size() << " possible bond fragmentation configs");
    81114  bool write_status = true;
    82   for (std::vector<std::string>::const_iterator iter = typelist.begin();
    83       iter != typelist.end();
    84       ++iter) {
    85     LOG(2, "INFO: Writing bond fragments for type " << (*iter) << ".");
     115  ExportGraph::SaturatedFragment_ptr CurrentFragment = getNextFragment();
     116  for (; (CurrentFragment != NULL) && (CurrentFragment->getKeySet() != ExportGraph::EmptySet);
     117      CurrentFragment = getNextFragment()) {
     118    const KeySet &set = CurrentFragment->getKeySet();
     119    LOG(2, "INFO: Writing bond fragments for set " << set << ".");
     120    // store config in stream
     121    {
     122      // open file
     123      FragmentNumber = FixedDigitNumber(TotalGraph.size(), FragmentCounter++);
     124      storeFragmentForAllTypes(
     125          CurrentFragment, FragmentNumber, FragmentCounter-1);
     126      delete[](FragmentNumber);
     127    }
     128    // store force index reference file
    86129    write_status = write_status
    87     && BondFragments.OutputConfigForListOfFragments(
    88         prefix,
    89         FormatParserStorage::getInstance().getTypeFromName(*iter));
    90   }
     130        && appendToForcesFile(CurrentFragment, ForcesFile, SortIndex);
     131    // explicitly release fragment
     132    CurrentFragment.reset();
     133  }
     134  if (CurrentFragment == NULL) {
     135    ELOG(1, "Some error while obtaining the next fragment occured.");
     136    return;
     137  }
     138  ForcesFile.close();
     139
    91140  if (write_status)
    92141    LOG(1, "All configs written.");
     
    94143    LOG(1, "Some config writing failed.");
    95144
    96   // store force index reference file
    97   {
    98     SortIndex_t SortIndex;
    99     BondFragments.StoreForcesFile(prefix, SortIndex);
    100   }
    101 
    102145  // store keysets file
    103146  TotalGraph.StoreKeySetFile(prefix);
    104147
    105148  // store Hydrogen saturation correction file
    106   BondFragments.AddHydrogenCorrection(prefix);
     149//  BondFragments.AddHydrogenCorrection(prefix);
    107150
    108151  // restore orbital and Stop values
     
    110153}
    111154
    112 
     155bool ExportGraph_ToFiles::storeFragmentForAllTypes(
     156    SaturatedFragment_ptr &CurrentFragment,
     157    char *FragmentNumber,
     158    size_t FragmentCounter) const
     159{
     160  bool write_status = true;
     161
     162  // go through all desired types
     163  for (std::vector<std::string>::const_iterator typeiter = typelist.begin();
     164      typeiter != typelist.end(); ++typeiter) {
     165    const std::string &typeName = *typeiter;
     166    const ParserTypes type =
     167        FormatParserStorage::getInstance().getTypeFromName(typeName);
     168    // create filenname and open
     169    const std::string FragmentName =
     170        prefix + FragmentNumber + "." + FormatParserStorage::getInstance().getSuffixFromType(type);
     171    std::ofstream outputFragment(FragmentName.c_str(), ios::out);
     172
     173    // write to this stream
     174    {
     175      std::stringstream output;
     176      output << "INFO: Saving bond fragment No. " << FragmentNumber << "/"
     177          << FragmentCounter << " as " << typeName << " ... ";
     178      const bool intermediate_result = CurrentFragment->OutputConfig(outputFragment,type);
     179      write_status &= intermediate_result;
     180      if (intermediate_result)
     181        output << " done.";
     182      else
     183        output << " failed.";
     184      LOG(2, output.str());
     185    }
     186
     187    // close file
     188    outputFragment.close();
     189    outputFragment.clear();
     190  }
     191
     192  return write_status;
     193}
     194
     195bool ExportGraph_ToFiles::appendToForcesFile(
     196    SaturatedFragment_ptr &CurrentFragment,
     197    std::ostream &ForcesFile,
     198    const SortIndex_t &SortIndex) const
     199{
     200  bool status = true;
     201//  periodentafel *periode=World::getInstance().getPeriode();
     202
     203  // open file for the force factors
     204  if (ForcesFile.good()) {
     205    //output << prefix << "Forces" << endl;
     206    const KeySet &FullMolecule = CurrentFragment->getFullMolecule();
     207    const KeySet &SaturationHydrogens = CurrentFragment->getSaturationHydrogens();
     208    for (KeySet::const_iterator keyiter = FullMolecule.begin();
     209        keyiter != FullMolecule.end();
     210        ++keyiter) {
     211      if (SaturationHydrogens.find(*keyiter) == SaturationHydrogens.end()) {
     212        ForcesFile << SortIndex.find(*keyiter) << "\t";
     213      } else {
     214        // otherwise a -1 to indicate an added saturation hydrogen
     215        ForcesFile << "-1\t";
     216      }
     217    }
     218//    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
     219//      periodentafel::const_iterator elemIter;
     220//      for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){
     221//        if ((*ListRunner)->hasElement((*elemIter).first)) { // if this element got atoms
     222//          for(molecule::iterator atomIter = (*ListRunner)->begin(); atomIter !=(*ListRunner)->end();++atomIter){
     223//            if ((*atomIter)->getType()->getAtomicNumber() == (*elemIter).first) {
     224//              if (((*atomIter)->GetTrueFather() != NULL) && ((*atomIter)->GetTrueFather() != (*atomIter))) {// if there is a rea
     225//                const atomId_t fatherid = (*atomIter)->GetTrueFather()->getId();
     226//                ForcesFile << SortIndex.find(fatherid) << "\t";
     227//              } else
     228//                // otherwise a -1 to indicate an added saturation hydrogen
     229//                ForcesFile << "-1\t";
     230//            }
     231//          }
     232//        }
     233//      }
     234//      ForcesFile << endl;
     235//    }
     236    ForcesFile << std::endl;
     237  } else {
     238    status = false;
     239    ELOG(1, "Failure on appending to ForcesFile.");
     240  }
     241
     242  return status;
     243}
  • src/Fragmentation/Exporters/ExportGraph_ToFiles.hpp

    rc39675 r7cdf58  
    4747
    4848private:
     49        /** Helper function to store a fragment for all desired types to file.
     50         *
     51         * \param CurrentFragment SaturatedFragment to store to file
     52         * \param FragmentNumber number padded with zeros used in filename
     53         * \param FragmentCounter enumeration of this fragment
     54         * \return true - file written successfully, false - writing failed
     55         */
     56        bool storeFragmentForAllTypes(
     57            SaturatedFragment_ptr &CurrentFragment,
     58            char *FragmentNumber,
     59            size_t FragmentCounter) const;
     60
     61        /** Helper function to append the key sets in this SaturatedFragment without
     62         * added hydrogens to an open stream.
     63         *
     64         * \param CurrentFragment fragment whose indices to write
     65   * \param ForcesFile open stream to write to
     66   * \param SortIndex Index to map from the BFS labeling to the sequence how of Ion_Type in the config
     67   * \return true - file written successfully, false - writing failed
     68   */
     69        bool appendToForcesFile(
     70            SaturatedFragment_ptr &CurrentFragment,
     71            std::ostream &ForcesFile,
     72            const SortIndex_t &SortIndex) const;
     73
     74private:
    4975        //!> prefix for fragment files
    5076        std::string prefix;
Note: See TracChangeset for help on using the changeset viewer.