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