| 1 | /** \file builder.cpp
 | 
|---|
| 2 |  *
 | 
|---|
| 3 |  * By stating absolute positions or binding angles and distances atomic positions of a molecule can be constructed.
 | 
|---|
| 4 |  * The output is the complete configuration file for PCP for direct use.
 | 
|---|
| 5 |  * Features:
 | 
|---|
| 6 |  * -# Atomic data is retrieved from a file, if not found requested and stored there for later re-use
 | 
|---|
| 7 |  * -# step-by-step construction of the molecule beginning either at a centre of with a certain atom
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  */
 | 
|---|
| 10 | 
 | 
|---|
| 11 | /*! \mainpage Molecuilder - a molecular set builder
 | 
|---|
| 12 |  *
 | 
|---|
| 13 |  * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
 | 
|---|
| 14 |  *
 | 
|---|
| 15 |  * \section about About the Program
 | 
|---|
| 16 |  *
 | 
|---|
| 17 |  *  Molecuilder is a short program, written in C++, that enables the construction of a coordinate set for the
 | 
|---|
| 18 |  *  atoms making up an molecule by the successive statement of binding angles and distances and referencing to
 | 
|---|
| 19 |  *  already constructed atoms.
 | 
|---|
| 20 |  *
 | 
|---|
| 21 |  *  A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
 | 
|---|
| 22 |  *  molecular dynamics implementation.
 | 
|---|
| 23 |  *
 | 
|---|
| 24 |  * \section install Installation
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  *  Installation should without problems succeed as follows:
 | 
|---|
| 27 |  *  -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
 | 
|---|
| 28 |  *  -# make
 | 
|---|
| 29 |  *  -# make install
 | 
|---|
| 30 |  *
 | 
|---|
| 31 |  *  Further useful commands are
 | 
|---|
| 32 |  *  -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
 | 
|---|
| 33 |  *  -# make doxygen-doc: Creates these html pages out of the documented source
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  * \section run Running
 | 
|---|
| 36 |  *
 | 
|---|
| 37 |  *  The program can be executed by running: ./molecuilder
 | 
|---|
| 38 |  *
 | 
|---|
| 39 |  *  Note, that it uses a database, called "elements.db", in the executable's directory. If the file is not found,
 | 
|---|
| 40 |  *  it is created and any given data on elements of the periodic table will be stored therein and re-used on
 | 
|---|
| 41 |  *  later re-execution.
 | 
|---|
| 42 |  *
 | 
|---|
| 43 |  * \section ref References
 | 
|---|
| 44 |  *
 | 
|---|
| 45 |  *  For the special configuration file format, see the documentation of pcp.
 | 
|---|
| 46 |  *
 | 
|---|
| 47 |  */
 | 
|---|
| 48 | 
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #include <boost/bind.hpp>
 | 
|---|
| 51 | 
 | 
|---|
| 52 | using namespace std;
 | 
|---|
| 53 | 
 | 
|---|
| 54 | #include <cstring>
 | 
|---|
| 55 | #include <cstdlib>
 | 
|---|
| 56 | 
 | 
|---|
| 57 | #include "analysis_bonds.hpp"
 | 
|---|
| 58 | #include "analysis_correlation.hpp"
 | 
|---|
| 59 | #include "atom.hpp"
 | 
|---|
| 60 | #include "bond.hpp"
 | 
|---|
| 61 | #include "bondgraph.hpp"
 | 
|---|
| 62 | #include "boundary.hpp"
 | 
|---|
| 63 | #include "CommandLineParser.hpp"
 | 
|---|
| 64 | #include "config.hpp"
 | 
|---|
| 65 | #include "element.hpp"
 | 
|---|
| 66 | #include "ellipsoid.hpp"
 | 
|---|
| 67 | #include "helpers.hpp"
 | 
|---|
| 68 | #include "leastsquaremin.hpp"
 | 
|---|
| 69 | #include "linkedcell.hpp"
 | 
|---|
| 70 | #include "log.hpp"
 | 
|---|
| 71 | #include "memoryusageobserver.hpp"
 | 
|---|
| 72 | #include "molecule.hpp"
 | 
|---|
| 73 | #include "periodentafel.hpp"
 | 
|---|
| 74 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| 75 | #include "UIElements/MainWindow.hpp"
 | 
|---|
| 76 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 77 | #include "Menu/ActionMenuItem.hpp"
 | 
|---|
| 78 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 79 | #include "Actions/ActionHistory.hpp"
 | 
|---|
| 80 | #include "Actions/MapOfActions.hpp"
 | 
|---|
| 81 | #include "Actions/MethodAction.hpp"
 | 
|---|
| 82 | #include "Actions/MoleculeAction/ChangeNameAction.hpp"
 | 
|---|
| 83 | #include "World.hpp"
 | 
|---|
| 84 | #include "version.h"
 | 
|---|
| 85 | #include "World.hpp"
 | 
|---|
| 86 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 87 | 
 | 
|---|
| 88 | /********************************************* Subsubmenu routine ************************************/
 | 
|---|
| 89 | #if 0
 | 
|---|
| 90 | /** Submenu for adding atoms to the molecule.
 | 
|---|
| 91 |  * \param *periode periodentafel
 | 
|---|
| 92 |  * \param *molecule molecules with atoms
 | 
|---|
| 93 |  */
 | 
|---|
| 94 | static void AddAtoms(periodentafel *periode, molecule *mol)
 | 
|---|
| 95 | {
 | 
|---|
| 96 |   atom *first, *second, *third, *fourth;
 | 
|---|
| 97 |   Vector **atoms;
 | 
|---|
| 98 |   Vector x,y,z,n;  // coordinates for absolute point in cell volume
 | 
|---|
| 99 |   double a,b,c;
 | 
|---|
| 100 |   char choice;  // menu choice char
 | 
|---|
| 101 |   bool valid;
 | 
|---|
| 102 | 
 | 
|---|
| 103 |   cout << Verbose(0) << "===========ADD ATOM============================" << endl;
 | 
|---|
| 104 |   cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
 | 
|---|
| 105 |   cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
 | 
|---|
| 106 |   cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
 | 
|---|
| 107 |   cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
 | 
|---|
| 108 |   cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
 | 
|---|
| 109 |   cout << Verbose(0) << "all else - go back" << endl;
 | 
|---|
| 110 |   cout << Verbose(0) << "===============================================" << endl;
 | 
|---|
| 111 |   cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
 | 
|---|
| 112 |   cout << Verbose(0) << "INPUT: ";
 | 
|---|
| 113 |   cin >> choice;
 | 
|---|
| 114 | 
 | 
|---|
| 115 |   switch (choice) {
 | 
|---|
| 116 |     default:
 | 
|---|
| 117 |       DoeLog(2) && (eLog()<< Verbose(2) << "Not a valid choice." << endl);
 | 
|---|
| 118 |       break;
 | 
|---|
| 119 |       case 'a': // absolute coordinates of atom
 | 
|---|
| 120 |         cout << Verbose(0) << "Enter absolute coordinates." << endl;
 | 
|---|
| 121 |         first = new atom;
 | 
|---|
| 122 |         first->x.AskPosition(World::getInstance().getDomain(), false);
 | 
|---|
| 123 |         first->type = periode->AskElement();  // give type
 | 
|---|
| 124 |         mol->AddAtom(first);  // add to molecule
 | 
|---|
| 125 |         break;
 | 
|---|
| 126 | 
 | 
|---|
| 127 |       case 'b': // relative coordinates of atom wrt to reference point
 | 
|---|
| 128 |         first = new atom;
 | 
|---|
| 129 |         valid = true;
 | 
|---|
| 130 |         do {
 | 
|---|
| 131 |           if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
 | 
|---|
| 132 |           cout << Verbose(0) << "Enter reference coordinates." << endl;
 | 
|---|
| 133 |           x.AskPosition(World::getInstance().getDomain(), true);
 | 
|---|
| 134 |           cout << Verbose(0) << "Enter relative coordinates." << endl;
 | 
|---|
| 135 |           first->x.AskPosition(World::getInstance().getDomain(), false);
 | 
|---|
| 136 |           first->x.AddVector((const Vector *)&x);
 | 
|---|
| 137 |           cout << Verbose(0) << "\n";
 | 
|---|
| 138 |         } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
 | 
|---|
| 139 |         first->type = periode->AskElement();  // give type
 | 
|---|
| 140 |         mol->AddAtom(first);  // add to molecule
 | 
|---|
| 141 |         break;
 | 
|---|
| 142 | 
 | 
|---|
| 143 |       case 'c': // relative coordinates of atom wrt to already placed atom
 | 
|---|
| 144 |         first = new atom;
 | 
|---|
| 145 |         valid = true;
 | 
|---|
| 146 |         do {
 | 
|---|
| 147 |           if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
 | 
|---|
| 148 |           second = mol->AskAtom("Enter atom number: ");
 | 
|---|
| 149 |           DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl);
 | 
|---|
| 150 |           first->x.AskPosition(World::getInstance().getDomain(), false);
 | 
|---|
| 151 |           for (int i=NDIM;i--;) {
 | 
|---|
| 152 |             first->x.x[i] += second->x.x[i];
 | 
|---|
| 153 |           }
 | 
|---|
| 154 |         } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
 | 
|---|
| 155 |         first->type = periode->AskElement();  // give type
 | 
|---|
| 156 |         mol->AddAtom(first);  // add to molecule
 | 
|---|
| 157 |         break;
 | 
|---|
| 158 | 
 | 
|---|
| 159 |     case 'd': // two atoms, two angles and a distance
 | 
|---|
| 160 |         first = new atom;
 | 
|---|
| 161 |         valid = true;
 | 
|---|
| 162 |         do {
 | 
|---|
| 163 |           if (!valid) {
 | 
|---|
| 164 |             DoeLog(2) && (eLog()<< Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl);
 | 
|---|
| 165 |           }
 | 
|---|
| 166 |           cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
 | 
|---|
| 167 |           second = mol->AskAtom("Enter central atom: ");
 | 
|---|
| 168 |           third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
 | 
|---|
| 169 |           fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
 | 
|---|
| 170 |           a = ask_value("Enter distance between central (first) and new atom: ");
 | 
|---|
| 171 |           b = ask_value("Enter angle between new, first and second atom (degrees): ");
 | 
|---|
| 172 |           b *= M_PI/180.;
 | 
|---|
| 173 |           bound(&b, 0., 2.*M_PI);
 | 
|---|
| 174 |           c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
 | 
|---|
| 175 |           c *= M_PI/180.;
 | 
|---|
| 176 |           bound(&c, -M_PI, M_PI);
 | 
|---|
| 177 |           cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
 | 
|---|
| 178 | /*
 | 
|---|
| 179 |           second->Output(1,1,(ofstream *)&cout);
 | 
|---|
| 180 |           third->Output(1,2,(ofstream *)&cout);
 | 
|---|
| 181 |           fourth->Output(1,3,(ofstream *)&cout);
 | 
|---|
| 182 |           n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
 | 
|---|
| 183 |           x.Copyvector(&second->x);
 | 
|---|
| 184 |           x.SubtractVector(&third->x);
 | 
|---|
| 185 |           x.Copyvector(&fourth->x);
 | 
|---|
| 186 |           x.SubtractVector(&third->x);
 | 
|---|
| 187 | 
 | 
|---|
| 188 |           if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
 | 
|---|
| 189 |          coutg() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
 | 
|---|
| 190 |             continue;
 | 
|---|
| 191 |           }
 | 
|---|
| 192 |           DoLog(0) && (Log() << Verbose(0) << "resulting relative coordinates: ");
 | 
|---|
| 193 |           z.Output();
 | 
|---|
| 194 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 195 |           */
 | 
|---|
| 196 |           // calc axis vector
 | 
|---|
| 197 |           x.CopyVector(&second->x);
 | 
|---|
| 198 |           x.SubtractVector(&third->x);
 | 
|---|
| 199 |           x.Normalize();
 | 
|---|
| 200 |           Log() << Verbose(0) << "x: ",
 | 
|---|
| 201 |           x.Output();
 | 
|---|
| 202 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 203 |           z.MakeNormalVector(&second->x,&third->x,&fourth->x);
 | 
|---|
| 204 |           Log() << Verbose(0) << "z: ",
 | 
|---|
| 205 |           z.Output();
 | 
|---|
| 206 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 207 |           y.MakeNormalVector(&x,&z);
 | 
|---|
| 208 |           Log() << Verbose(0) << "y: ",
 | 
|---|
| 209 |           y.Output();
 | 
|---|
| 210 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 211 | 
 | 
|---|
| 212 |           // rotate vector around first angle
 | 
|---|
| 213 |           first->x.CopyVector(&x);
 | 
|---|
| 214 |           first->x.RotateVector(&z,b - M_PI);
 | 
|---|
| 215 |           Log() << Verbose(0) << "Rotated vector: ",
 | 
|---|
| 216 |           first->x.Output();
 | 
|---|
| 217 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 218 |           // remove the projection onto the rotation plane of the second angle
 | 
|---|
| 219 |           n.CopyVector(&y);
 | 
|---|
| 220 |           n.Scale(first->x.ScalarProduct(&y));
 | 
|---|
| 221 |           Log() << Verbose(0) << "N1: ",
 | 
|---|
| 222 |           n.Output();
 | 
|---|
| 223 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 224 |           first->x.SubtractVector(&n);
 | 
|---|
| 225 |           Log() << Verbose(0) << "Subtracted vector: ",
 | 
|---|
| 226 |           first->x.Output();
 | 
|---|
| 227 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 228 |           n.CopyVector(&z);
 | 
|---|
| 229 |           n.Scale(first->x.ScalarProduct(&z));
 | 
|---|
| 230 |           Log() << Verbose(0) << "N2: ",
 | 
|---|
| 231 |           n.Output();
 | 
|---|
| 232 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 233 |           first->x.SubtractVector(&n);
 | 
|---|
| 234 |           Log() << Verbose(0) << "2nd subtracted vector: ",
 | 
|---|
| 235 |           first->x.Output();
 | 
|---|
| 236 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 237 | 
 | 
|---|
| 238 |           // rotate another vector around second angle
 | 
|---|
| 239 |           n.CopyVector(&y);
 | 
|---|
| 240 |           n.RotateVector(&x,c - M_PI);
 | 
|---|
| 241 |           Log() << Verbose(0) << "2nd Rotated vector: ",
 | 
|---|
| 242 |           n.Output();
 | 
|---|
| 243 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 244 | 
 | 
|---|
| 245 |           // add the two linear independent vectors
 | 
|---|
| 246 |           first->x.AddVector(&n);
 | 
|---|
| 247 |           first->x.Normalize();
 | 
|---|
| 248 |           first->x.Scale(a);
 | 
|---|
| 249 |           first->x.AddVector(&second->x);
 | 
|---|
| 250 | 
 | 
|---|
| 251 |           DoLog(0) && (Log() << Verbose(0) << "resulting coordinates: ");
 | 
|---|
| 252 |           first->x.Output();
 | 
|---|
| 253 |           DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 254 |         } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
 | 
|---|
| 255 |         first->type = periode->AskElement();  // give type
 | 
|---|
| 256 |         mol->AddAtom(first);  // add to molecule
 | 
|---|
| 257 |         break;
 | 
|---|
| 258 | 
 | 
|---|
| 259 |       case 'e': // least square distance position to a set of atoms
 | 
|---|
| 260 |         first = new atom;
 | 
|---|
| 261 |         atoms = new (Vector*[128]);
 | 
|---|
| 262 |         valid = true;
 | 
|---|
| 263 |         for(int i=128;i--;)
 | 
|---|
| 264 |           atoms[i] = NULL;
 | 
|---|
| 265 |         int i=0, j=0;
 | 
|---|
| 266 |         cout << Verbose(0) << "Now we need at least three molecules.\n";
 | 
|---|
| 267 |         do {
 | 
|---|
| 268 |           cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
 | 
|---|
| 269 |           cin >> j;
 | 
|---|
| 270 |           if (j != -1) {
 | 
|---|
| 271 |             second = mol->FindAtom(j);
 | 
|---|
| 272 |             atoms[i++] = &(second->x);
 | 
|---|
| 273 |           }
 | 
|---|
| 274 |         } while ((j != -1) && (i<128));
 | 
|---|
| 275 |         if (i >= 2) {
 | 
|---|
| 276 |           first->x.LSQdistance((const Vector **)atoms, i);
 | 
|---|
| 277 |           first->x.Output();
 | 
|---|
| 278 |           first->type = periode->AskElement();  // give type
 | 
|---|
| 279 |           mol->AddAtom(first);  // add to molecule
 | 
|---|
| 280 |         } else {
 | 
|---|
| 281 |           delete first;
 | 
|---|
| 282 |           cout << Verbose(0) << "Please enter at least two vectors!\n";
 | 
|---|
| 283 |         }
 | 
|---|
| 284 |         break;
 | 
|---|
| 285 |   };
 | 
|---|
| 286 | };
 | 
|---|
| 287 | 
 | 
|---|
| 288 | /** Submenu for centering the atoms in the molecule.
 | 
|---|
| 289 |  * \param *mol molecule with all the atoms
 | 
|---|
| 290 |  */
 | 
|---|
| 291 | static void CenterAtoms(molecule *mol)
 | 
|---|
| 292 | {
 | 
|---|
| 293 |   Vector x, y, helper;
 | 
|---|
| 294 |   char choice;  // menu choice char
 | 
|---|
| 295 | 
 | 
|---|
| 296 |   cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
 | 
|---|
| 297 |   cout << Verbose(0) << " a - on origin" << endl;
 | 
|---|
| 298 |   cout << Verbose(0) << " b - on center of gravity" << endl;
 | 
|---|
| 299 |   cout << Verbose(0) << " c - within box with additional boundary" << endl;
 | 
|---|
| 300 |   cout << Verbose(0) << " d - within given simulation box" << endl;
 | 
|---|
| 301 |   cout << Verbose(0) << "all else - go back" << endl;
 | 
|---|
| 302 |   cout << Verbose(0) << "===============================================" << endl;
 | 
|---|
| 303 |   cout << Verbose(0) << "INPUT: ";
 | 
|---|
| 304 |   cin >> choice;
 | 
|---|
| 305 | 
 | 
|---|
| 306 |   switch (choice) {
 | 
|---|
| 307 |     default:
 | 
|---|
| 308 |       cout << Verbose(0) << "Not a valid choice." << endl;
 | 
|---|
| 309 |       break;
 | 
|---|
| 310 |     case 'a':
 | 
|---|
| 311 |       cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
 | 
|---|
| 312 |       mol->CenterOrigin();
 | 
|---|
| 313 |       break;
 | 
|---|
| 314 |     case 'b':
 | 
|---|
| 315 |       cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
 | 
|---|
| 316 |       mol->CenterPeriodic();
 | 
|---|
| 317 |       break;
 | 
|---|
| 318 |     case 'c':
 | 
|---|
| 319 |       cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
 | 
|---|
| 320 |       for (int i=0;i<NDIM;i++) {
 | 
|---|
| 321 |         cout << Verbose(0) << "Enter axis " << i << " boundary: ";
 | 
|---|
| 322 |         cin >> y.x[i];
 | 
|---|
| 323 |       }
 | 
|---|
| 324 |       mol->CenterEdge(&x);  // make every coordinate positive
 | 
|---|
| 325 |       mol->Center.AddVector(&y); // translate by boundary
 | 
|---|
| 326 |       helper.CopyVector(&y);
 | 
|---|
| 327 |       helper.Scale(2.);
 | 
|---|
| 328 |       helper.AddVector(&x);
 | 
|---|
| 329 |       mol->SetBoxDimension(&helper);  // update Box of atoms by boundary
 | 
|---|
| 330 |       break;
 | 
|---|
| 331 |     case 'd':
 | 
|---|
| 332 |       cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
 | 
|---|
| 333 |       for (int i=0;i<NDIM;i++) {
 | 
|---|
| 334 |         cout << Verbose(0) << "Enter axis " << i << " boundary: ";
 | 
|---|
| 335 |         cin >> x.x[i];
 | 
|---|
| 336 |       }
 | 
|---|
| 337 |       // update Box of atoms by boundary
 | 
|---|
| 338 |       mol->SetBoxDimension(&x);
 | 
|---|
| 339 |       // center
 | 
|---|
| 340 |       mol->CenterInBox();
 | 
|---|
| 341 |       break;
 | 
|---|
| 342 |   }
 | 
|---|
| 343 | };
 | 
