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