| 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 |
|
|---|
| 40 | #include "Parser/PdbParser.hpp"
|
|---|
| 41 | #include "Parser/TremoloParser.hpp"
|
|---|
| 42 | #include "Parser/XyzParser.hpp"
|
|---|
| 43 | #include "Parser/FormatParserStorage.hpp"
|
|---|
| 44 | #include "Shapes/BaseShapes.hpp"
|
|---|
| 45 | #include "Shapes/ShapeOps.hpp"
|
|---|
| 46 |
|
|---|
| 47 | #include "Actions/MoleculeAction/CreateMicelleAction.hpp"
|
|---|
| 48 |
|
|---|
| 49 | #include "CreateMicelleAction.def"
|
|---|
| 50 | #include "Action_impl_pre.hpp"
|
|---|
| 51 |
|
|---|
| 52 | using namespace std;
|
|---|
| 53 |
|
|---|
| 54 | #include "UIElements/UIFactory.hpp"
|
|---|
| 55 | #include "UIElements/Dialog.hpp"
|
|---|
| 56 | #include "Actions/ValueStorage.hpp"
|
|---|
| 57 |
|
|---|
| 58 | // memento to remember the state when undoing
|
|---|
| 59 |
|
|---|
| 60 | #include <iostream>
|
|---|
| 61 | #include <fstream>
|
|---|
| 62 | #include <config.h>
|
|---|
| 63 | #include "atom.hpp"
|
|---|
| 64 | #include "molecule.hpp"
|
|---|
| 65 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 66 | #include "LinearAlgebra/Line.hpp"
|
|---|
| 67 | #include "World.hpp"
|
|---|
| 68 | #include <gsl/gsl_poly.h>
|
|---|
| 69 | #include <gsl/gsl_eigen.h>
|
|---|
| 70 | //#define PATH "/home/dueck/workspace/tenside/tmp/"
|
|---|
| 71 | #define AtomVector std::vector <atom *>
|
|---|
| 72 | #define MoleculeVector std::vector <molecule *>
|
|---|
| 73 | #define AtomList list <atom *>
|
|---|
| 74 |
|
|---|
| 75 | int Delta2(int x1, int x2);
|
|---|
| 76 | double Sqlength (Vector x);
|
|---|
| 77 |
|
|---|
| 78 | /** =========== define the function ====================== */
|
|---|
| 79 | Action::state_ptr MoleculeCreateMicelleAction::performCall()
|
|---|
| 80 | {
|
|---|
| 81 | getParametersfromValueStorage();
|
|---|
| 82 |
|
|---|
| 83 | AtomVector ever = World::getInstance().getAllAtoms();
|
|---|
| 84 |
|
|---|
| 85 | // as all parsed atoms go into same molecule
|
|---|
| 86 | // we don't need to create one and add them all to it
|
|---|
| 87 | MoleculeVector all = World::getInstance().getSelectedMolecules();
|
|---|
| 88 | ASSERT(!all.empty(), "MoleculeCreateMicelleAction::performCall() - no molecules selected.");
|
|---|
| 89 | molecule *stick = *(all.begin());
|
|---|
| 90 |
|
|---|
| 91 | //3.Molekuel zentrieren
|
|---|
| 92 |
|
|---|
| 93 | stick->CenterOrigin();
|
|---|
| 94 |
|
|---|
| 95 | //4.Haupttraegheitsachse bestimmen
|
|---|
| 96 | Vector den(0.0,0.0,1.0);
|
|---|
| 97 |
|
|---|
| 98 | MoleculeRotateToPrincipalAxisSystem(den);
|
|---|
| 99 | /* determine
|
|---|
| 100 | principal axis system and make greatest eigenvector be aligned along
|
|---|
| 101 | (0,0,1)
|
|---|
| 102 | */
|
|---|
| 103 | string path;
|
|---|
| 104 | /**/
|
|---|
| 105 | /*XyzParser *parserx = new XyzParser;
|
|---|
| 106 | {
|
|---|
| 107 | std::ofstream file;
|
|---|
| 108 | path = PATH;
|
|---|
| 109 | path += "/tensidrot.xyz";
|
|---|
| 110 | file.open(path.c_str());
|
|---|
| 111 | FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
|
|---|
| 112 | file.close();
|
|---|
| 113 | }*/
|
|---|
| 114 | //5.b: Molekuel um 180 Grad drehen
|
|---|
| 115 |
|
|---|
| 116 | Line RotationAxis(Vector(0.0,0.0,0.0), Vector(1.0,0.0,0.0)); // pt is the current Vector of point on surface
|
|---|
| 117 |
|
|---|
| 118 | for (molecule::iterator it=stick->begin(); it !=stick->end(); ++it)
|
|---|
| 119 | (*it)->setPosition(RotationAxis.rotateVector((*it)->getPosition(),M_PI));
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | /*{
|
|---|
| 123 | std::ofstream file;
|
|---|
| 124 | path = PATH;
|
|---|
| 125 | path += "/tensid2rot.xyz";
|
|---|
| 126 | file.open(path.c_str());
|
|---|
| 127 | FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
|
|---|
| 128 | file.close();
|
|---|
| 129 | }*/
|
|---|
| 130 |
|
|---|
| 131 | //6.Molekuel mehrfach strukturiert mit der Haupttraegheitsachse senkrecht zu einer parametrisierten Oberflaeche anordnen
|
|---|
| 132 |
|
|---|
| 133 | //6.1. Punkte auf der Oberflaeche bestimmen
|
|---|
| 134 | //Algorithmus entnommen aus "http://www.cgafaq.info/wiki/Evenly_distributed_points_on_sphere"
|
|---|
| 135 |
|
|---|
| 136 | int ka =0;
|
|---|
| 137 | //double radius= 1.5*sqrt(pow(1.55, 2)*params.N);
|
|---|
| 138 |
|
|---|
| 139 | Shape s = resize(Sphere(), params.radius);
|
|---|
| 140 | std::vector<Vector> pt = s.getHomogeneousPointsOnSurface(params.N);
|
|---|
| 141 |
|
|---|
| 142 | //6.2.a. "stick" 180 Grad an x-y-Ebene spiegeln
|
|---|
| 143 |
|
|---|
| 144 | for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
|
|---|
| 145 | {
|
|---|
| 146 | Vector pos= (**it2).getPosition();
|
|---|
| 147 | pos[2]= - pos[2];// -Min[2]
|
|---|
| 148 | (**it2).setPosition(pos);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | //6.2.b. "stick" um Radius und Molekuelausdehnung in z-Richtung verschieben.
|
|---|
| 153 |
|
|---|
| 154 | for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
|
|---|
| 155 | {
|
|---|
| 156 | Vector pos= (**it2).getPosition();
|
|---|
| 157 | pos[2]=pos[2]+params.radius; // -Min[2]
|
|---|
| 158 | (**it2).setPosition(pos);
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 | /*{
|
|---|
| 165 | std::ofstream file;
|
|---|
| 166 | path = PATH;
|
|---|
| 167 | path += "/tensid3rot.xyz";
|
|---|
| 168 | file.open(path.c_str());
|
|---|
| 169 | FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
|
|---|
| 170 | file.close();
|
|---|
| 171 | }*/
|
|---|
| 172 |
|
|---|
| 173 | //6.3.Erzeugen einer Molekuelliste, die das Molekuel "stick" "N" mal kopiert und um eine Sphaere herum verteilt
|
|---|
| 174 |
|
|---|
| 175 | //double MYEPSILON=1e-10;
|
|---|
| 176 |
|
|---|
| 177 | for (ka = 0; ka<params.N-1; ka++)
|
|---|
| 178 | {
|
|---|
| 179 | cout << "Creating " << ka+1 << " copy of tenside molecule 'stick' with " << stick->getAtomCount() << " atoms, ";
|
|---|
| 180 | molecule *Tensid=stick->CopyMolecule();
|
|---|
| 181 |
|
|---|
| 182 | cout << "rotating ...";
|
|---|
| 183 | Vector ZAxis(Vector(0.0,0.0,1.0));
|
|---|
| 184 | Vector Axis(pt[ka]);
|
|---|
| 185 | const double alpha = ZAxis.Angle(Axis);
|
|---|
| 186 | Axis.VectorProduct(ZAxis);
|
|---|
| 187 | Line RotationAxis(Vector(0.0,0.0,1.0), Axis); // pt is the current Vector of point on surface
|
|---|
| 188 |
|
|---|
| 189 | for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
|
|---|
| 190 | {
|
|---|
| 191 | (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
|
|---|
| 192 | *(*it2)+=params.center;
|
|---|
| 193 | }
|
|---|
| 194 | cout << "done." << endl;
|
|---|
| 195 |
|
|---|
| 196 | Tensid=NULL;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | cout << "shifting " << ka+1 << " copy of tenside molecule, ";
|
|---|
| 200 | molecule *Tensid=stick;
|
|---|
| 201 | cout << "rotating ...";
|
|---|
| 202 | Vector ZAxis(Vector(0.0,0.0,1.0));
|
|---|
| 203 | Vector Axis(pt[params.N-1]);
|
|---|
| 204 | const double alpha = ZAxis.Angle(Axis);
|
|---|
| 205 | Axis.VectorProduct(ZAxis);
|
|---|
| 206 | Line RotationAxis2(Vector(0.0,0.0,1.0), Axis); // pt is the current Vector of point on surface
|
|---|
| 207 |
|
|---|
| 208 | for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
|
|---|
| 209 | {
|
|---|
| 210 | (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
|
|---|
| 211 | *(*it2)+=params.center;
|
|---|
| 212 | }
|
|---|
| 213 | cout << "done." << endl;
|
|---|
| 214 |
|
|---|
| 215 | Tensid=NULL;
|
|---|
| 216 |
|
|---|
| 217 | GraphSubgraphDissection();
|
|---|
| 218 | return Action::success;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | Action::state_ptr MoleculeCreateMicelleAction::performUndo(Action::state_ptr _state)
|
|---|
| 222 | {
|
|---|
| 223 | // MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.());
|
|---|
| 224 |
|
|---|
| 225 | // string newName = state->mol->Name();
|
|---|
| 226 | // state->mol->setName(state->lastName);
|
|---|
| 227 |
|
|---|
| 228 | return Action::failure;
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | Action::state_ptr MoleculeCreateMicelleAction::performRedo(Action::state_ptr _state)
|
|---|
| 232 | {
|
|---|
| 233 | // Undo and redo have to do the same for this action
|
|---|
| 234 | return performUndo(_state);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 | bool MoleculeCreateMicelleAction::canUndo()
|
|---|
| 239 | {
|
|---|
| 240 | return false;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | bool MoleculeCreateMicelleAction::shouldUndo()
|
|---|
| 244 | {
|
|---|
| 245 | return false;
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | /** =========== end of function ====================== */
|
|---|