|---|
| 344 | 
 | 
|---|
| 345 | /** Submenu for aligning the atoms in the molecule.
 | 
|---|
| 346 |  * \param *periode periodentafel
 | 
|---|
| 347 |  * \param *mol molecule with all the atoms
 | 
|---|
| 348 |  */
 | 
|---|
| 349 | static void AlignAtoms(periodentafel *periode, molecule *mol)
 | 
|---|
| 350 | {
 | 
|---|
| 351 |   atom *first, *second, *third;
 | 
|---|
| 352 |   Vector x,n;
 | 
|---|
| 353 |   char choice;  // menu choice char
 | 
|---|
| 354 | 
 | 
|---|
| 355 |   cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
 | 
|---|
| 356 |   cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
 | 
|---|
| 357 |   cout << Verbose(0) << " b - state alignment vector" << endl;
 | 
|---|
| 358 |   cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
 | 
|---|
| 359 |   cout << Verbose(0) << " d - align automatically by least square fit" << endl;
 | 
|---|
| 360 |   cout << Verbose(0) << "all else - go back" << endl;
 | 
|---|
| 361 |   cout << Verbose(0) << "===============================================" << endl;
 | 
|---|
| 362 |   cout << Verbose(0) << "INPUT: ";
 | 
|---|
| 363 |   cin >> choice;
 | 
|---|
| 364 | 
 | 
|---|
| 365 |   switch (choice) {
 | 
|---|
| 366 |     default:
 | 
|---|
| 367 |     case 'a': // three atoms defining mirror plane
 | 
|---|
| 368 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 369 |       second = mol->AskAtom("Enter second atom: ");
 | 
|---|
| 370 |       third = mol->AskAtom("Enter third atom: ");
 | 
|---|
| 371 | 
 | 
|---|
| 372 |       n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
 | 
|---|
| 373 |       break;
 | 
|---|
| 374 |     case 'b': // normal vector of mirror plane
 | 
|---|
| 375 |       cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
 | 
|---|
| 376 |       n.AskPosition(World::getInstance().getDomain(),0);
 | 
|---|
| 377 |       n.Normalize();
 | 
|---|
| 378 |       break;
 | 
|---|
| 379 |     case 'c': // three atoms defining mirror plane
 | 
|---|
| 380 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 381 |       second = mol->AskAtom("Enter second atom: ");
 | 
|---|
| 382 | 
 | 
|---|
| 383 |       n.CopyVector((const Vector *)&first->x);
 | 
|---|
| 384 |       n.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 385 |       n.Normalize();
 | 
|---|
| 386 |       break;
 | 
|---|
| 387 |     case 'd':
 | 
|---|
| 388 |       char shorthand[4];
 | 
|---|
| 389 |       Vector a;
 | 
|---|
| 390 |       struct lsq_params param;
 | 
|---|
| 391 |       do {
 | 
|---|
| 392 |         fprintf(stdout, "Enter the element of atoms to be chosen: ");
 | 
|---|
| 393 |         fscanf(stdin, "%3s", shorthand);
 | 
|---|
| 394 |       } while ((param.type = periode->FindElement(shorthand)) == NULL);
 | 
|---|
| 395 |       cout << Verbose(0) << "Element is " << param.type->name << endl;
 | 
|---|
| 396 |       mol->GetAlignvector(¶m);
 | 
|---|
| 397 |       for (int i=NDIM;i--;) {
 | 
|---|
| 398 |         x.x[i] = gsl_vector_get(param.x,i);
 | 
|---|
| 399 |         n.x[i] = gsl_vector_get(param.x,i+NDIM);
 | 
|---|
| 400 |       }
 | 
|---|
| 401 |       gsl_vector_free(param.x);
 | 
|---|
| 402 |       cout << Verbose(0) << "Offset vector: ";
 | 
|---|
| 403 |       x.Output();
 | 
|---|
| 404 |       DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 405 |       n.Normalize();
 | 
|---|
| 406 |       break;
 | 
|---|
| 407 |   };
 | 
|---|
| 408 |   DoLog(0) && (Log() << Verbose(0) << "Alignment vector: ");
 | 
|---|
| 409 |   n.Output();
 | 
|---|
| 410 |   DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 411 |   mol->Align(&n);
 | 
|---|
| 412 | };
 | 
|---|
| 413 | 
 | 
|---|
| 414 | /** Submenu for mirroring the atoms in the molecule.
 | 
|---|
| 415 |  * \param *mol molecule with all the atoms
 | 
|---|
| 416 |  */
 | 
|---|
| 417 | static void MirrorAtoms(molecule *mol)
 | 
|---|
| 418 | {
 | 
|---|
| 419 |   atom *first, *second, *third;
 | 
|---|
| 420 |   Vector n;
 | 
|---|
| 421 |   char choice;  // menu choice char
 | 
|---|
| 422 | 
 | 
|---|
| 423 |   DoLog(0) && (Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl);
 | 
|---|
| 424 |   DoLog(0) && (Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl);
 | 
|---|
| 425 |   DoLog(0) && (Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl);
 | 
|---|
| 426 |   DoLog(0) && (Log() << Verbose(0) << " c - state two atoms in normal direction" << endl);
 | 
|---|
| 427 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 428 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 429 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 430 |   cin >> choice;
 | 
|---|
| 431 | 
 | 
|---|
| 432 |   switch (choice) {
 | 
|---|
| 433 |     default:
 | 
|---|
| 434 |     case 'a': // three atoms defining mirror plane
 | 
|---|
| 435 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 436 |       second = mol->AskAtom("Enter second atom: ");
 | 
|---|
| 437 |       third = mol->AskAtom("Enter third atom: ");
 | 
|---|
| 438 | 
 | 
|---|
| 439 |       n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
 | 
|---|
| 440 |       break;
 | 
|---|
| 441 |     case 'b': // normal vector of mirror plane
 | 
|---|
| 442 |       DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl);
 | 
|---|
| 443 |       n.AskPosition(World::getInstance().getDomain(),0);
 | 
|---|
| 444 |       n.Normalize();
 | 
|---|
| 445 |       break;
 | 
|---|
| 446 |     case 'c': // three atoms defining mirror plane
 | 
|---|
| 447 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 448 |       second = mol->AskAtom("Enter second atom: ");
 | 
|---|
| 449 | 
 | 
|---|
| 450 |       n.CopyVector((const Vector *)&first->x);
 | 
|---|
| 451 |       n.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 452 |       n.Normalize();
 | 
|---|
| 453 |       break;
 | 
|---|
| 454 |   };
 | 
|---|
| 455 |   DoLog(0) && (Log() << Verbose(0) << "Normal vector: ");
 | 
|---|
| 456 |   n.Output();
 | 
|---|
| 457 |   DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 458 |   mol->Mirror((const Vector *)&n);
 | 
|---|
| 459 | };
 | 
|---|
| 460 | 
 | 
|---|
| 461 | /** Submenu for removing the atoms from the molecule.
 | 
|---|
| 462 |  * \param *mol molecule with all the atoms
 | 
|---|
| 463 |  */
 | 
|---|
| 464 | static void RemoveAtoms(molecule *mol)
 | 
|---|
| 465 | {
 | 
|---|
| 466 |   atom *first, *second;
 | 
|---|
| 467 |   int axis;
 | 
|---|
| 468 |   double tmp1, tmp2;
 | 
|---|
| 469 |   char choice;  // menu choice char
 | 
|---|
| 470 | 
 | 
|---|
| 471 |   DoLog(0) && (Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl);
 | 
|---|
| 472 |   DoLog(0) && (Log() << Verbose(0) << " a - state atom for removal by number" << endl);
 | 
|---|
| 473 |   DoLog(0) && (Log() << Verbose(0) << " b - keep only in radius around atom" << endl);
 | 
|---|
| 474 |   DoLog(0) && (Log() << Verbose(0) << " c - remove this with one axis greater value" << endl);
 | 
|---|
| 475 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 476 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 477 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 478 |   cin >> choice;
 | 
|---|
| 479 | 
 | 
|---|
| 480 |   switch (choice) {
 | 
|---|
| 481 |     default:
 | 
|---|
| 482 |     case 'a':
 | 
|---|
| 483 |       if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
 | 
|---|
| 484 |         DoLog(1) && (Log() << Verbose(1) << "Atom removed." << endl);
 | 
|---|
| 485 |       else
 | 
|---|
| 486 |         DoLog(1) && (Log() << Verbose(1) << "Atom not found." << endl);
 | 
|---|
| 487 |       break;
 | 
|---|
| 488 |     case 'b':
 | 
|---|
| 489 |       second = mol->AskAtom("Enter number of atom as reference point: ");
 | 
|---|
| 490 |       DoLog(0) && (Log() << Verbose(0) << "Enter radius: ");
 | 
|---|
| 491 |       cin >> tmp1;
 | 
|---|
| 492 |       first = mol->start;
 | 
|---|
| 493 |       second = first->next;
 | 
|---|
| 494 |       while(second != mol->end) {
 | 
|---|
| 495 |         first = second;
 | 
|---|
| 496 |         second = first->next;
 | 
|---|
| 497 |         if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
 | 
|---|
| 498 |           mol->RemoveAtom(first);
 | 
|---|
| 499 |       }
 | 
|---|
| 500 |       break;
 | 
|---|
| 501 |     case 'c':
 | 
|---|
| 502 |       DoLog(0) && (Log() << Verbose(0) << "Which axis is it: ");
 | 
|---|
| 503 |       cin >> axis;
 | 
|---|
| 504 |       DoLog(0) && (Log() << Verbose(0) << "Lower boundary: ");
 | 
|---|
| 505 |       cin >> tmp1;
 | 
|---|
| 506 |       DoLog(0) && (Log() << Verbose(0) << "Upper boundary: ");
 | 
|---|
| 507 |       cin >> tmp2;
 | 
|---|
| 508 |       first = mol->start;
 | 
|---|
| 509 |       second = first->next;
 | 
|---|
| 510 |       while(second != mol->end) {
 | 
|---|
| 511 |         first = second;
 | 
|---|
| 512 |         second = first->next;
 | 
|---|
| 513 |         if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
 | 
|---|
| 514 |           //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
 | 
|---|
| 515 |           mol->RemoveAtom(first);
 | 
|---|
| 516 |         }
 | 
|---|
| 517 |       }
 | 
|---|
| 518 |       break;
 | 
|---|
| 519 |   };
 | 
|---|
| 520 |   //mol->Output();
 | 
|---|
| 521 |   choice = 'r';
 | 
|---|
| 522 | };
 | 
|---|
| 523 | 
 | 
|---|
| 524 | /** Submenu for measuring out the atoms in the molecule.
 | 
|---|
| 525 |  * \param *periode periodentafel
 | 
|---|
| 526 |  * \param *mol molecule with all the atoms
 | 
|---|
| 527 |  */
 | 
|---|
| 528 | static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
 | 
|---|
| 529 | {
 | 
|---|
| 530 |   atom *first, *second, *third;
 | 
|---|
| 531 |   Vector x,y;
 | 
|---|
| 532 |   double min[256], tmp1, tmp2, tmp3;
 | 
|---|
| 533 |   int Z;
 | 
|---|
| 534 |   char choice;  // menu choice char
 | 
|---|
| 535 | 
 | 
|---|
| 536 |   DoLog(0) && (Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl);
 | 
|---|
| 537 |   DoLog(0) && (Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl);
 | 
|---|
| 538 |   DoLog(0) && (Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl);
 | 
|---|
| 539 |   DoLog(0) && (Log() << Verbose(0) << " c - calculate bond angle" << endl);
 | 
|---|
| 540 |   DoLog(0) && (Log() << Verbose(0) << " d - calculate principal axis of the system" << endl);
 | 
|---|
| 541 |   DoLog(0) && (Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl);
 | 
|---|
| 542 |   DoLog(0) && (Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl);
 | 
|---|
| 543 |   DoLog(0) && (Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl);
 | 
|---|
| 544 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 545 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 546 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 547 |   cin >> choice;
 | 
|---|
| 548 | 
 | 
|---|
| 549 |   switch(choice) {
 | 
|---|
| 550 |     default:
 | 
|---|
| 551 |       DoLog(1) && (Log() << Verbose(1) << "Not a valid choice." << endl);
 | 
|---|
| 552 |       break;
 | 
|---|
| 553 |     case 'a':
 | 
|---|
| 554 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 555 |       for (int i=MAX_ELEMENTS;i--;)
 | 
|---|
| 556 |         min[i] = 0.;
 | 
|---|
| 557 | 
 | 
|---|
| 558 |       second = mol->start;
 | 
|---|
| 559 |       while ((second->next != mol->end)) {
 | 
|---|
| 560 |         second = second->next; // advance
 | 
|---|
| 561 |         Z = second->type->Z;
 | 
|---|
| 562 |         tmp1 = 0.;
 | 
|---|
| 563 |         if (first != second) {
 | 
|---|
| 564 |           x.CopyVector((const Vector *)&first->x);
 | 
|---|
| 565 |           x.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 566 |           tmp1 = x.Norm();
 | 
|---|
| 567 |         }
 | 
|---|
| 568 |         if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
 | 
|---|
| 569 |         //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
 | 
|---|
| 570 |       }
 | 
|---|
| 571 |       for (int i=MAX_ELEMENTS;i--;)
 | 
|---|
| 572 |         if (min[i] != 0.) Log() << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
 | 
|---|
| 573 |       break;
 | 
|---|
| 574 | 
 | 
|---|
| 575 |     case 'b':
 | 
|---|
| 576 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 577 |       second = mol->AskAtom("Enter second atom: ");
 | 
|---|
| 578 |       for (int i=NDIM;i--;)
 | 
|---|
| 579 |         min[i] = 0.;
 | 
|---|
| 580 |       x.CopyVector((const Vector *)&first->x);
 | 
|---|
| 581 |       x.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 582 |       tmp1 = x.Norm();
 | 
|---|
| 583 |       DoLog(1) && (Log() << Verbose(1) << "Distance vector is ");
 | 
|---|
| 584 |       x.Output();
 | 
|---|
| 585 |       DoLog(0) && (Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl);
 | 
|---|
| 586 |       break;
 | 
|---|
| 587 | 
 | 
|---|
| 588 |     case 'c':
 | 
|---|
| 589 |       DoLog(0) && (Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl);
 | 
|---|
| 590 |       first = mol->AskAtom("Enter first atom: ");
 | 
|---|
| 591 |       second = mol->AskAtom("Enter central atom: ");
 | 
|---|
| 592 |       third  = mol->AskAtom("Enter last atom: ");
 | 
|---|
| 593 |       tmp1 = tmp2 = tmp3 = 0.;
 | 
|---|
| 594 |       x.CopyVector((const Vector *)&first->x);
 | 
|---|
| 595 |       x.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 596 |       y.CopyVector((const Vector *)&third->x);
 | 
|---|
| 597 |       y.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 598 |       DoLog(0) && (Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ");
 | 
|---|
| 599 |       DoLog(0) && (Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl);
 | 
|---|
| 600 |       break;
 | 
|---|
| 601 |     case 'd':
 | 
|---|
| 602 |       DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
 | 
|---|
| 603 |       DoLog(0) && (Log() << Verbose(0) << "Shall we rotate? [0/1]: ");
 | 
|---|
| 604 |       cin >> Z;
 | 
|---|
| 605 |       if ((Z >=0) && (Z <=1))
 | 
|---|
| 606 |         mol->PrincipalAxisSystem((bool)Z);
 | 
|---|
| 607 |       else
 | 
|---|
| 608 |         mol->PrincipalAxisSystem(false);
 | 
|---|
| 609 |       break;
 | 
|---|
| 610 |     case 'e':
 | 
|---|
| 611 |       {
 | 
|---|
| 612 |         DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
 | 
|---|
| 613 |         class Tesselation *TesselStruct = NULL;
 | 
|---|
| 614 |         const LinkedCell *LCList = NULL;
 | 
|---|
| 615 |         LCList = new LinkedCell(mol, 10.);
 | 
|---|
| 616 |         FindConvexBorder(mol, TesselStruct, LCList, NULL);
 | 
|---|
| 617 |         double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
 | 
|---|
| 618 |         DoLog(0) && (Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl);\
 | 
|---|
| 619 |         delete(LCList);
 | 
|---|
| 620 |         delete(TesselStruct);
 | 
|---|
| 621 |       }
 | 
|---|
| 622 |       break;
 | 
|---|
| 623 |     case 'f':
 | 
|---|
| 624 |       mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
 | 
|---|
| 625 |       break;
 | 
|---|
| 626 |     case 'g':
 | 
|---|
| 627 |       {
 | 
|---|
| 628 |         char filename[255];
 | 
|---|
| 629 |         DoLog(0) && (Log() << Verbose(0) << "Please enter filename: " << endl);
 | 
|---|
| 630 |         cin >> filename;
 | 
|---|
| 631 |         DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl);
 | 
|---|
| 632 |         ofstream *output = new ofstream(filename, ios::trunc);
 | 
|---|
| 633 |         if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
 | 
|---|
| 634 |           DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
 | 
|---|
| 635 |         else
 | 
|---|
| 636 |           DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
 | 
|---|
| 637 |         output->close();
 | 
|---|
| 638 |         delete(output);
 | 
|---|
| 639 |       }
 | 
|---|
| 640 |       break;
 | 
|---|
| 641 |   }
 | 
|---|
| 642 | };
 | 
|---|
| 643 | 
 | 
|---|
| 644 | /** Submenu for measuring out the atoms in the molecule.
 | 
|---|
| 645 |  * \param *mol molecule with all the atoms
 | 
|---|
| 646 |  * \param *configuration configuration structure for the to be written config files of all fragments
 | 
|---|
| 647 |  */
 | 
|---|
| 648 | static void FragmentAtoms(molecule *mol, config *configuration)
 | 
