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

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 f8f14d was 97ebf8, checked in by Frederik Heber <heber@…>, 15 years ago

Added all commands defined in ParseCommandLineOptions() as Actions.

  • Actions are not yet used, except verbose, version and help.
  • Files are present and included in Makefile.am
  • not unit tests written so far
  • no action has been tested so far (except for MapOfActions)
  • structure introduced to to transition from ParseCommandLineOptions to actions.
  • program name and config file are fixed arguments.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * RepeatBoxAction.cpp
3 *
4 * Created on: May 12, 2010
5 * Author: heber
6 */
7
8#include "Actions/WorldAction/RepeatBoxAction.hpp"
9#include "CommandLineParser.hpp"
10#include "atom.hpp"
11#include "log.hpp"
12#include "molecule.hpp"
13#include "vector.hpp"
14#include "verbose.hpp"
15#include "World.hpp"
16
17#include <iostream>
18#include <string>
19
20using namespace std;
21
22#include "UIElements/UIFactory.hpp"
23#include "UIElements/Dialog.hpp"
24#include "Actions/MapOfActions.hpp"
25
26const char WorldRepeatBoxAction::NAME[] = "repeat-box";
27
28WorldRepeatBoxAction::WorldRepeatBoxAction() :
29 Action(NAME)
30{}
31
32WorldRepeatBoxAction::~WorldRepeatBoxAction()
33{}
34
35Action::state_ptr WorldRepeatBoxAction::performCall() {
36 Dialog *dialog = UIFactory::getInstance().makeDialog();
37 Vector Repeater;
38 int count;
39 const element ** Elements;
40 molecule *mol = NULL;
41 int j = 0;
42
43 dialog->queryVector(NAME, &Repeater, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription(NAME));
44 dialog->queryMolecule("molecule-by-id", &mol,MapOfActions::getInstance().getDescription("molecule-by-id"));
45
46 if(dialog->display()) {
47 double * const cell_size = World::getInstance().getDomain();
48 Vector x,y;
49 for (int axis = 1; axis <= NDIM; axis++) {
50 Vector ** vectors;
51 Repeater[axis] = floor(Repeater[axis]);
52 if (Repeater[axis] < 1) {
53 DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor must be greater than 1!" << endl);
54 Repeater[axis] = 1;
55 }
56 mol->CountAtoms(); // recount atoms
57 if (mol->AtomCount != 0) { // if there is more than none
58 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
59 Elements = new const element *[count];
60 vectors = new Vector *[count];
61 j = 0;
62 atom *first = mol->start;
63 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
64 first = first->next;
65 Elements[j] = first->type;
66 vectors[j] = &first->x;
67 j++;
68 }
69 if (count != j)
70 DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
71 x.Zero();
72 y.Zero();
73 y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
74 for (int i=1;i<Repeater[axis];i++) { // then add this list with respective translation factor times
75 x += y; // per factor one cell width further
76 for (int k=count;k--;) { // go through every atom of the original cell
77 first = World::getInstance().createAtom(); // create a new body
78 first->x = (*vectors[k]) + x;
79 first->type = Elements[k]; // insert original element
80 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
81 }
82 }
83 // free memory
84 delete[](Elements);
85 delete[](vectors);
86 // correct cell size
87 if (axis < 0) { // if sign was negative, we have to translate everything
88 x =(-(Repeater[axis]-1)) * y;
89 mol->Translate(&x);
90 }
91 cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= Repeater[axis];
92 }
93 }
94 delete dialog;
95 return Action::success;
96 } else {
97 delete dialog;
98 return Action::failure;
99 }
100}
101
102Action::state_ptr WorldRepeatBoxAction::performUndo(Action::state_ptr _state) {
103// ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
104
105 return Action::failure;
106// string newName = state->mol->getName();
107// state->mol->setName(state->lastName);
108//
109// return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
110}
111
112Action::state_ptr WorldRepeatBoxAction::performRedo(Action::state_ptr _state){
113 return Action::failure;
114}
115
116bool WorldRepeatBoxAction::canUndo() {
117 return false;
118}
119
120bool WorldRepeatBoxAction::shouldUndo() {
121 return false;
122}
123
124const string WorldRepeatBoxAction::getName() {
125 return NAME;
126}
Note: See TracBrowser for help on using the repository browser.