Changeset 0e894a


Ignore:
Timestamp:
Jul 12, 2017, 7:10:07 PM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps
Children:
33af20
Parents:
220d2c
git-author:
Frederik Heber <frederik.heber@…> (06/17/17 23:09:19)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:07)
Message:

Extracted getMinMaxTrajectories() into FormatParser_common.

Location:
src/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParser_common.cpp

    r220d2c r0e894a  
    3636
    3737#include <iostream>
    38 
     38#include <limits>
     39
     40#include "CodePatterns/Assert.hpp"
    3941#include "CodePatterns/Observer/Notification.hpp"
    4042#include "World.hpp"
     
    179181  return iter->second;
    180182}
     183
     184std::pair<size_t, size_t> FormatParser_common::getMinMaxTrajectories(
     185    const std::vector<const atom *> &_atoms) const
     186{
     187  // get max and min trajectories
     188  size_t min_trajectories = std::numeric_limits<size_t>::max();
     189  size_t max_trajectories = std::numeric_limits<size_t>::min();
     190  for (std::vector<const atom *>::const_iterator iter = _atoms.begin();
     191      iter != _atoms.end();
     192      ++iter) {
     193    if (max_trajectories < (*iter)->getTrajectorySize())
     194      max_trajectories = (*iter)->getTrajectorySize();
     195    if (min_trajectories > (*iter)->getTrajectorySize())
     196      min_trajectories = (*iter)->getTrajectorySize();
     197  }
     198  // no atoms? Then, they all have same amount
     199  if (_atoms.size() == 0)
     200    min_trajectories = max_trajectories = 1;
     201  ASSERT(min_trajectories == max_trajectories,
     202      "FormatParser_common::getMinMaxTrajectories() - not all atoms have same number of trajectories: "
     203      +toString(min_trajectories)+" != "+toString(max_trajectories)+".");
     204
     205  return std::make_pair(min_trajectories, max_trajectories);
     206}
  • src/Parser/FormatParser_common.hpp

    r220d2c r0e894a  
    5656  int getLocalId(const int global) const;
    5757
     58  std::pair<size_t, size_t> getMinMaxTrajectories(
     59      const std::vector<const atom *> &_atoms) const;
     60
    5861private:
    5962  //!> Output stream to write to when save() is called.
  • src/Parser/PdbParser.cpp

    r220d2c r0e894a  
    198198
    199199  // check for maximum number of time steps
    200   size_t max_timesteps = 0;
    201   for (vector<const atom *>::const_iterator atomIt = AtomList.begin();
    202       atomIt != AtomList.end(); atomIt++) {
    203     const atom * _atom = *atomIt;
    204     LOG(4, "INFO: Atom " << _atom->getName() << " "
    205         << *dynamic_cast<const AtomInfo *>(_atom) << ".");
    206     if (_atom->getTrajectorySize() > max_timesteps)
    207       max_timesteps = _atom->getTrajectorySize();
    208   }
    209   LOG(2,"INFO: Found a maximum of " << max_timesteps << " time steps to store.");
     200  std::pair<size_t, size_t> minmax_trajectories =
     201      getMinMaxTrajectories(AtomList);
     202  LOG(2, "INFO: There are " << minmax_trajectories.second << " steps to save.");
    210203
    211204  // re-distribute serials
     
    222215
    223216  // store all time steps (always do first step)
    224   for (size_t step = 0; (step == 0) || (step < max_timesteps); ++step) {
     217  for (size_t step = 0; (step == 0) || (step < minmax_trajectories.second); ++step) {
    225218    {
    226219      // add initial remark
  • src/Parser/XyzParser.cpp

    r220d2c r0e894a  
    169169
    170170  // get max and min trajectories
    171   size_t min_trajectories = std::numeric_limits<size_t>::max();
    172   size_t max_trajectories = std::numeric_limits<size_t>::min();
    173   for (std::vector<const atom *>::const_iterator iter = atoms.begin();
    174       iter != atoms.end();
    175       ++iter) {
    176     if (max_trajectories < (*iter)->getTrajectorySize())
    177       max_trajectories = (*iter)->getTrajectorySize();
    178     if (min_trajectories > (*iter)->getTrajectorySize())
    179       min_trajectories = (*iter)->getTrajectorySize();
    180   }
    181   // no atoms? Then, they all have same amount
    182   if (atoms.size() == 0)
    183     min_trajectories = max_trajectories = 1;
    184   ASSERT(min_trajectories == max_trajectories,
    185       "FormatParser< xyz >::save() - not all atoms have same number of trajectories: "
    186       +toString(min_trajectories)+" != "+toString(max_trajectories)+".");
    187   LOG(2, "INFO: There are " << max_trajectories << " steps to save.");
     171  std::pair<size_t, size_t> minmax_trajectories =
     172      getMinMaxTrajectories(atoms);
     173  LOG(2, "INFO: There are " << minmax_trajectories.second << " steps to save.");
    188174
    189175  // always store at least one step
    190   for (size_t step = 0; (step < max_trajectories) || (step == 0); ++step) {
     176  for (size_t step = 0; (step < minmax_trajectories.second) || (step == 0); ++step) {
    191177    if (step != 0)
    192178      *file << "\n";
Note: See TracChangeset for help on using the changeset viewer.