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 "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Descriptors/MoleculePtrDescriptor.hpp"
|
---|
23 | #include "atom.hpp"
|
---|
24 | #include "CodePatterns/Log.hpp"
|
---|
25 | #include "molecule.hpp"
|
---|
26 | #include "LinearAlgebra/Vector.hpp"
|
---|
27 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
28 | #include "CodePatterns/Verbose.hpp"
|
---|
29 | #include "World.hpp"
|
---|
30 | #include "Box.hpp"
|
---|
31 |
|
---|
32 | #include <iostream>
|
---|
33 | #include <string>
|
---|
34 | #include <vector>
|
---|
35 |
|
---|
36 | using namespace std;
|
---|
37 |
|
---|
38 | #include "Actions/WorldAction/RepeatBoxAction.hpp"
|
---|
39 |
|
---|
40 | // and construct the stuff
|
---|
41 | #include "RepeatBoxAction.def"
|
---|
42 | #include "Action_impl_pre.hpp"
|
---|
43 | /** =========== define the function ====================== */
|
---|
44 | Action::state_ptr WorldRepeatBoxAction::performCall() {
|
---|
45 | int count;
|
---|
46 | const element ** Elements;
|
---|
47 | molecule *mol = NULL;
|
---|
48 | int j = 0;
|
---|
49 | atom *Walker = NULL;
|
---|
50 | MoleculeListClass *molecules = World::getInstance().getMolecules();
|
---|
51 |
|
---|
52 | // obtain information
|
---|
53 | getParametersfromValueStorage();
|
---|
54 |
|
---|
55 | vector<molecule *> AllMolecules;
|
---|
56 | if (mol != NULL) {
|
---|
57 | DoLog(0) && (Log() << Verbose(0) << "Using molecule " << mol->name << "." << endl);
|
---|
58 | AllMolecules = World::getInstance().getAllMolecules(MoleculeByPtr(mol));
|
---|
59 | } else {
|
---|
60 | DoLog(0) && (Log() << Verbose(0) << "Using all molecules." << endl);
|
---|
61 | AllMolecules = World::getInstance().getAllMolecules();
|
---|
62 | }
|
---|
63 |
|
---|
64 | (cout << "Repeating box " << params.Repeater << " times for (x,y,z) axis." << endl);
|
---|
65 | RealSpaceMatrix M = World::getInstance().getDomain().getM();
|
---|
66 | RealSpaceMatrix newM = M;
|
---|
67 | Vector x,y;
|
---|
68 | int n[NDIM];
|
---|
69 | RealSpaceMatrix repMat;
|
---|
70 | for (int axis = 0; axis < NDIM; axis++) {
|
---|
71 | params.Repeater[axis] = floor(params.Repeater[axis]);
|
---|
72 | if (params.Repeater[axis] < 1) {
|
---|
73 | DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
|
---|
74 | params.Repeater[axis] = 1;
|
---|
75 | }
|
---|
76 | repMat.at(axis,axis) = params.Repeater[axis];
|
---|
77 | }
|
---|
78 | newM *= repMat;
|
---|
79 | World::getInstance().setDomain(newM);
|
---|
80 |
|
---|
81 | molecule *newmol = NULL;
|
---|
82 | std::vector<Vector> vectors;
|
---|
83 | for (n[0] = 0; n[0] < params.Repeater[0]; n[0]++) {
|
---|
84 | y[0] = n[0];
|
---|
85 | for (n[1] = 0; n[1] < params.Repeater[1]; n[1]++) {
|
---|
86 | y[1] = n[1];
|
---|
87 | for (n[2] = 0; n[2] < params.Repeater[2]; n[2]++) {
|
---|
88 | y[2] = n[2];
|
---|
89 | if ((n[0] == 0) && (n[1] == 0) && (n[2] == 0))
|
---|
90 | continue;
|
---|
91 | for (vector<molecule *>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
|
---|
92 | mol = *MolRunner;
|
---|
93 | DoLog(1) && (Log() << Verbose(1) << "Current mol is " << mol->name << "." << endl);
|
---|
94 | count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand
|
---|
95 | if (count != 0) { // if there is more than none
|
---|
96 | Elements = new const element *[count];
|
---|
97 | vectors.resize(count);
|
---|
98 | j = 0;
|
---|
99 | for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
|
---|
100 | Elements[j] = (*AtomRunner)->getType();
|
---|
101 | vectors[j] = (*AtomRunner)->getPosition();
|
---|
102 | j++;
|
---|
103 | }
|
---|
104 | if (count != j)
|
---|
105 | DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
|
---|
106 | x = y;
|
---|
107 | x *= M;
|
---|
108 | newmol = World::getInstance().createMolecule();
|
---|
109 | molecules->insert(newmol);
|
---|
110 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
111 | Walker = World::getInstance().createAtom(); // create a new body
|
---|
112 | Walker->setPosition((vectors[k]) + x);
|
---|
113 | Walker->setType(Elements[k]); // insert original element
|
---|
114 | cout << "new atom is " << *Walker << endl;
|
---|
115 | newmol->AddAtom(Walker); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
116 | }
|
---|
117 | // free memory
|
---|
118 | delete[](Elements);
|
---|
119 | } else {
|
---|
120 | DoLog(1) && (Log() << Verbose(1) << "\t ... is empty." << endl);
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | // give final box size
|
---|
128 | LOG(0, "Box domain is now " << World::getInstance().getDomain().getM());
|
---|
129 |
|
---|
130 | return Action::success;
|
---|
131 | }
|
---|
132 |
|
---|
133 | Action::state_ptr WorldRepeatBoxAction::performUndo(Action::state_ptr _state) {
|
---|
134 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
135 |
|
---|
136 | return Action::failure;
|
---|
137 | // string newName = state->mol->getName();
|
---|
138 | // state->mol->setName(state->lastName);
|
---|
139 | //
|
---|
140 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
141 | }
|
---|
142 |
|
---|
143 | Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
|
---|
144 | return Action::failure;
|
---|
145 | }
|
---|
146 |
|
---|
147 | bool WorldRepeatBoxAction::canUndo() {
|
---|
148 | return false;
|
---|
149 | }
|
---|
150 |
|
---|
151 | bool WorldRepeatBoxAction::shouldUndo() {
|
---|
152 | return false;
|
---|
153 | }
|
---|
154 | /** =========== end of function ====================== */
|
---|