| [e2e0a5a] | 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 | /** \file mizelledata.cpp
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  * Implementation of a micelle creator by Daniel Dueck.
 | 
|---|
 | 11 |  */
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | // include config.h
 | 
|---|
 | 14 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 15 | #include <config.h>
 | 
|---|
 | 16 | #endif
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include <iostream>
 | 
|---|
 | 21 | #include <fstream>
 | 
|---|
 | 22 | #include <config.h>
 | 
|---|
 | 23 | #include "atom.hpp"
 | 
|---|
 | 24 | #include "molecule.hpp"
 | 
|---|
 | 25 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 26 | #include "LinearAlgebra/Line.hpp"
 | 
|---|
 | 27 | #include "World.hpp"
 | 
|---|
 | 28 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
 | 29 | #include "Parser/TremoloParser.hpp"
 | 
|---|
 | 30 | #include "Parser/XyzParser.hpp"
 | 
|---|
 | 31 | #include "Parser/PdbParser.hpp"
 | 
|---|
 | 32 | #include "Parser/FormatParserStorage.hpp"
 | 
|---|
 | 33 | #include <gsl/gsl_poly.h>
 | 
|---|
 | 34 | #include <gsl/gsl_eigen.h>
 | 
|---|
 | 35 | #include "Actions/ActionHistory.hpp"
 | 
|---|
 | 36 | #include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
 | 
|---|
 | 37 | #include "Actions/GraphAction/SubgraphDissectionAction.hpp"
 | 
|---|
 | 38 | #include "Shapes/BaseShapes.hpp"
 | 
|---|
 | 39 | #include "Shapes/ShapeOps.hpp"
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #define PATH "/home/heber/tmp/"
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | #define AtomVector std::vector <atom *>
 | 
|---|
 | 44 | #define MoleculeVector std::vector <molecule *>
 | 
|---|
 | 45 | #define AtomList list <atom *>
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | int Delta2(int x1, int x2);
 | 
|---|
 | 48 | double Sqlength (Vector x);
 | 
|---|
 | 49 | int main ()
 | 
