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

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 eacc3b was 84c494, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the world store the cell_size within a Box object.

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