source: src/Actions/WorldAction/RepeatBoxAction.cpp@ 53d01c

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 53d01c 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: 5.6 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 * RepeatBoxAction.cpp
10 *
11 * Created on: May 12, 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/WorldAction/RepeatBoxAction.hpp"
23#include "Actions/ActionRegistry.hpp"
24#include "atom.hpp"
25#include "Helpers/Log.hpp"
26#include "molecule.hpp"
27#include "LinearAlgebra/Vector.hpp"
28#include "LinearAlgebra/Matrix.hpp"
29#include "Helpers/Verbose.hpp"
30#include "World.hpp"
31#include "Box.hpp"
32
33#include <iostream>
34#include <string>
35#include <vector>
36
37using namespace std;
38
39#include "UIElements/UIFactory.hpp"
40#include "UIElements/Dialog.hpp"
41#include "Actions/ValueStorage.hpp"
42#include "Descriptors/MoleculeDescriptor.hpp"
43#include "Descriptors/MoleculePtrDescriptor.hpp"
44
45const char WorldRepeatBoxAction::NAME[] = "repeat-box";
46
47WorldRepeatBoxAction::WorldRepeatBoxAction() :
48 Action(NAME)
49{}
50
51WorldRepeatBoxAction::~WorldRepeatBoxAction()
52{}
53
54void WorldRepeatBox(Vector &Repeater) {
55 ValueStorage::getInstance().setCurrentValue(WorldRepeatBoxAction::NAME, Repeater);
56 ActionRegistry::getInstance().getActionByName(WorldRepeatBoxAction::NAME)->call(Action::NonInteractive);
57};
58
59void WorldRepeatBoxAction::getParametersfromValueStorage()
60{};
61
62Dialog* WorldRepeatBoxAction::fillDialog(Dialog *dialog) {
63 ASSERT(dialog,"No Dialog given when filling action dialog");
64
65 dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
66
67 return dialog;
68}
69
70Action::state_ptr WorldRepeatBoxAction::performCall() {
71 Vector Repeater;
72 int count;
73 const element ** Elements;
74 molecule *mol = NULL;
75 int j = 0;
76 atom *Walker = NULL;
77 MoleculeListClass *molecules = World::getInstance().getMolecules();
78
79 ValueStorage::getInstance().queryCurrentValue(NAME, Repeater);
80
81 vector<molecule *> AllMolecules;
82 if (mol != NULL) {
83 DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl);
84 AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol));
85 } else {
86 DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl);
87 AllMolecules = World::getInstance().getAllMolecules();
88 }
89
90 (cout << "Repeating box " << Repeater << " times for (x,y,z) axis." << endl);
91 Matrix M = World::getInstance().getDomain().getM();
92 Matrix newM = M;
93 Vector x,y;
94 int n[NDIM];
95 Matrix repMat;
96 for (int axis = 0; axis < NDIM; axis++) {
97 Repeater[axis] = floor(Repeater[axis]);
98 if (Repeater[axis] < 1) {
99 DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
100 Repeater[axis] = 1;
101 }
102 repMat.at(axis,axis) = Repeater[axis];
103 }
104 newM *= repMat;
105 World::getInstance().setDomain(newM);
106
107 molecule *newmol = NULL;
108 std::vector<Vector> vectors;
109 for (n[0] = 0; n[0] < Repeater[0]; n[0]++) {
110 y[0] = n[0];
111 for (n[1] = 0; n[1] < Repeater[1]; n[1]++) {
112 y[1] = n[1];
113 for (n[2] = 0; n[2] < Repeater[2]; n[2]++) {
114 y[2] = n[2];
115 if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0))
116 continue;
117 for (vector<molecule *>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
118 mol = *MolRunner;
119 DoLog(1) && (Log() << Verbose(1) << "Current mol is " << mol->name << "." << endl);
120 count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand
121 if (count != 0) { // if there is more than none
122 Elements = new const element *[count];
123 vectors.resize(count);
124 j = 0;
125 for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
126 Elements[j] = (*AtomRunner)->getType();
127 vectors[j] = (*AtomRunner)->getPosition();
128 j++;
129 }
130 if (count != j)
131 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
132 x = y;
133 x *= M;
134 newmol = World::getInstance().createMolecule();
135 molecules->insert(newmol);
136 for (int k=count;k--;) { // go through every atom of the original cell
137 Walker = World::getInstance().createAtom(); // create a new body
138 Walker->setPosition((vectors[k]) + x);
139 Walker->setType(Elements[k]); // insert original element
140 cout << "new atom is " << *Walker << endl;
141 newmol->AddAtom(Walker); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
142 }
143 // free memory
144 delete[](Elements);
145 } else {
146 DoLog(1) && (Log() << Verbose(1) << "\t ... is empty." << endl);
147 }
148 }
149 }
150 }
151 }
152 return Action::success;
153}
154
155Action::state_ptr WorldRepeatBoxAction::performUndo(Action::state_ptr _state) {
156// ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
157
158 return Action::failure;
159// string newName = state->mol->getName();
160// state->mol->setName(state->lastName);
161//
162// return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
163}
164
165Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
166 return Action::failure;
167}
168
169bool WorldRepeatBoxAction::canUndo() {
170 return false;
171}
172
173bool WorldRepeatBoxAction::shouldUndo() {
174 return false;
175}
176
177const string WorldRepeatBoxAction::getName() {
178 return NAME;
179}
Note: See TracBrowser for help on using the repository browser.