source: src/Actions/GraphAction/SubgraphDissectionAction.cpp@ 22b786

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
Last change on this file since 22b786 was 22b786, checked in by Frederik Heber <heber@…>, 12 years ago

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.
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * SubgraphDissectionAction.cpp
25 *
26 * Created on: Mar 1, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "CodePatterns/Chronos.hpp"
38
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"
44
45#include "Descriptors/AtomDescriptor.hpp"
46
47#include "SubgraphDissectionAction.def"
48
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
70
71namespace MoleCuilder {
72
73// static instances
74ActionSequence GraphSubgraphDissectionAction::actions;
75bool GraphSubgraphDissectionAction::isPrepared = false;
76
77GraphSubgraphDissectionAction::GraphSubgraphDissectionAction() :
78 MakroAction(ActionTraits< GraphSubgraphDissectionAction >(), actions, false)
79{}
80
81GraphSubgraphDissectionAction::~GraphSubgraphDissectionAction()
82{}
83
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}
91
92void GraphSubgraphDissectionAction::unprepare(ActionRegistry &AR)
93{
94 // empty sequence
95 while (actions.removeLastAction() != NULL);
96 isPrepared = false;
97}
98
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;
119}
120
121Action::state_ptr GraphSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
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);
128
129 return state;
130}
131
132Action::state_ptr GraphSubgraphDissectionAction::performRedo(Action::state_ptr _state){
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;
141}
142
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
179}
Note: See TracBrowser for help on using the repository browser.