Ignore:
Timestamp:
Apr 8, 2013, 11:56:08 AM (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:
8652a30
Parents:
560cbf
git-author:
Frederik Heber <heber@…> (03/01/13 21:15:10)
git-committer:
Frederik Heber <heber@…> (04/08/13 11:56:08)
Message:

Made SubgraphDissection a MakroAction and added UpdateMoleculesAction.

  • MakroAction does not delete the ActionSequence eventually and it now obtains just a ref, not pointer.
  • TESTFIX: Changed ActionSequenceUnitTest::doesUndoTest() accordingly.
  • SubgraphDissection is right now still very ugly with lots of copy&paste from the preprocessor header files to get every function in place.
  • it could be made into a MakroAction because all three internal Actions do not require any options. How to achieve this with options is unsolved.
Location:
src/Actions/GraphAction
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GraphAction/SubgraphDissectionAction.cpp

    r560cbf r22b786  
    22 * Project: MoleCuilder
    33 * Description: creates and alters molecular systems
    4  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
     4 * Copyright (C)  2013 University of Bonn. All rights reserved.
    55 *
    66 *
     
    2424 * SubgraphDissectionAction.cpp
    2525 *
    26  *  Created on: May 9, 2010
     26 *  Created on: Mar 1, 2013
    2727 *      Author: heber
    2828 */
     
    3535#include "CodePatterns/MemDebug.hpp"
    3636
    37 #include "Descriptors/AtomIdDescriptor.hpp"
    38 #include "Descriptors/MoleculeDescriptor.hpp"
     37#include "CodePatterns/Chronos.hpp"
    3938
    40 #include "Atom/atom.hpp"
    41 #include "Bond/bond.hpp"
    42 #include "CodePatterns/Log.hpp"
    43 #include "CodePatterns/Verbose.hpp"
    44 #include "Graph/BondGraph.hpp"
    45 #include "Graph/DepthFirstSearchAnalysis.hpp"
    46 #include "molecule.hpp"
    47 #include "MoleculeListClass.hpp"
    48 #include "World.hpp"
     39#include "Actions/GraphAction/CreateAdjacencyAction.hpp"
     40#include "Actions/GraphAction/DestroyAdjacencyAction.hpp"
     41#include "Actions/GraphAction/UpdateMoleculesAction.hpp"
     42#include "Actions/GraphAction/SubgraphDissectionAction.hpp"
     43#include "Actions/ActionRegistry.hpp"
    4944
    50 #include <iostream>
    51 #include <string>
     45#include "Descriptors/AtomDescriptor.hpp"
    5246
    53 typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
    54 typedef std::map< atomId_t, atomId_t > AtomAtomList;
     47#include "SubgraphDissectionAction.def"
    5548
    56 #include "Actions/GraphAction/SubgraphDissectionAction.hpp"
     49// some derived names: if CATEGORY is not given, we don't prefix with it
     50#ifdef CATEGORY
     51#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
     52#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
     53#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
     54#else
     55#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
     56#define COMMAND ACTIONNAME
     57#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
     58#endif
     59// check if no lists given
     60#ifndef paramtypes
     61#define MAXPARAMTYPES 0
     62#else
     63#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
     64#endif
     65#ifndef paramdefaults
     66#define MAXPARAMDEFAULTS 0
     67#else
     68#define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
     69#endif
    5770
    58 using namespace MoleCuilder;
     71namespace MoleCuilder {
    5972
    60 // and construct the stuff
    61 #include "SubgraphDissectionAction.def"
    62 #include "Action_impl_pre.hpp"
    63 /** =========== define the function ====================== */
    64 Action::state_ptr GraphSubgraphDissectionAction::performCall() {
    65   // first create stuff for undo state
    66   LOG(0, "STATUS: Creating undo state.");
    67   MolAtomList moleculelist;
    68   vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
    69   for (vector<molecule *>::const_iterator moliter = allmolecules.begin(); moliter != allmolecules.end(); ++moliter) {
    70     std::vector<atomId_t> atomlist;
    71     atomlist.resize((*moliter)->size());
    72     for (molecule::const_iterator atomiter = (*moliter)->begin(); atomiter != (*moliter)->end(); ++atomiter) {
    73       atomlist.push_back((*atomiter)->getId());
    74     }
    75     moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist));
    76   }
    77   GraphSubgraphDissectionState *UndoState = new GraphSubgraphDissectionState(moleculelist, params);
     73// static instances
     74ActionSequence GraphSubgraphDissectionAction::actions;
     75bool GraphSubgraphDissectionAction::isPrepared = false;
    7876
    79   // 0a. remove all present molecules
    80   LOG(0, "STATUS: Removing all present molecules.");
    81   MoleculeListClass *molecules = World::getInstance().getMolecules();
    82   for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
    83     molecules->erase(*MolRunner);
    84     World::getInstance().destroyMolecule(*MolRunner);
    85   }
     77GraphSubgraphDissectionAction::GraphSubgraphDissectionAction() :
     78  MakroAction(ActionTraits< GraphSubgraphDissectionAction >(), actions, false)
     79{}
    8680
    87   // 1. create the bond structure of the single molecule
    88   LOG(0, "STATUS: (Re-)constructing adjacency.");
    89   BondGraph *BG = World::getInstance().getBondGraph();
    90   World::AtomComposite Set = World::getInstance().getAllAtoms();
    91   BG->CreateAdjacency(Set);
     81GraphSubgraphDissectionAction::~GraphSubgraphDissectionAction()
     82{}
    9283
    93   // 2. scan for connected subgraphs
    94   DepthFirstSearchAnalysis DFS;
    95   DFS();
    96   DFS.UpdateMoleculeStructure();
    97   if (World::getInstance().numMolecules() == 0) {
    98     //World::getInstance().destroyMolecule(mol);
    99     ELOG(1, "There are no molecules.");
    100     return Action::failure;
    101   }
     84void GraphSubgraphDissectionAction::prepare(ActionRegistry &AR)
     85{
     86  actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
     87  actions.addAction(AR.getActionByName(std::string("create-adjacency")));
     88  actions.addAction(AR.getActionByName(std::string("update-molecules")));
     89  isPrepared = true;
     90}
    10291
    103   LOG(1, "I scanned " << World::getInstance().numMolecules() << " molecules.");
     92void GraphSubgraphDissectionAction::unprepare(ActionRegistry &AR)
     93{
     94  // empty sequence
     95  while (actions.removeLastAction() != NULL);
     96  isPrepared = false;
     97}
    10498
    105   return Action::state_ptr(UndoState);
     99void reselectAtoms(const std::vector<atom *> &selected_atoms)
     100{
     101  World::getInstance().clearAtomSelection();
     102  for (std::vector<atom *>::const_iterator iter = selected_atoms.begin();
     103      iter != selected_atoms.end();
     104      ++iter)
     105    World::getInstance().selectAtom(*iter);
     106}
     107
     108Action::state_ptr GraphSubgraphDissectionAction::performCall(){
     109  // we need to "emulate" that all atoms have been selected without destroying
     110  // current selection
     111  Chronos::getInstance().startTiming(TOKEN);
     112  const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
     113  World::getInstance().selectAllAtoms(AllAtoms());
     114  Action::state_ptr state(MakroAction::performCall());
     115  reselectAtoms(selected_atoms);
     116  Chronos::getInstance().endTiming(TOKEN);
     117
     118  return state;
    106119}
    107120
    108121Action::state_ptr GraphSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
    109   GraphSubgraphDissectionState *state = assert_cast<GraphSubgraphDissectionState*>(_state.get());
     122  // we need to "emulate" that all atoms have been selected without destroying
     123  // current selection
     124  const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
     125  World::getInstance().selectAllAtoms(AllAtoms());
     126  Action::state_ptr state(MakroAction::performUndo(_state));
     127  reselectAtoms(selected_atoms);
    110128
    111   {
    112     // remove all present molecules
    113     MoleculeListClass *molecules = World::getInstance().getMolecules();
    114     vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
    115     for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
    116       molecules->erase(*MolRunner);
    117       World::getInstance().destroyMolecule(*MolRunner);
    118     }
    119   }
    120 
    121   {
    122     // construct the old state
    123     MoleculeListClass *molecules = World::getInstance().getMolecules();
    124     molecule *mol = NULL;
    125     for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
    126       mol = World::getInstance().createMolecule();
    127       if (mol->getId() != (*iter).first)
    128         World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
    129       for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter) {
    130         atom *Walker = World::getInstance().getAtom(AtomById(*atomiter));
    131         mol->AddAtom(Walker);
    132       }
    133       molecules->insert(mol);
    134     }
    135   }
    136 
    137   return Action::state_ptr(_state);
     129  return state;
    138130}
    139131
    140132Action::state_ptr GraphSubgraphDissectionAction::performRedo(Action::state_ptr _state){
    141   return performCall();
     133  // we need to "emulate" that all atoms have been selected without destroying
     134  // current selection
     135  const std::vector<atom *> selected_atoms = World::getInstance().getSelectedAtoms();
     136  World::getInstance().selectAllAtoms(AllAtoms());
     137  Action::state_ptr state(MakroAction::performRedo(_state));
     138  reselectAtoms(selected_atoms);
     139
     140  return state;
    142141}
    143142
    144 bool GraphSubgraphDissectionAction::canUndo() {
    145   return true;
     143// =========== command for calling action directly ===========
     144void COMMAND(
     145#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     146#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
     147#define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
     148#include BOOST_PP_LOCAL_ITERATE()
     149#endif
     150)
     151{
     152  ACTION *ToCall = dynamic_cast<ACTION*>(ActionRegistry::getInstance().getActionByName( TOKEN )); //->clone(params);
     153  //ACTION::PARAMS params;
     154#if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     155#define BOOST_PP_LOCAL_MACRO(n) value_print(~, n, paramreferences, ToCall->params.)
     156#define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
     157#include BOOST_PP_LOCAL_ITERATE()
     158#endif
     159  ToCall->call(Action::NonInteractive);
     160};
     161
     162void BOOST_PP_CAT( COMMAND, _stringargs)(
     163#if defined paramtypes && defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     164#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, , paramtypes), paramreferences)
     165#define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
     166#include BOOST_PP_LOCAL_ITERATE()
     167#endif
     168  ) {
     169  ACTION *ToCall = dynamic_cast<ACTION*>(ActionRegistry::getInstance().getActionByName( TOKEN )); //->clone(params);
     170  //ACTION::PARAMS params;
     171#if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     172#define BOOST_PP_LOCAL_MACRO(n) valuetype_print(~, n, paramreferences, paramtypes, ToCall->params. )
     173#define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
     174#include BOOST_PP_LOCAL_ITERATE()
     175#endif
     176  ToCall->call(MoleCuilder::Action::NonInteractive);
     177};
     178
    146179}
    147 
    148 bool GraphSubgraphDissectionAction::shouldUndo() {
    149   return true;
    150 }
    151 /** =========== end of function ====================== */
  • src/Actions/GraphAction/SubgraphDissectionAction.def

    r560cbf r22b786  
    22 * SubgraphDissectionAction.def
    33 *
    4  *  Created on: Aug 26, 2010
     4 *  Created on: Mar 1, 2013
    55 *      Author: heber
    66 */
  • src/Actions/GraphAction/SubgraphDissectionAction.hpp

    r560cbf r22b786  
    22 * SubgraphDissectionAction.hpp
    33 *
    4  *  Created on: May 9, 2010
     4 *  Created on: Mar 1, 2013
    55 *      Author: heber
    66 */
     
    1414#endif
    1515
    16 
    17 #include "Actions/Action.hpp"
     16#include "Actions/ActionSequence.hpp"
     17#include "Actions/ActionTraits.hpp"
     18#include "Actions/MakroAction.hpp"
    1819
    1920#include "SubgraphDissectionAction.def"
    20 #include "Action_impl_header.hpp"
     21
     22// some derived names: if CATEGORY is not given, we don't prefix with it
     23#ifdef CATEGORY
     24#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
     25#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
     26#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
     27#else
     28#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
     29#define COMMAND ACTIONNAME
     30#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
     31#endif
     32// check if no lists given
     33#ifndef paramtypes
     34#define MAXPARAMTYPES 0
     35#else
     36#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtypes)
     37#endif
     38#ifndef paramdefaults
     39#define MAXPARAMDEFAULTS 0
     40#else
     41#define MAXPARAMDEFAULTS BOOST_PP_SEQ_SIZE(paramdefaults)
     42#endif
     43
     44namespace MoleCuilder {
     45
     46// print a list of type ref followed, i.e. "int i, double position"
     47#define type_list(z,n,TYPELIST, VARLIST) \
     48  BOOST_PP_COMMA_IF(n)\
     49  BOOST_PP_SEQ_ELEM(n, TYPELIST) \
     50  BOOST_PP_SEQ_ELEM(n, VARLIST)
     51
     52void COMMAND(
     53#if defined paramtypes && defined paramreferences
     54#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, paramtypes, paramreferences)
     55#define BOOST_PP_LOCAL_LIMITS  (0, MAXPARAMTYPES-1)
     56#include BOOST_PP_LOCAL_ITERATE()
     57#endif
     58    );
     59
     60class GraphSubgraphDissectionAction;
     61
     62template <>
     63class ActionTraits<ACTION> : public ActionTrait {
     64public:
     65  ActionTraits() :
     66#ifndef SHORTFORM
     67    ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string()))
     68#else
     69    ActionTrait(OptionTrait(TOKEN, &typeid(void), DESCRIPTION, std::string(), SHORTFORM))
     70#endif /* SHORTFORM */
     71  {
     72  // initialize remainder of action info
     73#ifdef MENUNAME
     74    MenuTitle = MENUNAME;
     75#endif
     76#ifdef MENUPOSITION
     77    MenuPosition = MENUPOSITION;
     78#endif
     79
     80    // we got no options to initialize
     81  }
     82
     83  virtual ~ActionTraits() {
     84    //std::cout << "ActionTraits<" << BOOST_PP_STRINGIZE(ACTION) << ">::~ActionTraits() on instance " << this << " with name " << getName() << " called." << std::endl;
     85  }
     86};
     87
     88class GraphSubgraphDissectionAction : public MakroAction
     89{
     90public:
     91  GraphSubgraphDissectionAction();
     92  virtual ~GraphSubgraphDissectionAction();
     93
     94  // must be called after all primitive actions are present
     95  void prepare(ActionRegistry &AR);
     96  // must be called before alle primitive actions are removed
     97  void unprepare(ActionRegistry &AR);
     98
     99  virtual Action::state_ptr performCall();
     100  virtual Action::state_ptr performUndo(Action::state_ptr);
     101  virtual Action::state_ptr performRedo(Action::state_ptr);
     102
     103private:
     104  //!> flag to check whether actions have been prepared
     105  static bool isPrepared;
     106  //!> sequence of actions for this macro action
     107  static ActionSequence actions;
     108};
     109
     110}
     111
     112#undef ACTION
     113#undef COMMAND
     114#undef COMMANDFULL
     115#undef PARAMS
     116
     117#undef ACTIONNAME
     118#undef CATEGORY
     119#undef MENUNAME
     120#undef MENUPOSITION
     121#undef TOKEN
     122
     123#undef DESCRIPTION
     124#undef SHORTFORM
    21125
    22126#endif /* SUBGRAPHDISSECTIONACTION_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.