[bcf653] | 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 |
|
---|
[97ebf8] | 8 | /*
|
---|
| 9 | * RepeatBoxAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 12, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 21 |
|
---|
[1fd675] | 22 | #include "Descriptors/MoleculePtrDescriptor.hpp"
|
---|
[97ebf8] | 23 | #include "atom.hpp"
|
---|
[ad011c] | 24 | #include "CodePatterns/Log.hpp"
|
---|
[97ebf8] | 25 | #include "molecule.hpp"
|
---|
[57f243] | 26 | #include "LinearAlgebra/Vector.hpp"
|
---|
[cca9ef] | 27 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
[ad011c] | 28 | #include "CodePatterns/Verbose.hpp"
|
---|
[97ebf8] | 29 | #include "World.hpp"
|
---|
[84c494] | 30 | #include "Box.hpp"
|
---|
[97ebf8] | 31 |
|
---|
| 32 | #include <iostream>
|
---|
| 33 | #include <string>
|
---|
[d74077] | 34 | #include <vector>
|
---|
[97ebf8] | 35 |
|
---|
[1fd675] | 36 | #include "Actions/WorldAction/RepeatBoxAction.hpp"
|
---|
[bfe2c2] | 37 |
|
---|
[ce7fdc] | 38 | using namespace MoleCuilder;
|
---|
| 39 |
|
---|
[1fd675] | 40 | // and construct the stuff
|
---|
| 41 | #include "RepeatBoxAction.def"
|
---|
| 42 | #include "Action_impl_pre.hpp"
|
---|
| 43 | /** =========== define the function ====================== */
|
---|
[bfe2c2] | 44 | Action::state_ptr WorldRepeatBoxAction::performCall() {
|
---|
[97ebf8] | 45 | int count;
|
---|
| 46 | const element ** Elements;
|
---|
| 47 | molecule *mol = NULL;
|
---|
| 48 | int j = 0;
|
---|
[1024cb] | 49 | atom *Walker = NULL;
|
---|
[e30ce8] | 50 | MoleculeListClass *molecules = World::getInstance().getMolecules();
|
---|
[97ebf8] | 51 |
|
---|
[1fd675] | 52 | // obtain information
|
---|
| 53 | getParametersfromValueStorage();
|
---|
[bfe2c2] | 54 |
|
---|
[e30ce8] | 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 | }
|
---|
[97ebf8] | 63 |
|
---|
[1fd675] | 64 | (cout << "Repeating box " << params.Repeater << " times for (x,y,z) axis." << endl);
|
---|
[cca9ef] | 65 | RealSpaceMatrix M = World::getInstance().getDomain().getM();
|
---|
| 66 | RealSpaceMatrix newM = M;
|
---|
[bfe2c2] | 67 | Vector x,y;
|
---|
| 68 | int n[NDIM];
|
---|
[cca9ef] | 69 | RealSpaceMatrix repMat;
|
---|
[bfe2c2] | 70 | for (int axis = 0; axis < NDIM; axis++) {
|
---|
[1fd675] | 71 | params.Repeater[axis] = floor(params.Repeater[axis]);
|
---|
| 72 | if (params.Repeater[axis] < 1) {
|
---|
[bfe2c2] | 73 | DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
|
---|
[1fd675] | 74 | params.Repeater[axis] = 1;
|
---|
[e30ce8] | 75 | }
|
---|
[1fd675] | 76 | repMat.at(axis,axis) = params.Repeater[axis];
|
---|
[bfe2c2] | 77 | }
|
---|
| 78 | newM *= repMat;
|
---|
| 79 | World::getInstance().setDomain(newM);
|
---|
| 80 |
|
---|
| 81 | molecule *newmol = NULL;
|
---|
[d74077] | 82 | std::vector<Vector> vectors;
|
---|
[1fd675] | 83 | for (n[0] = 0; n[0] < params.Repeater[0]; n[0]++) {
|
---|
[bfe2c2] | 84 | y[0] = n[0];
|
---|
[1fd675] | 85 | for (n[1] = 0; n[1] < params.Repeater[1]; n[1]++) {
|
---|
[bfe2c2] | 86 | y[1] = n[1];
|
---|
[1fd675] | 87 | for (n[2] = 0; n[2] < params.Repeater[2]; n[2]++) {
|
---|
[bfe2c2] | 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];
|
---|
[d74077] | 97 | vectors.resize(count);
|
---|
[bfe2c2] | 98 | j = 0;
|
---|
| 99 | for(molecule::iterator AtomRunner = mol->begin(); AtomRunner != mol->end(); ++AtomRunner) {
|
---|
[d74077] | 100 | Elements[j] = (*AtomRunner)->getType();
|
---|
| 101 | vectors[j] = (*AtomRunner)->getPosition();
|
---|
[bfe2c2] | 102 | j++;
|
---|
[e30ce8] | 103 | }
|
---|
[bfe2c2] | 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
|
---|
[d74077] | 112 | Walker->setPosition((vectors[k]) + x);
|
---|
| 113 | Walker->setType(Elements[k]); // insert original element
|
---|
[bfe2c2] | 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);
|
---|
[97ebf8] | 121 | }
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
[3bd460a] | 126 |
|
---|
| 127 | // give final box size
|
---|
| 128 | LOG(0, "Box domain is now " << World::getInstance().getDomain().getM());
|
---|
| 129 |
|
---|
[bfe2c2] | 130 | return Action::success;
|
---|
[97ebf8] | 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 | }
|
---|
[1fd675] | 154 | /** =========== end of function ====================== */
|
---|