Changeset 73916f for src/Parser


Ignore:
Timestamp:
Dec 16, 2010, 5:32:22 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:
fc5c3a
Parents:
512f85
git-author:
Frederik Heber <heber@…> (12/11/10 15:57:00)
git-committer:
Frederik Heber <heber@…> (12/16/10 17:32:22)
Message:

Extended FormatParser::save() to use vector<atom *> to save.

  • This is needed to make the save functions also work on selected atoms or molecules only.
  • Within ParserCommonUnitTest, ParserTremoloUnitTest we create the vector by calling World's getAllAtoms() (which would have been done before in the specialized save() functions).
  • new functions in FormatParserStorage:
    • saveSelectedAtoms().
    • saveSelectedMolecules().
    • saveWorld().
  • renamed ::get() and ::put() to ::load() and ::save() to have it more consistent with underlying FormatParser functions and also to avoid misinterpretation with all ::get...() functions.
Location:
src/Parser
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParser.cpp

    r512f85 r73916f  
    5252  }
    5353
    54   save(saveStream);
     54  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     55  save(saveStream, atoms);
    5556}
    5657
  • src/Parser/FormatParser.hpp

    r512f85 r73916f  
    1313#include "parser.hpp"
    1414
     15class atom;
     16
    1517/**
    1618 * General parser which observes the change tracker.
     
    2022  FormatParser();
    2123  virtual ~FormatParser();
    22   virtual void save(std::ostream* file)=0;
     24  virtual void save(std::ostream* file, const std::vector<atom *> &atoms)=0;
    2325  virtual void load(std::istream* file)=0;
    2426  void setOstream(std::ostream* file);
  • src/Parser/FormatParserStorage.cpp

    r512f85 r73916f  
    3636
    3737#include "Helpers/Assert.hpp"
     38
     39#include "molecule.hpp"
    3840
    3941#include "Patterns/Singleton_impl.hpp"
     
    224226 * \return true - parsing ok, false - suffix unknown
    225227 */
    226 bool FormatParserStorage::get(std::istream &input, std::string suffix)
     228bool FormatParserStorage::load(std::istream &input, std::string suffix)
    227229{
    228230  if (suffix == ParserSuffixes[mpqc]) {
     
    243245}
    244246
     247/** Stores all selected atoms in an ostream depending on its suffix
     248 * \param &output output stream
     249 * \param suffix
     250 * \return true - storing ok, false - suffix unknown
     251 */
     252bool FormatParserStorage::saveSelectedAtoms(std::ostream &output, std::string suffix)
     253{
     254  std::vector<atom *> atoms = World::getInstance().getSelectedAtoms();
     255  return save(output, suffix, atoms);
     256}
     257
     258/** Stores all selected atoms in an ostream depending on its suffix
     259 * We store in the order of the atomic ids, not in the order they appear in the molecules.
     260 * Hence, we first create a vector from all selected molecules' atoms.
     261 * \param &output output stream
     262 * \param suffix
     263 * \return true - storing ok, false - suffix unknown
     264 */
     265bool FormatParserStorage::saveSelectedMolecules(std::ostream &output, std::string suffix)
     266{
     267  std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
     268  std::map<size_t, atom *> IdAtoms;
     269  for (std::vector<molecule *>::const_iterator MolIter = molecules.begin();
     270      MolIter != molecules.end();
     271      ++MolIter) {
     272    for(molecule::atomSet::const_iterator AtomIter = (*MolIter)->begin();
     273        AtomIter != (*MolIter)->end();
     274        ++AtomIter) {
     275      IdAtoms.insert( make_pair((*AtomIter)->getId(), (*AtomIter)) );
     276    }
     277  }
     278  std::vector<atom *> atoms;
     279  atoms.reserve(IdAtoms.size());
     280  for (std::map<size_t, atom *>::const_iterator iter = IdAtoms.begin();
     281      iter != IdAtoms.end();
     282      ++iter) {
     283    atoms.push_back(iter->second);
     284  }
     285  return save(output, suffix, atoms);
     286}
    245287
    246288/** Stores world in an ostream depending on its suffix
     
    249291 * \return true - storing ok, false - suffix unknown
    250292 */
    251 bool FormatParserStorage::put(std::ostream &output, std::string suffix)
     293bool FormatParserStorage::saveWorld(std::ostream &output, std::string suffix)
     294{
     295  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     296  return save(output, suffix, atoms);
     297}
     298
     299/** Stores a given vector of \a atoms in an ostream depending on its suffix
     300 * \param &output output stream
     301 * \param suffix
     302 * \return true - storing ok, false - suffix unknown
     303 */
     304bool FormatParserStorage::save(std::ostream &output, std::string suffix, const std::vector<atom *> &atoms)
    252305{
    253306  if (suffix == ParserSuffixes[mpqc]) {
    254     getMpqc().save(&output);
     307    getMpqc().save(&output, atoms);
    255308  } else if (suffix == ParserSuffixes[pcp]) {
    256     getPcp().save(&output);
     309    getPcp().save(&output, atoms);
    257310  } else if (suffix == ParserSuffixes[pdb]) {
    258     getPdb().save(&output);
     311    getPdb().save(&output, atoms);
    259312  } else if (suffix == ParserSuffixes[tremolo]) {
    260     getTremolo().save(&output);
     313    getTremolo().save(&output, atoms);
    261314  } else if (suffix == ParserSuffixes[xyz]) {
    262     getXyz().save(&output);
     315    getXyz().save(&output, atoms);
    263316  } else {
    264317    DoeLog(1) && (eLog() << Verbose(1) << "Unknown suffix " << suffix << " to for FormatParserStorage::put()." << endl);
  • src/Parser/FormatParserStorage.hpp

    r512f85 r73916f  
    2020#include <vector>
    2121
     22class atom;
    2223class FormatParser;
    2324class MpqcParser;
     
    4546  bool add(ParserTypes type);
    4647
    47   bool get(std::istream &input, std::string suffix);
    48   bool put(std::ostream &output, std::string suffix);
     48  bool load(std::istream &input, std::string suffix);
     49  bool save(std::ostream &output, std::string suffix, const std::vector<atom *> &atoms);
     50  bool saveSelectedAtoms(std::ostream &output, std::string suffix);
     51  bool saveSelectedMolecules(std::ostream &output, std::string suffix);
     52  bool saveWorld(std::ostream &output, std::string suffix);
    4953  MpqcParser &getMpqc();
    5054  PcpParser &getPcp();
  • src/Parser/MpqcParser.cpp

    r512f85 r73916f  
    5353}
    5454
    55 void MpqcParser::save(ostream *file)
     55/**
     56 * Saves the \a atoms into as a MPQC file.
     57 *
     58 * \param file where to save the state
     59 * \param atoms atoms to store
     60 */
     61void MpqcParser::save(ostream *file, const std::vector<atom *> &atoms)
    5662{
    5763  DoLog(0) && (Log() << Verbose(0) << "Saving changes to MPQC ." << std::endl);
    5864
    5965  if (HessianPresent)
    60     saveHessian(file);
     66    saveHessian(file, atoms);
    6167  else
    62     saveSimple(file);
     68    saveSimple(file, atoms);
    6369}
    6470
    6571/** Saves all atoms and data into a MPQC config file without hessian.
    6672 * \param *file output stream
     73 * \param atoms atoms to store
    6774 */
    68 void MpqcParser::saveSimple(ostream *file)
     75void MpqcParser::saveSimple(ostream *file, const std::vector<atom *> &atoms)
    6976{
    7077  Vector center;
     
    112119/** Saves all atoms and data into a MPQC config file with hessian.
    113120 * \param *file output stream
     121 * \param atoms atoms to store
    114122 */
    115 void MpqcParser::saveHessian(ostream *file)
     123void MpqcParser::saveHessian(ostream *file, const std::vector<atom *> &atoms)
    116124{
    117125  Vector center;
  • src/Parser/MpqcParser.hpp

    r512f85 r73916f  
    2222  ~MpqcParser();
    2323  void load(std::istream* file);
    24   void save(std::ostream* file);
     24  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2525
    2626  void setHessian(bool hessian);
     
    3030  bool HessianPresent;
    3131
    32   void saveSimple(std::ostream *file);
    33   void saveHessian(std::ostream *file);
     32  void saveSimple(std::ostream *file, const std::vector<atom *> &atoms);
     33  void saveHessian(std::ostream *file, const std::vector<atom *> &atoms);
    3434};
    3535
  • src/Parser/PcpParser.cpp

    r512f85 r73916f  
    368368}
    369369
    370 /** Saves the World into a PCP config file.
    371  * \param *file output stream to save to
    372  */
    373 void PcpParser::save(std::ostream* file)
     370/**
     371 * Saves the \a atoms into as a PCP file.
     372 *
     373 * \param file where to save the state
     374 * \param atoms atoms to store
     375 */
     376void PcpParser::save(std::ostream* file, const std::vector<atom *> &atoms)
    374377{
    375378  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pcp." << std::endl);
     
    379382  if (!file->fail()) {
    380383    // calculate number of Psis
    381     vector<atom *> allatoms = World::getInstance().getAllAtoms();
    382     CalculateOrbitals(allatoms);
     384    CalculateOrbitals(atoms);
    383385    *file << "# ParallelCarParinello - main configuration file - created with molecuilder" << endl;
    384386    *file << endl;
     
    468470    *file << "RelativeCoord\t" << RelativeCoord << "\t# whether ion coordinates are relative (1) or absolute (0)" << endl;
    469471    map<int, int> ZtoIndexMap;
    470     OutputElements(file, allatoms, ZtoIndexMap);
    471     OutputAtoms(file, allatoms, ZtoIndexMap);
     472    OutputElements(file, atoms, ZtoIndexMap);
     473    OutputAtoms(file, atoms, ZtoIndexMap);
    472474  } else {
    473475    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file." << endl);
     
    479481 * \param &allatoms all atoms to store away
    480482 */
    481 void PcpParser::CalculateOrbitals(vector<atom *> &allatoms)
     483void PcpParser::CalculateOrbitals(const std::vector<atom *> &allatoms)
    482484{
    483485  PlaneWaveSpecifics.MaxPsiDouble = PlaneWaveSpecifics.PsiMaxNoDown = PlaneWaveSpecifics.PsiMaxNoUp = PlaneWaveSpecifics.PsiType = 0;
    484   for (vector<atom *>::iterator runner = allatoms.begin(); runner != allatoms.end(); ++runner) {
     486  for (vector<atom *>::const_iterator runner = allatoms.begin(); runner != allatoms.end(); ++runner) {
    485487    PlaneWaveSpecifics.MaxPsiDouble += (*runner)->getType()->getNoValenceOrbitals();
    486488  }
     
    512514 * \param &ZtoIndexMap map of which atoms belong to which ion number
    513515 */
    514 void PcpParser::OutputElements(ostream *file, vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     516void PcpParser::OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    515517{
    516518  map<int, int> PresentElements;
    517519  pair <   map<int, int>::iterator, bool > Inserter;
    518520  // insert all found elements into the map
    519   for (vector<atom *>::iterator AtomRunner = allatoms.begin();AtomRunner != allatoms.end();++AtomRunner) {
     521  for (vector<atom *>::const_iterator AtomRunner = allatoms.begin();AtomRunner != allatoms.end();++AtomRunner) {
    520522    Inserter = PresentElements.insert(pair<int, int>((*AtomRunner)->getType()->getAtomicNumber(), 1));
    521523    if (!Inserter.second) // increase if present
     
    542544 * \param &ZtoIndexMap map of which atoms belong to which ion number
    543545 */
    544 void PcpParser::OutputAtoms(ostream *file, vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
     546void PcpParser::OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap)
    545547{
    546548  *file << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl;
     
    548550  pair <   map<int, int>::iterator, bool > Inserter;
    549551  int nr = 0;
    550   for (vector<atom *>::iterator AtomRunner = allatoms.begin();AtomRunner != allatoms.end();++AtomRunner) {
     552  for (vector<atom *>::const_iterator AtomRunner = allatoms.begin();AtomRunner != allatoms.end();++AtomRunner) {
    551553    Inserter = ZtoCountMap.insert( pair<int, int>((*AtomRunner)->getType()->getAtomicNumber(), 1) );
    552554    if (!Inserter.second)
  • src/Parser/PcpParser.hpp

    r512f85 r73916f  
    2020  ~PcpParser();
    2121  void load(std::istream* file);
    22   void save(std::ostream* file);
     22  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2323
    2424  bool operator==(const PcpParser& b) const;
     
    2727
    2828  void ParseThermostats(class ConfigFileBuffer * const fb);
    29   void OutputAtoms(ostream *file, vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
    30   void OutputElements(ostream *file, vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
    31   void CalculateOrbitals(vector<atom *> &allatoms);
     29  void OutputAtoms(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
     30  void OutputElements(ostream *file, const std::vector<atom *> &allatoms, map<int, int> &ZtoIndexMap);
     31  void CalculateOrbitals(const std::vector<atom *> &allatoms);
    3232
    3333  class StructParallelization {
  • src/Parser/PdbParser.cpp

    r512f85 r73916f  
    145145
    146146/**
    147  * Saves the World's current state into as a PDB file.
     147 * Saves the \a atoms into as a PDB file.
    148148 *
    149149 * \param file where to save the state
    150  */
    151 void PdbParser::save(ostream* file) {
     150 * \param atoms atoms to store
     151 */
     152void PdbParser::save(ostream* file, const std::vector<atom *> &AtomList)
     153{
    152154  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
    153155  {
     
    168170  atomIdMap.clear();
    169171  {
    170     std::vector<atom *> AtomList = World::getInstance().getAllAtoms();
    171     std::vector<molecule *> MolList = World::getInstance().getAllMolecules();
    172172    std::map<size_t,size_t> MolIdMap;
    173173    size_t MolNo = 1;  // residue number starts at 1 in pdb
    174     for (std::vector<molecule *>::const_iterator iter = MolList.begin();
    175         iter != MolList.end();
    176         ++iter) {
    177       MolIdMap[(*iter)->getId()] = MolNo++;
     174    for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     175      const molecule *mol = (*atomIt)->getMolecule();
     176      if ((mol != NULL) && (MolIdMap.find(mol->getId()) == MolIdMap.end())) {
     177        MolIdMap[mol->getId()] = MolNo++;
     178      }
    178179    }
    179180    const size_t MaxMol = MolNo;
     
    188189    // write ATOMs
    189190    int AtomNo = 1; // serial number starts at 1 in pdb
    190     for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     191    for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
    191192      PdbAtomInfoContainer &atomInfo = getadditionalAtomData(*atomIt);
    192193      // gather info about residue
     
    231232
    232233    // write CONECTs
    233     for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     234    for (vector<atom *>::const_iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
    234235      writeNeighbors(file, 4, *atomIt);
    235236    }
  • src/Parser/PdbParser.hpp

    r512f85 r73916f  
    2323  ~PdbParser();
    2424  void load(std::istream* file);
    25   void save(std::ostream* file);
     25  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2626
    2727  bool operator==(const PdbParser& b) const;
  • src/Parser/TremoloParser.cpp

    r512f85 r73916f  
    117117
    118118/**
    119  * Saves the World's current state into as a tremolo file.
     119 * Saves the \a atoms into as a tremolo file.
    120120 *
    121121 * \param file where to save the state
    122  */
    123 void TremoloParser::save(ostream* file) {
     122 * \param atoms atoms to store
     123 */
     124void TremoloParser::save(ostream* file, const std::vector<atom *> &AtomList) {
    124125  DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
    125126
    126   vector<atom*>::iterator atomIt;
     127  vector<atom*>::const_iterator atomIt;
    127128  vector<string>::iterator it;
    128129
     
    132133  }
    133134  *file << endl;
    134   vector<atom *> AtomList = World::getInstance().getAllAtoms();
    135135  for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
    136136    saveLine(file, *atomIt);
  • src/Parser/TremoloParser.hpp

    r512f85 r73916f  
    2626  ~TremoloParser();
    2727  void load(std::istream* file);
    28   void save(std::ostream* file);
     28  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2929  void setFieldsForSave(std::string atomDataLine);
    3030
  • src/Parser/XyzParser.cpp

    r512f85 r73916f  
    7878
    7979/**
    80  * Saves the current state of the World into the given XYZ file.
     80 * Saves the \a atoms into as a XYZ file.
    8181 *
    82  * \param XYZ file
     82 * \param file where to save the state
     83 * \param atoms atoms to store
    8384 */
    84 void XyzParser::save(ostream* file) {
     85void XyzParser::save(ostream* file, const std::vector<atom *> &atoms) {
    8586  DoLog(0) && (Log() << Verbose(0) << "Saving changes to xyz." << std::endl);
    8687  //if (comment == "") {
     
    9596      comment += time;
    9697  //}
    97   *file << World::getInstance().numAtoms() << endl << "\t" << comment << endl;
     98  *file << atoms.size() << endl << "\t" << comment << endl;
    9899
    99   vector<atom*> atoms = World::getInstance().getAllAtoms();
    100   for(vector<atom*>::iterator it = atoms.begin(); it != atoms.end(); it++) {
     100  for(vector<atom*>::const_iterator it = atoms.begin(); it != atoms.end(); it++) {
    101101    *file << noshowpoint << (*it)->getType()->getSymbol() << "\t" << (*it)->at(0) << "\t" << (*it)->at(1) << "\t" << (*it)->at(2) << endl;
    102102  }
  • src/Parser/XyzParser.hpp

    r512f85 r73916f  
    2020  ~XyzParser();
    2121  void load(std::istream* file);
    22   void save(std::ostream* file);
     22  void save(std::ostream* file, const std::vector<atom *> &atoms);
    2323
    2424private:
Note: See TracChangeset for help on using the changeset viewer.