Changeset 3d2559 for src


Ignore:
Timestamp:
Feb 27, 2013, 12:43:29 PM (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:
da2d5c
Parents:
dbcc47
git-author:
Frederik Heber <heber@…> (12/18/12 12:39:10)
git-committer:
Frederik Heber <heber@…> (02/27/13 12:43:29)
Message:

Added virtual stream_to/from functions to SerializablePotential.

  • this allows overriding in SaturationPotential and hence printing/parsing of both contained types.
Location:
src/Potentials
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/SerializablePotential.cpp

    rdbcc47 r3d2559  
    5151std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential)
    5252{
     53  potential.stream_to(ost);
     54  return ost;
     55}
     56
     57void SerializablePotential::stream_to(std::ostream &ost) const
     58{
    5359  // check stream
    5460  if (ost.bad())
     
    5662
    5763  /// print parameter key
    58   ost << potential.getToken() << ":";
     64  ost << getToken() << ":";
    5965  /// print associated particles
    60   const SerializablePotential::ParticleTypes_t &types = potential.getParticleTypes();
     66  const SerializablePotential::ParticleTypes_t &types = getParticleTypes();
    6167  for (size_t index=0; index < types.size(); ++index) {
    6268    ost << "\tparticle_type" << index+1 << "=" << types[index];
     
    6470  }
    6571  /// print coefficients
    66   const SerializablePotential::ParameterNames_t &paramNames = potential.getParameterNames();
    67   const SerializablePotential::parameters_t &params = potential.getParameters();
     72  const SerializablePotential::ParameterNames_t &paramNames = getParameterNames();
     73  const SerializablePotential::parameters_t &params = getParameters();
    6874  SerializablePotential::ParameterNames_t::const_iterator nameiter = paramNames.begin();
    6975  SerializablePotential::parameters_t::const_iterator valueiter = params.begin();
     
    7682  /// print terminating semi-colon
    7783  ost << ";";
    78   return ost;
    7984}
    8085
    8186std::istream& operator>>(std::istream &ist, SerializablePotential &potential)
     87{
     88  potential.stream_from(ist);
     89  return ist;
     90}
     91
     92void SerializablePotential::stream_from(std::istream &ist)
    8293{
    8394  // check stream
     
    8697
    8798  // create copy of current parameters, hence line may contain not all required
    88   SerializablePotential::parameters_t params(potential.getParameters());
     99  SerializablePotential::parameters_t params(getParameters());
    89100
    90101  // read in full line
     
    95106  const size_t colonpos = linestring.find(":");
    96107  if ((strBegin == std::string::npos) || (colonpos == std::string::npos) ||
    97       (linestring.substr(strBegin, colonpos-1) != potential.getToken()))
     108      (linestring.substr(strBegin, colonpos-1) != getToken()))
    98109    throw SerializablePotentialMissingValueException()
    99         << SerializablePotentialKey(potential.getName());
     110        << SerializablePotentialKey(getName());
    100111
    101112  // tokenize by ","
     
    130141        throw SerializablePotentialMissingValueException() << SerializablePotentialKey(key);
    131142      const std::string &value = *keyvalue_iter;
    132       potential.setParticleType(index, ConvertToParticleType(value));
     143      setParticleType(index, ConvertToParticleType(value));
    133144    } else {
    134       const size_t index = potential.getParameterIndex(key);
     145      const size_t index = getParameterIndex(key);
    135146      // parse the coefficients
    136147      if (index != (size_t)-1) {
     
    146157
    147158  /// set the new paremeters
    148   potential.setParameters(params);
    149   return ist;
     159  setParameters(params);
    150160}
    151161
  • src/Potentials/SerializablePotential.hpp

    rdbcc47 r3d2559  
    3737class SerializablePotential
    3838{
    39   //!> grant operator access to private functions
    40   friend std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
    41   //!> grant operator access to private functions
    42   friend std::istream& operator>>(std::istream &ost, SerializablePotential &potential);
    43 
    4439public:
    4540  //!> typedef for particle designation
     
    113108  const size_t getParameterIndex(const std::string &_name) const;
    114109
     110  /** Print parameters to given stream \a ost.
     111   *
     112   * These are virtual functions to allow for overriding and hence
     113   * changing the default behavior.
     114   *
     115   * @param ost stream to print to
     116   */
     117  virtual void stream_to(std::ostream &ost) const;
     118
     119  /** Parse parameters from given stream \a ist.
     120   *
     121   * These are virtual functions to allow for overriding and hence
     122   * changing the default behavior.
     123   *
     124   * @param ist stream to parse from
     125   */
     126  virtual void stream_from(std::istream &ist);
     127
    115128protected:
    116129
  • src/Potentials/Specifics/SaturationPotential.cpp

    rdbcc47 r3d2559  
    174174  params[angle_equilibrium_distance] = angle_params[PairPotential_Angle::equilibrium_distance];
    175175  return params;
     176}
     177
     178void SaturationPotential::stream_to(std::ostream &ost) const
     179{
     180  morse.stream_to(ost);
     181  ost << std::endl;
     182  angle.stream_to(ost);
     183}
     184
     185void SaturationPotential::stream_from(std::istream &ist)
     186{
     187  morse.stream_from(ist);
     188  ist >> ws;
     189  angle.stream_from(ist);
    176190}
    177191
     
    379393      "SaturationPotential::symmetrizeTypes() - failed to generate three types for angle.");
    380394  return types;
    381 }
    382 
    383 std::ostream& operator<<(std::ostream &ost, const SaturationPotential &potential)
    384 {
    385   ost << potential.morse;
    386   ost << potential.angle;
    387   return ost;
    388 }
    389 
    390 std::istream& operator>>(std::istream &ist, SaturationPotential &potential)
    391 {
    392   ist >> potential.morse;
    393   ist >> potential.angle;
    394   return ist;
    395395}
    396396
  • src/Potentials/Specifics/SaturationPotential.hpp

    rdbcc47 r3d2559  
    128128  { return ParameterNames; }
    129129
     130  /** Print parameters for both Morse and Angle potential.
     131   *
     132   * We override default parameter printing of SeralizablePotential
     133   * to print both parameters
     134   *
     135   * @param ost stream to print to
     136   */
     137  virtual void stream_to(std::ostream &ost) const;
     138
     139  /** Parse parameters for both Morse and Angle potential.
     140   *
     141   * We override default parameter parsing of SeralizablePotential
     142   * to parse both parameters
     143   *
     144   * @param ist stream to parse from
     145   */
     146  virtual void stream_from(std::istream &ist);
     147
    130148  /** States whether lower and upper boundaries should be used to constraint
    131149   * the parameter search for this function model.
     
    198216};
    199217
    200 /** Output operations stores .potentials line containing these parameters
    201  * coefficients and designations.
    202  *
    203  * \note We have to overrride this function in order to print both potentials
    204  * separately.
    205  *
    206  * \param ost output stream to print to
    207  * \param potential potential whose coefficients to print
    208  * \return output stream for concatenation
    209  */
    210 std::ostream& operator<<(std::ostream &ost, const SaturationPotential &potential);
    211 
    212 /** Input operation parses coefficients from a given line of a .potentials
    213  * file.
    214  *
    215  * \note We have to override this function in order to parse both potentials
    216  * separately.
    217  *
    218  * \param ist input stream to parse from
    219  * \param potential potential to set
    220  * \return input stream for concatenation
    221  */
    222 std::istream& operator>>(std::istream &ist, SaturationPotential &potential);
    223218
    224219#endif /* SATURATIONPOTENTIAL_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.