|---|
| 649 | {
 | 
|---|
| 650 |   int Order1;
 | 
|---|
| 651 |   clock_t start, end;
 | 
|---|
| 652 | 
 | 
|---|
| 653 |   DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
 | 
|---|
| 654 |   DoLog(0) && (Log() << Verbose(0) << "What's the desired bond order: ");
 | 
|---|
| 655 |   cin >> Order1;
 | 
|---|
| 656 |   if (mol->first->next != mol->last) {  // there are bonds
 | 
|---|
| 657 |     start = clock();
 | 
|---|
| 658 |     mol->FragmentMolecule(Order1, configuration);
 | 
|---|
| 659 |     end = clock();
 | 
|---|
| 660 |     DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
 | 
|---|
| 661 |   } else
 | 
|---|
| 662 |     DoLog(0) && (Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl);
 | 
|---|
| 663 | };
 | 
|---|
| 664 | 
 | 
|---|
| 665 | /********************************************** Submenu routine **************************************/
 | 
|---|
| 666 | 
 | 
|---|
| 667 | /** Submenu for manipulating atoms.
 | 
|---|
| 668 |  * \param *periode periodentafel
 | 
|---|
| 669 |  * \param *molecules list of molecules whose atoms are to be manipulated
 | 
|---|
| 670 |  */
 | 
|---|
| 671 | static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
 | 
|---|
| 672 | {
 | 
|---|
| 673 |   atom *first, *second, *third;
 | 
|---|
| 674 |   molecule *mol = NULL;
 | 
|---|
| 675 |   Vector x,y,z,n; // coordinates for absolute point in cell volume
 | 
|---|
| 676 |   double *factor; // unit factor if desired
 | 
|---|
| 677 |   double bond, minBond;
 | 
|---|
| 678 |   char choice;  // menu choice char
 | 
|---|
| 679 |   bool valid;
 | 
|---|
| 680 | 
 | 
|---|
| 681 |   DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl);
 | 
|---|
| 682 |   DoLog(0) && (Log() << Verbose(0) << "a - add an atom" << endl);
 | 
|---|
| 683 |   DoLog(0) && (Log() << Verbose(0) << "r - remove an atom" << endl);
 | 
|---|
| 684 |   DoLog(0) && (Log() << Verbose(0) << "b - scale a bond between atoms" << endl);
 | 
|---|
| 685 |   DoLog(0) && (Log() << Verbose(0) << "t - turn an atom round another bond" << endl);
 | 
|---|
| 686 |   DoLog(0) && (Log() << Verbose(0) << "u - change an atoms element" << endl);
 | 
|---|
| 687 |   DoLog(0) && (Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl);
 | 
|---|
| 688 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 689 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 690 |   if (molecules->NumberOfActiveMolecules() > 1)
 | 
|---|
| 691 |     DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
 | 
|---|
| 692 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 693 |   cin >> choice;
 | 
|---|
| 694 | 
 | 
|---|
| 695 |   switch (choice) {
 | 
|---|
| 696 |     default:
 | 
|---|
| 697 |       DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
 | 
|---|
| 698 |       break;
 | 
|---|
| 699 | 
 | 
|---|
| 700 |     case 'a': // add atom
 | 
|---|
| 701 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 702 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 703 |         mol = *ListRunner;
 | 
|---|
| 704 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 705 |         AddAtoms(periode, mol);
 | 
|---|
| 706 |       }
 | 
|---|
| 707 |       break;
 | 
|---|
| 708 | 
 | 
|---|
| 709 |     case 'b': // scale a bond
 | 
|---|
| 710 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 711 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 712 |         mol = *ListRunner;
 | 
|---|
| 713 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 714 |         DoLog(0) && (Log() << Verbose(0) << "Scaling bond length between two atoms." << endl);
 | 
|---|
| 715 |         first = mol->AskAtom("Enter first (fixed) atom: ");
 | 
|---|
| 716 |         second = mol->AskAtom("Enter second (shifting) atom: ");
 | 
|---|
| 717 |         minBond = 0.;
 | 
|---|
| 718 |         for (int i=NDIM;i--;)
 | 
|---|
| 719 |           minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
 | 
|---|
| 720 |         minBond = sqrt(minBond);
 | 
|---|
| 721 |         DoLog(0) && (Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl);
 | 
|---|
| 722 |         DoLog(0) && (Log() << Verbose(0) << "Enter new bond length [a.u.]: ");
 | 
|---|
| 723 |         cin >> bond;
 | 
|---|
| 724 |         for (int i=NDIM;i--;) {
 | 
|---|
| 725 |           second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
 | 
|---|
| 726 |         }
 | 
|---|
| 727 |         //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
 | 
|---|
| 728 |         //second->Output(second->type->No, 1);
 | 
|---|
| 729 |       }
 | 
|---|
| 730 |       break;
 | 
|---|
| 731 | 
 | 
|---|
| 732 |     case 'c': // unit scaling of the metric
 | 
|---|
| 733 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 734 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 735 |         mol = *ListRunner;
 | 
|---|
| 736 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 737 |        DoLog(0) && (Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl);
 | 
|---|
| 738 |        DoLog(0) && (Log() << Verbose(0) << "Enter three factors: ");
 | 
|---|
| 739 |        factor = new double[NDIM];
 | 
|---|
| 740 |        cin >> factor[0];
 | 
|---|
| 741 |        cin >> factor[1];
 | 
|---|
| 742 |        cin >> factor[2];
 | 
|---|
| 743 |        valid = true;
 | 
|---|
| 744 |        mol->Scale((const double ** const)&factor);
 | 
|---|
| 745 |        delete[](factor);
 | 
|---|
| 746 |       }
 | 
|---|
| 747 |      break;
 | 
|---|
| 748 | 
 | 
|---|
| 749 |     case 'l': // measure distances or angles
 | 
|---|
| 750 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 751 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 752 |         mol = *ListRunner;
 | 
|---|
| 753 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 754 |         MeasureAtoms(periode, mol, configuration);
 | 
|---|
| 755 |       }
 | 
|---|
| 756 |       break;
 | 
|---|
| 757 | 
 | 
|---|
| 758 |     case 'r': // remove atom
 | 
|---|
| 759 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 760 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 761 |         mol = *ListRunner;
 | 
|---|
| 762 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 763 |         RemoveAtoms(mol);
 | 
|---|
| 764 |       }
 | 
|---|
| 765 |       break;
 | 
|---|
| 766 | 
 | 
|---|
| 767 |     case 't': // turn/rotate atom
 | 
|---|
| 768 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 769 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 770 |           mol = *ListRunner;
 | 
|---|
| 771 |           DoLog(0) && (Log() << Verbose(0) << "Turning atom around another bond - first is atom to turn, second (central) and third specify bond" << endl);
 | 
|---|
| 772 |           first = mol->AskAtom("Enter turning atom: ");
 | 
|---|
| 773 |           second = mol->AskAtom("Enter central atom: ");
 | 
|---|
| 774 |           third  = mol->AskAtom("Enter bond atom: ");
 | 
|---|
| 775 |           cout << Verbose(0) << "Enter new angle in degrees: ";
 | 
|---|
| 776 |           double tmp = 0.;
 | 
|---|
| 777 |           cin >> tmp;
 | 
|---|
| 778 |           // calculate old angle
 | 
|---|
| 779 |           x.CopyVector((const Vector *)&first->x);
 | 
|---|
| 780 |           x.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 781 |           y.CopyVector((const Vector *)&third->x);
 | 
|---|
| 782 |           y.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 783 |           double alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
 | 
|---|
| 784 |           cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
 | 
|---|
| 785 |           cout << Verbose(0) << alpha << " degrees" << endl;
 | 
|---|
| 786 |           // rotate
 | 
|---|
| 787 |           z.MakeNormalVector(&x,&y);
 | 
|---|
| 788 |           x.RotateVector(&z,(alpha-tmp)*M_PI/180.);
 | 
|---|
| 789 |           x.AddVector(&second->x);
 | 
|---|
| 790 |           first->x.CopyVector(&x);
 | 
|---|
| 791 |           // check new angle
 | 
|---|
| 792 |           x.CopyVector((const Vector *)&first->x);
 | 
|---|
| 793 |           x.SubtractVector((const Vector *)&second->x);
 | 
|---|
| 794 |           alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
 | 
|---|
| 795 |           cout << Verbose(0) << "new Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
 | 
|---|
| 796 |           cout << Verbose(0) << alpha << " degrees" << endl;
 | 
|---|
| 797 |         }
 | 
|---|
| 798 |       break;
 | 
|---|
| 799 | 
 | 
|---|
| 800 |     case 'u': // change an atom's element
 | 
|---|
| 801 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 802 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 803 |         int Z;
 | 
|---|
| 804 |         mol = *ListRunner;
 | 
|---|
| 805 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 806 |         first = NULL;
 | 
|---|
| 807 |         do {
 | 
|---|
| 808 |           DoLog(0) && (Log() << Verbose(0) << "Change the element of which atom: ");
 | 
|---|
| 809 |           cin >> Z;
 | 
|---|
| 810 |         } while ((first = mol->FindAtom(Z)) == NULL);
 | 
|---|
| 811 |         DoLog(0) && (Log() << Verbose(0) << "New element by atomic number Z: ");
 | 
|---|
| 812 |         cin >> Z;
 | 
|---|
| 813 |         first->type = periode->FindElement(Z);
 | 
|---|
| 814 |         DoLog(0) && (Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl);
 | 
|---|
| 815 |       }
 | 
|---|
| 816 |       break;
 | 
|---|
| 817 |   }
 | 
|---|
| 818 | };
 | 
|---|
| 819 | 
 | 
|---|
| 820 | /** Submenu for manipulating molecules.
 | 
|---|
| 821 |  * \param *periode periodentafel
 | 
|---|
| 822 |  * \param *molecules list of molecule to manipulate
 | 
|---|
| 823 |  */
 | 
|---|
| 824 | static void ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
 | 
|---|
| 825 | {
 | 
|---|
| 826 |   atom *first = NULL;
 | 
|---|
| 827 |   Vector x,y,z,n; // coordinates for absolute point in cell volume
 | 
|---|
| 828 |   int j, axis, count, faktor;
 | 
|---|
| 829 |   char choice;  // menu choice char
 | 
|---|
| 830 |   molecule *mol = NULL;
 | 
|---|
| 831 |   element **Elements;
 | 
|---|
| 832 |   Vector **vectors;
 | 
|---|
| 833 |   MoleculeLeafClass *Subgraphs = NULL;
 | 
|---|
| 834 | 
 | 
|---|
| 835 |   DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl);
 | 
|---|
| 836 |   DoLog(0) && (Log() << Verbose(0) << "c - scale by unit transformation" << endl);
 | 
|---|
| 837 |   DoLog(0) && (Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl);
 | 
|---|
| 838 |   DoLog(0) && (Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl);
 | 
|---|
| 839 |   DoLog(0) && (Log() << Verbose(0) << "g - center atoms in box" << endl);
 | 
|---|
| 840 |   DoLog(0) && (Log() << Verbose(0) << "i - realign molecule" << endl);
 | 
|---|
| 841 |   DoLog(0) && (Log() << Verbose(0) << "m - mirror all molecules" << endl);
 | 
|---|
| 842 |   DoLog(0) && (Log() << Verbose(0) << "o - create connection matrix" << endl);
 | 
|---|
| 843 |   DoLog(0) && (Log() << Verbose(0) << "t - translate molecule by vector" << endl);
 | 
|---|
| 844 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 845 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 846 |   if (molecules->NumberOfActiveMolecules() > 1)
 | 
|---|
| 847 |     DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
 | 
|---|
| 848 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 849 |   cin >> choice;
 | 
|---|
| 850 | 
 | 
|---|
| 851 |   switch (choice) {
 | 
|---|
| 852 |     default:
 | 
|---|
| 853 |       DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
 | 
|---|
| 854 |       break;
 | 
|---|
| 855 | 
 | 
|---|
| 856 |     case 'd': // duplicate the periodic cell along a given axis, given times
 | 
|---|
| 857 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) 
 | 
|---|
| 858 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 859 |         mol = *ListRunner;
 | 
|---|
| 860 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 861 |         DoLog(0) && (Log() << Verbose(0) << "State the axis [(+-)123]: ");
 | 
|---|
| 862 |         cin >> axis;
 | 
|---|
| 863 |         DoLog(0) && (Log() << Verbose(0) << "State the factor: ");
 | 
|---|
| 864 |         cin >> faktor;
 | 
|---|
| 865 | 
 | 
|---|
| 866 |         mol->CountAtoms(); // recount atoms
 | 
|---|
| 867 |         if (mol->AtomCount != 0) {  // if there is more than none
 | 
|---|
| 868 |           count = mol->AtomCount;  // is changed becausing of adding, thus has to be stored away beforehand
 | 
|---|
| 869 |           Elements = new element *[count];
 | 
|---|
| 870 |           vectors = new Vector *[count];
 | 
|---|
| 871 |           j = 0;
 | 
|---|
| 872 |           first = mol->start;
 | 
|---|
| 873 |           while (first->next != mol->end) { // make a list of all atoms with coordinates and element
 | 
|---|
| 874 |             first = first->next;
 | 
|---|
| 875 |             Elements[j] = first->type;
 | 
|---|
| 876 |             vectors[j] = &first->x;
 | 
|---|
| 877 |             j++;
 | 
|---|
| 878 |           }
 | 
|---|
| 879 |           if (count != j)
 | 
|---|
| 880 |             DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
 | 
|---|
| 881 |           x.Zero();
 | 
|---|
| 882 |           y.Zero();
 | 
|---|
| 883 |           y.x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
 | 
|---|
| 884 |           for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
 | 
|---|
| 885 |             x.AddVector(&y); // per factor one cell width further
 | 
|---|
| 886 |             for (int k=count;k--;) { // go through every atom of the original cell
 | 
|---|
| 887 |               first = new atom(); // create a new body
 | 
|---|
| 888 |               first->x.CopyVector(vectors[k]);  // use coordinate of original atom
 | 
|---|
| 889 |               first->x.AddVector(&x);     // translate the coordinates
 | 
|---|
| 890 |               first->type = Elements[k];  // insert original element
 | 
|---|
| 891 |               mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
 | 
|---|
| 892 |             }
 | 
|---|
| 893 |           }
 | 
|---|
| 894 |           if (mol->first->next != mol->last) // if connect matrix is present already, redo it
 | 
|---|
| 895 |             mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
 | 
|---|
| 896 |           // free memory
 | 
|---|
| 897 |           delete[](Elements);
 | 
|---|
| 898 |           delete[](vectors);
 | 
|---|
| 899 |           // correct cell size
 | 
|---|
| 900 |           if (axis < 0) { // if sign was negative, we have to translate everything
 | 
|---|
| 901 |             x.Zero();
 | 
|---|
| 902 |             x.AddVector(&y);
 | 
|---|
| 903 |             x.Scale(-(faktor-1));
 | 
|---|
| 904 |             mol->Translate(&x);
 | 
|---|
| 905 |           }
 | 
|---|
| 906 |           World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
 | 
|---|
| 907 |         }
 | 
|---|
| 908 |       }
 | 
|---|
| 909 |       break;
 | 
|---|
| 910 | 
 | 
|---|
| 911 |     case 'f':
 | 
|---|
| 912 |       FragmentAtoms(mol, configuration);
 | 
|---|
| 913 |       break;
 | 
|---|
| 914 | 
 | 
|---|
| 915 |     case 'g': // center the atoms
 | 
|---|
| 916 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 917 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 918 |         mol = *ListRunner;
 | 
|---|
| 919 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 920 |         CenterAtoms(mol);
 | 
|---|
| 921 |       }
 | 
|---|
| 922 |       break;
 | 
|---|
| 923 | 
 | 
|---|
| 924 |     case 'i': // align all atoms
 | 
|---|
| 925 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 926 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 927 |         mol = *ListRunner;
 | 
|---|
| 928 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 929 |         AlignAtoms(periode, mol);
 | 
|---|
| 930 |       }
 | 
|---|
| 931 |       break;
 | 
|---|
| 932 | 
 | 
|---|
| 933 |     case 'm': // mirror atoms along a given axis
 | 
|---|
| 934 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 935 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 936 |         mol = *ListRunner;
 | 
|---|
| 937 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 938 |         MirrorAtoms(mol);
 | 
|---|
| 939 |       }
 | 
|---|
| 940 |       break;
 | 
|---|
| 941 | 
 | 
|---|
| 942 |     case 'o': // create the connection matrix
 | 
|---|
| 943 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 944 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 945 |           mol = *ListRunner;
 | 
|---|
| 946 |           double bonddistance;
 | 
|---|
| 947 |           clock_t start,end;
 | 
|---|
| 948 |           DoLog(0) && (Log() << Verbose(0) << "What's the maximum bond distance: ");
 | 
|---|
| 949 |           cin >> bonddistance;
 | 
|---|
| 950 |           start = clock();
 | 
|---|
| 951 |           mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
 | 
|---|
| 952 |           end = clock();
 | 
|---|
| 953 |           DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
 | 
|---|
| 954 |         }
 | 
|---|
| 955 |       break;
 | 
|---|
| 956 | 
 | 
|---|
| 957 |     case 't': // translate all atoms
 | 
|---|
| 958 |       for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 959 |         if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 960 |         mol = *ListRunner;
 | 
|---|
| 961 |         DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
 | 
|---|
| 962 |         DoLog(0) && (Log() << Verbose(0) << "Enter translation vector." << endl);
 | 
|---|
| 963 |         x.AskPosition(World::getInstance().getDomain(),0);
 | 
|---|
| 964 |         mol->Center.AddVector((const Vector *)&x);
 | 
|---|
| 965 |      }
 | 
|---|
| 966 |      break;
 | 
|---|
| 967 |   }
 | 
|---|
| 968 |   // Free all
 | 
|---|
| 969 |   if (Subgraphs != NULL) {  // free disconnected subgraph list of DFS analysis was performed
 | 
|---|
| 970 |     while (Subgraphs->next != NULL) {
 | 
|---|
| 971 |       Subgraphs = Subgraphs->next;
 | 
|---|
| 972 |       delete(Subgraphs->previous);
 | 
|---|
| 973 |     }
 | 
|---|
| 974 |     delete(Subgraphs);
 | 
|---|
| 975 |   }
 | 
|---|
| 976 | };
 | 
|---|
| 977 | 
 | 
|---|
| 978 | 
 | 
|---|
| 979 | /** Submenu for creating new molecules.
 | 
|---|
| 980 |  * \param *periode periodentafel
 | 
|---|
| 981 |  * \param *molecules list of molecules to add to
 | 
|---|
| 982 |  */
 | 
|---|
| 983 | static void EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
 | 
