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