source: src/Actions/MoleculeAction/FillWithMoleculeAction.cpp@ 0b2ce9

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 0b2ce9 was 0b2ce9, checked in by Frederik Heber <heber@…>, 15 years ago

Implemented macros for automatically generating repetitive stuff around Actions.

The idea is that only the following items have to be provided for by the user

  • parameters (i.e. for each the following tupel: type, token and reference)
  • perform...(), ...Undo(), ...

Therefore, we have three new files:

  • Action_impl_header.hpp: Is for the declarations in the header
  • Action_impl_pre.hpp: Is before definition of functions
  • Action_impl_post.hpp: is after definition of functions (cleanup)

Changes:

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * FillWithMoleculeAction.cpp
10 *
11 * Created on: May 10, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
23#include "Actions/ActionRegistry.hpp"
24#include "atom.hpp"
25#include "bondgraph.hpp"
26#include "boundary.hpp"
27#include "config.hpp"
28#include "molecule.hpp"
29#include "Helpers/Verbose.hpp"
30#include "World.hpp"
31
32
33#include <iostream>
34#include <string>
35
36using namespace std;
37
38#include "UIElements/UIFactory.hpp"
39#include "UIElements/Dialog.hpp"
40#include "Actions/ValueStorage.hpp"
41
42/****** MoleculeFillWithMoleculeAction *****/
43
44// memento to remember the state when undoing
45
46//class MoleculeFillWithMoleculeState : public ActionState {
47//public:
48// MoleculeFillWithMoleculeState(molecule* _mol,std::string _lastName) :
49// mol(_mol),
50// lastName(_lastName)
51// {}
52// molecule* mol;
53// std::string lastName;
54//};
55
56const char MoleculeFillWithMoleculeAction::NAME[] = "fill-molecule";
57
58MoleculeFillWithMoleculeAction::MoleculeFillWithMoleculeAction() :
59 Action(NAME)
60{}
61
62MoleculeFillWithMoleculeAction::~MoleculeFillWithMoleculeAction()
63{}
64
65void MoleculeFillWithMolecule(std::string &fillername, Vector &distances, Vector &lengths, double MaxDistance, bool DoRotate) {
66 ValueStorage::getInstance().setCurrentValue(MoleculeFillWithMoleculeAction::NAME, fillername);
67 ValueStorage::getInstance().setCurrentValue("distances", distances);
68 ValueStorage::getInstance().setCurrentValue("lengths", lengths);
69 ValueStorage::getInstance().setCurrentValue("DoRotate", MaxDistance);
70 ValueStorage::getInstance().setCurrentValue("MaxDistance", DoRotate);
71 ActionRegistry::getInstance().getActionByName(MoleculeFillWithMoleculeAction::NAME)->call(Action::NonInteractive);
72};
73
74void MoleculeFillWithMoleculeAction::getParametersfromValueStorage()
75{};
76
77Dialog* MoleculeFillWithMoleculeAction::fillDialog(Dialog *dialog) {
78 ASSERT(dialog,"No Dialog given when filling action dialog");
79
80 dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
81 dialog->queryVector("distances", false, ValueStorage::getInstance().getDescription("distances"));
82 dialog->queryVector("lengths", false, ValueStorage::getInstance().getDescription("lengths"));
83 dialog->queryBoolean("DoRotate", ValueStorage::getInstance().getDescription("DoRotate"));
84 dialog->queryDouble("MaxDistance", ValueStorage::getInstance().getDescription("MaxDistance"));
85
86 return dialog;
87}
88
89Action::state_ptr MoleculeFillWithMoleculeAction::performCall() {
90 string filename;
91 Vector distances;
92 Vector lengths;
93 double MaxDistance = -1.;
94 bool DoRotate = false;
95
96 ValueStorage::getInstance().queryCurrentValue(NAME, filename);
97 ValueStorage::getInstance().queryCurrentValue("distances", distances);
98 ValueStorage::getInstance().queryCurrentValue("lengths", lengths);
99 ValueStorage::getInstance().queryCurrentValue("DoRotate", DoRotate);
100 ValueStorage::getInstance().queryCurrentValue("MaxDistance", MaxDistance);
101
102 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << lengths[0] << "," << lengths[1] << "," << lengths[2] << "), distances (" << distances[0] << "," << distances[1] << "," << distances[2] << "), MaxDistance " << MaxDistance << ", DoRotate " << DoRotate << "." << endl);
103 // construct water molecule
104 molecule *filler = World::getInstance().createMolecule();
105 if (!filler->AddXYZFile(filename)) {
106 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << filename << "." << endl);
107 }
108 filler->SetNameFromFilename(filename.c_str());
109 molecule *Filling = NULL;
110// atom *first = NULL, *second = NULL, *third = NULL;
111// first = World::getInstance().createAtom();
112// first->type = World::getInstance().getPeriode()->FindElement(1);
113// first->x = Vector(0.441, -0.143, 0.);
114// filler->AddAtom(first);
115// second = World::getInstance().createAtom();
116// second->type = World::getInstance().getPeriode()->FindElement(1);
117// second->x = Vector(-0.464, 1.137, 0.0);
118// filler->AddAtom(second);
119// third = World::getInstance().createAtom();
120// third->type = World::getInstance().getPeriode()->FindElement(8);
121// third->x = Vector(-0.464, 0.177, 0.);
122// filler->AddAtom(third);
123// filler->AddBond(first, third, 1);
124// filler->AddBond(second, third, 1);
125 World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
126// filler->SetNameFromFilename("water");
127 // call routine
128 double distance[NDIM];
129 for (int i=0;i<NDIM;i++)
130 distance[i] = distances[i];
131 Filling = FillBoxWithMolecule(World::getInstance().getMolecules(), filler, *(World::getInstance().getConfig()), MaxDistance, distance, lengths[0], lengths[1], lengths[2], DoRotate);
132 if (Filling != NULL) {
133 Filling->ActiveFlag = false;
134 World::getInstance().getMolecules()->insert(Filling);
135 }
136 for (molecule::iterator iter = filler->begin(); !filler->empty(); iter = filler->begin()) {
137 atom *Walker = *iter;
138 filler->erase(iter);
139 World::getInstance().destroyAtom(Walker);
140 }
141 World::getInstance().destroyMolecule(filler);
142
143 return Action::success;
144}
145
146Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) {
147// MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
148
149// string newName = state->mol->getName();
150// state->mol->setName(state->lastName);
151
152 return Action::failure;
153}
154
155Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){
156 // Undo and redo have to do the same for this action
157 return performUndo(_state);
158}
159
160bool MoleculeFillWithMoleculeAction::canUndo() {
161 return false;
162}
163
164bool MoleculeFillWithMoleculeAction::shouldUndo() {
165 return false;
166}
167
168const string MoleculeFillWithMoleculeAction::getName() {
169 return NAME;
170}
Note: See TracBrowser for help on using the repository browser.