|---|
| 984 | {
 | 
|---|
| 985 |   char choice;  // menu choice char
 | 
|---|
| 986 |   Vector center;
 | 
|---|
| 987 |   int nr, count;
 | 
|---|
| 988 |   molecule *mol = NULL;
 | 
|---|
| 989 | 
 | 
|---|
| 990 |   DoLog(0) && (Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl);
 | 
|---|
| 991 |   DoLog(0) && (Log() << Verbose(0) << "c - create new molecule" << endl);
 | 
|---|
| 992 |   DoLog(0) && (Log() << Verbose(0) << "l - load molecule from xyz file" << endl);
 | 
|---|
| 993 |   DoLog(0) && (Log() << Verbose(0) << "n - change molecule's name" << endl);
 | 
|---|
| 994 |   DoLog(0) && (Log() << Verbose(0) << "N - give molecules filename" << endl);
 | 
|---|
| 995 |   DoLog(0) && (Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl);
 | 
|---|
| 996 |   DoLog(0) && (Log() << Verbose(0) << "r - remove a molecule" << endl);
 | 
|---|
| 997 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 998 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 999 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 1000 |   cin >> choice;
 | 
|---|
| 1001 | 
 | 
|---|
| 1002 |   switch (choice) {
 | 
|---|
| 1003 |     default:
 | 
|---|
| 1004 |       DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
 | 
|---|
| 1005 |       break;
 | 
|---|
| 1006 |     case 'c':
 | 
|---|
| 1007 |       mol = World::getInstance().createMolecule();
 | 
|---|
| 1008 |       molecules->insert(mol);
 | 
|---|
| 1009 |       break;
 | 
|---|
| 1010 | 
 | 
|---|
| 1011 |     case 'l': // load from XYZ file
 | 
|---|
| 1012 |       {
 | 
|---|
| 1013 |         char filename[MAXSTRINGSIZE];
 | 
|---|
| 1014 |         DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
 | 
|---|
| 1015 |         mol = World::getInstance().createMolecule();
 | 
|---|
| 1016 |         do {
 | 
|---|
| 1017 |           DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
 | 
|---|
| 1018 |           cin >> filename;
 | 
|---|
| 1019 |         } while (!mol->AddXYZFile(filename));
 | 
|---|
| 1020 |         mol->SetNameFromFilename(filename);
 | 
|---|
| 1021 |         // center at set box dimensions
 | 
|---|
| 1022 |         mol->CenterEdge(¢er);
 | 
|---|
| 1023 |         double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 1024 |         cell_size[0] = center.x[0];
 | 
|---|
| 1025 |         cell_size[1] = 0;
 | 
|---|
| 1026 |         cell_size[2] = center.x[1];
 | 
|---|
| 1027 |         cell_size[3] = 0;
 | 
|---|
| 1028 |         cell_size[4] = 0;
 | 
|---|
| 1029 |         cell_size[5] = center.x[2];
 | 
|---|
| 1030 |         molecules->insert(mol);
 | 
|---|
| 1031 |       }
 | 
|---|
| 1032 |       break;
 | 
|---|
| 1033 | 
 | 
|---|
| 1034 |     case 'n':
 | 
|---|
| 1035 |       {
 | 
|---|
| 1036 |         char filename[MAXSTRINGSIZE];
 | 
|---|
| 1037 |         do {
 | 
|---|
| 1038 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
 | 
|---|
| 1039 |           cin >> nr;
 | 
|---|
| 1040 |           mol = molecules->ReturnIndex(nr);
 | 
|---|
| 1041 |         } while (mol == NULL);
 | 
|---|
| 1042 |         DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
 | 
|---|
| 1043 |         cin >> filename;
 | 
|---|
| 1044 |         strcpy(mol->name, filename);
 | 
|---|
| 1045 |       }
 | 
|---|
| 1046 |       break;
 | 
|---|
| 1047 | 
 | 
|---|
| 1048 |     case 'N':
 | 
|---|
| 1049 |       {
 | 
|---|
| 1050 |         char filename[MAXSTRINGSIZE];
 | 
|---|
| 1051 |         do {
 | 
|---|
| 1052 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
 | 
|---|
| 1053 |           cin >> nr;
 | 
|---|
| 1054 |           mol = molecules->ReturnIndex(nr);
 | 
|---|
| 1055 |         } while (mol == NULL);
 | 
|---|
| 1056 |         DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
 | 
|---|
| 1057 |         cin >> filename;
 | 
|---|
| 1058 |         mol->SetNameFromFilename(filename);
 | 
|---|
| 1059 |       }
 | 
|---|
| 1060 |       break;
 | 
|---|
| 1061 | 
 | 
|---|
| 1062 |     case 'p': // parse XYZ file
 | 
|---|
| 1063 |       {
 | 
|---|
| 1064 |         char filename[MAXSTRINGSIZE];
 | 
|---|
| 1065 |         mol = NULL;
 | 
|---|
| 1066 |         do {
 | 
|---|
| 1067 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
 | 
|---|
| 1068 |           cin >> nr;
 | 
|---|
| 1069 |           mol = molecules->ReturnIndex(nr);
 | 
|---|
| 1070 |         } while (mol == NULL);
 | 
|---|
| 1071 |         DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
 | 
|---|
| 1072 |         do {
 | 
|---|
| 1073 |           DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
 | 
|---|
| 1074 |           cin >> filename;
 | 
|---|
| 1075 |         } while (!mol->AddXYZFile(filename));
 | 
|---|
| 1076 |         mol->SetNameFromFilename(filename);
 | 
|---|
| 1077 |       }
 | 
|---|
| 1078 |       break;
 | 
|---|
| 1079 | 
 | 
|---|
| 1080 |     case 'r':
 | 
|---|
| 1081 |       DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
 | 
|---|
| 1082 |       cin >> nr;
 | 
|---|
| 1083 |       count = 1;
 | 
|---|
| 1084 |       for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 1085 |         if (nr == (*ListRunner)->IndexNr) {
 | 
|---|
| 1086 |           mol = *ListRunner;
 | 
|---|
| 1087 |           molecules->ListOfMolecules.erase(ListRunner);
 | 
|---|
| 1088 |           delete(mol);
 | 
|---|
| 1089 |           break;
 | 
|---|
| 1090 |         }
 | 
|---|
| 1091 |       break;
 | 
|---|
| 1092 |   }
 | 
|---|
| 1093 | };
 | 
|---|
| 1094 | 
 | 
|---|
| 1095 | 
 | 
|---|
| 1096 | /** Submenu for merging molecules.
 | 
|---|
| 1097 |  * \param *periode periodentafel
 | 
|---|
| 1098 |  * \param *molecules list of molecules to add to
 | 
|---|
| 1099 |  */
 | 
|---|
| 1100 | static void MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
 | 
|---|
| 1101 | {
 | 
|---|
| 1102 |   char choice;  // menu choice char
 | 
|---|
| 1103 | 
 | 
|---|
| 1104 |   DoLog(0) && (Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl);
 | 
|---|
| 1105 |   DoLog(0) && (Log() << Verbose(0) << "a - simple add of one molecule to another" << endl);
 | 
|---|
| 1106 |   DoLog(0) && (Log() << Verbose(0) << "b - count the number of bonds of two elements" << endl);
 | 
|---|
| 1107 |   DoLog(0) && (Log() << Verbose(0) << "B - count the number of bonds of three elements " << endl);
 | 
|---|
| 1108 |   DoLog(0) && (Log() << Verbose(0) << "e - embedding merge of two molecules" << endl);
 | 
|---|
| 1109 |   DoLog(0) && (Log() << Verbose(0) << "h - count the number of hydrogen bonds" << endl);
 | 
|---|
| 1110 |   DoLog(0) && (Log() << Verbose(0) << "b - count the number of hydrogen bonds" << endl);
 | 
|---|
| 1111 |   DoLog(0) && (Log() << Verbose(0) << "m - multi-merge of all molecules" << endl);
 | 
|---|
| 1112 |   DoLog(0) && (Log() << Verbose(0) << "s - scatter merge of two molecules" << endl);
 | 
|---|
| 1113 |   DoLog(0) && (Log() << Verbose(0) << "t - simple merge of two molecules" << endl);
 | 
|---|
| 1114 |   DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
 | 
|---|
| 1115 |   DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
 | 
|---|
| 1116 |   DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
 | 
|---|
| 1117 |   cin >> choice;
 | 
|---|
| 1118 | 
 | 
|---|
| 1119 |   switch (choice) {
 | 
|---|
| 1120 |     default:
 | 
|---|
| 1121 |       DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
 | 
|---|
| 1122 |       break;
 | 
|---|
| 1123 | 
 | 
|---|
| 1124 |     case 'a':
 | 
|---|
| 1125 |       {
 | 
|---|
| 1126 |         int src, dest;
 | 
|---|
| 1127 |         molecule *srcmol = NULL, *destmol = NULL;
 | 
|---|
| 1128 |         {
 | 
|---|
| 1129 |           do {
 | 
|---|
| 1130 |             DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
 | 
|---|
| 1131 |             cin >> dest;
 | 
|---|
| 1132 |             destmol = molecules->ReturnIndex(dest);
 | 
|---|
| 1133 |           } while ((destmol == NULL) && (dest != -1));
 | 
|---|
| 1134 |           do {
 | 
|---|
| 1135 |             DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to add from: ");
 | 
|---|
| 1136 |             cin >> src;
 | 
|---|
| 1137 |             srcmol = molecules->ReturnIndex(src);
 | 
|---|
| 1138 |           } while ((srcmol == NULL) && (src != -1));
 | 
|---|
| 1139 |           if ((src != -1) && (dest != -1))
 | 
|---|
| 1140 |             molecules->SimpleAdd(srcmol, destmol);
 | 
|---|
| 1141 |         }
 | 
|---|
| 1142 |       }
 | 
|---|
| 1143 |       break;
 | 
|---|
| 1144 | 
 | 
|---|
| 1145 |     case 'b':
 | 
|---|
| 1146 |       {
 | 
|---|
| 1147 |         const int nr = 2;
 | 
|---|
| 1148 |         char *names[nr] = {"first", "second"};
 | 
|---|
| 1149 |         int Z[nr];
 | 
|---|
| 1150 |         element *elements[nr];
 | 
|---|
| 1151 |         for (int i=0;i<nr;i++) {
 | 
|---|
| 1152 |           Z[i] = 0;
 | 
|---|
| 1153 |           do {
 | 
|---|
| 1154 |             cout << "Enter " << names[i] << " element: ";
 | 
|---|
| 1155 |             cin >> Z[i];
 | 
|---|
| 1156 |           } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
 | 
|---|
| 1157 |           elements[i] = periode->FindElement(Z[i]);
 | 
|---|
| 1158 |         }
 | 
|---|
| 1159 |         const int count = CountBondsOfTwo(molecules, elements[0], elements[1]);
 | 
|---|
| 1160 |         cout << endl << "There are " << count << " ";
 | 
|---|
| 1161 |         for (int i=0;i<nr;i++) {
 | 
|---|
| 1162 |           if (i==0)
 | 
|---|
| 1163 |             cout << elements[i]->symbol;
 | 
|---|
| 1164 |           else
 | 
|---|
| 1165 |             cout << "-" << elements[i]->symbol;
 | 
|---|
| 1166 |         }
 | 
|---|
| 1167 |         cout << " bonds." << endl;
 | 
|---|
| 1168 |       }
 | 
|---|
| 1169 |     break;
 | 
|---|
| 1170 | 
 | 
|---|
| 1171 |     case 'B':
 | 
|---|
| 1172 |       {
 | 
|---|
| 1173 |         const int nr = 3;
 | 
|---|
| 1174 |         char *names[nr] = {"first", "second", "third"};
 | 
|---|
| 1175 |         int Z[nr];
 | 
|---|
| 1176 |         element *elements[nr];
 | 
|---|
| 1177 |         for (int i=0;i<nr;i++) {
 | 
|---|
| 1178 |           Z[i] = 0;
 | 
|---|
| 1179 |           do {
 | 
|---|
| 1180 |             cout << "Enter " << names[i] << " element: ";
 | 
|---|
| 1181 |             cin >> Z[i];
 | 
|---|
| 1182 |           } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
 | 
|---|
| 1183 |           elements[i] = periode->FindElement(Z[i]);
 | 
|---|
| 1184 |         }
 | 
|---|
| 1185 |         const int count = CountBondsOfThree(molecules, elements[0], elements[1], elements[2]);
 | 
|---|
| 1186 |         cout << endl << "There are " << count << " ";
 | 
|---|
| 1187 |         for (int i=0;i<nr;i++) {
 | 
|---|
| 1188 |           if (i==0)
 | 
|---|
| 1189 |             cout << elements[i]->symbol;
 | 
|---|
| 1190 |           else
 | 
|---|
| 1191 |             cout << "-" << elements[i]->symbol;
 | 
|---|
| 1192 |         }
 | 
|---|
| 1193 |         cout << " bonds." << endl;
 | 
|---|
| 1194 |       }
 | 
|---|
| 1195 |     break;
 | 
|---|
| 1196 | 
 | 
|---|
| 1197 |     case 'e':
 | 
|---|
| 1198 |       {
 | 
|---|
| 1199 |         int src, dest;
 | 
|---|
| 1200 |         molecule *srcmol = NULL, *destmol = NULL;
 | 
|---|
| 1201 |         do {
 | 
|---|
| 1202 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ");
 | 
|---|
| 1203 |           cin >> src;
 | 
|---|
| 1204 |           srcmol = molecules->ReturnIndex(src);
 | 
|---|
| 1205 |         } while ((srcmol == NULL) && (src != -1));
 | 
|---|
| 1206 |         do {
 | 
|---|
| 1207 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ");
 | 
|---|
| 1208 |           cin >> dest;
 | 
|---|
| 1209 |           destmol = molecules->ReturnIndex(dest);
 | 
|---|
| 1210 |         } while ((destmol == NULL) && (dest != -1));
 | 
|---|
| 1211 |         if ((src != -1) && (dest != -1))
 | 
|---|
| 1212 |           molecules->EmbedMerge(destmol, srcmol);
 | 
|---|
| 1213 |       }
 | 
|---|
| 1214 |       break;
 | 
|---|
| 1215 | 
 | 
|---|
| 1216 |     case 'h':
 | 
|---|
| 1217 |       {
 | 
|---|
| 1218 |         int Z;
 | 
|---|
| 1219 |         cout << "Please enter interface element: ";
 | 
|---|
| 1220 |         cin >> Z;
 | 
|---|
| 1221 |         element * const InterfaceElement = periode->FindElement(Z);
 | 
|---|
| 1222 |         cout << endl << "There are " << CountHydrogenBridgeBonds(molecules, InterfaceElement) << " hydrogen bridges with connections to " << (InterfaceElement != 0 ? InterfaceElement->name : "None") << "." << endl;
 | 
|---|
| 1223 |       }
 | 
|---|
| 1224 |       break;
 | 
|---|
| 1225 | 
 | 
|---|
| 1226 |     case 'm':
 | 
|---|
| 1227 |       {
 | 
|---|
| 1228 |         int nr;
 | 
|---|
| 1229 |         molecule *mol = NULL;
 | 
|---|
| 1230 |         do {
 | 
|---|
| 1231 |           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into: ");
 | 
|---|
| 1232 |           cin >> nr;
 | 
|---|
| 1233 |           mol = molecules->ReturnIndex(nr);
 | 
|---|
| 1234 |         } while ((mol == NULL) && (nr != -1));
 | 
|---|
| 1235 |         if (nr != -1) {
 | 
|---|
| 1236 |           int N = molecules->ListOfMolecules.size()-1;
 | 
|---|
| 1237 |           int *src = new int(N);
 | 
|---|
| 1238 |           for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 1239 |             if ((*ListRunner)->IndexNr != nr)
 | 
|---|
| 1240 |               src[N++] = (*ListRunner)->IndexNr;        
 | 
|---|
| 1241 |           molecules->SimpleMultiMerge(mol, src, N);
 | 
|---|
| 1242 |           delete[](src);
 | 
|---|
| 1243 |         }
 | 
|---|
| 1244 |       }
 | 
|---|
| 1245 |       break;
 | 
|---|
| 1246 | 
 | 
|---|
| 1247 |     case 's':
 | 
|---|
| 1248 |       DoLog(0) && (Log() << Verbose(0) << "Not implemented yet." << endl);
 | 
|---|
| 1249 |       break;
 | 
|---|
| 1250 | 
 | 
|---|
| 1251 |     case 't':
 | 
|---|
| 1252 |       {
 | 
|---|
| 1253 |         int src, dest;
 | 
|---|
| 1254 |         molecule *srcmol = NULL, *destmol = NULL;
 | 
|---|
| 1255 |         {
 | 
|---|
| 1256 |           do {
 | 
|---|
| 1257 |             DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
 | 
|---|
| 1258 |             cin >> dest;
 | 
|---|
| 1259 |             destmol = molecules->ReturnIndex(dest);
 | 
|---|
| 1260 |           } while ((destmol == NULL) && (dest != -1));
 | 
|---|
| 1261 |           do {
 | 
|---|
| 1262 |             DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to merge into: ");
 | 
|---|
| 1263 |             cin >> src;
 | 
|---|
| 1264 |             srcmol = molecules->ReturnIndex(src);
 | 
|---|
| 1265 |           } while ((srcmol == NULL) && (src != -1));
 | 
|---|
| 1266 |           if ((src != -1) && (dest != -1))
 | 
|---|
| 1267 |             molecules->SimpleMerge(srcmol, destmol);
 | 
|---|
| 1268 |         }
 | 
|---|
| 1269 |       }
 | 
|---|
| 1270 |       break;
 | 
|---|
| 1271 |   }
 | 
|---|
| 1272 | };
 | 
|---|
| 1273 | 
 | 
|---|
| 1274 | /********************************************** Test routine **************************************/
 | 
|---|
| 1275 | 
 | 
|---|
| 1276 | /** Is called always as option 'T' in the menu.
 | 
|---|
| 1277 |  * \param *molecules list of molecules
 | 
|---|
| 1278 |  */
 | 
|---|
| 1279 | static void testroutine(MoleculeListClass *molecules)
 | 
|---|
| 1280 | {
 | 
|---|
| 1281 |   // the current test routine checks the functionality of the KeySet&Graph concept:
 | 
|---|
| 1282 |   // We want to have a multiindex (the KeySet) describing a unique subgraph
 | 
|---|
| 1283 |   int i, comp, counter=0;
 | 
|---|
| 1284 | 
 | 
|---|
| 1285 |   // create a clone
 | 
|---|
| 1286 |   molecule *mol = NULL;
 | 
|---|
| 1287 |   if (molecules->ListOfMolecules.size() != 0) // clone
 | 
|---|
| 1288 |     mol = (molecules->ListOfMolecules.front())->CopyMolecule();
 | 
|---|
| 1289 |   else {
 | 
|---|
| 1290 |     DoeLog(0) && (eLog()<< Verbose(0) << "I don't have anything to test on ... ");
 | 
|---|
| 1291 |     performCriticalExit();
 | 
|---|
| 1292 |     return;
 | 
|---|
| 1293 |   }
 | 
|---|
| 1294 |   atom *Walker = mol->start;
 | 
|---|
| 1295 | 
 | 
|---|
| 1296 |   // generate some KeySets
 | 
|---|
| 1297 |   DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl);
 | 
|---|
| 1298 |   KeySet TestSets[mol->AtomCount+1];
 | 
|---|
| 1299 |   i=1;
 | 
|---|
| 1300 |   while (Walker->next != mol->end) {
 | 
|---|
| 1301 |     Walker = Walker->next;
 | 
|---|
| 1302 |     for (int j=0;j<i;j++) {
 | 
|---|
| 1303 |       TestSets[j].insert(Walker->nr);
 | 
|---|
| 1304 |     }
 | 
|---|
| 1305 |     i++;
 | 
|---|
| 1306 |   }
 | 
|---|
| 1307 |   DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl);
 | 
|---|
| 1308 |   KeySetTestPair test;
 | 
|---|
| 1309 |   test = TestSets[mol->AtomCount-1].insert(Walker->nr);
 | 
