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