Changeset 7a51be for src/Actions


Ignore:
Timestamp:
Feb 11, 2011, 9:37:26 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:
f649de
Parents:
170ba6
Message:

new function FormatParserStorage::get to obtain specialized FormatParser instance.

Location:
src/Actions/MoleculeAction
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp

    r170ba6 r7a51be  
    2323#include "bondgraph.hpp"
    2424#include "boundary.hpp"
     25#include "CodePatterns/Verbose.hpp"
    2526#include "config.hpp"
     27#include "Descriptors/MoleculeIdDescriptor.hpp"
     28#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2629#include "molecule.hpp"
    27 #include "CodePatterns/Verbose.hpp"
     30#include "Parser/FormatParserStorage.hpp"
    2831#include "World.hpp"
    2932
    30 #include "Descriptors/MoleculeIdDescriptor.hpp"
    31 #include "Parser/MpqcParser.hpp"
    32 #include "Parser/PcpParser.hpp"
    33 #include "Parser/PdbParser.hpp"
    34 #include "Parser/TremoloParser.hpp"
    35 #include "Parser/XyzParser.hpp"
    36 #include "Parser/FormatParserStorage.hpp"
    3733
    3834#include <algorithm>
     
    7066  ifstream input;
    7167  input.open(params.fillername.string().c_str());
    72   switch (FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix)) {
    73     case mpqc:
    74       {
    75         MpqcParser mpqcparser;
    76         mpqcparser.load(&input);
    77         break;
    78       }
    79     case pcp:
    80       {
    81         PcpParser pcpparser;
    82         pcpparser.load(&input);
    83         break;
    84       }
    85     case pdb:
    86       {
    87         PdbParser pdbparser;
    88         pdbparser.load(&input);
    89         break;
    90       }
    91     case tremolo:
    92       {
    93         TremoloParser tremoloparser;
    94         tremoloparser.load(&input);
    95         break;
    96       }
    97     case xyz:
    98       {
    99         XyzParser xyzparser;
    100         xyzparser.load(&input);
    101         break;
    102       }
    103     default:
    104       DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl);
    105       break;
    106   }
     68  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
     69  FormatParser &parser = FormatParserStorage::getInstance().get(type);
     70  parser.load(&input);
    10771
    10872  // search the filler molecule that has been just parsed
    109   molecule *filler = NULL;
    110   for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
    111       iter != World::getInstance().moleculeEnd();
    112       ++iter)
    113     filler = *iter; // get last molecule
     73  molecule *filler = World::getInstance().getMolecule(MoleculeByOrder(-1)); // get last molecule
    11474  filler->SetNameFromFilename(params.fillername.string().c_str());
    11575  World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
  • src/Actions/MoleculeAction/FillWithMoleculeAction.cpp

    r170ba6 r7a51be  
    2323#include "bondgraph.hpp"
    2424#include "boundary.hpp"
     25#include "CodePatterns/Verbose.hpp"
    2526#include "config.hpp"
     27#include "Descriptors/MoleculeIdDescriptor.hpp"
     28#include "Descriptors/MoleculeOrderDescriptor.hpp"
    2629#include "molecule.hpp"
    27 #include "CodePatterns/Verbose.hpp"
     30#include "Parser/FormatParserStorage.hpp"
    2831#include "World.hpp"
    2932
     
    5356      << ", DoRotate " << params.DoRotate << "." << endl);
    5457  // construct water molecule
    55   molecule *filler = World::getInstance().createMolecule();
    56   if (!filler->AddXYZFile(params.fillername.string())) {
    57     DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl);
    58   }
     58  std::vector<molecule *> presentmolecules = World::getInstance().getAllMolecules();
     59//  DoLog(0) && (Log() << Verbose(0) << presentmolecules.size() << " molecules initially are present." << std::endl);
     60  std::string FilenameSuffix = params.fillername.string().substr(params.fillername.string().find_last_of('.')+1, params.fillername.string().length());
     61  ifstream input;
     62  input.open(params.fillername.string().c_str());
     63  ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
     64  FormatParser &parser = FormatParserStorage::getInstance().get(type);
     65  parser.load(&input);
     66
     67  // search the filler molecule that has been just parsed
     68  molecule *filler = World::getInstance().getMolecule(MoleculeByOrder(-1)); // get last molecule
    5969  filler->SetNameFromFilename(params.fillername.string().c_str());
    60   molecule *Filling = NULL;
    61 //    atom *first = NULL, *second = NULL, *third = NULL;
    62 //    first = World::getInstance().createAtom();
    63 //    first->type = World::getInstance().getPeriode()->FindElement(1);
    64 //    first->x = Vector(0.441, -0.143, 0.);
    65 //    filler->AddAtom(first);
    66 //    second = World::getInstance().createAtom();
    67 //    second->type = World::getInstance().getPeriode()->FindElement(1);
    68 //    second->x = Vector(-0.464, 1.137, 0.0);
    69 //    filler->AddAtom(second);
    70 //    third = World::getInstance().createAtom();
    71 //    third->type = World::getInstance().getPeriode()->FindElement(8);
    72 //    third->x = Vector(-0.464, 0.177, 0.);
    73 //    filler->AddAtom(third);
    74 //    filler->AddBond(first, third, 1);
    75 //    filler->AddBond(second, third, 1);
    7670  World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
    77 //    filler->SetNameFromFilename("water");
     71  // TODO: Remove the erasure of molecule when saving does not depend on them anymore.
     72  World::getInstance().getMolecules()->erase(filler); // remove it, Parser adds it automatically
     73
    7874  // call routine
    7975  double distance[NDIM];
    8076  for (int i=0;i<NDIM;i++)
    8177    distance[i] = params.distances[i];
    82   Filling = FillBoxWithMolecule(
     78  FillBoxWithMolecule(
    8379      World::getInstance().getMolecules(),
    8480      filler, *(World::getInstance().getConfig()),
     
    8985      params.RandMoleculeDisplacement,
    9086      params.DoRotate);
    91   if (Filling != NULL) {
    92     Filling->ActiveFlag = false;
    93     World::getInstance().getMolecules()->insert(Filling);
    94   }
    9587  for (molecule::iterator iter = filler->begin(); !filler->empty(); iter = filler->begin()) {
    9688    atom *Walker = *iter;
     
    10092  World::getInstance().destroyMolecule(filler);
    10193
    102   return Action::success;
     94  // generate list of newly created molecules
     95  // (we can in general remove more quickly from a list than a vector)
     96  std::vector<molecule *> fillermolecules = World::getInstance().getAllMolecules();
     97//  DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules are present." << std::endl);
     98  std::list<molecule *> fillermolecules_list;
     99  std::copy( fillermolecules.begin(),  fillermolecules.end(), std::back_inserter( fillermolecules_list ));
     100//  DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules have been copied." << std::endl);
     101  for (std::vector<molecule *>::const_iterator iter = presentmolecules.begin();
     102      iter != presentmolecules.end();
     103      ++iter) {
     104    fillermolecules_list.remove(*iter);
     105  }
     106//  DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules left after removal." << std::endl);
     107  fillermolecules.clear();
     108  std::copy(fillermolecules_list.begin(), fillermolecules_list.end(), std::back_inserter( fillermolecules ));
     109
     110//  DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules have been inserted." << std::endl);
     111
     112  return Action::state_ptr(new MoleculeFillWithMoleculeState(fillermolecules,params));
    103113}
    104114
    105115Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) {
    106 //  MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
     116  MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
    107117
    108 //  string newName = state->mol->getName();
    109 //  state->mol->setName(state->lastName);
     118  MoleculeListClass *MolList = World::getInstance().getMolecules();
    110119
    111   return Action::failure;
     120  BOOST_FOREACH(molecule *_mol, state->fillermolecules) {
     121    MolList->erase(_mol);
     122    if ((_mol != NULL) && (!(World::getInstance().getAllMolecules(MoleculeById(_mol->getId()))).empty())) {
     123      for(molecule::iterator iter = _mol->begin();
     124          !_mol->empty();
     125          iter = _mol->begin()) {
     126        atom *Walker = *iter;
     127        _mol->erase(iter);
     128        World::getInstance().destroyAtom(Walker);
     129      }
     130      World::getInstance().destroyMolecule(_mol);
     131    }
     132  }
     133
     134  // as molecules and atoms from state are removed, we have to create a new one
     135  std::vector<molecule *> fillermolecules;
     136  return Action::state_ptr(new MoleculeFillWithMoleculeState(fillermolecules,state->params));
    112137}
    113138
    114139Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){
    115   // Undo and redo have to do the same for this action
    116   return performUndo(_state);
     140  //MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
     141
     142  return Action::failure;
     143  //return Action::state_ptr(_state);
    117144}
    118145
    119146bool MoleculeFillWithMoleculeAction::canUndo() {
    120   return false;
     147  return true;
    121148}
    122149
    123150bool MoleculeFillWithMoleculeAction::shouldUndo() {
    124   return false;
     151  return true;
    125152}
    126153/** =========== end of function ====================== */
  • src/Actions/MoleculeAction/FillWithMoleculeAction.def

    r170ba6 r7a51be  
    1919#define paramreferences (fillername)(distances)(boundary)(RandAtomDisplacement)(RandMoleculeDisplacement)(MaxDistance)(DoRotate)
    2020
    21 #undef statetypes
    22 #undef statereferences
     21#define statetypes (std::vector<molecule *>)
     22#define statereferences (fillermolecules)
    2323
    2424// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.