|---|
| 1310 |   if (test.second) {
 | 
|---|
| 1311 |     DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
 | 
|---|
| 1312 |   } else {
 | 
|---|
| 1313 |     DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl);
 | 
|---|
| 1314 |   }
 | 
|---|
| 1315 |   TestSets[mol->AtomCount].insert(mol->end->previous->nr);
 | 
|---|
| 1316 |   TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
 | 
|---|
| 1317 | 
 | 
|---|
| 1318 |   // constructing Graph structure
 | 
|---|
| 1319 |   DoLog(0) && (Log() << Verbose(0) << "Generating Subgraph class." << endl);
 | 
|---|
| 1320 |   Graph Subgraphs;
 | 
|---|
| 1321 | 
 | 
|---|
| 1322 |   // insert KeySets into Subgraphs
 | 
|---|
| 1323 |   DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl);
 | 
|---|
| 1324 |   for (int j=0;j<mol->AtomCount;j++) {
 | 
|---|
| 1325 |     Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
 | 
|---|
| 1326 |   }
 | 
|---|
| 1327 |   DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl);
 | 
|---|
| 1328 |   GraphTestPair test2;
 | 
|---|
| 1329 |   test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
 | 
|---|
| 1330 |   if (test2.second) {
 | 
|---|
| 1331 |     DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
 | 
|---|
| 1332 |   } else {
 | 
|---|
| 1333 |     DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl);
 | 
|---|
| 1334 |   }
 | 
|---|
| 1335 | 
 | 
|---|
| 1336 |   // show graphs
 | 
|---|
| 1337 |   DoLog(0) && (Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl);
 | 
|---|
| 1338 |   Graph::iterator A = Subgraphs.begin();
 | 
|---|
| 1339 |   while (A !=  Subgraphs.end()) {
 | 
|---|
| 1340 |     DoLog(0) && (Log() << Verbose(0) << (*A).second.first << ": ");
 | 
|---|
| 1341 |     KeySet::iterator key = (*A).first.begin();
 | 
|---|
| 1342 |     comp = -1;
 | 
|---|
| 1343 |     while (key != (*A).first.end()) {
 | 
|---|
| 1344 |       if ((*key) > comp)
 | 
|---|
| 1345 |         DoLog(0) && (Log() << Verbose(0) << (*key) << " ");
 | 
|---|
| 1346 |       else
 | 
|---|
| 1347 |         DoLog(0) && (Log() << Verbose(0) << (*key) << "! ");
 | 
|---|
| 1348 |       comp = (*key);
 | 
|---|
| 1349 |       key++;
 | 
|---|
| 1350 |     }
 | 
|---|
| 1351 |     DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| 1352 |     A++;
 | 
|---|
| 1353 |   }
 | 
|---|
| 1354 |   delete(mol);
 | 
|---|
| 1355 | };
 | 
|---|
| 1356 | 
 | 
|---|
| 1357 | #endif
 | 
|---|
| 1358 | 
 | 
|---|
| 1359 | /** Tries given filename or standard on saving the config file.
 | 
|---|
| 1360 |  * \param *ConfigFileName name of file
 | 
|---|
| 1361 |  * \param *configuration pointer to configuration structure with all the values
 | 
|---|
| 1362 |  * \param *periode pointer to periodentafel structure with all the elements
 | 
|---|
| 1363 |  * \param *molecules list of molecules structure with all the atoms and coordinates
 | 
|---|
| 1364 |  */
 | 
|---|
| 1365 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
 | 
|---|
| 1366 | {
 | 
|---|
| 1367 |   char filename[MAXSTRINGSIZE];
 | 
|---|
| 1368 |   ofstream output;
 | 
|---|
| 1369 |   molecule *mol = World::getInstance().createMolecule();
 | 
|---|
| 1370 |   mol->SetNameFromFilename(ConfigFileName);
 | 
|---|
| 1371 | 
 | 
|---|
| 1372 |   if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
 | 
|---|
| 1373 |     DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
 | 
|---|
| 1374 |   }
 | 
|---|
| 1375 | 
 | 
|---|
| 1376 | 
 | 
|---|
| 1377 |   // first save as PDB data
 | 
|---|
| 1378 |   if (ConfigFileName != NULL)
 | 
|---|
| 1379 |     strcpy(filename, ConfigFileName);
 | 
|---|
| 1380 |   if (output == NULL)
 | 
|---|
| 1381 |     strcpy(filename,"main_pcp_linux");
 | 
|---|
| 1382 |   DoLog(0) && (Log() << Verbose(0) << "Saving as pdb input ");
 | 
|---|
| 1383 |   if (configuration->SavePDB(filename, molecules))
 | 
|---|
| 1384 |     DoLog(0) && (Log() << Verbose(0) << "done." << endl);
 | 
|---|
| 1385 |   else
 | 
|---|
| 1386 |     DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1387 | 
 | 
|---|
| 1388 |   // then save as tremolo data file
 | 
|---|
| 1389 |   if (ConfigFileName != NULL)
 | 
|---|
| 1390 |     strcpy(filename, ConfigFileName);
 | 
|---|
| 1391 |   if (output == NULL)
 | 
|---|
| 1392 |     strcpy(filename,"main_pcp_linux");
 | 
|---|
| 1393 |   DoLog(0) && (Log() << Verbose(0) << "Saving as tremolo data input ");
 | 
|---|
| 1394 |   if (configuration->SaveTREMOLO(filename, molecules))
 | 
|---|
| 1395 |     DoLog(0) && (Log() << Verbose(0) << "done." << endl);
 | 
|---|
| 1396 |   else
 | 
|---|
| 1397 |     DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1398 | 
 | 
|---|
| 1399 |   // translate each to its center and merge all molecules in MoleculeListClass into this molecule
 | 
|---|
| 1400 |   int N = molecules->ListOfMolecules.size();
 | 
|---|
| 1401 |   int *src = new int[N];
 | 
|---|
| 1402 |   N=0;
 | 
|---|
| 1403 |   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
 | 
|---|
| 1404 |     src[N++] = (*ListRunner)->IndexNr;
 | 
|---|
| 1405 |     (*ListRunner)->Translate(&(*ListRunner)->Center);
 | 
|---|
| 1406 |   }
 | 
|---|
| 1407 |   molecules->SimpleMultiAdd(mol, src, N);
 | 
|---|
| 1408 |   delete[](src);
 | 
|---|
| 1409 | 
 | 
|---|
| 1410 |   // ... and translate back
 | 
|---|
| 1411 |   for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
 | 
|---|
| 1412 |     (*ListRunner)->Center.Scale(-1.);
 | 
|---|
| 1413 |     (*ListRunner)->Translate(&(*ListRunner)->Center);
 | 
|---|
| 1414 |     (*ListRunner)->Center.Scale(-1.);
 | 
|---|
| 1415 |   }
 | 
|---|
| 1416 | 
 | 
|---|
| 1417 |   DoLog(0) && (Log() << Verbose(0) << "Storing configuration ... " << endl);
 | 
|---|
| 1418 |   // get correct valence orbitals
 | 
|---|
| 1419 |   mol->CalculateOrbitals(*configuration);
 | 
|---|
| 1420 |   configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
 | 
|---|
| 1421 |   if (ConfigFileName != NULL) { // test the file name
 | 
|---|
| 1422 |     strcpy(filename, ConfigFileName);
 | 
|---|
| 1423 |     output.open(filename, ios::trunc);
 | 
|---|
| 1424 |   } else if (strlen(configuration->configname) != 0) {
 | 
|---|
| 1425 |     strcpy(filename, configuration->configname);
 | 
|---|
| 1426 |     output.open(configuration->configname, ios::trunc);
 | 
|---|
| 1427 |     } else {
 | 
|---|
| 1428 |       strcpy(filename, DEFAULTCONFIG);
 | 
|---|
| 1429 |       output.open(DEFAULTCONFIG, ios::trunc);
 | 
|---|
| 1430 |     }
 | 
|---|
| 1431 |   output.close();
 | 
|---|
| 1432 |   output.clear();
 | 
|---|
| 1433 |   DoLog(0) && (Log() << Verbose(0) << "Saving of config file ");
 | 
|---|
| 1434 |   if (configuration->Save(filename, periode, mol))
 | 
|---|
| 1435 |     DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
 | 
|---|
| 1436 |   else
 | 
|---|
| 1437 |     DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1438 | 
 | 
|---|
| 1439 |   // and save to xyz file
 | 
|---|
| 1440 |   if (ConfigFileName != NULL) {
 | 
|---|
| 1441 |     strcpy(filename, ConfigFileName);
 | 
|---|
| 1442 |     strcat(filename, ".xyz");
 | 
|---|
| 1443 |     output.open(filename, ios::trunc);
 | 
|---|
| 1444 |   }
 | 
|---|
| 1445 |   if (output == NULL) {
 | 
|---|
| 1446 |     strcpy(filename,"main_pcp_linux");
 | 
|---|
| 1447 |     strcat(filename, ".xyz");
 | 
|---|
| 1448 |     output.open(filename, ios::trunc);
 | 
|---|
| 1449 |   }
 | 
|---|
| 1450 |   DoLog(0) && (Log() << Verbose(0) << "Saving of XYZ file ");
 | 
|---|
| 1451 |   if (mol->MDSteps <= 1) {
 | 
|---|
| 1452 |     if (mol->OutputXYZ(&output))
 | 
|---|
| 1453 |       DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
 | 
|---|
| 1454 |     else
 | 
|---|
| 1455 |       DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1456 |   } else {
 | 
|---|
| 1457 |     if (mol->OutputTrajectoriesXYZ(&output))
 | 
|---|
| 1458 |       DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
 | 
|---|
| 1459 |     else
 | 
|---|
| 1460 |       DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1461 |   }
 | 
|---|
| 1462 |   output.close();
 | 
|---|
| 1463 |   output.clear();
 | 
|---|
| 1464 | 
 | 
|---|
| 1465 |   // and save as MPQC configuration
 | 
|---|
| 1466 |   if (ConfigFileName != NULL)
 | 
|---|
| 1467 |     strcpy(filename, ConfigFileName);
 | 
|---|
| 1468 |   if (output == NULL)
 | 
|---|
| 1469 |     strcpy(filename,"main_pcp_linux");
 | 
|---|
| 1470 |   DoLog(0) && (Log() << Verbose(0) << "Saving as mpqc input ");
 | 
|---|
| 1471 |   if (configuration->SaveMPQC(filename, mol))
 | 
|---|
| 1472 |     DoLog(0) && (Log() << Verbose(0) << "done." << endl);
 | 
|---|
| 1473 |   else
 | 
|---|
| 1474 |     DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
 | 
|---|
| 1475 | 
 | 
|---|
| 1476 |   if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
 | 
|---|
| 1477 |     DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
 | 
|---|
| 1478 |   }
 | 
|---|
| 1479 | 
 | 
|---|
| 1480 |   World::getInstance().destroyMolecule(mol);
 | 
|---|
| 1481 | };
 | 
|---|
| 1482 | 
 | 
|---|
| 1483 | /** Parses the command line options.
 | 
|---|
| 1484 |  * Note that this function is from now on transitional. All commands that are not passed
 | 
|---|
| 1485 |  * here are handled by CommandLineParser and the actions of CommandLineUIFactory.
 | 
|---|
| 1486 |  * \param argc argument count
 | 
|---|
| 1487 |  * \param **argv arguments array
 | 
|---|
| 1488 |  * \param *molecules list of molecules structure
 | 
|---|
| 1489 |  * \param *periode elements structure
 | 
|---|
| 1490 |  * \param configuration config file structure
 | 
|---|
| 1491 |  * \param *ConfigFileName pointer to config file name in **argv
 | 
|---|
| 1492 |  * \param *PathToDatabases pointer to db's path in **argv
 | 
|---|
| 1493 |  * \param &ArgcList list of arguments that we do not parse here
 | 
|---|
| 1494 |  * \return exit code (0 - successful, all else - something's wrong)
 | 
|---|
| 1495 |  */
 | 
|---|
| 1496 | static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,
 | 
|---|
| 1497 |                                    config& configuration, char *&ConfigFileName, set<int> &ArgcList)
 | 
|---|
| 1498 | {
 | 
|---|
| 1499 |   Vector x,y,z,n;  // coordinates for absolute point in cell volume
 | 
|---|
| 1500 |   double *factor; // unit factor if desired
 | 
|---|
| 1501 |   ifstream test;
 | 
|---|
| 1502 |   ofstream output;
 | 
|---|
| 1503 |   string line;
 | 
|---|
| 1504 |   atom *first;
 | 
|---|
| 1505 |   bool SaveFlag = false;
 | 
|---|
| 1506 |   int ExitFlag = 0;
 | 
|---|
| 1507 |   int j;
 | 
|---|
| 1508 |   double volume = 0.;
 | 
|---|
| 1509 |   enum ConfigStatus configPresent = absent;
 | 
|---|
| 1510 |   clock_t start,end;
 | 
|---|
| 1511 |   double MaxDistance = -1;
 | 
|---|
| 1512 |   int argptr;
 | 
|---|
| 1513 |   molecule *mol = NULL;
 | 
|---|
| 1514 |   string BondGraphFileName("\n");
 | 
|---|
| 1515 |   strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
 | 
|---|
| 1516 | 
 | 
|---|
| 1517 |   if (argc > 1) { // config file specified as option
 | 
|---|
| 1518 |     // 1. : Parse options that just set variables or print help
 | 
|---|
| 1519 |     argptr = 1;
 | 
|---|
| 1520 |     do {
 | 
|---|
| 1521 |       if (argv[argptr][0] == '-') {
 | 
|---|
| 1522 |         DoLog(0) && (Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n");
 | 
|---|
| 1523 |         argptr++;
 | 
|---|
| 1524 |         switch(argv[argptr-1][1]) {
 | 
|---|
| 1525 |           case 'h':
 | 
|---|
| 1526 |           case 'H':
 | 
|---|
| 1527 |           case '?':
 | 
|---|
| 1528 |             ArgcList.insert(argptr-1);
 | 
|---|
| 1529 |             return(1);
 | 
|---|
| 1530 |             break;
 | 
|---|
| 1531 |           case 'v':
 | 
|---|
| 1532 |             setVerbosity(atoi(argv[argptr]));
 | 
|---|
| 1533 |             ArgcList.insert(argptr-1);
 | 
|---|
| 1534 |             ArgcList.insert(argptr);
 | 
|---|
| 1535 |             argptr++;
 | 
|---|
| 1536 |             break;
 | 
|---|
| 1537 |           case 'V':
 | 
|---|
| 1538 |             ArgcList.insert(argptr-1);
 | 
|---|
| 1539 |             return(1);
 | 
|---|
| 1540 |             break;
 | 
|---|
| 1541 |           case 'B':
 | 
|---|
| 1542 |             if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1543 |             if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
 | 
|---|
| 1544 |               ExitFlag = 255;
 | 
|---|
| 1545 |               DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
 | 
|---|
| 1546 |               performCriticalExit();
 | 
|---|
| 1547 |             } else {
 | 
|---|
| 1548 |               SaveFlag = true;
 | 
|---|
| 1549 |               j = -1;
 | 
|---|
| 1550 |               DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
 | 
|---|
| 1551 |               double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 1552 |               for (int i=0;i<6;i++) {
 | 
|---|
| 1553 |                 cell_size[i] = atof(argv[argptr+i]);
 | 
|---|
| 1554 |               }
 | 
|---|
| 1555 |               argptr+=6;
 | 
|---|
| 1556 |             }
 | 
|---|
| 1557 |             break;
 | 
|---|
| 1558 |           case 'e':
 | 
|---|
| 1559 |             if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 1560 |               DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl);
 | 
|---|
| 1561 |               performCriticalExit();
 | 
|---|
| 1562 |             } else {
 | 
|---|
| 1563 |               DoLog(0) && (Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl);
 | 
|---|
| 1564 |               strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1);
 | 
|---|
| 1565 |               argptr+=1;
 | 
|---|
| 1566 |             }
 | 
|---|
| 1567 |             break;
 | 
|---|
| 1568 |           case 'g':
 | 
|---|
| 1569 |             if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 1570 |               DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl);
 | 
|---|
| 1571 |               performCriticalExit();
 | 
|---|
| 1572 |             } else {
 | 
|---|
| 1573 |               BondGraphFileName = argv[argptr];
 | 
|---|
| 1574 |               DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl);
 | 
|---|
| 1575 |               argptr+=1;
 | 
|---|
| 1576 |             }
 | 
|---|
| 1577 |             break;
 | 
|---|
| 1578 |           case 'M':
 | 
|---|
| 1579 |             if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 1580 |               ExitFlag = 255;
 | 
|---|
| 1581 |               DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -M <basis name>" << endl);
 | 
|---|
| 1582 |               performCriticalExit();
 | 
|---|
| 1583 |             } else {
 | 
|---|
| 1584 |               configuration.basis = argv[argptr];
 | 
|---|
| 1585 |               DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl);
 | 
|---|
| 1586 |               argptr+=1;
 | 
|---|
| 1587 |             }
 | 
|---|
| 1588 |             break;
 | 
|---|
| 1589 |           case 'n':
 | 
|---|
| 1590 |             DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl);
 | 
|---|
| 1591 |             configuration.FastParsing = true;
 | 
|---|
| 1592 |             break;
 | 
|---|
| 1593 |           case 'X':
 | 
|---|
| 1594 |             {
 | 
|---|
| 1595 |               World::getInstance().setDefaultName(argv[argptr]);
 | 
|---|
| 1596 |               DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << World::getInstance().getDefaultName() << "." << endl);
 | 
|---|
| 1597 |             }
 | 
|---|
| 1598 |             break;
 | 
|---|
| 1599 |           default:   // no match? Step on
 | 
|---|
| 1600 |             argptr++;
 | 
|---|
| 1601 |             break;
 | 
|---|
| 1602 |         }
 | 
|---|
| 1603 |       } else
 | 
|---|
| 1604 |         argptr++;
 | 
|---|
| 1605 |     } while (argptr < argc);
 | 
|---|
| 1606 | 
 | 
|---|
| 1607 |     // 3a. Parse the element database
 | 
|---|
| 1608 |     if (periode->LoadPeriodentafel(configuration.databasepath)) {
 | 
|---|
| 1609 |       DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
 | 
|---|
| 1610 |       //periode->Output();
 | 
|---|
| 1611 |     } else {
 | 
|---|
| 1612 |       DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
 | 
|---|
| 1613 |       return 1;
 | 
|---|
| 1614 |     }
 | 
|---|
| 1615 |     // 3b. Find config file name and parse if possible, also BondGraphFileName
 | 
|---|
| 1616 |     if (argv[1][0] != '-') {
 | 
|---|
| 1617 |       // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
 | 
|---|
| 1618 |       DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl);
 | 
|---|
| 1619 |       test.open(argv[1], ios::in);
 | 
|---|
| 1620 |       if (test == NULL) {
 | 
|---|
| 1621 |         //return (1);
 | 
|---|
| 1622 |         output.open(argv[1], ios::out);
 | 
|---|
| 1623 |         if (output == NULL) {
 | 
|---|
| 1624 |           DoLog(1) && (Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl);
 | 
|---|
| 1625 |           configPresent = absent;
 | 
|---|
| 1626 |         } else {
 | 
|---|
| 1627 |           DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl);
 | 
|---|
| 1628 |           ConfigFileName = argv[1];
 | 
|---|
| 1629 |           configPresent = empty;
 | 
|---|
| 1630 |           output.close();
 | 
|---|
| 1631 |         }
 | 
