source: src/Actions/MoleculeAction/FillWithMoleculeAction.cpp@ 259b2b

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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