Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    rcabb46 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);
Note: See TracChangeset for help on using the changeset viewer.