|---|
| 1632 |       } else {
 | 
|---|
| 1633 |         test.close();
 | 
|---|
| 1634 |         ConfigFileName = argv[1];
 | 
|---|
| 1635 |         DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
 | 
|---|
| 1636 |         switch (configuration.TestSyntax(ConfigFileName, periode)) {
 | 
|---|
| 1637 |           case 1:
 | 
|---|
| 1638 |             DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl);
 | 
|---|
| 1639 |             configuration.Load(ConfigFileName, BondGraphFileName, periode, molecules);
 | 
|---|
| 1640 |             configPresent = present;
 | 
|---|
| 1641 |             break;
 | 
|---|
| 1642 |           case 0:
 | 
|---|
| 1643 |             DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl);
 | 
|---|
| 1644 |             configuration.LoadOld(ConfigFileName, BondGraphFileName, periode, molecules);
 | 
|---|
| 1645 |             configPresent = present;
 | 
|---|
| 1646 |             break;
 | 
|---|
| 1647 |           default:
 | 
|---|
| 1648 |             DoLog(0) && (Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl);
 | 
|---|
| 1649 |             configPresent = empty;
 | 
|---|
| 1650 |        }
 | 
|---|
| 1651 |       }
 | 
|---|
| 1652 |     } else
 | 
|---|
| 1653 |       configPresent = absent;
 | 
|---|
| 1654 |      // set mol to first active molecule
 | 
|---|
| 1655 |      if (molecules->ListOfMolecules.size() != 0) {
 | 
|---|
| 1656 |        for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 1657 |          if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 1658 |            mol = *ListRunner;
 | 
|---|
| 1659 |            break;
 | 
|---|
| 1660 |          }
 | 
|---|
| 1661 |      }
 | 
|---|
| 1662 |      if (mol == NULL) {
 | 
|---|
| 1663 |        mol = World::getInstance().createMolecule();
 | 
|---|
| 1664 |        mol->ActiveFlag = true;
 | 
|---|
| 1665 |        if (ConfigFileName != NULL)
 | 
|---|
| 1666 |          mol->SetNameFromFilename(ConfigFileName);
 | 
|---|
| 1667 |        molecules->insert(mol);
 | 
|---|
| 1668 |      }
 | 
|---|
| 1669 |      if (configuration.BG == NULL) {
 | 
|---|
| 1670 |        configuration.BG = new BondGraph(configuration.GetIsAngstroem());
 | 
|---|
| 1671 |        if ((!BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
 | 
|---|
| 1672 |          DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
 | 
|---|
| 1673 |        } else {
 | 
|---|
| 1674 |          DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
 | 
|---|
| 1675 |        }
 | 
|---|
| 1676 |      }
 | 
|---|
| 1677 | 
 | 
|---|
| 1678 |     // 4. parse again through options, now for those depending on elements db and config presence
 | 
|---|
| 1679 |     argptr = 1;
 | 
|---|
| 1680 |     do {
 | 
|---|
| 1681 |       DoLog(0) && (Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl);
 | 
|---|
| 1682 |       if (argv[argptr][0] == '-') {
 | 
|---|
| 1683 |         argptr++;
 | 
|---|
| 1684 |         if ((configPresent == present) || (configPresent == empty)) {
 | 
|---|
| 1685 |           switch(argv[argptr-1][1]) {
 | 
|---|
| 1686 |             case 'p':
 | 
|---|
| 1687 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1688 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 1689 |                 ExitFlag = 255;
 | 
|---|
| 1690 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl);
 | 
|---|
| 1691 |                 performCriticalExit();
 | 
|---|
| 1692 |               } else {
 | 
|---|
| 1693 |                 SaveFlag = true;
 | 
|---|
| 1694 |                 DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
 | 
|---|
| 1695 |                 if (!mol->AddXYZFile(argv[argptr]))
 | 
|---|
| 1696 |                   DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
 | 
|---|
| 1697 |                 else {
 | 
|---|
| 1698 |                   DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
 | 
|---|
| 1699 |                   configPresent = present;
 | 
|---|
| 1700 |                 }
 | 
|---|
| 1701 |               }
 | 
|---|
| 1702 |               break;
 | 
|---|
| 1703 |             case 'a':
 | 
|---|
| 1704 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1705 |               if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) {
 | 
|---|
| 1706 |                 ExitFlag = 255;
 | 
|---|
| 1707 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl);
 | 
|---|
| 1708 |                 performCriticalExit();
 | 
|---|
| 1709 |               } else {
 | 
|---|
| 1710 |                 SaveFlag = true;
 | 
|---|
| 1711 |                 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
 | 
|---|
| 1712 |                 first = World::getInstance().createAtom();
 | 
|---|
| 1713 |                 first->type = periode->FindElement(atoi(argv[argptr]));
 | 
|---|
| 1714 |                 if (first->type != NULL)
 | 
|---|
| 1715 |                   DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl);
 | 
|---|
| 1716 |                 for (int i=NDIM;i--;)
 | 
|---|
| 1717 |                   first->x[i] = atof(argv[argptr+1+i]);
 | 
|---|
| 1718 |                 if (first->type != NULL) {
 | 
|---|
| 1719 |                   mol->AddAtom(first);  // add to molecule
 | 
|---|
| 1720 |                   if ((configPresent == empty) && (mol->AtomCount != 0))
 | 
|---|
| 1721 |                     configPresent = present;
 | 
|---|
| 1722 |                 } else
 | 
|---|
| 1723 |                   DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl);
 | 
|---|
| 1724 |                 argptr+=4;
 | 
|---|
| 1725 |               }
 | 
|---|
| 1726 |               break;
 | 
|---|
| 1727 |             default:   // no match? Don't step on (this is done in next switch's default)
 | 
|---|
| 1728 |               break;
 | 
|---|
| 1729 |           }
 | 
|---|
| 1730 |         }
 | 
|---|
| 1731 |         if (configPresent == present) {
 | 
|---|
| 1732 |           switch(argv[argptr-1][1]) {
 | 
|---|
| 1733 |             case 'D':
 | 
|---|
| 1734 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1735 |               {
 | 
|---|
| 1736 |                 DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
 | 
|---|
| 1737 |                 MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
 | 
|---|
| 1738 |                 int *MinimumRingSize = new int[mol->AtomCount];
 | 
|---|
| 1739 |                 atom ***ListOfLocalAtoms = NULL;
 | 
|---|
| 1740 |                 class StackClass<bond *> *BackEdgeStack = NULL;
 | 
|---|
| 1741 |                 class StackClass<bond *> *LocalBackEdgeStack = NULL;
 | 
|---|
| 1742 |                 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
 | 
|---|
| 1743 |                 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
 | 
|---|
| 1744 |                 if (Subgraphs != NULL) {
 | 
|---|
| 1745 |                   int FragmentCounter = 0;
 | 
|---|
| 1746 |                   while (Subgraphs->next != NULL) {
 | 
|---|
| 1747 |                     Subgraphs = Subgraphs->next;
 | 
|---|
| 1748 |                     Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
 | 
|---|
| 1749 |                     LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
 | 
|---|
| 1750 |                     Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
 | 
|---|
| 1751 |                     Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
 | 
|---|
| 1752 |                     delete(LocalBackEdgeStack);
 | 
|---|
| 1753 |                     delete(Subgraphs->previous);
 | 
|---|
| 1754 |                     FragmentCounter++;
 | 
|---|
| 1755 |                   }
 | 
|---|
| 1756 |                   delete(Subgraphs);
 | 
|---|
| 1757 |                   for (int i=0;i<FragmentCounter;i++)
 | 
|---|
| 1758 |                     Free(&ListOfLocalAtoms[i]);
 | 
|---|
| 1759 |                   Free(&ListOfLocalAtoms);
 | 
|---|
| 1760 |                 }
 | 
|---|
| 1761 |                 delete(BackEdgeStack);
 | 
|---|
| 1762 |                 delete[](MinimumRingSize);
 | 
|---|
| 1763 |               }
 | 
|---|
| 1764 |               //argptr+=1;
 | 
|---|
| 1765 |               break;
 | 
|---|
| 1766 |             case 'I':
 | 
|---|
| 1767 |               DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
 | 
|---|
| 1768 |               // @TODO rather do the dissection afterwards
 | 
|---|
| 1769 |               molecules->DissectMoleculeIntoConnectedSubgraphs(periode, &configuration);
 | 
|---|
| 1770 |               mol = NULL;
 | 
|---|
| 1771 |               if (molecules->ListOfMolecules.size() != 0) {
 | 
|---|
| 1772 |                 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
 | 
|---|
| 1773 |                   if ((*ListRunner)->ActiveFlag) {
 | 
|---|
| 1774 |                     mol = *ListRunner;
 | 
|---|
| 1775 |                     break;
 | 
|---|
| 1776 |                   }
 | 
|---|
| 1777 |               }
 | 
|---|
| 1778 |               if ((mol == NULL) && (!molecules->ListOfMolecules.empty())) {
 | 
|---|
| 1779 |                 mol = *(molecules->ListOfMolecules.begin());
 | 
|---|
| 1780 |                 if (mol != NULL)
 | 
|---|
| 1781 |                   mol->ActiveFlag = true;
 | 
|---|
| 1782 |               }
 | 
|---|
| 1783 |               break;
 | 
|---|
| 1784 |             case 'C':
 | 
|---|
| 1785 |               {
 | 
|---|
| 1786 |                 int ranges[3] = {1, 1, 1};
 | 
|---|
| 1787 |                 bool periodic = (argv[argptr-1][2] =='p');
 | 
|---|
| 1788 |                 if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1789 |                 if ((argptr >= argc)) {
 | 
|---|
| 1790 |                   ExitFlag = 255;
 | 
|---|
| 1791 |                   DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C[p] <type: E/P/S> [more params] <output> <bin output> <BinStart> <BinEnd>" << endl);
 | 
|---|
| 1792 |                   performCriticalExit();
 | 
|---|
| 1793 |                 } else {
 | 
|---|
| 1794 |                   switch(argv[argptr][0]) {
 | 
|---|
| 1795 |                     case 'E':
 | 
|---|
| 1796 |                       {
 | 
|---|
| 1797 |                         if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+2])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-')) {
 | 
|---|
| 1798 |                           ExitFlag = 255;
 | 
|---|
| 1799 |                           DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C E <Z1> <Z2> <output> <bin output> <binstart> <binend>" << endl);
 | 
|---|
| 1800 |                           performCriticalExit();
 | 
|---|
| 1801 |                         } else {
 | 
|---|
| 1802 |                           ofstream output(argv[argptr+3]);
 | 
|---|
| 1803 |                           ofstream binoutput(argv[argptr+4]);
 | 
|---|
| 1804 |                           const double BinStart = atof(argv[argptr+5]);
 | 
|---|
| 1805 |                           const double BinEnd = atof(argv[argptr+6]);
 | 
|---|
| 1806 | 
 | 
|---|
| 1807 |                           const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
 | 
|---|
| 1808 |                           const element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2]));
 | 
|---|
| 1809 |                           PairCorrelationMap *correlationmap = NULL;
 | 
|---|
| 1810 |                           if (periodic)
 | 
|---|
| 1811 |                             correlationmap = PeriodicPairCorrelation(molecules, elemental, elemental2, ranges);
 | 
|---|
| 1812 |                           else
 | 
|---|
| 1813 |                             correlationmap = PairCorrelation(molecules, elemental, elemental2);
 | 
|---|
| 1814 |                           //OutputCorrelationToSurface(&output, correlationmap);
 | 
|---|
| 1815 |                           BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd );
 | 
|---|
| 1816 |                           OutputCorrelation ( &binoutput, binmap );
 | 
|---|
| 1817 |                           output.close();
 | 
|---|
| 1818 |                           binoutput.close();
 | 
|---|
| 1819 |                           delete(binmap);
 | 
|---|
| 1820 |                           delete(correlationmap);
 | 
|---|
| 1821 |                           argptr+=7;
 | 
|---|
| 1822 |                         }
 | 
|---|
| 1823 |                       }
 | 
|---|
| 1824 |                       break;
 | 
|---|
| 1825 | 
 | 
|---|
| 1826 |                     case 'P':
 | 
|---|
| 1827 |                       {
 | 
|---|
| 1828 |                         if ((argptr+8 >= argc) || (!IsValidNumber(argv[argptr+1])) ||  (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+7])) || (!IsValidNumber(argv[argptr+8])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-') || (argv[argptr+5][0] == '-') || (argv[argptr+6][0] == '-')) {
 | 
|---|
| 1829 |                           ExitFlag = 255;
 | 
|---|
| 1830 |                           DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C P <Z1> <x> <y> <z> <output> <bin output> <binstart> <binend>" << endl);
 | 
|---|
| 1831 |                           performCriticalExit();
 | 
|---|
| 1832 |                         } else {
 | 
|---|
| 1833 |                           ofstream output(argv[argptr+5]);
 | 
|---|
| 1834 |                           ofstream binoutput(argv[argptr+6]);
 | 
|---|
| 1835 |                           const double BinStart = atof(argv[argptr+7]);
 | 
|---|
| 1836 |                           const double BinEnd = atof(argv[argptr+8]);
 | 
|---|
| 1837 | 
 | 
|---|
| 1838 |                           const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
 | 
|---|
| 1839 |                           Vector *Point = new Vector((const double) atof(argv[argptr+1]),(const double) atof(argv[argptr+2]),(const double) atof(argv[argptr+3]));
 | 
|---|
| 1840 |                           CorrelationToPointMap *correlationmap = NULL;
 | 
|---|
| 1841 |                           if (periodic)
 | 
|---|
| 1842 |                             correlationmap  = PeriodicCorrelationToPoint(molecules, elemental, Point, ranges);
 | 
|---|
| 1843 |                           else
 | 
|---|
| 1844 |                             correlationmap = CorrelationToPoint(molecules, elemental, Point);
 | 
|---|
| 1845 |                           //OutputCorrelationToSurface(&output, correlationmap);
 | 
|---|
| 1846 |                           BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd );
 | 
|---|
| 1847 |                           OutputCorrelation ( &binoutput, binmap );
 | 
|---|
| 1848 |                           output.close();
 | 
|---|
| 1849 |                           binoutput.close();
 | 
|---|
| 1850 |                           delete(Point);
 | 
|---|
| 1851 |                           delete(binmap);
 | 
|---|
| 1852 |                           delete(correlationmap);
 | 
|---|
| 1853 |                           argptr+=9;
 | 
|---|
| 1854 |                         }
 | 
|---|
| 1855 |                       }
 | 
|---|
| 1856 |                       break;
 | 
|---|
| 1857 | 
 | 
|---|
| 1858 |                     case 'S':
 | 
|---|
| 1859 |                       {
 | 
|---|
| 1860 |                         if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-')) {
 | 
|---|
| 1861 |                           ExitFlag = 255;
 | 
|---|
| 1862 |                           DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C S <Z> <output> <bin output> <BinWidth> <BinStart> <BinEnd>" << endl);
 | 
|---|
| 1863 |                           performCriticalExit();
 | 
|---|
| 1864 |                         } else {
 | 
|---|
| 1865 |                           ofstream output(argv[argptr+2]);
 | 
|---|
| 1866 |                           ofstream binoutput(argv[argptr+3]);
 | 
|---|
| 1867 |                           const double radius = 4.;
 | 
|---|
| 1868 |                           const double BinWidth = atof(argv[argptr+4]);
 | 
|---|
| 1869 |                           const double BinStart = atof(argv[argptr+5]);
 | 
|---|
| 1870 |                           const double BinEnd = atof(argv[argptr+6]);
 | 
|---|
| 1871 |                           double LCWidth = 20.;
 | 
|---|
| 1872 |                           if (BinEnd > 0) {
 | 
|---|
| 1873 |                             if (BinEnd > 2.*radius)
 | 
|---|
| 1874 |                                 LCWidth = BinEnd;
 | 
|---|
| 1875 |                             else
 | 
|---|
| 1876 |                               LCWidth = 2.*radius;
 | 
|---|
| 1877 |                           }
 | 
|---|
| 1878 | 
 | 
|---|
| 1879 |                           // get the boundary
 | 
|---|
| 1880 |                           class molecule *Boundary = NULL;
 | 
|---|
| 1881 |                           class Tesselation *TesselStruct = NULL;
 | 
|---|
| 1882 |                           const LinkedCell *LCList = NULL;
 | 
|---|
| 1883 |                           // find biggest molecule
 | 
|---|
| 1884 |                           int counter  = 0;
 | 
|---|
| 1885 |                           for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
 | 
|---|
| 1886 |                             if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
 | 
|---|
| 1887 |                               Boundary = *BigFinder;
 | 
|---|
| 1888 |                             }
 | 
|---|
| 1889 |                             counter++;
 | 
|---|
| 1890 |                           }
 | 
|---|
| 1891 |                           bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives");
 | 
|---|
| 1892 |                           counter = 0;
 | 
|---|
| 1893 |                           for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
 | 
|---|
| 1894 |                             Actives[counter++] = (*BigFinder)->ActiveFlag;
 | 
|---|
| 1895 |                             (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
 | 
|---|
| 1896 |                           }
 | 
|---|
| 1897 |                           LCList = new LinkedCell(Boundary, LCWidth);
 | 
|---|
| 1898 |                           const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
 | 
|---|
| 1899 |                           FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
 | 
|---|
| 1900 |                           CorrelationToSurfaceMap *surfacemap = NULL;
 | 
|---|
| 1901 |                           if (periodic)
 | 
|---|
| 1902 |                             surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges);
 | 
|---|
| 1903 |                           else
 | 
|---|
| 1904 |                             surfacemap = CorrelationToSurface( molecules, elemental, TesselStruct, LCList);
 | 
|---|
| 1905 |                           OutputCorrelationToSurface(&output, surfacemap);
 | 
|---|
| 1906 |                           // check whether radius was appropriate
 | 
|---|
| 1907 |                           {
 | 
|---|
| 1908 |                             double start; double end;
 | 
|---|
| 1909 |                             GetMinMax( surfacemap, start, end);
 | 
|---|
| 1910 |                             if (LCWidth < end)
 | 
|---|
| 1911 |                               DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell width is smaller than the found range of values! Bins can only be correct up to: " << radius << "." << endl);
 | 
|---|
| 1912 |                           }
 | 
|---|
| 1913 |                           BinPairMap *binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
 | 
|---|
| 1914 |                           OutputCorrelation ( &binoutput, binmap );
 | 
|---|
| 1915 |                           output.close();
 | 
|---|
| 1916 |                           binoutput.close();
 | 
|---|
| 1917 |                           for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++)
 | 
|---|
| 1918 |                             (*BigFinder)->ActiveFlag = Actives[counter++];
 | 
|---|
| 1919 |                           Free(&Actives);
 | 
|---|
| 1920 |                           delete(LCList);
 | 
|---|
| 1921 |                           delete(TesselStruct);
 | 
|---|
| 1922 |                           delete(binmap);
 | 
|---|
| 1923 |                           delete(surfacemap);
 | 