|---|
 | 50 | {
 | 
|---|
 | 51 |   setVerbosity(4);
 | 
|---|
 | 52 |   // need to init the history before any action is created
 | 
|---|
 | 53 |   ActionHistory::init();
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 | //1.Molekuel aus pdbfile einlesen und in Variablen speichern
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | string path;
 | 
|---|
 | 58 | {
 | 
|---|
 | 59 |   std::ifstream file;
 | 
|---|
 | 60 |   path = PATH;
 | 
|---|
 | 61 |   path += "/tensid.data";
 | 
|---|
 | 62 |   file.open(path.c_str());
 | 
|---|
 | 63 |   FormatParserStorage::getInstance().getTremolo().load(&file);
 | 
|---|
 | 64 |   file.close();
 | 
|---|
 | 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 | molecule *stick = ever[0]->getMolecule();
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | //3.Molekuel zentrieren
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | stick->CenterOrigin();
 | 
|---|
 | 75 | 
 | 
|---|
 | 76 | //4.Haupttraegheitsachse bestimmen
 | 
|---|
 | 77 | Vector den(0.0,0.0,1.0);
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | World::getInstance().clearMoleculeSelection();  // unselect all
 | 
|---|
 | 80 | World::getInstance().selectMolecule(stick);     // select the desired molecule for the following action
 | 
|---|
 | 81 | MoleculeRotateToPrincipalAxisSystem(den);
 | 
|---|
 | 82 | /* determine
 | 
|---|
 | 83 | principal axis system and make greatest eigenvector be aligned along
 | 
|---|
 | 84 | (0,0,1)
 | 
|---|
 | 85 | */
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | /**/
 | 
|---|
 | 88 | {
 | 
|---|
 | 89 |   std::ofstream file;
 | 
|---|
 | 90 |   path = PATH;
 | 
|---|
 | 91 |   path += "/tensidrot.xyz";
 | 
|---|
 | 92 |   file.open(path.c_str());
 | 
|---|
 | 93 |   FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
 | 
|---|
 | 94 |   file.close();
 | 
|---|
 | 95 | }
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | //5.b: Molekuel um 180 Grad drehen
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | 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
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 | for (molecule::iterator it=stick->begin(); it !=stick->end(); ++it)
 | 
|---|
 | 102 |   (*it)->setPosition(RotationAxis.rotateVector((*it)->getPosition(),M_PI));
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 | {
 | 
|---|
 | 107 |   std::ofstream file;
 | 
|---|
 | 108 |   path = PATH;
 | 
|---|
 | 109 |   path += "/tensid2rot.xyz";
 | 
|---|
 | 110 |   file.open(path.c_str());
 | 
|---|
 | 111 |   FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
 | 
|---|
 | 112 |   file.close();
 | 
|---|
 | 113 | }
 | 
|---|
 | 114 | 
 | 
|---|
 | 115 | //6.Molekuel mehrfach strukturiert mit der Haupttraegheitsachse senkrecht zu einer parametrisierten Oberflaeche anordnen
 | 
|---|
 | 116 | 
 | 
|---|
 | 117 | int N=200;
 | 
|---|
 | 118 | //6.1. Punkte auf der Oberflaeche bestimmen
 | 
|---|
 | 119 | //Algorithmus entnommen aus "http://www.cgafaq.info/wiki/Evenly_distributed_points_on_sphere"
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | int ka =0;
 | 
|---|
 | 122 | double radius= 1.5*sqrt(pow(1.55, 2)*N);
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 | Shape s = resize(Sphere(), radius);
 | 
|---|
 | 125 | std::vector<Vector> pt = s.getHomogeneousPointsOnSurface(N);
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | //6.2."stick" um Radius und Molekuelausdehnung in z-Richtung verschieben.
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2) {
 | 
|---|
 | 130 |         Vector pos= (**it2).getPosition();
 | 
|---|
 | 131 |         pos[2]=pos[2]+radius; // -Min[2]
 | 
|---|
 | 132 |         (**it2).setPosition(pos);
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | {
 | 
|---|
 | 136 |   std::ofstream file;
 | 
|---|
 | 137 |   path = PATH;
 | 
|---|
 | 138 |   path += "/tensid3rot.xyz";
 | 
|---|
 | 139 |   file.open(path.c_str());
 | 
|---|
 | 140 |   FormatParserStorage::getInstance().getXyz().save(&file, World::getInstance().getAllAtoms());
 | 
|---|
 | 141 |   file.close();
 | 
|---|
 | 142 | }
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | //6.3.Erzeugen einer Molekuelliste, die das Molekuel "stick" "N" mal kopiert und um eine Sphaere herum verteilt 
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 | //double MYEPSILON=1e-10;
 | 
|---|
 | 147 | 
 | 
|---|
 | 148 | for (ka = 0; ka<N; ka++){
 | 
|---|
 | 149 |   cout << "Creating " << ka+1 << " copy of tenside molecule, ";
 | 
|---|
 | 150 |         molecule *Tensid=stick->CopyMolecule();
 | 
|---|
 | 151 | 
 | 
|---|
 | 152 |         cout << "rotating ...";
 | 
|---|
 | 153 |   Vector ZAxis(Vector(0.0,0.0,1.0));
 | 
|---|
 | 154 |   Vector Axis(pt[ka]);
 | 
|---|
 | 155 |   const double alpha = ZAxis.Angle(Axis);
 | 
|---|
 | 156 |   Axis.VectorProduct(ZAxis);
 | 
|---|
 | 157 |   Line RotationAxis(Vector(0.0,0.0,1.0), Axis); // pt is the current Vector of point on surface
 | 
|---|
 | 158 | 
 | 
|---|
 | 159 |   for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
 | 
|---|
 | 160 |     (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
 | 
|---|
 | 161 |   cout << "done." << endl;
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 |   Tensid=NULL;
 | 
|---|
 | 164 | }
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 | GraphSubgraphDissection();
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | molecule::iterator it2= stick->begin();
 | 
|---|
 | 169 | while(it2!=stick->end()) {
 | 
|---|
 | 170 |                 atom *part=*it2;
 | 
|---|
 | 171 |                 ++it2;
 | 
|---|
 | 172 |                 stick->RemoveAtom(part);
 | 
|---|
 | 173 |                 World::getInstance().destroyAtom (part);
 | 
|---|
 | 174 |   };
 | 
|---|
 | 175 | World::getInstance().destroyMolecule(stick);
 | 
|---|
 | 176 | 
 | 
|---|
 | 177 | //7. Speichern der Molekuelliste in einem data-file
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | {
 | 
|---|
 | 180 |   std::ofstream file;
 | 
|---|
 | 181 |   path = PATH;
 | 
|---|
 | 182 |   path += "/tensidoutput2.pdb";
 | 
|---|
 | 183 |   file.open(path.c_str());
 | 
|---|
 | 184 |   FormatParserStorage::getInstance().getPdb().save(&file, World::getInstance().getAllAtoms());
 | 
|---|
 | 185 |   file.close();
 | 
|---|
 | 186 | }
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 | {
 | 
|---|
 | 189 |   std::ofstream file;
 | 
|---|
 | 190 |   path = PATH;
 | 
|---|
 | 191 |   path += "/tensidoutput2.data";
 | 
|---|
 | 192 |   file.open(path.c_str());
 | 
|---|
 | 193 |   FormatParserStorage::getInstance().getTremolo().save(&file, World::getInstance().getAllAtoms());
 | 
|---|
 | 194 |   file.close();
 | 
|---|
 | 195 | }
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 | //Anhang
 | 
|---|
 | 198 | 
 | 
|---|
 | 199 | 
 | 
|---|
 | 200 | //gsl_matrix_free (Tensor1);
 | 
|---|
 | 201 |  //gsl_vector_complex_free (eval);
 | 
|---|
 | 202 | //gsl_matrix_complex_free (evec);
 | 
|---|
 | 203 | //gsl_eigen_nonsymmv_free (w);
 | 
|---|
 | 204 | 
 | 
|---|
 | 205 | 
 | 
|---|
 | 206 | MoleculeVector never= World::getInstance().getAllMolecules();
 | 
|---|
 | 207 | MoleculeVector::iterator it3 = never.begin();
 | 
|---|
 | 208 | while(it3!=never.end()) {
 | 
|---|
 | 209 |                 molecule *Tensid=*it3;
 | 
|---|
 | 210 |                 ++it3;
 | 
|---|
 | 211 |                 World::getInstance().destroyMolecule(Tensid);
 | 
|---|
 | 212 |   };
 | 
|---|
 | 213 | ever=World::getInstance().getAllAtoms();
 | 
|---|
 | 214 | AtomVector::iterator it=ever.begin();
 | 
|---|
 | 215 | while(it!=ever.end()) {
 | 
|---|
 | 216 |         atom *member=*it;
 | 
|---|
 | 217 |         ++it;
 | 
|---|
 | 218 |         World::getInstance().destroyAtom(member);
 | 
|---|
 | 219 |         member=NULL;
 | 
|---|
 | 220 | }
 | 
|---|
 | 221 | 
 | 
|---|
 | 222 | //delete parserx;
 | 
|---|
 | 223 | /*for(int Zaehler=0; Zaehler<3;Zaehler++){
 | 
|---|
 | 224 |         delete[] Tensor[Zaehler];
 | 
|---|
 | 225 |         }
 | 
|---|
 | 226 | delete[] Tensor;
 | 
|---|
 | 227 | for(int Zaehler=0; Zaehler<3;Zaehler++){
 | 
|---|
 | 228 |         delete[] rotationmatrix[Zaehler];
 | 
|---|
 | 229 | }
 | 
|---|
 | 230 | delete[] rotationmatrix;
 | 
|---|
 | 231 | */
 | 
|---|
 | 232 | /*for (ka = 0; ka<N; ka++){
 | 
|---|
 | 233 |     delete pt[ka];
 | 
|---|
 | 234 | }
 | 
|---|
 | 235 | delete[] pt;
 | 
|---|
 | 236 | */
 | 
|---|
 | 237 | 
 | 
|---|
 | 238 | return 0;
 | 
|---|
 | 239 | }
 | 
|---|
 | 240 | 
 | 
|---|
 | 241 | int Delta2 (int x1, int x2) { 
 | 
|---|
 | 242 |         if (x1==x2) return 1;
 | 
|---|
 | 243 |         else return 0;  
 | 
|---|
 | 244 | }
 | 
|---|
 | 245 | 
 | 
|---|
 | 246 | double Sqlength (Vector x){
 | 
|---|
 | 247 |         double ergebnis= x[0]*x[0]+x[1]*x[1]+x[2]*x[2];
 | 
|---|
 | 248 |         return ergebnis;
 | 
|---|
 | 249 |         }
 | 
|---|
 | 250 | 
 | 
|---|
 | 251 | /*double[3] rotate (double[3] in[3], double theta, double phi) {
 | 
|---|
 | 252 |         double **rotationmatrix;
 | 
|---|
 | 253 |         rotationmatrix=new double *[3];
 | 
|---|
 | 254 |         for(int Zaehler=0; Zaehler<3;Zaehler++){
 | 
|---|
 | 255 |                 rotationmatrix[Zaehler]=new double[3];
 | 
|---|
 | 256 |                 }
 | 
|---|
 | 257 |         rotationmatrix[0][0]=cos(theta)*cos(phi);
 | 
|---|
 | 258 |         rotationmatrix[0][1]=-sin(phi);
 | 
|---|
 | 259 |         rotationmatrix[0][2]=sin(theta)*cos(phi);
 | 
|---|
 | 260 |         rotationmatrix[1][0]=cos(theta)*sin(phi);
 | 
|---|
 | 261 |         rotationmatrix[1][1]=cos(phi);
 | 
|---|
 | 262 |         rotationmatrix[1][2]=sin(theta)*sin(phi);
 | 
|---|
 | 263 |         rotationmatrix[2][0]=-sin(theta);
 | 
|---|
 | 264 |         rotationmatrix[2][1]=0;
 | 
|---|
 | 265 |         rotationmatrix[2][2]=cos(theta);
 | 
|---|
 | 266 |         double zahl[3];
 | 
|---|
 | 267 |         for(int Zaehler=0; Zaehler<3;Zaehler++){
 | 
|---|
 | 268 |                         Zahl[Zaehler]=rotationmatrix[Zaehler][0]*in[0]+rotationmatrix[Zaehler][1]*in[1]+rotationmatrix[Zaehler][2]*in[2];
 | 
|---|
 | 269 |                         }
 | 
|---|
 | 270 |         for(int Zaehler=0; Zaehler<3;Zaehler++){
 | 
|---|
 | 271 |                 delete[] rotationmatrix[Zaehler];
 | 
|---|
 | 272 |         }
 | 
|---|
 | 273 |         delete[] rotationmatrix;
 | 
|---|
 | 274 | }*/
 | 
|---|