| [14de469] | 1 | /** \file builder.cpp | 
|---|
| [a8bcea6] | 2 | * | 
|---|
| [14de469] | 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 | 
|---|
| [a8bcea6] | 8 | * | 
|---|
| [14de469] | 9 | */ | 
|---|
|  | 10 |  | 
|---|
|  | 11 | /*! \mainpage Molecuilder - a molecular set builder | 
|---|
| [a8bcea6] | 12 | * | 
|---|
| [14de469] | 13 | * This introductory shall briefly make aquainted with the program, helping in installing and a first run. | 
|---|
| [a8bcea6] | 14 | * | 
|---|
| [14de469] | 15 | * \section about About the Program | 
|---|
| [a8bcea6] | 16 | * | 
|---|
| [042f82] | 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. | 
|---|
| [a8bcea6] | 20 | * | 
|---|
| [042f82] | 21 | *  A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello | 
|---|
|  | 22 | *  molecular dynamics implementation. | 
|---|
| [a8bcea6] | 23 | * | 
|---|
| [14de469] | 24 | * \section install Installation | 
|---|
| [a8bcea6] | 25 | * | 
|---|
| [042f82] | 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 | 
|---|
| [a8bcea6] | 30 | * | 
|---|
| [042f82] | 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 | 
|---|
| [a8bcea6] | 34 | * | 
|---|
| [14de469] | 35 | * \section run Running | 
|---|
| [a8bcea6] | 36 | * | 
|---|
| [042f82] | 37 | *  The program can be executed by running: ./molecuilder | 
|---|
| [a8bcea6] | 38 | * | 
|---|
| [042f82] | 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. | 
|---|
| [a8bcea6] | 42 | * | 
|---|
| [14de469] | 43 | * \section ref References | 
|---|
| [a8bcea6] | 44 | * | 
|---|
| [042f82] | 45 | *  For the special configuration file format, see the documentation of pcp. | 
|---|
| [a8bcea6] | 46 | * | 
|---|
| [14de469] | 47 | */ | 
|---|
|  | 48 |  | 
|---|
| [112b09] | 49 | #include "Helpers/MemDebug.hpp" | 
|---|
| [14de469] | 50 |  | 
|---|
| [12b845] | 51 | #include <boost/bind.hpp> | 
|---|
|  | 52 |  | 
|---|
| [14de469] | 53 | using namespace std; | 
|---|
|  | 54 |  | 
|---|
| [49e1ae] | 55 | #include <cstring> | 
|---|
| [0fb9f6] | 56 | #include <cstdlib> | 
|---|
| [49e1ae] | 57 |  | 
|---|
| [388049] | 58 | #include "analysis_bonds.hpp" | 
|---|
| [db6bf74] | 59 | #include "analysis_correlation.hpp" | 
|---|
| [f66195] | 60 | #include "atom.hpp" | 
|---|
|  | 61 | #include "bond.hpp" | 
|---|
| [b70721] | 62 | #include "bondgraph.hpp" | 
|---|
| [6ac7ee] | 63 | #include "boundary.hpp" | 
|---|
| [c6efc1] | 64 | #include "CommandLineParser.hpp" | 
|---|
| [f66195] | 65 | #include "config.hpp" | 
|---|
|  | 66 | #include "element.hpp" | 
|---|
| [6ac7ee] | 67 | #include "ellipsoid.hpp" | 
|---|
| [14de469] | 68 | #include "helpers.hpp" | 
|---|
| [f66195] | 69 | #include "leastsquaremin.hpp" | 
|---|
|  | 70 | #include "linkedcell.hpp" | 
|---|
| [e138de] | 71 | #include "log.hpp" | 
|---|
| [aac3ef] | 72 | #include "memoryusageobserver.hpp" | 
|---|
| [cee0b57] | 73 | #include "molecule.hpp" | 
|---|
| [f66195] | 74 | #include "periodentafel.hpp" | 
|---|
| [cc04b7] | 75 | #include "UIElements/UIFactory.hpp" | 
|---|
| [5f5a7b] | 76 | #include "UIElements/TextUI/TextUIFactory.hpp" | 
|---|
|  | 77 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp" | 
|---|
| [cc04b7] | 78 | #include "UIElements/MainWindow.hpp" | 
|---|
| [45f5d6] | 79 | #include "UIElements/Dialog.hpp" | 
|---|
| [12b845] | 80 | #include "Menu/ActionMenuItem.hpp" | 
|---|
| [a1e929] | 81 | #include "Parser/ChangeTracker.hpp" | 
|---|
| [12b845] | 82 | #include "Actions/ActionRegistry.hpp" | 
|---|
| [d56640] | 83 | #include "Actions/ActionHistory.hpp" | 
|---|
| [97ebf8] | 84 | #include "Actions/MapOfActions.hpp" | 
|---|
| [12b845] | 85 | #include "Actions/MethodAction.hpp" | 
|---|
| [03bb99] | 86 | #include "Actions/MoleculeAction/ChangeNameAction.hpp" | 
|---|
| [354859] | 87 | #include "World.hpp" | 
|---|
| [a8eb4a] | 88 | #include "version.h" | 
|---|
| [b34306] | 89 | #include "World.hpp" | 
|---|
| [112b09] | 90 |  | 
|---|
| [12b845] | 91 |  | 
|---|
| [1907a7] | 92 | /********************************************* Subsubmenu routine ************************************/ | 
|---|
| [1ca488f] | 93 | #if 0 | 
|---|
| [14de469] | 94 | /** Submenu for adding atoms to the molecule. | 
|---|
|  | 95 | * \param *periode periodentafel | 
|---|
| [1907a7] | 96 | * \param *molecule molecules with atoms | 
|---|
| [14de469] | 97 | */ | 
|---|
| [7f3b9d] | 98 | static void AddAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [14de469] | 99 | { | 
|---|
| [042f82] | 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 |  | 
|---|
| [58ed4a] | 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: "; | 
|---|
| [042f82] | 117 | cin >> choice; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | switch (choice) { | 
|---|
| [1907a7] | 120 | default: | 
|---|
| [58ed4a] | 121 | DoeLog(2) && (eLog()<< Verbose(2) << "Not a valid choice." << endl); | 
|---|
| [1907a7] | 122 | break; | 
|---|
| [042f82] | 123 | case 'a': // absolute coordinates of atom | 
|---|
| [58ed4a] | 124 | cout << Verbose(0) << "Enter absolute coordinates." << endl; | 
|---|
| [1907a7] | 125 | first = new atom; | 
|---|
| [5f612ee] | 126 | first->x.AskPosition(World::getInstance().getDomain(), false); | 
|---|
| [042f82] | 127 | first->type = periode->AskElement();  // give type | 
|---|
|  | 128 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 129 | break; | 
|---|
| [6ac7ee] | 130 |  | 
|---|
| [042f82] | 131 | case 'b': // relative coordinates of atom wrt to reference point | 
|---|
| [1907a7] | 132 | first = new atom; | 
|---|
|  | 133 | valid = true; | 
|---|
|  | 134 | do { | 
|---|
| [58ed4a] | 135 | if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl); | 
|---|
|  | 136 | cout << Verbose(0) << "Enter reference coordinates." << endl; | 
|---|
| [5f612ee] | 137 | x.AskPosition(World::getInstance().getDomain(), true); | 
|---|
| [58ed4a] | 138 | cout << Verbose(0) << "Enter relative coordinates." << endl; | 
|---|
| [5f612ee] | 139 | first->x.AskPosition(World::getInstance().getDomain(), false); | 
|---|
| [1907a7] | 140 | first->x.AddVector((const Vector *)&x); | 
|---|
| [58ed4a] | 141 | cout << Verbose(0) << "\n"; | 
|---|
| [1907a7] | 142 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
| [042f82] | 143 | first->type = periode->AskElement();  // give type | 
|---|
|  | 144 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 145 | break; | 
|---|
| [6ac7ee] | 146 |  | 
|---|
| [042f82] | 147 | case 'c': // relative coordinates of atom wrt to already placed atom | 
|---|
| [1907a7] | 148 | first = new atom; | 
|---|
|  | 149 | valid = true; | 
|---|
|  | 150 | do { | 
|---|
| [58ed4a] | 151 | if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl); | 
|---|
| [1907a7] | 152 | second = mol->AskAtom("Enter atom number: "); | 
|---|
| [a67d19] | 153 | DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl); | 
|---|
| [5f612ee] | 154 | first->x.AskPosition(World::getInstance().getDomain(), false); | 
|---|
| [1907a7] | 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))); | 
|---|
| [042f82] | 159 | first->type = periode->AskElement();  // give type | 
|---|
|  | 160 | mol->AddAtom(first);  // add to molecule | 
|---|
| [1907a7] | 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) { | 
|---|
| [58ed4a] | 168 | DoeLog(2) && (eLog()<< Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl); | 
|---|
| [1907a7] | 169 | } | 
|---|
| [58ed4a] | 170 | cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl; | 
|---|
| [1907a7] | 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); | 
|---|
| [58ed4a] | 181 | cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl; | 
|---|
| [14de469] | 182 | /* | 
|---|
| [1907a7] | 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)) { | 
|---|
| [58ed4a] | 193 | coutg() << Verbose(0) << "Failure solving self-dependent linear system!" << endl; | 
|---|
| [1907a7] | 194 | continue; | 
|---|
|  | 195 | } | 
|---|
| [a67d19] | 196 | DoLog(0) && (Log() << Verbose(0) << "resulting relative coordinates: "); | 
|---|
| [e138de] | 197 | z.Output(); | 
|---|
| [a67d19] | 198 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 199 | */ | 
|---|
|  | 200 | // calc axis vector | 
|---|
|  | 201 | x.CopyVector(&second->x); | 
|---|
|  | 202 | x.SubtractVector(&third->x); | 
|---|
|  | 203 | x.Normalize(); | 
|---|
| [e138de] | 204 | Log() << Verbose(0) << "x: ", | 
|---|
|  | 205 | x.Output(); | 
|---|
| [a67d19] | 206 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 207 | z.MakeNormalVector(&second->x,&third->x,&fourth->x); | 
|---|
| [e138de] | 208 | Log() << Verbose(0) << "z: ", | 
|---|
|  | 209 | z.Output(); | 
|---|
| [a67d19] | 210 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 211 | y.MakeNormalVector(&x,&z); | 
|---|
| [e138de] | 212 | Log() << Verbose(0) << "y: ", | 
|---|
|  | 213 | y.Output(); | 
|---|
| [a67d19] | 214 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 215 |  | 
|---|
|  | 216 | // rotate vector around first angle | 
|---|
|  | 217 | first->x.CopyVector(&x); | 
|---|
|  | 218 | first->x.RotateVector(&z,b - M_PI); | 
|---|
| [e138de] | 219 | Log() << Verbose(0) << "Rotated vector: ", | 
|---|
|  | 220 | first->x.Output(); | 
|---|
| [a67d19] | 221 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 222 | // remove the projection onto the rotation plane of the second angle | 
|---|
|  | 223 | n.CopyVector(&y); | 
|---|
| [658efb] | 224 | n.Scale(first->x.ScalarProduct(&y)); | 
|---|
| [e138de] | 225 | Log() << Verbose(0) << "N1: ", | 
|---|
|  | 226 | n.Output(); | 
|---|
| [a67d19] | 227 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 228 | first->x.SubtractVector(&n); | 
|---|
| [e138de] | 229 | Log() << Verbose(0) << "Subtracted vector: ", | 
|---|
|  | 230 | first->x.Output(); | 
|---|
| [a67d19] | 231 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 232 | n.CopyVector(&z); | 
|---|
| [658efb] | 233 | n.Scale(first->x.ScalarProduct(&z)); | 
|---|
| [e138de] | 234 | Log() << Verbose(0) << "N2: ", | 
|---|
|  | 235 | n.Output(); | 
|---|
| [a67d19] | 236 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 237 | first->x.SubtractVector(&n); | 
|---|
| [e138de] | 238 | Log() << Verbose(0) << "2nd subtracted vector: ", | 
|---|
|  | 239 | first->x.Output(); | 
|---|
| [a67d19] | 240 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 241 |  | 
|---|
|  | 242 | // rotate another vector around second angle | 
|---|
|  | 243 | n.CopyVector(&y); | 
|---|
|  | 244 | n.RotateVector(&x,c - M_PI); | 
|---|
| [e138de] | 245 | Log() << Verbose(0) << "2nd Rotated vector: ", | 
|---|
|  | 246 | n.Output(); | 
|---|
| [a67d19] | 247 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 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 |  | 
|---|
| [a67d19] | 255 | DoLog(0) && (Log() << Verbose(0) << "resulting coordinates: "); | 
|---|
| [e138de] | 256 | first->x.Output(); | 
|---|
| [a67d19] | 257 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [1907a7] | 258 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
| [042f82] | 259 | first->type = periode->AskElement();  // give type | 
|---|
|  | 260 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 261 | break; | 
|---|
| [6ac7ee] | 262 |  | 
|---|
| [042f82] | 263 | case 'e': // least square distance position to a set of atoms | 
|---|
| [1907a7] | 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; | 
|---|
| [58ed4a] | 270 | cout << Verbose(0) << "Now we need at least three molecules.\n"; | 
|---|
| [1907a7] | 271 | do { | 
|---|
| [58ed4a] | 272 | cout << Verbose(0) << "Enter " << i+1 << "th atom: "; | 
|---|
| [1907a7] | 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) { | 
|---|
| [776b64] | 280 | first->x.LSQdistance((const Vector **)atoms, i); | 
|---|
| [e138de] | 281 | first->x.Output(); | 
|---|
| [042f82] | 282 | first->type = periode->AskElement();  // give type | 
|---|
|  | 283 | mol->AddAtom(first);  // add to molecule | 
|---|
| [1907a7] | 284 | } else { | 
|---|
|  | 285 | delete first; | 
|---|
| [58ed4a] | 286 | cout << Verbose(0) << "Please enter at least two vectors!\n"; | 
|---|
| [1907a7] | 287 | } | 
|---|
| [042f82] | 288 | break; | 
|---|
|  | 289 | }; | 
|---|
| [14de469] | 290 | }; | 
|---|
|  | 291 |  | 
|---|
|  | 292 | /** Submenu for centering the atoms in the molecule. | 
|---|
| [1907a7] | 293 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 294 | */ | 
|---|
| [7f3b9d] | 295 | static void CenterAtoms(molecule *mol) | 
|---|
| [14de469] | 296 | { | 
|---|
| [042f82] | 297 | Vector x, y, helper; | 
|---|
|  | 298 | char choice;  // menu choice char | 
|---|
|  | 299 |  | 
|---|
| [58ed4a] | 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: "; | 
|---|
| [042f82] | 308 | cin >> choice; | 
|---|
|  | 309 |  | 
|---|
|  | 310 | switch (choice) { | 
|---|
|  | 311 | default: | 
|---|
| [58ed4a] | 312 | cout << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [042f82] | 313 | break; | 
|---|
|  | 314 | case 'a': | 
|---|
| [58ed4a] | 315 | cout << Verbose(0) << "Centering atoms in config file on origin." << endl; | 
|---|
| [e138de] | 316 | mol->CenterOrigin(); | 
|---|
| [042f82] | 317 | break; | 
|---|
|  | 318 | case 'b': | 
|---|
| [58ed4a] | 319 | cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl; | 
|---|
| [e138de] | 320 | mol->CenterPeriodic(); | 
|---|
| [042f82] | 321 | break; | 
|---|
|  | 322 | case 'c': | 
|---|
| [58ed4a] | 323 | cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl; | 
|---|
| [042f82] | 324 | for (int i=0;i<NDIM;i++) { | 
|---|
| [58ed4a] | 325 | cout << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [042f82] | 326 | cin >> y.x[i]; | 
|---|
|  | 327 | } | 
|---|
| [e138de] | 328 | mol->CenterEdge(&x);  // make every coordinate positive | 
|---|
| [437922] | 329 | mol->Center.AddVector(&y); // translate by boundary | 
|---|
| [042f82] | 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': | 
|---|
| [58ed4a] | 336 | cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
| [042f82] | 337 | for (int i=0;i<NDIM;i++) { | 
|---|
| [58ed4a] | 338 | cout << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [042f82] | 339 | cin >> x.x[i]; | 
|---|
|  | 340 | } | 
|---|
|  | 341 | // update Box of atoms by boundary | 
|---|
|  | 342 | mol->SetBoxDimension(&x); | 
|---|
| [36ec71] | 343 | // center | 
|---|
| [e138de] | 344 | mol->CenterInBox(); | 
|---|
| [042f82] | 345 | break; | 
|---|
|  | 346 | } | 
|---|
| [14de469] | 347 | }; | 
|---|
|  | 348 |  | 
|---|
|  | 349 | /** Submenu for aligning the atoms in the molecule. | 
|---|
|  | 350 | * \param *periode periodentafel | 
|---|
| [1907a7] | 351 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 352 | */ | 
|---|
| [7f3b9d] | 353 | static void AlignAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [14de469] | 354 | { | 
|---|
| [042f82] | 355 | atom *first, *second, *third; | 
|---|
|  | 356 | Vector x,n; | 
|---|
|  | 357 | char choice;  // menu choice char | 
|---|
|  | 358 |  | 
|---|
| [58ed4a] | 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: "; | 
|---|
| [042f82] | 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 | 
|---|
| [58ed4a] | 379 | cout << Verbose(0) << "Enter normal vector of mirror plane." << endl; | 
|---|
| [5f612ee] | 380 | n.AskPosition(World::getInstance().getDomain(),0); | 
|---|
| [042f82] | 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); | 
|---|
| [58ed4a] | 399 | cout << Verbose(0) << "Element is " << param.type->name << endl; | 
|---|
| [042f82] | 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); | 
|---|
| [58ed4a] | 406 | cout << Verbose(0) << "Offset vector: "; | 
|---|
| [e138de] | 407 | x.Output(); | 
|---|
| [a67d19] | 408 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [042f82] | 409 | n.Normalize(); | 
|---|
|  | 410 | break; | 
|---|
|  | 411 | }; | 
|---|
| [a67d19] | 412 | DoLog(0) && (Log() << Verbose(0) << "Alignment vector: "); | 
|---|
| [e138de] | 413 | n.Output(); | 
|---|
| [a67d19] | 414 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [042f82] | 415 | mol->Align(&n); | 
|---|
| [14de469] | 416 | }; | 
|---|
|  | 417 |  | 
|---|
|  | 418 | /** Submenu for mirroring the atoms in the molecule. | 
|---|
| [1907a7] | 419 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 420 | */ | 
|---|
| [7f3b9d] | 421 | static void MirrorAtoms(molecule *mol) | 
|---|
| [14de469] | 422 | { | 
|---|
| [042f82] | 423 | atom *first, *second, *third; | 
|---|
|  | 424 | Vector n; | 
|---|
|  | 425 | char choice;  // menu choice char | 
|---|
|  | 426 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [042f82] | 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 | 
|---|
| [a67d19] | 446 | DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl); | 
|---|
| [5f612ee] | 447 | n.AskPosition(World::getInstance().getDomain(),0); | 
|---|
| [042f82] | 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 | }; | 
|---|
| [a67d19] | 459 | DoLog(0) && (Log() << Verbose(0) << "Normal vector: "); | 
|---|
| [e138de] | 460 | n.Output(); | 
|---|
| [a67d19] | 461 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [042f82] | 462 | mol->Mirror((const Vector *)&n); | 
|---|
| [14de469] | 463 | }; | 
|---|
|  | 464 |  | 
|---|
|  | 465 | /** Submenu for removing the atoms from the molecule. | 
|---|
| [1907a7] | 466 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 467 | */ | 
|---|
| [7f3b9d] | 468 | static void RemoveAtoms(molecule *mol) | 
|---|
| [14de469] | 469 | { | 
|---|
| [042f82] | 470 | atom *first, *second; | 
|---|
|  | 471 | int axis; | 
|---|
|  | 472 | double tmp1, tmp2; | 
|---|
|  | 473 | char choice;  // menu choice char | 
|---|
|  | 474 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [042f82] | 482 | cin >> choice; | 
|---|
|  | 483 |  | 
|---|
|  | 484 | switch (choice) { | 
|---|
|  | 485 | default: | 
|---|
|  | 486 | case 'a': | 
|---|
|  | 487 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: "))) | 
|---|
| [a67d19] | 488 | DoLog(1) && (Log() << Verbose(1) << "Atom removed." << endl); | 
|---|
| [042f82] | 489 | else | 
|---|
| [a67d19] | 490 | DoLog(1) && (Log() << Verbose(1) << "Atom not found." << endl); | 
|---|
| [042f82] | 491 | break; | 
|---|
|  | 492 | case 'b': | 
|---|
|  | 493 | second = mol->AskAtom("Enter number of atom as reference point: "); | 
|---|
| [a67d19] | 494 | DoLog(0) && (Log() << Verbose(0) << "Enter radius: "); | 
|---|
| [042f82] | 495 | cin >> tmp1; | 
|---|
|  | 496 | first = mol->start; | 
|---|
| [c54da3] | 497 | second = first->next; | 
|---|
| [375b458] | 498 | while(second != mol->end) { | 
|---|
|  | 499 | first = second; | 
|---|
| [c54da3] | 500 | second = first->next; | 
|---|
| [042f82] | 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': | 
|---|
| [a67d19] | 506 | DoLog(0) && (Log() << Verbose(0) << "Which axis is it: "); | 
|---|
| [042f82] | 507 | cin >> axis; | 
|---|
| [a67d19] | 508 | DoLog(0) && (Log() << Verbose(0) << "Lower boundary: "); | 
|---|
| [042f82] | 509 | cin >> tmp1; | 
|---|
| [a67d19] | 510 | DoLog(0) && (Log() << Verbose(0) << "Upper boundary: "); | 
|---|
| [042f82] | 511 | cin >> tmp2; | 
|---|
|  | 512 | first = mol->start; | 
|---|
| [a5b2c3a] | 513 | second = first->next; | 
|---|
|  | 514 | while(second != mol->end) { | 
|---|
|  | 515 | first = second; | 
|---|
|  | 516 | second = first->next; | 
|---|
| [375b458] | 517 | if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ... | 
|---|
| [e138de] | 518 | //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl; | 
|---|
| [042f82] | 519 | mol->RemoveAtom(first); | 
|---|
| [375b458] | 520 | } | 
|---|
| [042f82] | 521 | } | 
|---|
|  | 522 | break; | 
|---|
|  | 523 | }; | 
|---|
| [e138de] | 524 | //mol->Output(); | 
|---|
| [042f82] | 525 | choice = 'r'; | 
|---|
| [14de469] | 526 | }; | 
|---|
|  | 527 |  | 
|---|
|  | 528 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
|  | 529 | * \param *periode periodentafel | 
|---|
| [1907a7] | 530 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 531 | */ | 
|---|
| [d52ea1b] | 532 | static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration) | 
|---|
| [14de469] | 533 | { | 
|---|
| [042f82] | 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 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [042f82] | 551 | cin >> choice; | 
|---|
|  | 552 |  | 
|---|
|  | 553 | switch(choice) { | 
|---|
|  | 554 | default: | 
|---|
| [a67d19] | 555 | DoLog(1) && (Log() << Verbose(1) << "Not a valid choice." << endl); | 
|---|
| [042f82] | 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; | 
|---|
| [e138de] | 573 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl; | 
|---|
| [042f82] | 574 | } | 
|---|
|  | 575 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
| [e138de] | 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; | 
|---|
| [042f82] | 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(); | 
|---|
| [a67d19] | 587 | DoLog(1) && (Log() << Verbose(1) << "Distance vector is "); | 
|---|
| [e138de] | 588 | x.Output(); | 
|---|
| [a67d19] | 589 | DoLog(0) && (Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl); | 
|---|
| [042f82] | 590 | break; | 
|---|
|  | 591 |  | 
|---|
|  | 592 | case 'c': | 
|---|
| [a67d19] | 593 | DoLog(0) && (Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl); | 
|---|
| [042f82] | 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); | 
|---|
| [a67d19] | 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); | 
|---|
| [042f82] | 604 | break; | 
|---|
|  | 605 | case 'd': | 
|---|
| [a67d19] | 606 | DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl); | 
|---|
|  | 607 | DoLog(0) && (Log() << Verbose(0) << "Shall we rotate? [0/1]: "); | 
|---|
| [042f82] | 608 | cin >> Z; | 
|---|
|  | 609 | if ((Z >=0) && (Z <=1)) | 
|---|
| [e138de] | 610 | mol->PrincipalAxisSystem((bool)Z); | 
|---|
| [042f82] | 611 | else | 
|---|
| [e138de] | 612 | mol->PrincipalAxisSystem(false); | 
|---|
| [042f82] | 613 | break; | 
|---|
|  | 614 | case 'e': | 
|---|
| [d30402] | 615 | { | 
|---|
| [a67d19] | 616 | DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope."); | 
|---|
| [d30402] | 617 | class Tesselation *TesselStruct = NULL; | 
|---|
| [776b64] | 618 | const LinkedCell *LCList = NULL; | 
|---|
|  | 619 | LCList = new LinkedCell(mol, 10.); | 
|---|
| [e138de] | 620 | FindConvexBorder(mol, TesselStruct, LCList, NULL); | 
|---|
|  | 621 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration); | 
|---|
| [a67d19] | 622 | DoLog(0) && (Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl);\ | 
|---|
| [776b64] | 623 | delete(LCList); | 
|---|
| [d30402] | 624 | delete(TesselStruct); | 
|---|
|  | 625 | } | 
|---|
| [042f82] | 626 | break; | 
|---|
|  | 627 | case 'f': | 
|---|
| [e138de] | 628 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps); | 
|---|
| [042f82] | 629 | break; | 
|---|
|  | 630 | case 'g': | 
|---|
|  | 631 | { | 
|---|
|  | 632 | char filename[255]; | 
|---|
| [a67d19] | 633 | DoLog(0) && (Log() << Verbose(0) << "Please enter filename: " << endl); | 
|---|
| [042f82] | 634 | cin >> filename; | 
|---|
| [a67d19] | 635 | DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl); | 
|---|
| [042f82] | 636 | ofstream *output = new ofstream(filename, ios::trunc); | 
|---|
| [e138de] | 637 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) | 
|---|
| [a67d19] | 638 | DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl); | 
|---|
| [042f82] | 639 | else | 
|---|
| [a67d19] | 640 | DoLog(2) && (Log() << Verbose(2) << "File stored." << endl); | 
|---|
| [042f82] | 641 | output->close(); | 
|---|
|  | 642 | delete(output); | 
|---|
|  | 643 | } | 
|---|
|  | 644 | break; | 
|---|
|  | 645 | } | 
|---|
| [14de469] | 646 | }; | 
|---|
|  | 647 |  | 
|---|
|  | 648 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
| [1907a7] | 649 | * \param *mol molecule with all the atoms | 
|---|
| [14de469] | 650 | * \param *configuration configuration structure for the to be written config files of all fragments | 
|---|
|  | 651 | */ | 
|---|
| [7f3b9d] | 652 | static void FragmentAtoms(molecule *mol, config *configuration) | 
|---|
| [14de469] | 653 | { | 
|---|
| [042f82] | 654 | int Order1; | 
|---|
|  | 655 | clock_t start, end; | 
|---|
|  | 656 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [042f82] | 659 | cin >> Order1; | 
|---|
|  | 660 | if (mol->first->next != mol->last) {  // there are bonds | 
|---|
|  | 661 | start = clock(); | 
|---|
| [e138de] | 662 | mol->FragmentMolecule(Order1, configuration); | 
|---|
| [042f82] | 663 | end = clock(); | 
|---|
| [a67d19] | 664 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); | 
|---|
| [042f82] | 665 | } else | 
|---|
| [a67d19] | 666 | DoLog(0) && (Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl); | 
|---|
| [14de469] | 667 | }; | 
|---|
|  | 668 |  | 
|---|
| [1907a7] | 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 | { | 
|---|
| [cb85c2e] | 677 | atom *first, *second, *third; | 
|---|
| [1907a7] | 678 | molecule *mol = NULL; | 
|---|
|  | 679 | Vector x,y,z,n; // coordinates for absolute point in cell volume | 
|---|
|  | 680 | double *factor; // unit factor if desired | 
|---|
| [f1cccd] | 681 | double bond, minBond; | 
|---|
| [1907a7] | 682 | char choice;  // menu choice char | 
|---|
|  | 683 | bool valid; | 
|---|
|  | 684 |  | 
|---|
| [a67d19] | 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); | 
|---|
| [63f06e] | 694 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
| [58ed4a] | 695 | DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl); | 
|---|
| [a67d19] | 696 | DoLog(0) && (Log() << Verbose(0) << "INPUT: "); | 
|---|
| [1907a7] | 697 | cin >> choice; | 
|---|
|  | 698 |  | 
|---|
|  | 699 | switch (choice) { | 
|---|
|  | 700 | default: | 
|---|
| [a67d19] | 701 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl); | 
|---|
| [1907a7] | 702 | break; | 
|---|
|  | 703 |  | 
|---|
|  | 704 | case 'a': // add atom | 
|---|
| [63f06e] | 705 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 706 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 707 | mol = *ListRunner; | 
|---|
| [a67d19] | 708 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 709 | AddAtoms(periode, mol); | 
|---|
|  | 710 | } | 
|---|
|  | 711 | break; | 
|---|
|  | 712 |  | 
|---|
|  | 713 | case 'b': // scale a bond | 
|---|
| [63f06e] | 714 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 715 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 716 | mol = *ListRunner; | 
|---|
| [a67d19] | 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); | 
|---|
| [1907a7] | 719 | first = mol->AskAtom("Enter first (fixed) atom: "); | 
|---|
|  | 720 | second = mol->AskAtom("Enter second (shifting) atom: "); | 
|---|
| [f1cccd] | 721 | minBond = 0.; | 
|---|
| [1907a7] | 722 | for (int i=NDIM;i--;) | 
|---|
| [f1cccd] | 723 | minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]); | 
|---|
|  | 724 | minBond = sqrt(minBond); | 
|---|
| [a67d19] | 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.]: "); | 
|---|
| [1907a7] | 727 | cin >> bond; | 
|---|
|  | 728 | for (int i=NDIM;i--;) { | 
|---|
| [f1cccd] | 729 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond); | 
|---|
| [1907a7] | 730 | } | 
|---|
| [e138de] | 731 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; | 
|---|
|  | 732 | //second->Output(second->type->No, 1); | 
|---|
| [1907a7] | 733 | } | 
|---|
|  | 734 | break; | 
|---|
|  | 735 |  | 
|---|
|  | 736 | case 'c': // unit scaling of the metric | 
|---|
| [63f06e] | 737 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 738 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 739 | mol = *ListRunner; | 
|---|
| [a67d19] | 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: "); | 
|---|
| [1907a7] | 743 | factor = new double[NDIM]; | 
|---|
|  | 744 | cin >> factor[0]; | 
|---|
|  | 745 | cin >> factor[1]; | 
|---|
|  | 746 | cin >> factor[2]; | 
|---|
|  | 747 | valid = true; | 
|---|
| [776b64] | 748 | mol->Scale((const double ** const)&factor); | 
|---|
| [1907a7] | 749 | delete[](factor); | 
|---|
|  | 750 | } | 
|---|
|  | 751 | break; | 
|---|
|  | 752 |  | 
|---|
|  | 753 | case 'l': // measure distances or angles | 
|---|
| [63f06e] | 754 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 755 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 756 | mol = *ListRunner; | 
|---|
| [a67d19] | 757 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 758 | MeasureAtoms(periode, mol, configuration); | 
|---|
|  | 759 | } | 
|---|
|  | 760 | break; | 
|---|
|  | 761 |  | 
|---|
|  | 762 | case 'r': // remove atom | 
|---|
| [63f06e] | 763 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 764 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 765 | mol = *ListRunner; | 
|---|
| [a67d19] | 766 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 767 | RemoveAtoms(mol); | 
|---|
|  | 768 | } | 
|---|
|  | 769 | break; | 
|---|
|  | 770 |  | 
|---|
| [cb85c2e] | 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; | 
|---|
| [a67d19] | 775 | DoLog(0) && (Log() << Verbose(0) << "Turning atom around another bond - first is atom to turn, second (central) and third specify bond" << endl); | 
|---|
| [cb85c2e] | 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 |  | 
|---|
| [1907a7] | 804 | case 'u': // change an atom's element | 
|---|
| [63f06e] | 805 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 806 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 807 | int Z; | 
|---|
|  | 808 | mol = *ListRunner; | 
|---|
| [a67d19] | 809 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 810 | first = NULL; | 
|---|
|  | 811 | do { | 
|---|
| [a67d19] | 812 | DoLog(0) && (Log() << Verbose(0) << "Change the element of which atom: "); | 
|---|
| [1907a7] | 813 | cin >> Z; | 
|---|
|  | 814 | } while ((first = mol->FindAtom(Z)) == NULL); | 
|---|
| [a67d19] | 815 | DoLog(0) && (Log() << Verbose(0) << "New element by atomic number Z: "); | 
|---|
| [1907a7] | 816 | cin >> Z; | 
|---|
|  | 817 | first->type = periode->FindElement(Z); | 
|---|
| [a67d19] | 818 | DoLog(0) && (Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl); | 
|---|
| [1907a7] | 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 | { | 
|---|
| [4777e9] | 830 | atom *first = NULL; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [a67d19] | 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); | 
|---|
| [63f06e] | 850 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
| [58ed4a] | 851 | DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl); | 
|---|
| [a67d19] | 852 | DoLog(0) && (Log() << Verbose(0) << "INPUT: "); | 
|---|
| [1907a7] | 853 | cin >> choice; | 
|---|
|  | 854 |  | 
|---|
|  | 855 | switch (choice) { | 
|---|
|  | 856 | default: | 
|---|
| [a67d19] | 857 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl); | 
|---|
| [1907a7] | 858 | break; | 
|---|
|  | 859 |  | 
|---|
|  | 860 | case 'd': // duplicate the periodic cell along a given axis, given times | 
|---|
| [63f06e] | 861 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 862 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 863 | mol = *ListRunner; | 
|---|
| [a67d19] | 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]: "); | 
|---|
| [1907a7] | 866 | cin >> axis; | 
|---|
| [a67d19] | 867 | DoLog(0) && (Log() << Verbose(0) << "State the factor: "); | 
|---|
| [1907a7] | 868 | cin >> faktor; | 
|---|
|  | 869 |  | 
|---|
| [e138de] | 870 | mol->CountAtoms(); // recount atoms | 
|---|
| [1024cb] | 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 | 
|---|
| [1907a7] | 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) | 
|---|
| [58ed4a] | 884 | DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl); | 
|---|
| [1907a7] | 885 | x.Zero(); | 
|---|
|  | 886 | y.Zero(); | 
|---|
| [5f612ee] | 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 | 
|---|
| [1907a7] | 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 | 
|---|
| [e138de] | 899 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
| [1907a7] | 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 | } | 
|---|
| [5f612ee] | 910 | World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; | 
|---|
| [1907a7] | 911 | } | 
|---|
|  | 912 | } | 
|---|
|  | 913 | break; | 
|---|
|  | 914 |  | 
|---|
|  | 915 | case 'f': | 
|---|
|  | 916 | FragmentAtoms(mol, configuration); | 
|---|
|  | 917 | break; | 
|---|
|  | 918 |  | 
|---|
|  | 919 | case 'g': // center the atoms | 
|---|
| [63f06e] | 920 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 921 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 922 | mol = *ListRunner; | 
|---|
| [a67d19] | 923 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 924 | CenterAtoms(mol); | 
|---|
|  | 925 | } | 
|---|
|  | 926 | break; | 
|---|
|  | 927 |  | 
|---|
|  | 928 | case 'i': // align all atoms | 
|---|
| [63f06e] | 929 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 930 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 931 | mol = *ListRunner; | 
|---|
| [a67d19] | 932 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 933 | AlignAtoms(periode, mol); | 
|---|
|  | 934 | } | 
|---|
|  | 935 | break; | 
|---|
|  | 936 |  | 
|---|
|  | 937 | case 'm': // mirror atoms along a given axis | 
|---|
| [63f06e] | 938 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 939 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 940 | mol = *ListRunner; | 
|---|
| [a67d19] | 941 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl); | 
|---|
| [1907a7] | 942 | MirrorAtoms(mol); | 
|---|
|  | 943 | } | 
|---|
|  | 944 | break; | 
|---|
|  | 945 |  | 
|---|
|  | 946 | case 'o': // create the connection matrix | 
|---|
| [63f06e] | 947 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 948 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [b6d8a9] | 949 | mol = *ListRunner; | 
|---|
|  | 950 | double bonddistance; | 
|---|
|  | 951 | clock_t start,end; | 
|---|
| [a67d19] | 952 | DoLog(0) && (Log() << Verbose(0) << "What's the maximum bond distance: "); | 
|---|
| [b6d8a9] | 953 | cin >> bonddistance; | 
|---|
|  | 954 | start = clock(); | 
|---|
| [e138de] | 955 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
| [b6d8a9] | 956 | end = clock(); | 
|---|
| [a67d19] | 957 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); | 
|---|
| [b6d8a9] | 958 | } | 
|---|
| [1907a7] | 959 | break; | 
|---|
|  | 960 |  | 
|---|
|  | 961 | case 't': // translate all atoms | 
|---|
| [63f06e] | 962 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 963 | if ((*ListRunner)->ActiveFlag) { | 
|---|
| [1907a7] | 964 | mol = *ListRunner; | 
|---|
| [a67d19] | 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); | 
|---|
| [5f612ee] | 967 | x.AskPosition(World::getInstance().getDomain(),0); | 
|---|
| [63f06e] | 968 | mol->Center.AddVector((const Vector *)&x); | 
|---|
| [1907a7] | 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 | 
|---|
| [63f06e] | 990 | Vector center; | 
|---|
| [1907a7] | 991 | int nr, count; | 
|---|
|  | 992 | molecule *mol = NULL; | 
|---|
|  | 993 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [1907a7] | 1004 | cin >> choice; | 
|---|
|  | 1005 |  | 
|---|
|  | 1006 | switch (choice) { | 
|---|
|  | 1007 | default: | 
|---|
| [a67d19] | 1008 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl); | 
|---|
| [1907a7] | 1009 | break; | 
|---|
|  | 1010 | case 'c': | 
|---|
| [5f612ee] | 1011 | mol = World::getInstance().createMolecule(); | 
|---|
| [1907a7] | 1012 | molecules->insert(mol); | 
|---|
|  | 1013 | break; | 
|---|
|  | 1014 |  | 
|---|
| [63f06e] | 1015 | case 'l': // load from XYZ file | 
|---|
|  | 1016 | { | 
|---|
|  | 1017 | char filename[MAXSTRINGSIZE]; | 
|---|
| [a67d19] | 1018 | DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl); | 
|---|
| [5f612ee] | 1019 | mol = World::getInstance().createMolecule(); | 
|---|
| [63f06e] | 1020 | do { | 
|---|
| [a67d19] | 1021 | DoLog(0) && (Log() << Verbose(0) << "Enter file name: "); | 
|---|
| [63f06e] | 1022 | cin >> filename; | 
|---|
|  | 1023 | } while (!mol->AddXYZFile(filename)); | 
|---|
|  | 1024 | mol->SetNameFromFilename(filename); | 
|---|
|  | 1025 | // center at set box dimensions | 
|---|
| [e138de] | 1026 | mol->CenterEdge(¢er); | 
|---|
| [5f612ee] | 1027 | double * const cell_size = World::getInstance().getDomain(); | 
|---|
| [b34306] | 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]; | 
|---|
| [63f06e] | 1034 | molecules->insert(mol); | 
|---|
|  | 1035 | } | 
|---|
| [1907a7] | 1036 | break; | 
|---|
|  | 1037 |  | 
|---|
|  | 1038 | case 'n': | 
|---|
| [63f06e] | 1039 | { | 
|---|
|  | 1040 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1041 | do { | 
|---|
| [a67d19] | 1042 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: "); | 
|---|
| [63f06e] | 1043 | cin >> nr; | 
|---|
|  | 1044 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 1045 | } while (mol == NULL); | 
|---|
| [a67d19] | 1046 | DoLog(0) && (Log() << Verbose(0) << "Enter name: "); | 
|---|
| [63f06e] | 1047 | cin >> filename; | 
|---|
|  | 1048 | strcpy(mol->name, filename); | 
|---|
|  | 1049 | } | 
|---|
| [1907a7] | 1050 | break; | 
|---|
|  | 1051 |  | 
|---|
|  | 1052 | case 'N': | 
|---|
| [63f06e] | 1053 | { | 
|---|
|  | 1054 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1055 | do { | 
|---|
| [a67d19] | 1056 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: "); | 
|---|
| [63f06e] | 1057 | cin >> nr; | 
|---|
|  | 1058 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 1059 | } while (mol == NULL); | 
|---|
| [a67d19] | 1060 | DoLog(0) && (Log() << Verbose(0) << "Enter name: "); | 
|---|
| [63f06e] | 1061 | cin >> filename; | 
|---|
|  | 1062 | mol->SetNameFromFilename(filename); | 
|---|
|  | 1063 | } | 
|---|
| [1907a7] | 1064 | break; | 
|---|
|  | 1065 |  | 
|---|
|  | 1066 | case 'p': // parse XYZ file | 
|---|
| [63f06e] | 1067 | { | 
|---|
|  | 1068 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1069 | mol = NULL; | 
|---|
|  | 1070 | do { | 
|---|
| [a67d19] | 1071 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: "); | 
|---|
| [63f06e] | 1072 | cin >> nr; | 
|---|
|  | 1073 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 1074 | } while (mol == NULL); | 
|---|
| [a67d19] | 1075 | DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl); | 
|---|
| [63f06e] | 1076 | do { | 
|---|
| [a67d19] | 1077 | DoLog(0) && (Log() << Verbose(0) << "Enter file name: "); | 
|---|
| [63f06e] | 1078 | cin >> filename; | 
|---|
|  | 1079 | } while (!mol->AddXYZFile(filename)); | 
|---|
|  | 1080 | mol->SetNameFromFilename(filename); | 
|---|
|  | 1081 | } | 
|---|
| [1907a7] | 1082 | break; | 
|---|
|  | 1083 |  | 
|---|
|  | 1084 | case 'r': | 
|---|
| [a67d19] | 1085 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: "); | 
|---|
| [1907a7] | 1086 | cin >> nr; | 
|---|
|  | 1087 | count = 1; | 
|---|
| [f7f7a4] | 1088 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
| [63f06e] | 1089 | if (nr == (*ListRunner)->IndexNr) { | 
|---|
|  | 1090 | mol = *ListRunner; | 
|---|
|  | 1091 | molecules->ListOfMolecules.erase(ListRunner); | 
|---|
|  | 1092 | delete(mol); | 
|---|
| [f7f7a4] | 1093 | break; | 
|---|
| [63f06e] | 1094 | } | 
|---|
| [1907a7] | 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 |  | 
|---|
| [a67d19] | 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: "); | 
|---|
| [1907a7] | 1121 | cin >> choice; | 
|---|
|  | 1122 |  | 
|---|
|  | 1123 | switch (choice) { | 
|---|
|  | 1124 | default: | 
|---|
| [a67d19] | 1125 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl); | 
|---|
| [1907a7] | 1126 | break; | 
|---|
|  | 1127 |  | 
|---|
| [63f06e] | 1128 | case 'a': | 
|---|
|  | 1129 | { | 
|---|
|  | 1130 | int src, dest; | 
|---|
|  | 1131 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 1132 | { | 
|---|
|  | 1133 | do { | 
|---|
| [a67d19] | 1134 | DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: "); | 
|---|
| [63f06e] | 1135 | cin >> dest; | 
|---|
|  | 1136 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 1137 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 1138 | do { | 
|---|
| [a67d19] | 1139 | DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to add from: "); | 
|---|
| [63f06e] | 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 |  | 
|---|
| [f18185] | 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 |  | 
|---|
| [1907a7] | 1201 | case 'e': | 
|---|
| [f7f7a4] | 1202 | { | 
|---|
|  | 1203 | int src, dest; | 
|---|
|  | 1204 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 1205 | do { | 
|---|
| [a67d19] | 1206 | DoLog(0) && (Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): "); | 
|---|
| [f7f7a4] | 1207 | cin >> src; | 
|---|
|  | 1208 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 1209 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 1210 | do { | 
|---|
| [a67d19] | 1211 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): "); | 
|---|
| [f7f7a4] | 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 | } | 
|---|
| [1907a7] | 1218 | break; | 
|---|
|  | 1219 |  | 
|---|
| [1cbf47] | 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 |  | 
|---|
| [1907a7] | 1230 | case 'm': | 
|---|
| [63f06e] | 1231 | { | 
|---|
|  | 1232 | int nr; | 
|---|
|  | 1233 | molecule *mol = NULL; | 
|---|
|  | 1234 | do { | 
|---|
| [a67d19] | 1235 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into: "); | 
|---|
| [63f06e] | 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 | } | 
|---|
| [1907a7] | 1249 | break; | 
|---|
|  | 1250 |  | 
|---|
|  | 1251 | case 's': | 
|---|
| [a67d19] | 1252 | DoLog(0) && (Log() << Verbose(0) << "Not implemented yet." << endl); | 
|---|
| [1907a7] | 1253 | break; | 
|---|
|  | 1254 |  | 
|---|
|  | 1255 | case 't': | 
|---|
| [63f06e] | 1256 | { | 
|---|
|  | 1257 | int src, dest; | 
|---|
|  | 1258 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 1259 | { | 
|---|
|  | 1260 | do { | 
|---|
| [a67d19] | 1261 | DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: "); | 
|---|
| [63f06e] | 1262 | cin >> dest; | 
|---|
|  | 1263 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 1264 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 1265 | do { | 
|---|
| [a67d19] | 1266 | DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to merge into: "); | 
|---|
| [63f06e] | 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 | } | 
|---|
| [1907a7] | 1274 | break; | 
|---|
|  | 1275 | } | 
|---|
|  | 1276 | }; | 
|---|
|  | 1277 |  | 
|---|
| [14de469] | 1278 | /********************************************** Test routine **************************************/ | 
|---|
|  | 1279 |  | 
|---|
|  | 1280 | /** Is called always as option 'T' in the menu. | 
|---|
| [1907a7] | 1281 | * \param *molecules list of molecules | 
|---|
| [14de469] | 1282 | */ | 
|---|
| [1907a7] | 1283 | static void testroutine(MoleculeListClass *molecules) | 
|---|
| [14de469] | 1284 | { | 
|---|
| [042f82] | 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 | 
|---|
| [1907a7] | 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 { | 
|---|
| [58ed4a] | 1294 | DoeLog(0) && (eLog()<< Verbose(0) << "I don't have anything to test on ... "); | 
|---|
| [e359a8] | 1295 | performCriticalExit(); | 
|---|
| [1907a7] | 1296 | return; | 
|---|
|  | 1297 | } | 
|---|
|  | 1298 | atom *Walker = mol->start; | 
|---|
| [6ac7ee] | 1299 |  | 
|---|
| [042f82] | 1300 | // generate some KeySets | 
|---|
| [a67d19] | 1301 | DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl); | 
|---|
| [1024cb] | 1302 | KeySet TestSets[mol->getAtomCount()+1]; | 
|---|
| [042f82] | 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 | } | 
|---|
| [a67d19] | 1311 | DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl); | 
|---|
| [042f82] | 1312 | KeySetTestPair test; | 
|---|
| [1024cb] | 1313 | test = TestSets[mol->getAtomCount()-1].insert(Walker->nr); | 
|---|
| [042f82] | 1314 | if (test.second) { | 
|---|
| [a67d19] | 1315 | DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); | 
|---|
| [042f82] | 1316 | } else { | 
|---|
| [a67d19] | 1317 | DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl); | 
|---|
| [042f82] | 1318 | } | 
|---|
| [1024cb] | 1319 | TestSets[mol->getAtomCount()].insert(mol->end->previous->nr); | 
|---|
|  | 1320 | TestSets[mol->getAtomCount()].insert(mol->end->previous->previous->previous->nr); | 
|---|
| [042f82] | 1321 |  | 
|---|
|  | 1322 | // constructing Graph structure | 
|---|
| [a67d19] | 1323 | DoLog(0) && (Log() << Verbose(0) << "Generating Subgraph class." << endl); | 
|---|
| [042f82] | 1324 | Graph Subgraphs; | 
|---|
|  | 1325 |  | 
|---|
|  | 1326 | // insert KeySets into Subgraphs | 
|---|
| [a67d19] | 1327 | DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl); | 
|---|
| [1024cb] | 1328 | for (int j=0;j<mol->getAtomCount();j++) { | 
|---|
| [042f82] | 1329 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1330 | } | 
|---|
| [a67d19] | 1331 | DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl); | 
|---|
| [042f82] | 1332 | GraphTestPair test2; | 
|---|
| [1024cb] | 1333 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.))); | 
|---|
| [042f82] | 1334 | if (test2.second) { | 
|---|
| [a67d19] | 1335 | DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl); | 
|---|
| [042f82] | 1336 | } else { | 
|---|
| [a67d19] | 1337 | DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl); | 
|---|
| [042f82] | 1338 | } | 
|---|
|  | 1339 |  | 
|---|
|  | 1340 | // show graphs | 
|---|
| [a67d19] | 1341 | DoLog(0) && (Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl); | 
|---|
| [042f82] | 1342 | Graph::iterator A = Subgraphs.begin(); | 
|---|
|  | 1343 | while (A !=  Subgraphs.end()) { | 
|---|
| [a67d19] | 1344 | DoLog(0) && (Log() << Verbose(0) << (*A).second.first << ": "); | 
|---|
| [042f82] | 1345 | KeySet::iterator key = (*A).first.begin(); | 
|---|
|  | 1346 | comp = -1; | 
|---|
|  | 1347 | while (key != (*A).first.end()) { | 
|---|
|  | 1348 | if ((*key) > comp) | 
|---|
| [a67d19] | 1349 | DoLog(0) && (Log() << Verbose(0) << (*key) << " "); | 
|---|
| [042f82] | 1350 | else | 
|---|
| [a67d19] | 1351 | DoLog(0) && (Log() << Verbose(0) << (*key) << "! "); | 
|---|
| [042f82] | 1352 | comp = (*key); | 
|---|
|  | 1353 | key++; | 
|---|
|  | 1354 | } | 
|---|
| [a67d19] | 1355 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [042f82] | 1356 | A++; | 
|---|
|  | 1357 | } | 
|---|
|  | 1358 | delete(mol); | 
|---|
| [14de469] | 1359 | }; | 
|---|
|  | 1360 |  | 
|---|
| [dbe929] | 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 | 
|---|
| [1907a7] | 1366 | * \param *molecules list of molecules structure with all the atoms and coordinates | 
|---|
| [dbe929] | 1367 | */ | 
|---|
| [1907a7] | 1368 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules) | 
|---|
| [dbe929] | 1369 | { | 
|---|
| [042f82] | 1370 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1371 | ofstream output; | 
|---|
| [5f612ee] | 1372 | molecule *mol = World::getInstance().createMolecule(); | 
|---|
| [6a7f78c] | 1373 | mol->SetNameFromFilename(ConfigFileName); | 
|---|
| [042f82] | 1374 |  | 
|---|
| [568be7] | 1375 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
| [58ed4a] | 1376 | DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl); | 
|---|
| [568be7] | 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"); | 
|---|
| [a67d19] | 1385 | DoLog(0) && (Log() << Verbose(0) << "Saving as pdb input "); | 
|---|
| [568be7] | 1386 | if (configuration->SavePDB(filename, molecules)) | 
|---|
| [a67d19] | 1387 | DoLog(0) && (Log() << Verbose(0) << "done." << endl); | 
|---|
| [568be7] | 1388 | else | 
|---|
| [a67d19] | 1389 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [568be7] | 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"); | 
|---|
| [a67d19] | 1396 | DoLog(0) && (Log() << Verbose(0) << "Saving as tremolo data input "); | 
|---|
| [568be7] | 1397 | if (configuration->SaveTREMOLO(filename, molecules)) | 
|---|
| [a67d19] | 1398 | DoLog(0) && (Log() << Verbose(0) << "done." << endl); | 
|---|
| [568be7] | 1399 | else | 
|---|
| [a67d19] | 1400 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [568be7] | 1401 |  | 
|---|
| [437922] | 1402 | // translate each to its center and merge all molecules in MoleculeListClass into this molecule | 
|---|
| [042f82] | 1403 | int N = molecules->ListOfMolecules.size(); | 
|---|
| [ae38fb] | 1404 | int *src = new int[N]; | 
|---|
| [042f82] | 1405 | N=0; | 
|---|
| [437922] | 1406 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { | 
|---|
| [042f82] | 1407 | src[N++] = (*ListRunner)->IndexNr; | 
|---|
| [437922] | 1408 | (*ListRunner)->Translate(&(*ListRunner)->Center); | 
|---|
|  | 1409 | } | 
|---|
| [042f82] | 1410 | molecules->SimpleMultiAdd(mol, src, N); | 
|---|
| [ae38fb] | 1411 | delete[](src); | 
|---|
| [357fba] | 1412 |  | 
|---|
| [437922] | 1413 | // ... and translate back | 
|---|
| [63f06e] | 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 | } | 
|---|
| [042f82] | 1419 |  | 
|---|
| [a67d19] | 1420 | DoLog(0) && (Log() << Verbose(0) << "Storing configuration ... " << endl); | 
|---|
| [042f82] | 1421 | // get correct valence orbitals | 
|---|
|  | 1422 | mol->CalculateOrbitals(*configuration); | 
|---|
|  | 1423 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble; | 
|---|
|  | 1424 | if (ConfigFileName != NULL) { // test the file name | 
|---|
| [437922] | 1425 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1426 | output.open(filename, ios::trunc); | 
|---|
| [042f82] | 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(); | 
|---|
| [a67d19] | 1436 | DoLog(0) && (Log() << Verbose(0) << "Saving of config file "); | 
|---|
| [042f82] | 1437 | if (configuration->Save(filename, periode, mol)) | 
|---|
| [a67d19] | 1438 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl); | 
|---|
| [042f82] | 1439 | else | 
|---|
| [a67d19] | 1440 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [042f82] | 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 | } | 
|---|
| [a67d19] | 1453 | DoLog(0) && (Log() << Verbose(0) << "Saving of XYZ file "); | 
|---|
| [042f82] | 1454 | if (mol->MDSteps <= 1) { | 
|---|
|  | 1455 | if (mol->OutputXYZ(&output)) | 
|---|
| [a67d19] | 1456 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl); | 
|---|
| [042f82] | 1457 | else | 
|---|
| [a67d19] | 1458 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [042f82] | 1459 | } else { | 
|---|
|  | 1460 | if (mol->OutputTrajectoriesXYZ(&output)) | 
|---|
| [a67d19] | 1461 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl); | 
|---|
| [042f82] | 1462 | else | 
|---|
| [a67d19] | 1463 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [042f82] | 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"); | 
|---|
| [a67d19] | 1473 | DoLog(0) && (Log() << Verbose(0) << "Saving as mpqc input "); | 
|---|
| [042f82] | 1474 | if (configuration->SaveMPQC(filename, mol)) | 
|---|
| [a67d19] | 1475 | DoLog(0) && (Log() << Verbose(0) << "done." << endl); | 
|---|
| [042f82] | 1476 | else | 
|---|
| [a67d19] | 1477 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl); | 
|---|
| [042f82] | 1478 |  | 
|---|
|  | 1479 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
| [58ed4a] | 1480 | DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl); | 
|---|
| [042f82] | 1481 | } | 
|---|
| [568be7] | 1482 |  | 
|---|
| [5f612ee] | 1483 | World::getInstance().destroyMolecule(mol); | 
|---|
| [dbe929] | 1484 | }; | 
|---|
|  | 1485 |  | 
|---|
| [da3024e] | 1486 | #endif | 
|---|
|  | 1487 |  | 
|---|
| [ca2b83] | 1488 | /** Parses the command line options. | 
|---|
| [97ebf8] | 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. | 
|---|
| [ca2b83] | 1491 | * \param argc argument count | 
|---|
|  | 1492 | * \param **argv arguments array | 
|---|
| [1907a7] | 1493 | * \param *molecules list of molecules structure | 
|---|
| [ca2b83] | 1494 | * \param *periode elements structure | 
|---|
|  | 1495 | * \param configuration config file structure | 
|---|
|  | 1496 | * \param *ConfigFileName pointer to config file name in **argv | 
|---|
| [d7d29c] | 1497 | * \param *PathToDatabases pointer to db's path in **argv | 
|---|
| [97ebf8] | 1498 | * \param &ArgcList list of arguments that we do not parse here | 
|---|
| [ca2b83] | 1499 | * \return exit code (0 - successful, all else - something's wrong) | 
|---|
|  | 1500 | */ | 
|---|
| [97ebf8] | 1501 | static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, | 
|---|
| [6ca1f7] | 1502 | config& configuration, char **ConfigFileName, set<int> &ArgcList) | 
|---|
| [14de469] | 1503 | { | 
|---|
| [042f82] | 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.; | 
|---|
| [f1cccd] | 1512 | enum ConfigStatus configPresent = absent; | 
|---|
| [042f82] | 1513 | int argptr; | 
|---|
| [b6d8a9] | 1514 | molecule *mol = NULL; | 
|---|
| [6a7f78c] | 1515 | string BondGraphFileName("\n"); | 
|---|
| [6ac7ee] | 1516 |  | 
|---|
| [042f82] | 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] == '-') { | 
|---|
| [a67d19] | 1522 | DoLog(0) && (Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n"); | 
|---|
| [042f82] | 1523 | argptr++; | 
|---|
|  | 1524 | switch(argv[argptr-1][1]) { | 
|---|
|  | 1525 | case 'h': | 
|---|
|  | 1526 | case 'H': | 
|---|
|  | 1527 | case '?': | 
|---|
| [f65e1f] | 1528 | ArgcList.insert(argptr-1); | 
|---|
| [97ebf8] | 1529 | return(1); | 
|---|
| [042f82] | 1530 | break; | 
|---|
|  | 1531 | case 'v': | 
|---|
| [9d2a92] | 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 | } | 
|---|
| [717e0c] | 1541 | break; | 
|---|
| [042f82] | 1542 | case 'V': | 
|---|
| [f65e1f] | 1543 | ArgcList.insert(argptr-1); | 
|---|
| [eff648] | 1544 | return(1); | 
|---|
| [042f82] | 1545 | break; | 
|---|
| [58ed4a] | 1546 | case 'B': | 
|---|
|  | 1547 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [9d2a92] | 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 | } | 
|---|
| [58ed4a] | 1561 | break; | 
|---|
| [042f82] | 1562 | case 'e': | 
|---|
|  | 1563 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [58ed4a] | 1564 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl); | 
|---|
| [e359a8] | 1565 | performCriticalExit(); | 
|---|
| [042f82] | 1566 | } else { | 
|---|
| [198494] | 1567 | ArgcList.insert(argptr-1); | 
|---|
|  | 1568 | ArgcList.insert(argptr); | 
|---|
| [042f82] | 1569 | argptr+=1; | 
|---|
|  | 1570 | } | 
|---|
|  | 1571 | break; | 
|---|
| [b21a64] | 1572 | case 'g': | 
|---|
|  | 1573 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [58ed4a] | 1574 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl); | 
|---|
| [e359a8] | 1575 | performCriticalExit(); | 
|---|
| [b21a64] | 1576 | } else { | 
|---|
| [39af9f] | 1577 | ArgcList.insert(argptr-1); | 
|---|
|  | 1578 | ArgcList.insert(argptr); | 
|---|
| [b21a64] | 1579 | argptr+=1; | 
|---|
|  | 1580 | } | 
|---|
|  | 1581 | break; | 
|---|
| [5188f5] | 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 { | 
|---|
| [bdaacd] | 1588 | ArgcList.insert(argptr-1); | 
|---|
|  | 1589 | ArgcList.insert(argptr); | 
|---|
| [5188f5] | 1590 | argptr+=1; | 
|---|
|  | 1591 | } | 
|---|
|  | 1592 | break; | 
|---|
| [042f82] | 1593 | case 'n': | 
|---|
| [9d2a92] | 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 | } | 
|---|
| [042f82] | 1603 | break; | 
|---|
| [046783] | 1604 | case 'X': | 
|---|
| [9d2a92] | 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; | 
|---|
| [046783] | 1613 | } | 
|---|
|  | 1614 | break; | 
|---|
| [042f82] | 1615 | default:   // no match? Step on | 
|---|
|  | 1616 | argptr++; | 
|---|
|  | 1617 | break; | 
|---|
|  | 1618 | } | 
|---|
|  | 1619 | } else | 
|---|
|  | 1620 | argptr++; | 
|---|
|  | 1621 | } while (argptr < argc); | 
|---|
|  | 1622 |  | 
|---|
| [34e0013] | 1623 | // 3b. Find config file name and parse if possible, also BondGraphFileName | 
|---|
| [042f82] | 1624 | if (argv[1][0] != '-') { | 
|---|
| [b6d8a9] | 1625 | // simply create a new molecule, wherein the config file is loaded and the manipulation takes place | 
|---|
| [a67d19] | 1626 | DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl); | 
|---|
| [042f82] | 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) { | 
|---|
| [a67d19] | 1632 | DoLog(1) && (Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl); | 
|---|
| [f1cccd] | 1633 | configPresent = absent; | 
|---|
| [042f82] | 1634 | } else { | 
|---|
| [a67d19] | 1635 | DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl); | 
|---|
| [6ca1f7] | 1636 | strcpy(*ConfigFileName, argv[1]); | 
|---|
| [f1cccd] | 1637 | configPresent = empty; | 
|---|
| [042f82] | 1638 | output.close(); | 
|---|
|  | 1639 | } | 
|---|
|  | 1640 | } else { | 
|---|
|  | 1641 | test.close(); | 
|---|
| [6ca1f7] | 1642 | strcpy(*ConfigFileName, argv[1]); | 
|---|
| [a67d19] | 1643 | DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... "); | 
|---|
| [6ca1f7] | 1644 | switch (configuration.TestSyntax(*ConfigFileName, periode)) { | 
|---|
| [042f82] | 1645 | case 1: | 
|---|
| [a67d19] | 1646 | DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl); | 
|---|
| [6ca1f7] | 1647 | configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules); | 
|---|
| [f1cccd] | 1648 | configPresent = present; | 
|---|
| [042f82] | 1649 | break; | 
|---|
|  | 1650 | case 0: | 
|---|
| [a67d19] | 1651 | DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl); | 
|---|
| [6ca1f7] | 1652 | configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules); | 
|---|
| [f1cccd] | 1653 | configPresent = present; | 
|---|
| [042f82] | 1654 | break; | 
|---|
|  | 1655 | default: | 
|---|
| [a67d19] | 1656 | DoLog(0) && (Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl); | 
|---|
| [f1cccd] | 1657 | configPresent = empty; | 
|---|
| [042f82] | 1658 | } | 
|---|
|  | 1659 | } | 
|---|
|  | 1660 | } else | 
|---|
| [f1cccd] | 1661 | configPresent = absent; | 
|---|
| [fa649a] | 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) { | 
|---|
| [23b547] | 1671 | mol = World::getInstance().createMolecule(); | 
|---|
| [fa649a] | 1672 | mol->ActiveFlag = true; | 
|---|
| [6ca1f7] | 1673 | if (*ConfigFileName != NULL) | 
|---|
|  | 1674 | mol->SetNameFromFilename(*ConfigFileName); | 
|---|
| [fa649a] | 1675 | molecules->insert(mol); | 
|---|
|  | 1676 | } | 
|---|
|  | 1677 |  | 
|---|
| [042f82] | 1678 | // 4. parse again through options, now for those depending on elements db and config presence | 
|---|
|  | 1679 | argptr = 1; | 
|---|
|  | 1680 | do { | 
|---|
| [a67d19] | 1681 | DoLog(0) && (Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl); | 
|---|
| [042f82] | 1682 | if (argv[argptr][0] == '-') { | 
|---|
|  | 1683 | argptr++; | 
|---|
| [f1cccd] | 1684 | if ((configPresent == present) || (configPresent == empty)) { | 
|---|
| [042f82] | 1685 | switch(argv[argptr-1][1]) { | 
|---|
|  | 1686 | case 'p': | 
|---|
| [ebcade] | 1687 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1688 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1689 | ExitFlag = 255; | 
|---|
| [58ed4a] | 1690 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl); | 
|---|
| [e359a8] | 1691 | performCriticalExit(); | 
|---|
| [042f82] | 1692 | } else { | 
|---|
|  | 1693 | SaveFlag = true; | 
|---|
| [a1e929] | 1694 | configPresent = present; | 
|---|
|  | 1695 | ArgcList.insert(argptr-1); | 
|---|
|  | 1696 | ArgcList.insert(argptr); | 
|---|
|  | 1697 | argptr+=1; | 
|---|
| [042f82] | 1698 | } | 
|---|
|  | 1699 | break; | 
|---|
|  | 1700 | case 'a': | 
|---|
| [ebcade] | 1701 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f0a3ec] | 1702 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [042f82] | 1703 | ExitFlag = 255; | 
|---|
| [f0a3ec] | 1704 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for adding atom: -a <Z> --position <x> <y> <z>" << endl); | 
|---|
| [e359a8] | 1705 | performCriticalExit(); | 
|---|
| [042f82] | 1706 | } else { | 
|---|
| [f0a3ec] | 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; | 
|---|
| [042f82] | 1714 | } | 
|---|
|  | 1715 | break; | 
|---|
|  | 1716 | default:   // no match? Don't step on (this is done in next switch's default) | 
|---|
|  | 1717 | break; | 
|---|
|  | 1718 | } | 
|---|
|  | 1719 | } | 
|---|
| [f1cccd] | 1720 | if (configPresent == present) { | 
|---|
| [042f82] | 1721 | switch(argv[argptr-1][1]) { | 
|---|
|  | 1722 | case 'D': | 
|---|
| [ebcade] | 1723 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [9d2a92] | 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; | 
|---|
| [042f82] | 1732 | } | 
|---|
|  | 1733 | break; | 
|---|
| [3930eb] | 1734 | case 'I': | 
|---|
| [a67d19] | 1735 | DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl); | 
|---|
| [6866aa] | 1736 | ArgcList.insert(argptr-1); | 
|---|
|  | 1737 | argptr+=0; | 
|---|
| [3930eb] | 1738 | break; | 
|---|
| [db6bf74] | 1739 | case 'C': | 
|---|
| [58ed4a] | 1740 | { | 
|---|
|  | 1741 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f0a3ec] | 1742 | if ((argptr+11 >= argc)) { | 
|---|
| [58ed4a] | 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': | 
|---|
| [58bbd3] | 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; | 
|---|
| [58ed4a] | 1763 | break; | 
|---|
|  | 1764 |  | 
|---|
|  | 1765 | case 'P': | 
|---|
| [58bbd3] | 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; | 
|---|
| [58ed4a] | 1783 | break; | 
|---|
|  | 1784 |  | 
|---|
|  | 1785 | case 'S': | 
|---|
| [58bbd3] | 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; | 
|---|
| [58ed4a] | 1803 | break; | 
|---|
| [09048c] | 1804 |  | 
|---|
| [58ed4a] | 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; | 
|---|
| [f4e1f5] | 1810 | } | 
|---|
|  | 1811 | } | 
|---|
| [58ed4a] | 1812 | break; | 
|---|
| [db6bf74] | 1813 | } | 
|---|
| [042f82] | 1814 | case 'E': | 
|---|
| [ebcade] | 1815 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [54b953] | 1816 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr]))) { | 
|---|
| [042f82] | 1817 | ExitFlag = 255; | 
|---|
| [54b953] | 1818 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> --element <Z>" << endl); | 
|---|
| [e359a8] | 1819 | performCriticalExit(); | 
|---|
| [042f82] | 1820 | } else { | 
|---|
| [54b953] | 1821 | ArgcList.insert(argptr-1); | 
|---|
|  | 1822 | ArgcList.insert(argptr); | 
|---|
|  | 1823 | ArgcList.insert(argptr+1); | 
|---|
|  | 1824 | ArgcList.insert(argptr+2); | 
|---|
|  | 1825 | argptr+=3; | 
|---|
| [042f82] | 1826 | } | 
|---|
|  | 1827 | break; | 
|---|
| [9f97c5] | 1828 | case 'F': | 
|---|
| [ebcade] | 1829 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [9d2a92] | 1830 | if ((argptr+12 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [9f97c5] | 1831 | ExitFlag = 255; | 
|---|
| [9d2a92] | 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); | 
|---|
| [e359a8] | 1833 | performCriticalExit(); | 
|---|
| [9f97c5] | 1834 | } else { | 
|---|
| [9d2a92] | 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; | 
|---|
| [9f97c5] | 1850 | } | 
|---|
|  | 1851 | break; | 
|---|
| [042f82] | 1852 | case 'A': | 
|---|
| [ebcade] | 1853 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f4bd01] | 1854 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [042f82] | 1855 | ExitFlag =255; | 
|---|
| [f4bd01] | 1856 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile> --molecule-by-id <molecule_id>" << endl); | 
|---|
| [e359a8] | 1857 | performCriticalExit(); | 
|---|
| [042f82] | 1858 | } else { | 
|---|
| [f4bd01] | 1859 | ArgcList.insert(argptr-1); | 
|---|
|  | 1860 | ArgcList.insert(argptr); | 
|---|
|  | 1861 | ArgcList.insert(argptr+1); | 
|---|
|  | 1862 | ArgcList.insert(argptr+2); | 
|---|
|  | 1863 | argptr+=3; | 
|---|
| [042f82] | 1864 | } | 
|---|
|  | 1865 | break; | 
|---|
| [1f1b23] | 1866 |  | 
|---|
|  | 1867 | case 'J': | 
|---|
|  | 1868 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [77de81] | 1869 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [1f1b23] | 1870 | ExitFlag =255; | 
|---|
| [77de81] | 1871 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -J <path> --molecule-by-id <molecule_id>" << endl); | 
|---|
| [1f1b23] | 1872 | performCriticalExit(); | 
|---|
|  | 1873 | } else { | 
|---|
| [77de81] | 1874 | ArgcList.insert(argptr-1); | 
|---|
|  | 1875 | ArgcList.insert(argptr); | 
|---|
|  | 1876 | ArgcList.insert(argptr+1); | 
|---|
|  | 1877 | ArgcList.insert(argptr+2); | 
|---|
|  | 1878 | argptr+=3; | 
|---|
| [1f1b23] | 1879 | } | 
|---|
|  | 1880 | break; | 
|---|
|  | 1881 |  | 
|---|
|  | 1882 | case 'j': | 
|---|
|  | 1883 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 1884 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1885 | ExitFlag =255; | 
|---|
| [77de81] | 1886 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path> --molecule-by-id <molecule_id>" << endl); | 
|---|
| [1f1b23] | 1887 | performCriticalExit(); | 
|---|
|  | 1888 | } else { | 
|---|
| [77de81] | 1889 | ArgcList.insert(argptr-1); | 
|---|
|  | 1890 | ArgcList.insert(argptr); | 
|---|
|  | 1891 | ArgcList.insert(argptr+1); | 
|---|
|  | 1892 | ArgcList.insert(argptr+2); | 
|---|
|  | 1893 | argptr+=3; | 
|---|
| [1f1b23] | 1894 | } | 
|---|
|  | 1895 | break; | 
|---|
|  | 1896 |  | 
|---|
| [042f82] | 1897 | case 'N': | 
|---|
| [ebcade] | 1898 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [980dd6] | 1899 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){ | 
|---|
| [042f82] | 1900 | ExitFlag = 255; | 
|---|
| [980dd6] | 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); | 
|---|
| [e359a8] | 1902 | performCriticalExit(); | 
|---|
| [042f82] | 1903 | } else { | 
|---|
| [980dd6] | 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; | 
|---|
| [042f82] | 1911 | } | 
|---|
|  | 1912 | break; | 
|---|
|  | 1913 | case 'S': | 
|---|
| [ebcade] | 1914 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [a307af] | 1915 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [042f82] | 1916 | ExitFlag = 255; | 
|---|
| [a307af] | 1917 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file> --molecule-by-id 0" << endl); | 
|---|
| [e359a8] | 1918 | performCriticalExit(); | 
|---|
| [042f82] | 1919 | } else { | 
|---|
| [a307af] | 1920 | ArgcList.insert(argptr-1); | 
|---|
|  | 1921 | ArgcList.insert(argptr); | 
|---|
|  | 1922 | ArgcList.insert(argptr+1); | 
|---|
|  | 1923 | ArgcList.insert(argptr+2); | 
|---|
|  | 1924 | argptr+=3; | 
|---|
| [042f82] | 1925 | } | 
|---|
|  | 1926 | break; | 
|---|
| [85bac0] | 1927 | case 'L': | 
|---|
| [ebcade] | 1928 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [a02462] | 1929 | if ((argptr+8 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [f7f7a4] | 1930 | ExitFlag = 255; | 
|---|
| [a02462] | 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); | 
|---|
| [e359a8] | 1932 | performCriticalExit(); | 
|---|
| [f7f7a4] | 1933 | } else { | 
|---|
| [a02462] | 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; | 
|---|
| [f7f7a4] | 1945 | } | 
|---|
| [85bac0] | 1946 | break; | 
|---|
| [042f82] | 1947 | case 'P': | 
|---|
| [ebcade] | 1948 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [aacce8] | 1949 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [042f82] | 1950 | ExitFlag = 255; | 
|---|
| [aacce8] | 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); | 
|---|
| [e359a8] | 1952 | performCriticalExit(); | 
|---|
| [042f82] | 1953 | } else { | 
|---|
| [aacce8] | 1954 | ArgcList.insert(argptr-1); | 
|---|
|  | 1955 | ArgcList.insert(argptr); | 
|---|
|  | 1956 | ArgcList.insert(argptr+1); | 
|---|
|  | 1957 | ArgcList.insert(argptr+2); | 
|---|
|  | 1958 | argptr+=3; | 
|---|
| [042f82] | 1959 | } | 
|---|
|  | 1960 | break; | 
|---|
| [a5b2c3a] | 1961 | case 'R': | 
|---|
| [ebcade] | 1962 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [e2b47c] | 1963 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-'))  { | 
|---|
| [a5b2c3a] | 1964 | ExitFlag = 255; | 
|---|
| [e2b47c] | 1965 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <distance> --position <x> <y> <z>" << endl); | 
|---|
| [e359a8] | 1966 | performCriticalExit(); | 
|---|
| [a5b2c3a] | 1967 | } else { | 
|---|
| [e2b47c] | 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; | 
|---|
| [a5b2c3a] | 1975 | } | 
|---|
|  | 1976 | break; | 
|---|
| [042f82] | 1977 | case 't': | 
|---|
| [ebcade] | 1978 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [77b2d7] | 1979 | if ((argptr+4 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [21c017] | 1980 | ExitFlag = 255; | 
|---|
| [77b2d7] | 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); | 
|---|
| [e359a8] | 1982 | performCriticalExit(); | 
|---|
| [21c017] | 1983 | } else { | 
|---|
| [77b2d7] | 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; | 
|---|
| [21c017] | 1993 | } | 
|---|
|  | 1994 | break; | 
|---|
| [042f82] | 1995 | case 's': | 
|---|
| [ebcade] | 1996 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [158c594] | 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 | } | 
|---|
| [042f82] | 2008 | break; | 
|---|
|  | 2009 | case 'b': | 
|---|
| [ebcade] | 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])) ) { | 
|---|
| [042f82] | 2012 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2013 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl); | 
|---|
| [e359a8] | 2014 | performCriticalExit(); | 
|---|
| [042f82] | 2015 | } else { | 
|---|
| [158c594] | 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); | 
|---|
| [21c017] | 2023 | argptr+=6; | 
|---|
| [042f82] | 2024 | } | 
|---|
|  | 2025 | break; | 
|---|
| [f3278b] | 2026 | case 'B': | 
|---|
| [ebcade] | 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])) ) { | 
|---|
| [f3278b] | 2029 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2030 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl); | 
|---|
| [e359a8] | 2031 | performCriticalExit(); | 
|---|
| [f3278b] | 2032 | } else { | 
|---|
| [158c594] | 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); | 
|---|
| [f3278b] | 2040 | argptr+=6; | 
|---|
|  | 2041 | } | 
|---|
|  | 2042 | break; | 
|---|
| [042f82] | 2043 | case 'c': | 
|---|
| [ebcade] | 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])) ) { | 
|---|
| [042f82] | 2046 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2047 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl); | 
|---|
| [e359a8] | 2048 | performCriticalExit(); | 
|---|
| [042f82] | 2049 | } else { | 
|---|
| [116f37] | 2050 | ArgcList.insert(argptr-1); | 
|---|
|  | 2051 | ArgcList.insert(argptr); | 
|---|
|  | 2052 | ArgcList.insert(argptr+1); | 
|---|
|  | 2053 | ArgcList.insert(argptr+2); | 
|---|
| [21c017] | 2054 | argptr+=3; | 
|---|
| [042f82] | 2055 | } | 
|---|
|  | 2056 | break; | 
|---|
|  | 2057 | case 'O': | 
|---|
| [ebcade] | 2058 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [584a2a] | 2059 | ArgcList.insert(argptr-1); | 
|---|
| [21c017] | 2060 | argptr+=0; | 
|---|
| [042f82] | 2061 | break; | 
|---|
|  | 2062 | case 'r': | 
|---|
| [ebcade] | 2063 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2064 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])))  { | 
|---|
|  | 2065 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2066 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl); | 
|---|
| [e359a8] | 2067 | performCriticalExit(); | 
|---|
| [ebcade] | 2068 | } else { | 
|---|
| [d55743e] | 2069 | ArgcList.insert(argptr-1); | 
|---|
|  | 2070 | ArgcList.insert(argptr); | 
|---|
| [ebcade] | 2071 | argptr+=1; | 
|---|
|  | 2072 | } | 
|---|
| [042f82] | 2073 | break; | 
|---|
|  | 2074 | case 'f': | 
|---|
| [ebcade] | 2075 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [e4b5de] | 2076 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [042f82] | 2077 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2078 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl); | 
|---|
| [e359a8] | 2079 | performCriticalExit(); | 
|---|
| [042f82] | 2080 | } else { | 
|---|
| [e4b5de] | 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; | 
|---|
| [042f82] | 2088 | } | 
|---|
|  | 2089 | break; | 
|---|
|  | 2090 | case 'm': | 
|---|
| [ebcade] | 2091 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 2092 | j = atoi(argv[argptr++]); | 
|---|
|  | 2093 | if ((j<0) || (j>1)) { | 
|---|
| [58ed4a] | 2094 | DoeLog(1) && (eLog()<< Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl); | 
|---|
| [042f82] | 2095 | j = 0; | 
|---|
|  | 2096 | } | 
|---|
|  | 2097 | if (j) { | 
|---|
|  | 2098 | SaveFlag = true; | 
|---|
| [a67d19] | 2099 | DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl); | 
|---|
| [2b5574] | 2100 | mol->PrincipalAxisSystem((bool)j); | 
|---|
| [042f82] | 2101 | } else | 
|---|
| [2b5574] | 2102 | ArgcList.insert(argptr-1); | 
|---|
|  | 2103 | argptr+=0; | 
|---|
| [042f82] | 2104 | break; | 
|---|
|  | 2105 | case 'o': | 
|---|
| [ebcade] | 2106 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f6bd32] | 2107 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){ | 
|---|
| [042f82] | 2108 | ExitFlag = 255; | 
|---|
| [f6bd32] | 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); | 
|---|
| [e359a8] | 2110 | performCriticalExit(); | 
|---|
| [042f82] | 2111 | } else { | 
|---|
| [f6bd32] | 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; | 
|---|
| [042f82] | 2119 | } | 
|---|
|  | 2120 | break; | 
|---|
|  | 2121 | case 'U': | 
|---|
| [ebcade] | 2122 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2123 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) { | 
|---|
| [042f82] | 2124 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2125 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl); | 
|---|
| [e359a8] | 2126 | performCriticalExit(); | 
|---|
| [042f82] | 2127 | } else { | 
|---|
|  | 2128 | volume = atof(argv[argptr++]); | 
|---|
| [a67d19] | 2129 | DoLog(0) && (Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl); | 
|---|
| [042f82] | 2130 | } | 
|---|
|  | 2131 | case 'u': | 
|---|
| [ebcade] | 2132 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2133 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) { | 
|---|
| [042f82] | 2134 | if (volume != -1) | 
|---|
|  | 2135 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2136 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl); | 
|---|
| [e359a8] | 2137 | performCriticalExit(); | 
|---|
| [042f82] | 2138 | } else { | 
|---|
| [48ab70a] | 2139 | ArgcList.insert(argptr-1); | 
|---|
|  | 2140 | ArgcList.insert(argptr); | 
|---|
|  | 2141 | argptr+=1; | 
|---|
| [042f82] | 2142 | } | 
|---|
|  | 2143 | break; | 
|---|
|  | 2144 | case 'd': | 
|---|
| [ebcade] | 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])) ) { | 
|---|
| [042f82] | 2147 | ExitFlag = 255; | 
|---|
| [58ed4a] | 2148 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl); | 
|---|
| [e359a8] | 2149 | performCriticalExit(); | 
|---|
| [042f82] | 2150 | } else { | 
|---|
| [e30ce8] | 2151 | ArgcList.insert(argptr-1); | 
|---|
|  | 2152 | ArgcList.insert(argptr); | 
|---|
|  | 2153 | ArgcList.insert(argptr+1); | 
|---|
|  | 2154 | ArgcList.insert(argptr+2); | 
|---|
|  | 2155 | argptr+=3; | 
|---|
| [042f82] | 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) | 
|---|
| [6ca1f7] | 2167 | configuration.SaveAll(*ConfigFileName, periode, molecules); | 
|---|
| [042f82] | 2168 | } else {  // no arguments, hence scan the elements db | 
|---|
|  | 2169 | if (periode->LoadPeriodentafel(configuration.databasepath)) | 
|---|
| [a67d19] | 2170 | DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl); | 
|---|
| [042f82] | 2171 | else | 
|---|
| [a67d19] | 2172 | DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl); | 
|---|
| [042f82] | 2173 | configuration.RetrieveConfigPathAndName("main_pcp_linux"); | 
|---|
|  | 2174 | } | 
|---|
|  | 2175 | return(ExitFlag); | 
|---|
| [ca2b83] | 2176 | }; | 
|---|
|  | 2177 |  | 
|---|
|  | 2178 | /********************************************** Main routine **************************************/ | 
|---|
| [14de469] | 2179 |  | 
|---|
| [148d8f0] | 2180 | void cleanUp(){ | 
|---|
| [a1e929] | 2181 | ChangeTracker::purgeInstance(); | 
|---|
| [23b547] | 2182 | World::purgeInstance(); | 
|---|
| [354859] | 2183 | logger::purgeInstance(); | 
|---|
|  | 2184 | errorLogger::purgeInstance(); | 
|---|
| [97ebf8] | 2185 | UIFactory::purgeInstance(); | 
|---|
|  | 2186 | MapOfActions::purgeInstance(); | 
|---|
| [c6efc1] | 2187 | CommandLineParser::purgeInstance(); | 
|---|
| [e73a8a2] | 2188 | ActionRegistry::purgeInstance(); | 
|---|
| [632bc3] | 2189 | ActionHistory::purgeInstance(); | 
|---|
| [cd5047] | 2190 | #ifdef LOG_OBSERVER | 
|---|
|  | 2191 | cout << observerLog().getLog(); | 
|---|
|  | 2192 | #endif | 
|---|
| [68f03d] | 2193 | Memory::getState(); | 
|---|
| [354859] | 2194 | } | 
|---|
|  | 2195 |  | 
|---|
| [ca2b83] | 2196 | int main(int argc, char **argv) | 
|---|
|  | 2197 | { | 
|---|
| [a7b761b] | 2198 | // while we are non interactive, we want to abort from asserts | 
|---|
|  | 2199 | //ASSERT_DO(Assert::Abort); | 
|---|
| [85bc8e] | 2200 | Vector x, y, z, n; | 
|---|
|  | 2201 | ifstream test; | 
|---|
|  | 2202 | ofstream output; | 
|---|
|  | 2203 | string line; | 
|---|
| [97ebf8] | 2204 | char **Arguments = NULL; | 
|---|
|  | 2205 | int ArgcSize = 0; | 
|---|
| [99fcaf] | 2206 | int ExitFlag = 0; | 
|---|
| [97ebf8] | 2207 | bool ArgumentsCopied = false; | 
|---|
| [6ca1f7] | 2208 | char *ConfigFileName = new char[MAXSTRINGSIZE]; | 
|---|
| [229e3c] | 2209 |  | 
|---|
| [4eb4fe] | 2210 | // print version check whether arguments are present at all | 
|---|
| [5f612ee] | 2211 | cout << ESPACKVersion << endl; | 
|---|
| [4eb4fe] | 2212 | if (argc < 2) { | 
|---|
|  | 2213 | cout << "Obtain help with " << argv[0] << " -h." << endl; | 
|---|
| [eff648] | 2214 | cleanUp(); | 
|---|
|  | 2215 | Memory::getState(); | 
|---|
| [4eb4fe] | 2216 | return(1); | 
|---|
|  | 2217 | } | 
|---|
|  | 2218 |  | 
|---|
| [5f612ee] | 2219 |  | 
|---|
| [85bc8e] | 2220 | setVerbosity(0); | 
|---|
| [d56640] | 2221 | // need to init the history before any action is created | 
|---|
|  | 2222 | ActionHistory::init(); | 
|---|
| [6ac7ee] | 2223 |  | 
|---|
| [a7b761b] | 2224 | // In the interactive mode, we can leave the user the choice in case of error | 
|---|
|  | 2225 | ASSERT_DO(Assert::Ask); | 
|---|
|  | 2226 |  | 
|---|
| [0fb9f6] | 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 |  | 
|---|
| [97ebf8] | 2231 | // Parse command line options and if present create respective UI | 
|---|
| [12b845] | 2232 | { | 
|---|
| [f65e1f] | 2233 | set<int> ArgcList; | 
|---|
|  | 2234 | ArgcList.insert(0); // push back program! | 
|---|
|  | 2235 | ArgcList.insert(1); // push back config file name | 
|---|
| [97ebf8] | 2236 | // handle arguments by ParseCommandLineOptions() | 
|---|
| [6ca1f7] | 2237 | ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), &ConfigFileName, ArgcList); | 
|---|
| [e4b5de] | 2238 | World::getInstance().setExitFlag(ExitFlag); | 
|---|
| [97ebf8] | 2239 | // copy all remaining arguments to a new argv | 
|---|
| [920c70] | 2240 | Arguments = new char *[ArgcList.size()]; | 
|---|
| [97ebf8] | 2241 | cout << "The following arguments are handled by CommandLineParser: "; | 
|---|
| [f65e1f] | 2242 | for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) { | 
|---|
| [920c70] | 2243 | Arguments[ArgcSize] = new char[strlen(argv[*ArgcRunner])+2]; | 
|---|
| [97ebf8] | 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(); | 
|---|
| [7e6b00] | 2252 | map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap(); | 
|---|
|  | 2253 | CommandLineParser::getInstance().Run(ArgcSize,Arguments, ShortFormToActionMap); | 
|---|
| [97ebf8] | 2254 | if (!CommandLineParser::getInstance().isEmpty()) { | 
|---|
|  | 2255 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl); | 
|---|
| [5f5a7b] | 2256 | UIFactory::registerFactory(new CommandLineUIFactory::description()); | 
|---|
|  | 2257 | UIFactory::makeUserInterface("CommandLine"); | 
|---|
| [97ebf8] | 2258 | } else { | 
|---|
|  | 2259 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl); | 
|---|
| [5f5a7b] | 2260 | UIFactory::registerFactory(new TextUIFactory::description()); | 
|---|
|  | 2261 | UIFactory::makeUserInterface("Text"); | 
|---|
| [97ebf8] | 2262 | } | 
|---|
| [c6efc1] | 2263 | } | 
|---|
| [6ac7ee] | 2264 |  | 
|---|
| [c6efc1] | 2265 | { | 
|---|
| [d893f79] | 2266 | MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(); | 
|---|
| [12b845] | 2267 | mainWindow->display(); | 
|---|
|  | 2268 | delete mainWindow; | 
|---|
|  | 2269 | } | 
|---|
| [6ac7ee] | 2270 |  | 
|---|
| [6ca1f7] | 2271 | Log() << Verbose(0) << "Saving to " << ConfigFileName << "." << endl; | 
|---|
|  | 2272 | World::getInstance().getConfig()->SaveAll(ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules()); | 
|---|
| [042f82] | 2273 |  | 
|---|
| [97ebf8] | 2274 | // free the new argv | 
|---|
|  | 2275 | if (ArgumentsCopied) { | 
|---|
|  | 2276 | for (int i=0; i<ArgcSize;i++) | 
|---|
| [920c70] | 2277 | delete[](Arguments[i]); | 
|---|
|  | 2278 | delete[](Arguments); | 
|---|
| [97ebf8] | 2279 | } | 
|---|
| [6ca1f7] | 2280 | delete[](ConfigFileName); | 
|---|
| [632bc3] | 2281 |  | 
|---|
| [e4b5de] | 2282 | ExitFlag = World::getInstance().getExitFlag(); | 
|---|
| [99fcaf] | 2283 | return (ExitFlag == 1 ? 0 : ExitFlag); | 
|---|
| [14de469] | 2284 | } | 
|---|
|  | 2285 |  | 
|---|
|  | 2286 | /********************************************** E N D **************************************************/ | 
|---|