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