|---|
| 1924 |                           argptr+=7;
 | 
|---|
| 1925 |                         }
 | 
|---|
| 1926 |                       }
 | 
|---|
| 1927 |                       break;
 | 
|---|
| 1928 | 
 | 
|---|
| 1929 |                     default:
 | 
|---|
| 1930 |                       ExitFlag = 255;
 | 
|---|
| 1931 |                       DoeLog(0) && (eLog()<< Verbose(0) << "Invalid type given for pair correlation analysis: -C <type: E/P/S> [more params] <output> <bin output>" << endl);
 | 
|---|
| 1932 |                       performCriticalExit();
 | 
|---|
| 1933 |                       break;
 | 
|---|
| 1934 |                   }
 | 
|---|
| 1935 |                 }
 | 
|---|
| 1936 |                 break;
 | 
|---|
| 1937 |               }
 | 
|---|
| 1938 |             case 'E':
 | 
|---|
| 1939 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1940 |               if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
 | 
|---|
| 1941 |                 ExitFlag = 255;
 | 
|---|
| 1942 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl);
 | 
|---|
| 1943 |                 performCriticalExit();
 | 
|---|
| 1944 |               } else {
 | 
|---|
| 1945 |                 SaveFlag = true;
 | 
|---|
| 1946 |                 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl);
 | 
|---|
| 1947 |                 first = mol->FindAtom(atoi(argv[argptr]));
 | 
|---|
| 1948 |                 first->type = periode->FindElement(atoi(argv[argptr+1]));
 | 
|---|
| 1949 |                 argptr+=2;
 | 
|---|
| 1950 |               }
 | 
|---|
| 1951 |               break;
 | 
|---|
| 1952 |             case 'F':
 | 
|---|
| 1953 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1954 |               MaxDistance = -1;
 | 
|---|
| 1955 |               if (argv[argptr-1][2] == 'F') { // option is -FF?
 | 
|---|
| 1956 |                 // fetch first argument as max distance to surface
 | 
|---|
| 1957 |                 MaxDistance = atof(argv[argptr++]);
 | 
|---|
| 1958 |                 DoLog(0) && (Log() << Verbose(0) << "Filling with maximum layer distance of " << MaxDistance << "." << endl);
 | 
|---|
| 1959 |               }
 | 
|---|
| 1960 |               if ((argptr+7 >=argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+7]))) {
 | 
|---|
| 1961 |                 ExitFlag = 255;
 | 
|---|
| 1962 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <xyz of filler> <dist_x> <dist_y> <dist_z> <boundary> <randatom> <randmol> <DoRotate>" << endl);
 | 
|---|
| 1963 |                 performCriticalExit();
 | 
|---|
| 1964 |               } else {
 | 
|---|
| 1965 |                 SaveFlag = true;
 | 
|---|
| 1966 |                 DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl);
 | 
|---|
| 1967 |                 // construct water molecule
 | 
|---|
| 1968 |                 molecule *filler = World::getInstance().createMolecule();
 | 
|---|
| 1969 |                 if (!filler->AddXYZFile(argv[argptr])) {
 | 
|---|
| 1970 |                   DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl);
 | 
|---|
| 1971 |                 }
 | 
|---|
| 1972 |                 filler->SetNameFromFilename(argv[argptr]);
 | 
|---|
| 1973 |                 configuration.BG->ConstructBondGraph(filler);
 | 
|---|
| 1974 |                 molecule *Filling = NULL;
 | 
|---|
| 1975 |                 // call routine
 | 
|---|
| 1976 |                 double distance[NDIM];
 | 
|---|
| 1977 |                 for (int i=0;i<NDIM;i++)
 | 
|---|
| 1978 |                   distance[i] = atof(argv[argptr+i+1]);
 | 
|---|
| 1979 |                 Filling = FillBoxWithMolecule(molecules, filler, configuration, MaxDistance, distance, atof(argv[argptr+4]), atof(argv[argptr+5]), atof(argv[argptr+6]), atoi(argv[argptr+7]));
 | 
|---|
| 1980 |                 if (Filling != NULL) {
 | 
|---|
| 1981 |                   Filling->ActiveFlag = false;
 | 
|---|
| 1982 |                   molecules->insert(Filling);
 | 
|---|
| 1983 |                 }
 | 
|---|
| 1984 |                 World::getInstance().destroyMolecule(filler);
 | 
|---|
| 1985 |                 argptr+=6;
 | 
|---|
| 1986 |               }
 | 
|---|
| 1987 |               break;
 | 
|---|
| 1988 |             case 'A':
 | 
|---|
| 1989 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 1990 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 1991 |                 ExitFlag =255;
 | 
|---|
| 1992 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl);
 | 
|---|
| 1993 |                 performCriticalExit();
 | 
|---|
| 1994 |               } else {
 | 
|---|
| 1995 |                 DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl);
 | 
|---|
| 1996 |                 ifstream input(argv[argptr]);
 | 
|---|
| 1997 |                 mol->CreateAdjacencyListFromDbondFile(&input);
 | 
|---|
| 1998 |                 input.close();
 | 
|---|
| 1999 |                 argptr+=1;
 | 
|---|
| 2000 |               }
 | 
|---|
| 2001 |               break;
 | 
|---|
| 2002 | 
 | 
|---|
| 2003 |             case 'J':
 | 
|---|
| 2004 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2005 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 2006 |                 ExitFlag =255;
 | 
|---|
| 2007 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -j <path>" << endl);
 | 
|---|
| 2008 |                 performCriticalExit();
 | 
|---|
| 2009 |               } else {
 | 
|---|
| 2010 |                 DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << argv[argptr] << "." << endl);
 | 
|---|
| 2011 |                 configuration.BG->ConstructBondGraph(mol);
 | 
|---|
| 2012 |                 mol->StoreAdjacencyToFile(NULL, argv[argptr]);
 | 
|---|
| 2013 |                 argptr+=1;
 | 
|---|
| 2014 |               }
 | 
|---|
| 2015 |               break;
 | 
|---|
| 2016 | 
 | 
|---|
| 2017 |             case 'j':
 | 
|---|
| 2018 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2019 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 2020 |                 ExitFlag =255;
 | 
|---|
| 2021 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path>" << endl);
 | 
|---|
| 2022 |                 performCriticalExit();
 | 
|---|
| 2023 |               } else {
 | 
|---|
| 2024 |                 DoLog(0) && (Log() << Verbose(0) << "Storing bonds to path " << argv[argptr] << "." << endl);
 | 
|---|
| 2025 |                 configuration.BG->ConstructBondGraph(mol);
 | 
|---|
| 2026 |                 mol->StoreBondsToFile(NULL, argv[argptr]);
 | 
|---|
| 2027 |                 argptr+=1;
 | 
|---|
| 2028 |               }
 | 
|---|
| 2029 |               break;
 | 
|---|
| 2030 | 
 | 
|---|
| 2031 |             case 'N':
 | 
|---|
| 2032 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2033 |               if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
 | 
|---|
| 2034 |                 ExitFlag = 255;
 | 
|---|
| 2035 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl);
 | 
|---|
| 2036 |                 performCriticalExit();
 | 
|---|
| 2037 |               } else {
 | 
|---|
| 2038 |                 class Tesselation *T = NULL;
 | 
|---|
| 2039 |                 const LinkedCell *LCList = NULL;
 | 
|---|
| 2040 |                 molecule * Boundary = NULL;
 | 
|---|
| 2041 |                 //string filename(argv[argptr+1]);
 | 
|---|
| 2042 |                 //filename.append(".csv");
 | 
|---|
| 2043 |                 DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of biggest molecule.");
 | 
|---|
| 2044 |                 DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl);
 | 
|---|
| 2045 |                 // find biggest molecule
 | 
|---|
| 2046 |                 int counter  = 0;
 | 
|---|
| 2047 |                 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
 | 
|---|
| 2048 |                   (*BigFinder)->CountAtoms();
 | 
|---|
| 2049 |                   if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
 | 
|---|
| 2050 |                     Boundary = *BigFinder;
 | 
|---|
| 2051 |                   }
 | 
|---|
| 2052 |                   counter++;
 | 
|---|
| 2053 |                 }
 | 
|---|
| 2054 |                 DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl);
 | 
|---|
| 2055 |                 start = clock();
 | 
|---|
| 2056 |                 LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.);
 | 
|---|
| 2057 |                 if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]))
 | 
|---|
| 2058 |                   ExitFlag = 255;
 | 
|---|
| 2059 |                 //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
 | 
|---|
| 2060 |                 end = clock();
 | 
|---|
| 2061 |                 DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
 | 
|---|
| 2062 |                 delete(LCList);
 | 
|---|
| 2063 |                 delete(T);
 | 
|---|
| 2064 |                 argptr+=2;
 | 
|---|
| 2065 |               }
 | 
|---|
| 2066 |               break;
 | 
|---|
| 2067 |             case 'S':
 | 
|---|
| 2068 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2069 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 2070 |                 ExitFlag = 255;
 | 
|---|
| 2071 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl);
 | 
|---|
| 2072 |                 performCriticalExit();
 | 
|---|
| 2073 |               } else {
 | 
|---|
| 2074 |                 DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl);
 | 
|---|
| 2075 |                 ofstream *output = new ofstream(argv[argptr], ios::trunc);
 | 
|---|
| 2076 |                 if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
 | 
|---|
| 2077 |                   DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
 | 
|---|
| 2078 |                 else
 | 
|---|
| 2079 |                   DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
 | 
|---|
| 2080 |                 output->close();
 | 
|---|
| 2081 |                 delete(output);
 | 
|---|
| 2082 |                 argptr+=1;
 | 
|---|
| 2083 |               }
 | 
|---|
| 2084 |               break;
 | 
|---|
| 2085 |             case 'L':
 | 
|---|
| 2086 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2087 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 2088 |                 ExitFlag = 255;
 | 
|---|
| 2089 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for linear interpolation: -L <step0> <step1> <prefix> <identity mapping?>" << endl);
 | 
|---|
| 2090 |                 performCriticalExit();
 | 
|---|
| 2091 |               } else {
 | 
|---|
| 2092 |                 SaveFlag = true;
 | 
|---|
| 2093 |                 DoLog(1) && (Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl);
 | 
|---|
| 2094 |                 if (atoi(argv[argptr+3]) == 1)
 | 
|---|
| 2095 |                   DoLog(1) && (Log() << Verbose(1) << "Using Identity for the permutation map." << endl);
 | 
|---|
| 2096 |                 if (!mol->LinearInterpolationBetweenConfiguration(atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false)
 | 
|---|
| 2097 |                   DoLog(2) && (Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl);
 | 
|---|
| 2098 |                 else
 | 
|---|
| 2099 |                   DoLog(2) && (Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl);
 | 
|---|
| 2100 |                 argptr+=4;
 | 
|---|
| 2101 |               }
 | 
|---|
| 2102 |               break;
 | 
|---|
| 2103 |             case 'P':
 | 
|---|
| 2104 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2105 |               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
 | 
|---|
| 2106 |                 ExitFlag = 255;
 | 
|---|
| 2107 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl);
 | 
|---|
| 2108 |                 performCriticalExit();
 | 
|---|
| 2109 |               } else {
 | 
|---|
| 2110 |                 SaveFlag = true;
 | 
|---|
| 2111 |                 DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
 | 
|---|
| 2112 |                 if (!mol->VerletForceIntegration(argv[argptr], configuration))
 | 
|---|
| 2113 |                   DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
 | 
|---|
| 2114 |                 else
 | 
|---|
| 2115 |                   DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
 | 
|---|
| 2116 |                 argptr+=1;
 | 
|---|
| 2117 |               }
 | 
|---|
| 2118 |               break;
 | 
|---|
| 2119 |             case 'R':
 | 
|---|
| 2120 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2121 |               if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])))  {
 | 
|---|
| 2122 |                 ExitFlag = 255;
 | 
|---|
| 2123 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl);
 | 
|---|
| 2124 |                 performCriticalExit();
 | 
|---|
| 2125 |               } else {
 | 
|---|
| 2126 |                 SaveFlag = true;
 | 
|---|
| 2127 |                 DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl);
 | 
|---|
| 2128 |                 double tmp1 = atof(argv[argptr+1]);
 | 
|---|
| 2129 |                 atom *third = mol->FindAtom(atoi(argv[argptr]));
 | 
|---|
| 2130 |                 atom *first = mol->start;
 | 
|---|
| 2131 |                 if ((third != NULL) && (first != mol->end)) {
 | 
|---|
| 2132 |                   atom *second = first->next;
 | 
|---|
| 2133 |                   while(second != mol->end) {
 | 
|---|
| 2134 |                     first = second;
 | 
|---|
| 2135 |                     second = first->next;
 | 
|---|
| 2136 |                     if (first->x.DistanceSquared(third->x) > tmp1*tmp1) {// distance to first above radius ...
 | 
|---|
| 2137 |                       mol->RemoveAtom(first);
 | 
|---|
| 2138 |                     }
 | 
|---|
| 2139 |                   }
 | 
|---|
| 2140 |                 } else {
 | 
|---|
| 2141 |                   DoeLog(1) && (eLog()<< Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl);
 | 
|---|
| 2142 |                 }
 | 
|---|
| 2143 |                 argptr+=2;
 | 
|---|
| 2144 |               }
 | 
|---|
| 2145 |               break;
 | 
|---|
| 2146 |             case 't':
 | 
|---|
| 2147 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2148 |               if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
 | 
|---|
| 2149 |                 ExitFlag = 255;
 | 
|---|
| 2150 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl);
 | 
|---|
| 2151 |                 performCriticalExit();
 | 
|---|
| 2152 |               } else {
 | 
|---|
| 2153 |                 if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2154 |                 SaveFlag = true;
 | 
|---|
| 2155 |                 DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
 | 
|---|
| 2156 |                 for (int i=NDIM;i--;)
 | 
|---|
| 2157 |                   x[i] = atof(argv[argptr+i]);
 | 
|---|
| 2158 |                 mol->Translate((const Vector *)&x);
 | 
|---|
| 2159 |                 argptr+=3;
 | 
|---|
| 2160 |               }
 | 
|---|
| 2161 |               break;
 | 
|---|
| 2162 |             case 'T':
 | 
|---|
| 2163 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2164 |               if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
 | 
|---|
| 2165 |                 ExitFlag = 255;
 | 
|---|
| 2166 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl);
 | 
|---|
| 2167 |                 performCriticalExit();
 | 
|---|
| 2168 |               } else {
 | 
|---|
| 2169 |                 if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2170 |                 SaveFlag = true;
 | 
|---|
| 2171 |                 DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl);
 | 
|---|
| 2172 |                 for (int i=NDIM;i--;)
 | 
|---|
| 2173 |                   x[i] = atof(argv[argptr+i]);
 | 
|---|
| 2174 |                 mol->TranslatePeriodically((const Vector *)&x);
 | 
|---|
| 2175 |                 argptr+=3;
 | 
|---|
| 2176 |               }
 | 
|---|
| 2177 |               break;
 | 
|---|
| 2178 |             case 's':
 | 
|---|
| 2179 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2180 |               if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
 | 
|---|
| 2181 |                 ExitFlag = 255;
 | 
|---|
| 2182 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl);
 | 
|---|
| 2183 |                 performCriticalExit();
 | 
|---|
| 2184 |               } else {
 | 
|---|
| 2185 |                 SaveFlag = true;
 | 
|---|
| 2186 |                 j = -1;
 | 
|---|
| 2187 |                 DoLog(1) && (Log() << Verbose(1) << "Scaling all ion positions by factor." << endl);
 | 
|---|
| 2188 |                 factor = new double[NDIM];
 | 
|---|
| 2189 |                 factor[0] = atof(argv[argptr]);
 | 
|---|
| 2190 |                 factor[1] = atof(argv[argptr+1]);
 | 
|---|
| 2191 |                 factor[2] = atof(argv[argptr+2]);
 | 
|---|
| 2192 |                 mol->Scale((const double ** const)&factor);
 | 
|---|
| 2193 |                 double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 2194 |                 for (int i=0;i<NDIM;i++) {
 | 
|---|
| 2195 |                   j += i+1;
 | 
|---|
| 2196 |                   x[i] = atof(argv[NDIM+i]);
 | 
|---|
| 2197 |                   cell_size[j]*=factor[i];
 | 
|---|
| 2198 |                 }
 | 
|---|
| 2199 |                 delete[](factor);
 | 
|---|
| 2200 |                 argptr+=3;
 | 
|---|
| 2201 |               }
 | 
|---|
| 2202 |               break;
 | 
|---|
| 2203 |             case 'b':
 | 
|---|
| 2204 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2205 |               if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
 | 
|---|
| 2206 |                 ExitFlag = 255;
 | 
|---|
| 2207 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
 | 
|---|
| 2208 |                 performCriticalExit();
 | 
|---|
| 2209 |               } else {
 | 
|---|
| 2210 |                 SaveFlag = true;
 | 
|---|
| 2211 |                 j = -1;
 | 
|---|
| 2212 |                 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
 | 
|---|
| 2213 |                 double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 2214 |                 for (int i=0;i<6;i++) {
 | 
|---|
| 2215 |                   cell_size[i] = atof(argv[argptr+i]);
 | 
|---|
| 2216 |                 }
 | 
|---|
| 2217 |                 // center
 | 
|---|
| 2218 |                 mol->CenterInBox();
 | 
|---|
| 2219 |                 argptr+=6;
 | 
|---|
| 2220 |               }
 | 
|---|
| 2221 |               break;
 | 
|---|
| 2222 |             case 'B':
 | 
|---|
| 2223 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2224 |               if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
 | 
|---|
| 2225 |                 ExitFlag = 255;
 | 
|---|
| 2226 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
 | 
|---|
| 2227 |                 performCriticalExit();
 | 
|---|
| 2228 |               } else {
 | 
|---|
| 2229 |                 SaveFlag = true;
 | 
|---|
| 2230 |                 j = -1;
 | 
|---|
| 2231 |                 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
 | 
|---|
| 2232 |                 double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 2233 |                 for (int i=0;i<6;i++) {
 | 
|---|
| 2234 |                   cell_size[i] = atof(argv[argptr+i]);
 | 
|---|
| 2235 |                 }
 | 
|---|
| 2236 |                 // center
 | 
|---|
| 2237 |                 mol->BoundInBox();
 | 
|---|
| 2238 |                 argptr+=6;
 | 
|---|
| 2239 |               }
 | 
|---|
| 2240 |               break;
 | 
|---|
| 2241 |             case 'c':
 | 
|---|
| 2242 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2243 |               if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
 | 
|---|
| 2244 |                 ExitFlag = 255;
 | 
|---|
| 2245 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl);
 | 
|---|
| 2246 |                 performCriticalExit();
 | 
|---|
| 2247 |               } else {
 | 
|---|
| 2248 |                 SaveFlag = true;
 | 
|---|
| 2249 |                 j = -1;
 | 
|---|
| 2250 |                 DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl);
 | 
|---|
| 2251 |                 // make every coordinate positive
 | 
|---|
| 2252 |                 mol->CenterEdge(&x);
 | 
|---|
| 2253 |                 // update Box of atoms by boundary
 | 
|---|
| 2254 |                 mol->SetBoxDimension(&x);
 | 
|---|
| 2255 |                 // translate each coordinate by boundary
 | 
