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