source: src/Actions/MoleculeAction/CreateMicelleAction.cpp@ aa8cc2

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 aa8cc2 was f6ba43, checked in by Frederik Heber <heber@…>, 13 years ago

Many smaller changes to CreateMicelleAction to get it fully working and compliant.

Changes to MoleculeCreateMicelleAction::performCall():

  • returns Action::success when no molecule is selected.
  • we check for selection of not more than one molecule.
  • we store full undo (positions in selected molecule and added molecules).
  • new parameter DoRotate to tell whether to mirror molecule along z axis or not.
  • FIX: we rotate to PAS only in case of more than one atom present in molecule.
  • FIX: copied molecules are added to World's MoleculeListClass (and correctly removed in performUndo()).
  • FIX: Placed shifting original molecule into own block and corrected usage of RotationAxis.
  • Also performUndo() is fully implemented.
  • we can... and shouldUndo().
  • added regression test on both do and Undo.
  • Property mode set to 100644
File size: 7.4 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 * CreateMicelleAction.cpp
10 *
11 * Created on: Sept 29, 2010
12 * Author: dueck
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19#include "CodePatterns/MemDebug.hpp"
20
21#include "Actions/ActionHistory.hpp"
22#include "Actions/ActionRegistry.hpp"
23#include "Actions/GraphAction/SubgraphDissectionAction.hpp"
24#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
25#include "Descriptors/AtomIdDescriptor.hpp"
26#include "Descriptors/MoleculeDescriptor.hpp"
27
28#include "atom.hpp"
29#include "Bond/bond.hpp"
30#include "CodePatterns/Assert.hpp"
31#include "CodePatterns/Log.hpp"
32#include "CodePatterns/Verbose.hpp"
33#include "LinearAlgebra/Line.hpp"
34#include "molecule.hpp"
35#include "World.hpp"
36
37#include <iostream>
38#include <string>
39#include <vector>
40
41#include "Parser/PdbParser.hpp"
42#include "Parser/TremoloParser.hpp"
43#include "Parser/XyzParser.hpp"
44#include "Parser/FormatParserStorage.hpp"
45#include "Shapes/BaseShapes.hpp"
46#include "Shapes/ShapeOps.hpp"
47
48#include "Actions/MoleculeAction/CreateMicelleAction.hpp"
49
50#include "CreateMicelleAction.def"
51#include "Action_impl_pre.hpp"
52
53#include "UIElements/UIFactory.hpp"
54#include "UIElements/Dialog.hpp"
55#include "Actions/ValueStorage.hpp"
56
57
58/** =========== define the function ====================== */
59Action::state_ptr MoleculeCreateMicelleAction::performCall()
60{
61 typedef std::vector <atom *> AtomVector;
62 typedef std::vector <molecule *> MoleculeVector;
63
64 getParametersfromValueStorage();
65
66 AtomVector ever = World::getInstance().getAllAtoms();
67
68 // as all parsed atoms go into same molecule
69 // we don't need to create one and add them all to it
70 MoleculeVector all = World::getInstance().getSelectedMolecules();
71
72 // return success when none are selected
73 if (all.empty())
74 return Action::success;
75
76 // check that there is precisely one molecule
77 ASSERT(all.size() == 1,
78 "MoleculeCreateMicelleAction::performCall() - more than one molecule selected, this is not supported.");
79
80 molecule *stick = *(all.begin());
81
82
83 // create undo state for original molecule
84 std::vector<Vector> stickPositions;
85 for (molecule::const_iterator iter = stick->begin(); iter != stick->end(); ++iter)
86 stickPositions.push_back((*iter)->getPosition());
87
88 // determine principal axis system and rotate such that greatest extension is along z axis
89 if(stick->size() > 1) { // only rotate if more than one molecule present
90 Vector den(0.0,0.0,1.0);
91
92 MoleculeRotateToPrincipalAxisSystem(den);
93 }
94
95 // center molecule
96 stick->CenterOrigin();
97
98 /// Align molecule with its PAS multiple times with the some surface
99
100 // get points on surface
101
102 //double radius= 1.5*sqrt(pow(1.55, 2)*params.N);
103
104 Shape s = resize(Sphere(), params.radius);
105 std::vector<Vector> pt = s.getHomogeneousPointsOnSurface(params.N);
106
107 // mirror along x-y plane
108
109 // additionally invert molecule if desired
110 if (params.DoRotate) {
111 for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
112 {
113 Vector pos= (**it2).getPosition();
114 pos[2]= - pos[2];// -Min[2]
115 (**it2).setPosition(pos);
116 }
117 }
118
119 // shift molecule by its extension along z axis
120
121 for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
122 {
123 Vector pos= (**it2).getPosition();
124 pos[2]=pos[2]+params.radius;
125 (**it2).setPosition(pos);
126 }
127
128 // copy molecule N times and rotate it to point radially away from surface
129
130 //double MYEPSILON=1e-10;
131
132 // gather created molecules for undo state
133 std::vector<molecule *> CreatedMolecules;
134
135 // TODO: remove this when we do not need MoleculeListClass anymore
136 MoleculeListClass *&molecules = World::getInstance().getMolecules();
137
138 size_t ka = 0;
139 for (; ka<pt.size()-1; ka++)
140 {
141 LOG(1, "STATUS: Creating " << ka+1 << " copy of tenside molecule 'stick' with " << stick->getAtomCount() << " atoms, ");
142 molecule *Tensid=stick->CopyMolecule();
143 molecules->insert(Tensid);
144 CreatedMolecules.push_back(Tensid);
145
146 Vector ZAxis(Vector(0.0,0.0,1.0));
147 Vector Axis(pt[ka]);
148 const double alpha = ZAxis.Angle(Axis);
149 Axis.VectorProduct(ZAxis);
150 Line RotationAxis(Vector(0.0,0.0,1.0), Axis); // pt is the current Vector of point on surface
151 LOG(2, "INFO: Rotating along axis " << RotationAxis << " by angle " << alpha << ".");
152
153 for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
154 {
155 (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
156 *(*it2)+=params.center;
157 }
158
159 Tensid=NULL;
160 }
161
162 // shift molecule at given position on surface
163 {
164 LOG(1, "STATUS: Shifting " << ka+1 << " copy of tenside molecule 'stick' with " << stick->getAtomCount() << " atoms, ");
165 molecule *Tensid=stick;
166 // this molecule was present before, hence do not remove it!
167 //CreatedMolecules.push_back(Tensid);
168
169 Vector ZAxis(Vector(0.0,0.0,1.0));
170 Vector Axis(pt[pt.size()-1]);
171 const double alpha = ZAxis.Angle(Axis);
172 Axis.VectorProduct(ZAxis);
173 Line RotationAxis(Vector(0.0,0.0,1.0), Axis); // pt is the current Vector of point on surface
174 LOG(2, "INFO: Rotating along axis " << RotationAxis << " by angle " << alpha << ".");
175
176 for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
177 {
178 (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
179 *(*it2)+=params.center;
180 }
181 }
182
183
184 return Action::state_ptr(new MoleculeCreateMicelleState(CreatedMolecules, stick, stickPositions, params));
185}
186
187Action::state_ptr MoleculeCreateMicelleAction::performUndo(Action::state_ptr _state)
188{
189 MoleculeCreateMicelleState *state = assert_cast<MoleculeCreateMicelleState*>(_state.get());
190
191 // removing all created molecules
192 MoleculeListClass *&molecules = World::getInstance().getMolecules();
193 LOG(0, "STATUS: Removing " << state->CreatedMolecules.size() << " molecules again.");
194 for(std::vector<molecule *>::const_iterator iter = state->CreatedMolecules.begin();
195 iter != state->CreatedMolecules.end();
196 ++iter) {
197 LOG(2, "INFO: Removing " << (*iter)->getName());
198 for(molecule::iterator AtomRunner = (*iter)->begin();
199 !(*iter)->empty();
200 AtomRunner = (*iter)->begin()) {
201 World::getInstance().destroyAtom(*AtomRunner);
202 }
203 //LOG(3, "INFO: molecules contains still " << molecules->ListOfMolecules.size() << " molecules.");
204 molecules->erase(*iter);
205 World::getInstance().destroyMolecule(*iter);
206 }
207
208 // undo changes to original molecule
209 ASSERT(state->stickPositions.size() == state->stick->size(),
210 "MoleculeCreateMicelleAction::performUndo() - number of stored positions ("
211 +toString(state->stickPositions.size())+") and number of atoms ("
212 +toString(state->stick->size())+") do not match.");
213 std::vector<Vector>::const_iterator PosIter = state->stickPositions.begin();
214 molecule::iterator iter = state->stick->begin();
215 for (; iter != state->stick->end(); ++iter, ++PosIter)
216 (*iter)->setPosition(*PosIter);
217
218 return Action::state_ptr(_state);
219}
220
221Action::state_ptr MoleculeCreateMicelleAction::performRedo(Action::state_ptr _state)
222{
223 LOG(0, "STATUS: CreateMicelleAction::performRedo() is nit implemented yet.");
224 return Action::failure;
225}
226
227
228bool MoleculeCreateMicelleAction::canUndo()
229{
230 return true;
231}
232
233bool MoleculeCreateMicelleAction::shouldUndo()
234{
235 return true;
236}
237
238/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.