source: src/Actions/WorldAction/RepeatBoxAction.cpp@ 9cd807

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 9cd807 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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