source: src/Actions/MoleculeAction/FillWithMoleculeAction.cpp@ faa1c9

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * FillWithMoleculeAction.cpp
3 *
4 * Created on: May 10, 2010
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
16#include "Actions/ActionRegistry.hpp"
17#include "atom.hpp"
18#include "bondgraph.hpp"
19#include "boundary.hpp"
20#include "config.hpp"
21#include "molecule.hpp"
22#include "Helpers/Verbose.hpp"
23#include "World.hpp"
24
25
26#include <iostream>
27#include <string>
28
29using namespace std;
30
31#include "UIElements/UIFactory.hpp"
32#include "UIElements/Dialog.hpp"
33#include "Actions/ValueStorage.hpp"
34
35/****** MoleculeFillWithMoleculeAction *****/
36
37// memento to remember the state when undoing
38
39//class MoleculeFillWithMoleculeState : public ActionState {
40//public:
41// MoleculeFillWithMoleculeState(molecule* _mol,std::string _lastName) :
42// mol(_mol),
43// lastName(_lastName)
44// {}
45// molecule* mol;
46// std::string lastName;
47//};
48
49const char MoleculeFillWithMoleculeAction::NAME[] = "fill-molecule";
50
51MoleculeFillWithMoleculeAction::MoleculeFillWithMoleculeAction() :
52 Action(NAME)
53{}
54
55MoleculeFillWithMoleculeAction::~MoleculeFillWithMoleculeAction()
56{}
57
58void MoleculeFillWithMolecule(std::string &fillername, Vector &distances, Vector &lengths, double MaxDistance, bool DoRotate) {
59 ValueStorage::getInstance().setCurrentValue(MoleculeFillWithMoleculeAction::NAME, fillername);
60 ValueStorage::getInstance().setCurrentValue("distances", distances);
61 ValueStorage::getInstance().setCurrentValue("lengths", lengths);
62 ValueStorage::getInstance().setCurrentValue("DoRotate", MaxDistance);
63 ValueStorage::getInstance().setCurrentValue("MaxDistance", DoRotate);
64 ActionRegistry::getInstance().getActionByName(MoleculeFillWithMoleculeAction::NAME)->call(Action::NonInteractive);
65};
66
67Dialog* MoleculeFillWithMoleculeAction::fillDialog(Dialog *dialog) {
68 ASSERT(dialog,"No Dialog given when filling action dialog");
69
70 dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
71 dialog->queryVector("distances", false, ValueStorage::getInstance().getDescription("distances"));
72 dialog->queryVector("lengths", false, ValueStorage::getInstance().getDescription("lengths"));
73 dialog->queryBoolean("DoRotate", ValueStorage::getInstance().getDescription("DoRotate"));
74 dialog->queryDouble("MaxDistance", ValueStorage::getInstance().getDescription("MaxDistance"));
75
76 return dialog;
77}
78
79Action::state_ptr MoleculeFillWithMoleculeAction::performCall() {
80 string filename;
81 Vector distances;
82 Vector lengths;
83 double MaxDistance = -1.;
84 bool DoRotate = false;
85
86 ValueStorage::getInstance().queryCurrentValue(NAME, filename);
87 ValueStorage::getInstance().queryCurrentValue("distances", distances);
88 ValueStorage::getInstance().queryCurrentValue("lengths", lengths);
89 ValueStorage::getInstance().queryCurrentValue("DoRotate", DoRotate);
90 ValueStorage::getInstance().queryCurrentValue("MaxDistance", MaxDistance);
91
92 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << lengths[0] << "," << lengths[1] << "," << lengths[2] << "), distances (" << distances[0] << "," << distances[1] << "," << distances[2] << "), MaxDistance " << MaxDistance << ", DoRotate " << DoRotate << "." << endl);
93 // construct water molecule
94 molecule *filler = World::getInstance().createMolecule();
95 if (!filler->AddXYZFile(filename)) {
96 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << filename << "." << endl);
97 }
98 filler->SetNameFromFilename(filename.c_str());
99 molecule *Filling = NULL;
100// atom *first = NULL, *second = NULL, *third = NULL;
101// first = World::getInstance().createAtom();
102// first->type = World::getInstance().getPeriode()->FindElement(1);
103// first->x = Vector(0.441, -0.143, 0.);
104// filler->AddAtom(first);
105// second = World::getInstance().createAtom();
106// second->type = World::getInstance().getPeriode()->FindElement(1);
107// second->x = Vector(-0.464, 1.137, 0.0);
108// filler->AddAtom(second);
109// third = World::getInstance().createAtom();
110// third->type = World::getInstance().getPeriode()->FindElement(8);
111// third->x = Vector(-0.464, 0.177, 0.);
112// filler->AddAtom(third);
113// filler->AddBond(first, third, 1);
114// filler->AddBond(second, third, 1);
115 World::getInstance().getConfig()->BG->ConstructBondGraph(filler);
116// filler->SetNameFromFilename("water");
117 // call routine
118 double distance[NDIM];
119 for (int i=0;i<NDIM;i++)
120 distance[i] = distances[i];
121 Filling = FillBoxWithMolecule(World::getInstance().getMolecules(), filler, *(World::getInstance().getConfig()), MaxDistance, distance, lengths[0], lengths[1], lengths[2], DoRotate);
122 if (Filling != NULL) {
123 Filling->ActiveFlag = false;
124 World::getInstance().getMolecules()->insert(Filling);
125 }
126 for (molecule::iterator iter = filler->begin(); !filler->empty(); iter = filler->begin()) {
127 atom *Walker = *iter;
128 filler->erase(iter);
129 World::getInstance().destroyAtom(Walker);
130 }
131 World::getInstance().destroyMolecule(filler);
132
133 return Action::success;
134}
135
136Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) {
137// MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());
138
139// string newName = state->mol->getName();
140// state->mol->setName(state->lastName);
141
142 return Action::failure;
143}
144
145Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){
146 // Undo and redo have to do the same for this action
147 return performUndo(_state);
148}
149
150bool MoleculeFillWithMoleculeAction::canUndo() {
151 return false;
152}
153
154bool MoleculeFillWithMoleculeAction::shouldUndo() {
155 return false;
156}
157
158const string MoleculeFillWithMoleculeAction::getName() {
159 return NAME;
160}
Note: See TracBrowser for help on using the repository browser.