source: src/Actions/WorldAction/RepeatBoxAction.cpp@ e4b2f6

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 e4b2f6 was 3bd460a, checked in by Frederik Heber <heber@…>, 14 years ago

All Actions on domain now state the final domain size.

  • default text is "Box domain is now ..." and is checked also in regression test.
  • Property mode set to 100644
File size: 5.0 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 "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
36using 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 ====================== */
44Action::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
133Action::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
143Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
144 return Action::failure;
145}
146
147bool WorldRepeatBoxAction::canUndo() {
148 return false;
149}
150
151bool WorldRepeatBoxAction::shouldUndo() {
152 return false;
153}
154/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.