|---|
| 2256 |                 double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 2257 |                 j=-1;
 | 
|---|
| 2258 |                 for (int i=0;i<NDIM;i++) {
 | 
|---|
| 2259 |                   j += i+1;
 | 
|---|
| 2260 |                   x[i] = atof(argv[argptr+i]);
 | 
|---|
| 2261 |                   cell_size[j] += x[i]*2.;
 | 
|---|
| 2262 |                 }
 | 
|---|
| 2263 |                 mol->Translate((const Vector *)&x);
 | 
|---|
| 2264 |                 argptr+=3;
 | 
|---|
| 2265 |               }
 | 
|---|
| 2266 |               break;
 | 
|---|
| 2267 |             case 'O':
 | 
|---|
| 2268 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2269 |               SaveFlag = true;
 | 
|---|
| 2270 |               DoLog(1) && (Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl);
 | 
|---|
| 2271 |               x.Zero();
 | 
|---|
| 2272 |               mol->CenterEdge(&x);
 | 
|---|
| 2273 |               mol->SetBoxDimension(&x);
 | 
|---|
| 2274 |               argptr+=0;
 | 
|---|
| 2275 |               break;
 | 
|---|
| 2276 |             case 'r':
 | 
|---|
| 2277 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2278 |               if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])))  {
 | 
|---|
| 2279 |                 ExitFlag = 255;
 | 
|---|
| 2280 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl);
 | 
|---|
| 2281 |                 performCriticalExit();
 | 
|---|
| 2282 |               } else {
 | 
|---|
| 2283 |                 SaveFlag = true;
 | 
|---|
| 2284 |                 DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl);
 | 
|---|
| 2285 |                 atom *first = mol->FindAtom(atoi(argv[argptr]));
 | 
|---|
| 2286 |                 mol->RemoveAtom(first);
 | 
|---|
| 2287 |                 argptr+=1;
 | 
|---|
| 2288 |               }
 | 
|---|
| 2289 |               break;
 | 
|---|
| 2290 |             case 'f':
 | 
|---|
| 2291 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2292 |               if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
 | 
|---|
| 2293 |                 ExitFlag = 255;
 | 
|---|
| 2294 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl);
 | 
|---|
| 2295 |                 performCriticalExit();
 | 
|---|
| 2296 |               } else {
 | 
|---|
| 2297 |                 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl);
 | 
|---|
| 2298 |                 DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
 | 
|---|
| 2299 |                 start = clock();
 | 
|---|
| 2300 |                 mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
 | 
|---|
| 2301 |                 DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
 | 
|---|
| 2302 |                 if (mol->first->next != mol->last) {
 | 
|---|
| 2303 |                   ExitFlag = mol->FragmentMolecule(atoi(argv[argptr+1]), &configuration);
 | 
|---|
| 2304 |                 }
 | 
|---|
| 2305 |                 end = clock();
 | 
|---|
| 2306 |                 DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
 | 
|---|
| 2307 |                 argptr+=2;
 | 
|---|
| 2308 |               }
 | 
|---|
| 2309 |               break;
 | 
|---|
| 2310 |             case 'm':
 | 
|---|
| 2311 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2312 |               j = atoi(argv[argptr++]);
 | 
|---|
| 2313 |               if ((j<0) || (j>1)) {
 | 
|---|
| 2314 |                 DoeLog(1) && (eLog()<< Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl);
 | 
|---|
| 2315 |                 j = 0;
 | 
|---|
| 2316 |               }
 | 
|---|
| 2317 |               if (j) {
 | 
|---|
| 2318 |                 SaveFlag = true;
 | 
|---|
| 2319 |                 DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl);
 | 
|---|
| 2320 |               } else
 | 
|---|
| 2321 |                 DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
 | 
|---|
| 2322 |               mol->PrincipalAxisSystem((bool)j);
 | 
|---|
| 2323 |               break;
 | 
|---|
| 2324 |             case 'o':
 | 
|---|
| 2325 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2326 |               if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
 | 
|---|
| 2327 |                 ExitFlag = 255;
 | 
|---|
| 2328 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl);
 | 
|---|
| 2329 |                 performCriticalExit();
 | 
|---|
| 2330 |               } else {
 | 
|---|
| 2331 |                 class Tesselation *TesselStruct = NULL;
 | 
|---|
| 2332 |                 const LinkedCell *LCList = NULL;
 | 
|---|
| 2333 |                 DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
 | 
|---|
| 2334 |                 DoLog(1) && (Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl);
 | 
|---|
| 2335 |                 DoLog(1) && (Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl);
 | 
|---|
| 2336 |                 LCList = new LinkedCell(mol, 10.);
 | 
|---|
| 2337 |                 //FindConvexBorder(mol, LCList, argv[argptr]);
 | 
|---|
| 2338 |                 FindNonConvexBorder(mol, TesselStruct, LCList, 5., argv[argptr+1]);
 | 
|---|
| 2339 | //                RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]);
 | 
|---|
| 2340 |                 double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, argv[argptr]);
 | 
|---|
| 2341 |                 double clustervolume = VolumeOfConvexEnvelope(TesselStruct, &configuration);
 | 
|---|
| 2342 |                 DoLog(0) && (Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
 | 
|---|
| 2343 |                 DoLog(0) && (Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
 | 
|---|
| 2344 |                 delete(TesselStruct);
 | 
|---|
| 2345 |                 delete(LCList);
 | 
|---|
| 2346 |                 argptr+=2;
 | 
|---|
| 2347 |               }
 | 
|---|
| 2348 |               break;
 | 
|---|
| 2349 |             case 'U':
 | 
|---|
| 2350 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2351 |               if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
 | 
|---|
| 2352 |                 ExitFlag = 255;
 | 
|---|
| 2353 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl);
 | 
|---|
| 2354 |                 performCriticalExit();
 | 
|---|
| 2355 |               } else {
 | 
|---|
| 2356 |                 volume = atof(argv[argptr++]);
 | 
|---|
| 2357 |                 DoLog(0) && (Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl);
 | 
|---|
| 2358 |               }
 | 
|---|
| 2359 |             case 'u':
 | 
|---|
| 2360 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2361 |               if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
 | 
|---|
| 2362 |                 if (volume != -1)
 | 
|---|
| 2363 |                   ExitFlag = 255;
 | 
|---|
| 2364 |                   DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl);
 | 
|---|
| 2365 |                   performCriticalExit();
 | 
|---|
| 2366 |               } else {
 | 
|---|
| 2367 |                 double density;
 | 
|---|
| 2368 |                 SaveFlag = true;
 | 
|---|
| 2369 |                 DoLog(0) && (Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.");
 | 
|---|
| 2370 |                 density = atof(argv[argptr++]);
 | 
|---|
| 2371 |                 if (density < 1.0) {
 | 
|---|
| 2372 |                   DoeLog(1) && (eLog()<< Verbose(1) << "Density must be greater than 1.0g/cm^3 !" << endl);
 | 
|---|
| 2373 |                   density = 1.3;
 | 
|---|
| 2374 |                 }
 | 
|---|
| 2375 | //                for(int i=0;i<NDIM;i++) {
 | 
|---|
| 2376 | //                  repetition[i] = atoi(argv[argptr++]);
 | 
|---|
| 2377 | //                  if (repetition[i] < 1)
 | 
|---|
| 2378 | //                    DoeLog(1) && (eLog()<< Verbose(1) << "repetition value must be greater 1!" << endl);
 | 
|---|
| 2379 | //                  repetition[i] = 1;
 | 
|---|
| 2380 | //                }
 | 
|---|
| 2381 |                 PrepareClustersinWater(&configuration, mol, volume, density);  // if volume == 0, will calculate from ConvexEnvelope
 | 
|---|
| 2382 |               }
 | 
|---|
| 2383 |               break;
 | 
|---|
| 2384 |             case 'd':
 | 
|---|
| 2385 |               if (ExitFlag == 0) ExitFlag = 1;
 | 
|---|
| 2386 |               if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
 | 
|---|
| 2387 |                 ExitFlag = 255;
 | 
|---|
| 2388 |                 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl);
 | 
|---|
| 2389 |                 performCriticalExit();
 | 
|---|
| 2390 |               } else {
 | 
|---|
| 2391 |                 SaveFlag = true;
 | 
|---|
| 2392 |                 double * const cell_size = World::getInstance().getDomain();
 | 
|---|
| 2393 |                 for (int axis = 1; axis <= NDIM; axis++) {
 | 
|---|
| 2394 |                   int faktor = atoi(argv[argptr++]);
 | 
|---|
| 2395 |                   int count;
 | 
|---|
| 2396 |                   const element ** Elements;
 | 
|---|
| 2397 |                   Vector ** vectors;
 | 
|---|
| 2398 |                   if (faktor < 1) {
 | 
|---|
| 2399 |                     DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor mus be greater than 1!" << endl);
 | 
|---|
| 2400 |                     faktor = 1;
 | 
|---|
| 2401 |                   }
 | 
|---|
| 2402 |                   mol->CountAtoms();  // recount atoms
 | 
|---|
| 2403 |                   if (mol->AtomCount != 0) {  // if there is more than none
 | 
|---|
| 2404 |                     count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand
 | 
|---|
| 2405 |                     Elements = new const element *[count];
 | 
|---|
| 2406 |                     vectors = new Vector *[count];
 | 
|---|
| 2407 |                     j = 0;
 | 
|---|
| 2408 |                     first = mol->start;
 | 
|---|
| 2409 |                     while (first->next != mol->end) {  // make a list of all atoms with coordinates and element
 | 
|---|
| 2410 |                       first = first->next;
 | 
|---|
| 2411 |                       Elements[j] = first->type;
 | 
|---|
| 2412 |                       vectors[j] = &first->x;
 | 
|---|
| 2413 |                       j++;
 | 
|---|
| 2414 |                     }
 | 
|---|
| 2415 |                     if (count != j)
 | 
|---|
| 2416 |                       DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
 | 
|---|
| 2417 |                     x.Zero();
 | 
|---|
| 2418 |                     y.Zero();
 | 
|---|
| 2419 |                     y[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
 | 
|---|
| 2420 |                     for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
 | 
|---|
| 2421 |                       x += y; // per factor one cell width further
 | 
|---|
| 2422 |                       for (int k=count;k--;) { // go through every atom of the original cell
 | 
|---|
| 2423 |                         first = World::getInstance().createAtom(); // create a new body
 | 
|---|
| 2424 |                         first->x = (*vectors[k]) + x;
 | 
|---|
| 2425 |                         first->type = Elements[k];  // insert original element
 | 
|---|
| 2426 |                         mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
 | 
|---|
| 2427 |                       }
 | 
|---|
| 2428 |                     }
 | 
|---|
| 2429 |                     // free memory
 | 
|---|
| 2430 |                     delete[](Elements);
 | 
|---|
| 2431 |                     delete[](vectors);
 | 
|---|
| 2432 |                     // correct cell size
 | 
|---|
| 2433 |                     if (axis < 0) { // if sign was negative, we have to translate everything
 | 
|---|
| 2434 |                       x =(-(faktor-1)) * y;
 | 
|---|
| 2435 |                       mol->Translate(&x);
 | 
|---|
| 2436 |                     }
 | 
|---|
| 2437 |                     cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
 | 
|---|
| 2438 |                   }
 | 
|---|
| 2439 |                 }
 | 
|---|
| 2440 |               }
 | 
|---|
| 2441 |               break;
 | 
|---|
| 2442 |             default:   // no match? Step on
 | 
|---|
| 2443 |               if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
 | 
|---|
| 2444 |                 argptr++;
 | 
|---|
| 2445 |               break;
 | 
|---|
| 2446 |           }
 | 
|---|
| 2447 |         }
 | 
|---|
| 2448 |       } else argptr++;
 | 
|---|
| 2449 |     } while (argptr < argc);
 | 
|---|
| 2450 |     if (SaveFlag)
 | 
|---|
| 2451 |       configuration.SaveAll(ConfigFileName, periode, molecules);
 | 
|---|
| 2452 |   } else {  // no arguments, hence scan the elements db
 | 
|---|
| 2453 |     if (periode->LoadPeriodentafel(configuration.databasepath))
 | 
|---|
| 2454 |       DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
 | 
|---|
| 2455 |     else
 | 
|---|
| 2456 |       DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
 | 
|---|
| 2457 |     configuration.RetrieveConfigPathAndName("main_pcp_linux");
 | 
|---|
| 2458 |   }
 | 
|---|
| 2459 |   return(ExitFlag);
 | 
|---|
| 2460 | };
 | 
|---|
| 2461 | 
 | 
|---|
| 2462 | /********************************************** Main routine **************************************/
 | 
|---|
| 2463 | 
 | 
|---|
| 2464 | void cleanUp(){
 | 
|---|
| 2465 |   World::purgeInstance();
 | 
|---|
| 2466 |   Log() << Verbose(0) <<  "Maximum of allocated memory: "
 | 
|---|
| 2467 |     << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
 | 
|---|
| 2468 |   Log() << Verbose(0) <<  "Remaining non-freed memory: "
 | 
|---|
| 2469 |     << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
 | 
|---|
| 2470 |   MemoryUsageObserver::purgeInstance();
 | 
|---|
| 2471 |   logger::purgeInstance();
 | 
|---|
| 2472 |   errorLogger::purgeInstance();
 | 
|---|
| 2473 |   UIFactory::purgeInstance();
 | 
|---|
| 2474 |   MapOfActions::purgeInstance();
 | 
|---|
| 2475 |   CommandLineParser::purgeInstance();
 | 
|---|
| 2476 |   ActionRegistry::purgeInstance();
 | 
|---|
| 2477 |   ActionHistory::purgeInstance();
 | 
|---|
| 2478 |   Memory::getState();
 | 
|---|
| 2479 | }
 | 
|---|
| 2480 | 
 | 
|---|
| 2481 | int main(int argc, char **argv)
 | 
|---|
| 2482 | {
 | 
|---|
| 2483 |     config *configuration = World::getInstance().getConfig();
 | 
|---|
| 2484 |     Vector x, y, z, n;
 | 
|---|
| 2485 |     ifstream test;
 | 
|---|
| 2486 |     ofstream output;
 | 
|---|
| 2487 |     string line;
 | 
|---|
| 2488 |     char **Arguments = NULL;
 | 
|---|
| 2489 |     int ArgcSize = 0;
 | 
|---|
| 2490 |     int ExitFlag = 0;
 | 
|---|
| 2491 |     bool ArgumentsCopied = false;
 | 
|---|
| 2492 | 
 | 
|---|
| 2493 |     // print version check whether arguments are present at all
 | 
|---|
| 2494 |     cout << ESPACKVersion << endl;
 | 
|---|
| 2495 |     if (argc < 2) {
 | 
|---|
| 2496 |       cout << "Obtain help with " << argv[0] << " -h." << endl;
 | 
|---|
| 2497 |       cleanUp();
 | 
|---|
| 2498 |       Memory::getState();
 | 
|---|
| 2499 |       return(1);
 | 
|---|
| 2500 |     }
 | 
|---|
| 2501 | 
 | 
|---|
| 2502 | 
 | 
|---|
| 2503 |     setVerbosity(0);
 | 
|---|
| 2504 |     // need to init the history before any action is created
 | 
|---|
| 2505 |     ActionHistory::init();
 | 
|---|
| 2506 | 
 | 
|---|
| 2507 |     // from this moment on, we need to be sure to deeinitialize in the correct order
 | 
|---|
| 2508 |     // this is handled by the cleanup function
 | 
|---|
| 2509 |     atexit(cleanUp);
 | 
|---|
| 2510 | 
 | 
|---|
| 2511 |     // Parse command line options and if present create respective UI
 | 
|---|
| 2512 |     {
 | 
|---|
| 2513 |       set<int> ArgcList;
 | 
|---|
| 2514 |       ArgcList.insert(0); // push back program!
 | 
|---|
| 2515 |       ArgcList.insert(1); // push back config file name
 | 
|---|
| 2516 |       char ConfigFileName[MAXSTRINGSIZE];
 | 
|---|
| 2517 |       // handle arguments by ParseCommandLineOptions()
 | 
|---|
| 2518 |       ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), (char *&)ConfigFileName, ArgcList);
 | 
|---|
| 2519 |       // copy all remaining arguments to a new argv
 | 
|---|
| 2520 |       Arguments = Malloc<char *>(ArgcList.size(), "main - **Arguments");
 | 
|---|
| 2521 |       cout << "The following arguments are handled by CommandLineParser: ";
 | 
|---|
| 2522 |       for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) {
 | 
|---|
| 2523 |         Arguments[ArgcSize] = Malloc<char>(strlen(argv[*ArgcRunner])+2, "main - *Arguments[]");
 | 
|---|
| 2524 |         strcpy(Arguments[ArgcSize], argv[*ArgcRunner]);
 | 
|---|
| 2525 |         cout << " " << argv[*ArgcRunner];
 | 
|---|
| 2526 |         ArgcSize++;
 | 
|---|
| 2527 |       }
 | 
|---|
| 2528 |       cout << endl;
 | 
|---|
| 2529 |       ArgumentsCopied = true;
 | 
|---|
| 2530 |       // handle remaining arguments by CommandLineParser
 | 
|---|
| 2531 |       MapOfActions::getInstance().AddOptionsToParser();
 | 
|---|
| 2532 |       CommandLineParser::getInstance().Run(ArgcSize,Arguments);
 | 
|---|
| 2533 |       if (!CommandLineParser::getInstance().isEmpty()) {
 | 
|---|
| 2534 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
 | 
|---|
| 2535 |         UIFactory::makeUserInterface(UIFactory::CommandLine);
 | 
|---|
| 2536 |       } else {
 | 
|---|
| 2537 |         DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
 | 
|---|
| 2538 |         UIFactory::makeUserInterface(UIFactory::Text);
 | 
|---|
| 2539 |       }
 | 
|---|
| 2540 |     }
 | 
|---|
| 2541 | 
 | 
|---|
| 2542 |     {
 | 
|---|
| 2543 |       MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
 | 
|---|
| 2544 |       mainWindow->display();
 | 
|---|
| 2545 |       delete mainWindow;
 | 
|---|
| 2546 |     }
 | 
|---|
| 2547 | 
 | 
|---|
| 2548 |     if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath))
 | 
|---|
| 2549 |         Log() << Verbose(0) << "Saving of elements.db successful." << endl;
 | 
|---|
| 2550 | 
 | 
|---|
| 2551 |     else
 | 
|---|
| 2552 |         Log() << Verbose(0) << "Saving of elements.db failed." << endl;
 | 
|---|
| 2553 | 
 | 
|---|
| 2554 |   // free the new argv
 | 
|---|
| 2555 |   if (ArgumentsCopied) {
 | 
|---|
| 2556 |     for (int i=0; i<ArgcSize;i++)
 | 
|---|
| 2557 |       Free(&Arguments[i]);
 | 
|---|
| 2558 |     Free(&Arguments);
 | 
|---|
| 2559 |   }
 | 
|---|
| 2560 | 
 | 
|---|
| 2561 |   return (ExitFlag == 1 ? 0 : ExitFlag);
 | 
|---|
| 2562 | }
 | 
|---|
| 2563 | 
 | 
|---|
| 2564 | /********************************************** E N D **************************************************/
 | 
|---|