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

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

  • Property mode set to 100644
File size: 5.5 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
59Dialog * WorldRepeatBoxAction::fillDialog(Dialog *dialog) {
60 ASSERT(dialog,"No Dialog given when filling action dialog");
61
62 dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
63
64 return dialog;
65}
66
67Action::state_ptr WorldRepeatBoxAction::performCall() {
68 Vector Repeater;
69 int count;
70 const element ** Elements;
71 molecule *mol = NULL;
72 int j = 0;
73 atom *Walker = NULL;
74 MoleculeListClass *molecules = World::getInstance().getMolecules();
75
76 ValueStorage::getInstance().queryCurrentValue(NAME, Repeater);
77
78 vector<molecule *> AllMolecules;
79 if (mol != NULL) {
80 DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl);
81 AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol));
82 } else {
83 DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl);
84 AllMolecules = World::getInstance().getAllMolecules();
85 }
86
87 (cout << "Repeating box " << Repeater << " times for (x,y,z) axis." << endl);
88 Matrix M = World::getInstance().getDomain().getM();
89 Matrix newM = M;
90 Vector x,y;
91 int n[NDIM];
92 Matrix repMat;
93 for (int axis = 0; axis < NDIM; axis++) {
94 Repeater[axis] = floor(Repeater[axis]);
95 if (Repeater[axis] < 1) {
96 DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
97 Repeater[axis] = 1;
98 }
99 repMat.at(axis,axis) = Repeater[axis];
100 }
101 newM *= repMat;
102 World::getInstance().setDomain(newM);
103
104 molecule *newmol = NULL;
105 std::vector<Vector> vectors;
106 for (n[0] = 0; n[0] < Repeater[0]; n[0]++) {
107 y[0] = n[0];
108 for (n[1] = 0; n[1] < Repeater[1]; n[1]++) {
109 y[1] = n[1];
110 for (n[2] = 0; n[2] < Repeater[2]; n[2]++) {
111 y[2] = n[2];
112 if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0))
113 continue;
114 for (vector<molecule *>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
115 mol = *MolRunner;
116 DoLog(1) && (Log() << Verbose(1) << "Current mol is " << mol->name << "." << endl);
117 count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand
118 if (count != 0) { // if there is more than none
119 Elements = new const element *[count];
120 vectors.resize(count);
121 j = 0;
122 for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
123 Elements[j] = (*AtomRunner)->getType();
124 vectors[j] = (*AtomRunner)->getPosition();
125 j++;
126 }
127 if (count != j)
128 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
129 x = y;
130 x *= M;
131 newmol = World::getInstance().createMolecule();
132 molecules->insert(newmol);
133 for (int k=count;k--;) { // go through every atom of the original cell
134 Walker = World::getInstance().createAtom(); // create a new body
135 Walker->setPosition((vectors[k]) + x);
136 Walker->setType(Elements[k]); // insert original element
137 cout << "new atom is " << *Walker << endl;
138 newmol->AddAtom(Walker); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
139 }
140 // free memory
141 delete[](Elements);
142 } else {
143 DoLog(1) && (Log() << Verbose(1) << "\t ... is empty." << endl);
144 }
145 }
146 }
147 }
148 }
149 return Action::success;
150}
151
152Action::state_ptr WorldRepeatBoxAction::performUndo(Action::state_ptr _state) {
153// ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
154
155 return Action::failure;
156// string newName = state->mol->getName();
157// state->mol->setName(state->lastName);
158//
159// return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
160}
161
162Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
163 return Action::failure;
164}
165
166bool WorldRepeatBoxAction::canUndo() {
167 return false;
168}
169
170bool WorldRepeatBoxAction::shouldUndo() {
171 return false;
172}
173
174const string WorldRepeatBoxAction::getName() {
175 return NAME;
176}
Note: See TracBrowser for help on using the repository browser.