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

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

Shifted all modules related to atoms into own subfolder src/Atom/

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