source: src/Actions/MoleculeAction/FillWithMoleculeAction.cpp@ 8f4df1

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 8f4df1 was 952f38, checked in by Frederik Heber <heber@…>, 14 years ago

created LibMolecuilderHelpers.

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