| [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" | 
|---|
| [e138de] | 63 | #include "log.hpp" | 
|---|
| [b66c22] | 64 | #include "memoryusageobserverunittest.hpp" | 
|---|
| [cee0b57] | 65 | #include "molecule.hpp" | 
|---|
| [f66195] | 66 | #include "periodentafel.hpp" | 
|---|
| [a8eb4a] | 67 | #include "version.h" | 
|---|
| [f66195] | 68 |  | 
|---|
| [1907a7] | 69 | /********************************************* Subsubmenu routine ************************************/ | 
|---|
| [14de469] | 70 |  | 
|---|
|  | 71 | /** Submenu for adding atoms to the molecule. | 
|---|
|  | 72 | * \param *periode periodentafel | 
|---|
| [1907a7] | 73 | * \param *molecule molecules with atoms | 
|---|
| [14de469] | 74 | */ | 
|---|
| [7f3b9d] | 75 | static void AddAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [14de469] | 76 | { | 
|---|
| [042f82] | 77 | atom *first, *second, *third, *fourth; | 
|---|
|  | 78 | Vector **atoms; | 
|---|
|  | 79 | Vector x,y,z,n;  // coordinates for absolute point in cell volume | 
|---|
|  | 80 | double a,b,c; | 
|---|
|  | 81 | char choice;  // menu choice char | 
|---|
|  | 82 | bool valid; | 
|---|
|  | 83 |  | 
|---|
| [e138de] | 84 | Log() << Verbose(0) << "===========ADD ATOM============================" << endl; | 
|---|
|  | 85 | Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl; | 
|---|
|  | 86 | Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl; | 
|---|
|  | 87 | Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl; | 
|---|
|  | 88 | Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl; | 
|---|
|  | 89 | Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl; | 
|---|
|  | 90 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 91 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 92 | Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl; | 
|---|
|  | 93 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 94 | cin >> choice; | 
|---|
|  | 95 |  | 
|---|
|  | 96 | switch (choice) { | 
|---|
| [1907a7] | 97 | default: | 
|---|
| [717e0c] | 98 | eLog() << Verbose(2) << "Not a valid choice." << endl; | 
|---|
| [1907a7] | 99 | break; | 
|---|
| [042f82] | 100 | case 'a': // absolute coordinates of atom | 
|---|
| [e138de] | 101 | Log() << Verbose(0) << "Enter absolute coordinates." << endl; | 
|---|
| [1907a7] | 102 | first = new atom; | 
|---|
|  | 103 | first->x.AskPosition(mol->cell_size, false); | 
|---|
| [042f82] | 104 | first->type = periode->AskElement();  // give type | 
|---|
|  | 105 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 106 | break; | 
|---|
| [6ac7ee] | 107 |  | 
|---|
| [042f82] | 108 | case 'b': // relative coordinates of atom wrt to reference point | 
|---|
| [1907a7] | 109 | first = new atom; | 
|---|
|  | 110 | valid = true; | 
|---|
|  | 111 | do { | 
|---|
| [717e0c] | 112 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
| [e138de] | 113 | Log() << Verbose(0) << "Enter reference coordinates." << endl; | 
|---|
| [1907a7] | 114 | x.AskPosition(mol->cell_size, true); | 
|---|
| [e138de] | 115 | Log() << Verbose(0) << "Enter relative coordinates." << endl; | 
|---|
| [1907a7] | 116 | first->x.AskPosition(mol->cell_size, false); | 
|---|
|  | 117 | first->x.AddVector((const Vector *)&x); | 
|---|
| [e138de] | 118 | Log() << Verbose(0) << "\n"; | 
|---|
| [1907a7] | 119 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
| [042f82] | 120 | first->type = periode->AskElement();  // give type | 
|---|
|  | 121 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 122 | break; | 
|---|
| [6ac7ee] | 123 |  | 
|---|
| [042f82] | 124 | case 'c': // relative coordinates of atom wrt to already placed atom | 
|---|
| [1907a7] | 125 | first = new atom; | 
|---|
|  | 126 | valid = true; | 
|---|
|  | 127 | do { | 
|---|
| [717e0c] | 128 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
| [1907a7] | 129 | second = mol->AskAtom("Enter atom number: "); | 
|---|
| [e138de] | 130 | Log() << Verbose(0) << "Enter relative coordinates." << endl; | 
|---|
| [1907a7] | 131 | first->x.AskPosition(mol->cell_size, false); | 
|---|
|  | 132 | for (int i=NDIM;i--;) { | 
|---|
|  | 133 | first->x.x[i] += second->x.x[i]; | 
|---|
|  | 134 | } | 
|---|
|  | 135 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
| [042f82] | 136 | first->type = periode->AskElement();  // give type | 
|---|
|  | 137 | mol->AddAtom(first);  // add to molecule | 
|---|
| [1907a7] | 138 | break; | 
|---|
|  | 139 |  | 
|---|
|  | 140 | case 'd': // two atoms, two angles and a distance | 
|---|
|  | 141 | first = new atom; | 
|---|
|  | 142 | valid = true; | 
|---|
|  | 143 | do { | 
|---|
|  | 144 | if (!valid) { | 
|---|
| [717e0c] | 145 | eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl; | 
|---|
| [1907a7] | 146 | } | 
|---|
| [e138de] | 147 | Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl; | 
|---|
| [1907a7] | 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); | 
|---|
| [e138de] | 158 | Log() << 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)) { | 
|---|
| [e138de] | 170 | Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl; | 
|---|
| [1907a7] | 171 | continue; | 
|---|
|  | 172 | } | 
|---|
| [e138de] | 173 | Log() << Verbose(0) << "resulting relative coordinates: "; | 
|---|
|  | 174 | z.Output(); | 
|---|
|  | 175 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 176 | */ | 
|---|
|  | 177 | // calc axis vector | 
|---|
|  | 178 | x.CopyVector(&second->x); | 
|---|
|  | 179 | x.SubtractVector(&third->x); | 
|---|
|  | 180 | x.Normalize(); | 
|---|
| [e138de] | 181 | Log() << Verbose(0) << "x: ", | 
|---|
|  | 182 | x.Output(); | 
|---|
|  | 183 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 184 | z.MakeNormalVector(&second->x,&third->x,&fourth->x); | 
|---|
| [e138de] | 185 | Log() << Verbose(0) << "z: ", | 
|---|
|  | 186 | z.Output(); | 
|---|
|  | 187 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 188 | y.MakeNormalVector(&x,&z); | 
|---|
| [e138de] | 189 | Log() << Verbose(0) << "y: ", | 
|---|
|  | 190 | y.Output(); | 
|---|
|  | 191 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 192 |  | 
|---|
|  | 193 | // rotate vector around first angle | 
|---|
|  | 194 | first->x.CopyVector(&x); | 
|---|
|  | 195 | first->x.RotateVector(&z,b - M_PI); | 
|---|
| [e138de] | 196 | Log() << Verbose(0) << "Rotated vector: ", | 
|---|
|  | 197 | first->x.Output(); | 
|---|
|  | 198 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 199 | // remove the projection onto the rotation plane of the second angle | 
|---|
|  | 200 | n.CopyVector(&y); | 
|---|
| [658efb] | 201 | n.Scale(first->x.ScalarProduct(&y)); | 
|---|
| [e138de] | 202 | Log() << Verbose(0) << "N1: ", | 
|---|
|  | 203 | n.Output(); | 
|---|
|  | 204 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 205 | first->x.SubtractVector(&n); | 
|---|
| [e138de] | 206 | Log() << Verbose(0) << "Subtracted vector: ", | 
|---|
|  | 207 | first->x.Output(); | 
|---|
|  | 208 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 209 | n.CopyVector(&z); | 
|---|
| [658efb] | 210 | n.Scale(first->x.ScalarProduct(&z)); | 
|---|
| [e138de] | 211 | Log() << Verbose(0) << "N2: ", | 
|---|
|  | 212 | n.Output(); | 
|---|
|  | 213 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 214 | first->x.SubtractVector(&n); | 
|---|
| [e138de] | 215 | Log() << Verbose(0) << "2nd subtracted vector: ", | 
|---|
|  | 216 | first->x.Output(); | 
|---|
|  | 217 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 218 |  | 
|---|
|  | 219 | // rotate another vector around second angle | 
|---|
|  | 220 | n.CopyVector(&y); | 
|---|
|  | 221 | n.RotateVector(&x,c - M_PI); | 
|---|
| [e138de] | 222 | Log() << Verbose(0) << "2nd Rotated vector: ", | 
|---|
|  | 223 | n.Output(); | 
|---|
|  | 224 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 232 | Log() << Verbose(0) << "resulting coordinates: "; | 
|---|
|  | 233 | first->x.Output(); | 
|---|
|  | 234 | Log() << Verbose(0) << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 247 | Log() << Verbose(0) << "Now we need at least three molecules.\n"; | 
|---|
| [1907a7] | 248 | do { | 
|---|
| [e138de] | 249 | Log() << Verbose(0) << "Enter " << i+1 << "th atom: "; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 259 | first->x.Output(); | 
|---|
| [042f82] | 260 | first->type = periode->AskElement();  // give type | 
|---|
|  | 261 | mol->AddAtom(first);  // add to molecule | 
|---|
| [1907a7] | 262 | } else { | 
|---|
|  | 263 | delete first; | 
|---|
| [e138de] | 264 | Log() << Verbose(0) << "Please enter at least two vectors!\n"; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 278 | Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl; | 
|---|
|  | 279 | Log() << Verbose(0) << " a - on origin" << endl; | 
|---|
|  | 280 | Log() << Verbose(0) << " b - on center of gravity" << endl; | 
|---|
|  | 281 | Log() << Verbose(0) << " c - within box with additional boundary" << endl; | 
|---|
|  | 282 | Log() << Verbose(0) << " d - within given simulation box" << endl; | 
|---|
|  | 283 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 284 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 285 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 286 | cin >> choice; | 
|---|
|  | 287 |  | 
|---|
|  | 288 | switch (choice) { | 
|---|
|  | 289 | default: | 
|---|
| [e138de] | 290 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [042f82] | 291 | break; | 
|---|
|  | 292 | case 'a': | 
|---|
| [e138de] | 293 | Log() << Verbose(0) << "Centering atoms in config file on origin." << endl; | 
|---|
|  | 294 | mol->CenterOrigin(); | 
|---|
| [042f82] | 295 | break; | 
|---|
|  | 296 | case 'b': | 
|---|
| [e138de] | 297 | Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl; | 
|---|
|  | 298 | mol->CenterPeriodic(); | 
|---|
| [042f82] | 299 | break; | 
|---|
|  | 300 | case 'c': | 
|---|
| [e138de] | 301 | Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl; | 
|---|
| [042f82] | 302 | for (int i=0;i<NDIM;i++) { | 
|---|
| [e138de] | 303 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [042f82] | 304 | cin >> y.x[i]; | 
|---|
|  | 305 | } | 
|---|
| [e138de] | 306 | mol->CenterEdge(&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': | 
|---|
| [e138de] | 314 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
| [042f82] | 315 | for (int i=0;i<NDIM;i++) { | 
|---|
| [e138de] | 316 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [042f82] | 317 | cin >> x.x[i]; | 
|---|
|  | 318 | } | 
|---|
|  | 319 | // update Box of atoms by boundary | 
|---|
|  | 320 | mol->SetBoxDimension(&x); | 
|---|
| [36ec71] | 321 | // center | 
|---|
| [e138de] | 322 | mol->CenterInBox(); | 
|---|
| [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 |  | 
|---|
| [e138de] | 337 | Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl; | 
|---|
|  | 338 | Log() << Verbose(0) << " a - state three atoms defining align plane" << endl; | 
|---|
|  | 339 | Log() << Verbose(0) << " b - state alignment vector" << endl; | 
|---|
|  | 340 | Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl; | 
|---|
|  | 341 | Log() << Verbose(0) << " d - align automatically by least square fit" << endl; | 
|---|
|  | 342 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 343 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 344 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 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 | 
|---|
| [e138de] | 357 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; | 
|---|
| [042f82] | 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); | 
|---|
| [e138de] | 377 | Log() << Verbose(0) << "Element is " << param.type->name << endl; | 
|---|
| [042f82] | 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); | 
|---|
| [e138de] | 384 | Log() << Verbose(0) << "Offset vector: "; | 
|---|
|  | 385 | x.Output(); | 
|---|
|  | 386 | Log() << Verbose(0) << endl; | 
|---|
| [042f82] | 387 | n.Normalize(); | 
|---|
|  | 388 | break; | 
|---|
|  | 389 | }; | 
|---|
| [e138de] | 390 | Log() << Verbose(0) << "Alignment vector: "; | 
|---|
|  | 391 | n.Output(); | 
|---|
|  | 392 | Log() << Verbose(0) << endl; | 
|---|
| [042f82] | 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 |  | 
|---|
| [e138de] | 405 | Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl; | 
|---|
|  | 406 | Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl; | 
|---|
|  | 407 | Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl; | 
|---|
|  | 408 | Log() << Verbose(0) << " c - state two atoms in normal direction" << endl; | 
|---|
|  | 409 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 410 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 411 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 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 | 
|---|
| [e138de] | 424 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; | 
|---|
| [042f82] | 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 | }; | 
|---|
| [e138de] | 437 | Log() << Verbose(0) << "Normal vector: "; | 
|---|
|  | 438 | n.Output(); | 
|---|
|  | 439 | Log() << Verbose(0) << endl; | 
|---|
| [042f82] | 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 |  | 
|---|
| [e138de] | 453 | Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl; | 
|---|
|  | 454 | Log() << Verbose(0) << " a - state atom for removal by number" << endl; | 
|---|
|  | 455 | Log() << Verbose(0) << " b - keep only in radius around atom" << endl; | 
|---|
|  | 456 | Log() << Verbose(0) << " c - remove this with one axis greater value" << endl; | 
|---|
|  | 457 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 458 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 459 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 460 | cin >> choice; | 
|---|
|  | 461 |  | 
|---|
|  | 462 | switch (choice) { | 
|---|
|  | 463 | default: | 
|---|
|  | 464 | case 'a': | 
|---|
|  | 465 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: "))) | 
|---|
| [e138de] | 466 | Log() << Verbose(1) << "Atom removed." << endl; | 
|---|
| [042f82] | 467 | else | 
|---|
| [e138de] | 468 | Log() << Verbose(1) << "Atom not found." << endl; | 
|---|
| [042f82] | 469 | break; | 
|---|
|  | 470 | case 'b': | 
|---|
|  | 471 | second = mol->AskAtom("Enter number of atom as reference point: "); | 
|---|
| [e138de] | 472 | Log() << Verbose(0) << "Enter radius: "; | 
|---|
| [042f82] | 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': | 
|---|
| [e138de] | 484 | Log() << Verbose(0) << "Which axis is it: "; | 
|---|
| [042f82] | 485 | cin >> axis; | 
|---|
| [e138de] | 486 | Log() << Verbose(0) << "Lower boundary: "; | 
|---|
| [042f82] | 487 | cin >> tmp1; | 
|---|
| [e138de] | 488 | Log() << 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 ... | 
|---|
| [e138de] | 496 | //Log() << Verbose(0) << "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 | }; | 
|---|
| [e138de] | 502 | //mol->Output(); | 
|---|
| [042f82] | 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 |  | 
|---|
| [e138de] | 518 | Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl; | 
|---|
|  | 519 | Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl; | 
|---|
|  | 520 | Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl; | 
|---|
|  | 521 | Log() << Verbose(0) << " c - calculate bond angle" << endl; | 
|---|
|  | 522 | Log() << Verbose(0) << " d - calculate principal axis of the system" << endl; | 
|---|
|  | 523 | Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl; | 
|---|
|  | 524 | Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl; | 
|---|
|  | 525 | Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl; | 
|---|
|  | 526 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 527 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 528 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [042f82] | 529 | cin >> choice; | 
|---|
|  | 530 |  | 
|---|
|  | 531 | switch(choice) { | 
|---|
|  | 532 | default: | 
|---|
| [e138de] | 533 | Log() << Verbose(1) << "Not a valid choice." << endl; | 
|---|
| [042f82] | 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; | 
|---|
| [e138de] | 551 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl; | 
|---|
| [042f82] | 552 | } | 
|---|
|  | 553 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
| [e138de] | 554 | if (min[i] != 0.) Log() << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl; | 
|---|
| [042f82] | 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(); | 
|---|
| [e138de] | 565 | Log() << Verbose(1) << "Distance vector is "; | 
|---|
|  | 566 | x.Output(); | 
|---|
|  | 567 | Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl; | 
|---|
| [042f82] | 568 | break; | 
|---|
|  | 569 |  | 
|---|
|  | 570 | case 'c': | 
|---|
| [e138de] | 571 | Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl; | 
|---|
| [042f82] | 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); | 
|---|
| [e138de] | 580 | Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": "; | 
|---|
|  | 581 | Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; | 
|---|
| [042f82] | 582 | break; | 
|---|
|  | 583 | case 'd': | 
|---|
| [e138de] | 584 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl; | 
|---|
|  | 585 | Log() << Verbose(0) << "Shall we rotate? [0/1]: "; | 
|---|
| [042f82] | 586 | cin >> Z; | 
|---|
|  | 587 | if ((Z >=0) && (Z <=1)) | 
|---|
| [e138de] | 588 | mol->PrincipalAxisSystem((bool)Z); | 
|---|
| [042f82] | 589 | else | 
|---|
| [e138de] | 590 | mol->PrincipalAxisSystem(false); | 
|---|
| [042f82] | 591 | break; | 
|---|
|  | 592 | case 'e': | 
|---|
| [d30402] | 593 | { | 
|---|
| [e138de] | 594 | Log() << Verbose(0) << "Evaluating volume of the convex envelope."; | 
|---|
| [d30402] | 595 | class Tesselation *TesselStruct = NULL; | 
|---|
| [776b64] | 596 | const LinkedCell *LCList = NULL; | 
|---|
|  | 597 | LCList = new LinkedCell(mol, 10.); | 
|---|
| [e138de] | 598 | FindConvexBorder(mol, TesselStruct, LCList, NULL); | 
|---|
|  | 599 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration); | 
|---|
|  | 600 | Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\ | 
|---|
| [776b64] | 601 | delete(LCList); | 
|---|
| [d30402] | 602 | delete(TesselStruct); | 
|---|
|  | 603 | } | 
|---|
| [042f82] | 604 | break; | 
|---|
|  | 605 | case 'f': | 
|---|
| [e138de] | 606 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps); | 
|---|
| [042f82] | 607 | break; | 
|---|
|  | 608 | case 'g': | 
|---|
|  | 609 | { | 
|---|
|  | 610 | char filename[255]; | 
|---|
| [e138de] | 611 | Log() << Verbose(0) << "Please enter filename: " << endl; | 
|---|
| [042f82] | 612 | cin >> filename; | 
|---|
| [e138de] | 613 | Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl; | 
|---|
| [042f82] | 614 | ofstream *output = new ofstream(filename, ios::trunc); | 
|---|
| [e138de] | 615 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) | 
|---|
|  | 616 | Log() << Verbose(2) << "File could not be written." << endl; | 
|---|
| [042f82] | 617 | else | 
|---|
| [e138de] | 618 | Log() << Verbose(2) << "File stored." << endl; | 
|---|
| [042f82] | 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 |  | 
|---|
| [e138de] | 635 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; | 
|---|
|  | 636 | Log() << Verbose(0) << "What's the desired bond order: "; | 
|---|
| [042f82] | 637 | cin >> Order1; | 
|---|
|  | 638 | if (mol->first->next != mol->last) {  // there are bonds | 
|---|
|  | 639 | start = clock(); | 
|---|
| [e138de] | 640 | mol->FragmentMolecule(Order1, configuration); | 
|---|
| [042f82] | 641 | end = clock(); | 
|---|
| [e138de] | 642 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
| [042f82] | 643 | } else | 
|---|
| [e138de] | 644 | Log() << 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 |  | 
|---|
| [e138de] | 663 | Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl; | 
|---|
|  | 664 | Log() << Verbose(0) << "a - add an atom" << endl; | 
|---|
|  | 665 | Log() << Verbose(0) << "r - remove an atom" << endl; | 
|---|
|  | 666 | Log() << Verbose(0) << "b - scale a bond between atoms" << endl; | 
|---|
|  | 667 | Log() << Verbose(0) << "u - change an atoms element" << endl; | 
|---|
|  | 668 | Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl; | 
|---|
|  | 669 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 670 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
| [63f06e] | 671 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
| [717e0c] | 672 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
| [e138de] | 673 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [1907a7] | 674 | cin >> choice; | 
|---|
|  | 675 |  | 
|---|
|  | 676 | switch (choice) { | 
|---|
|  | 677 | default: | 
|---|
| [e138de] | 678 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 685 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 694 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 695 | Log() << Verbose(0) << "Scaling bond length between two atoms." << endl; | 
|---|
| [1907a7] | 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); | 
|---|
| [e138de] | 702 | Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl; | 
|---|
|  | 703 | Log() << Verbose(0) << "Enter new bond length [a.u.]: "; | 
|---|
| [1907a7] | 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 | } | 
|---|
| [e138de] | 708 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; | 
|---|
|  | 709 | //second->Output(second->type->No, 1); | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 717 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 718 | Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl; | 
|---|
|  | 719 | Log() << Verbose(0) << "Enter three factors: "; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 734 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 743 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 753 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 754 | first = NULL; | 
|---|
|  | 755 | do { | 
|---|
| [e138de] | 756 | Log() << Verbose(0) << "Change the element of which atom: "; | 
|---|
| [1907a7] | 757 | cin >> Z; | 
|---|
|  | 758 | } while ((first = mol->FindAtom(Z)) == NULL); | 
|---|
| [e138de] | 759 | Log() << Verbose(0) << "New element by atomic number Z: "; | 
|---|
| [1907a7] | 760 | cin >> Z; | 
|---|
|  | 761 | first->type = periode->FindElement(Z); | 
|---|
| [e138de] | 762 | Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 783 | Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl; | 
|---|
|  | 784 | Log() << Verbose(0) << "c - scale by unit transformation" << endl; | 
|---|
|  | 785 | Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl; | 
|---|
|  | 786 | Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl; | 
|---|
|  | 787 | Log() << Verbose(0) << "g - center atoms in box" << endl; | 
|---|
|  | 788 | Log() << Verbose(0) << "i - realign molecule" << endl; | 
|---|
|  | 789 | Log() << Verbose(0) << "m - mirror all molecules" << endl; | 
|---|
|  | 790 | Log() << Verbose(0) << "o - create connection matrix" << endl; | 
|---|
|  | 791 | Log() << Verbose(0) << "t - translate molecule by vector" << endl; | 
|---|
|  | 792 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 793 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
| [63f06e] | 794 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
| [717e0c] | 795 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
| [e138de] | 796 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [1907a7] | 797 | cin >> choice; | 
|---|
|  | 798 |  | 
|---|
|  | 799 | switch (choice) { | 
|---|
|  | 800 | default: | 
|---|
| [e138de] | 801 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 808 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 809 | Log() << Verbose(0) << "State the axis [(+-)123]: "; | 
|---|
| [1907a7] | 810 | cin >> axis; | 
|---|
| [e138de] | 811 | Log() << Verbose(0) << "State the factor: "; | 
|---|
| [1907a7] | 812 | cin >> faktor; | 
|---|
|  | 813 |  | 
|---|
| [e138de] | 814 | mol->CountAtoms(); // recount atoms | 
|---|
| [1907a7] | 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) | 
|---|
| [717e0c] | 828 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl; | 
|---|
| [1907a7] | 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 | 
|---|
| [e138de] | 843 | mol->CreateAdjacencyList(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; | 
|---|
| [e138de] | 867 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 876 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 885 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [1907a7] | 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; | 
|---|
| [e138de] | 896 | Log() << Verbose(0) << "What's the maximum bond distance: "; | 
|---|
| [b6d8a9] | 897 | cin >> bonddistance; | 
|---|
|  | 898 | start = clock(); | 
|---|
| [e138de] | 899 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
| [b6d8a9] | 900 | end = clock(); | 
|---|
| [e138de] | 901 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
| [b6d8a9] | 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; | 
|---|
| [e138de] | 909 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 910 | Log() << Verbose(0) << "Enter translation vector." << endl; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 938 | Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl; | 
|---|
|  | 939 | Log() << Verbose(0) << "c - create new molecule" << endl; | 
|---|
|  | 940 | Log() << Verbose(0) << "l - load molecule from xyz file" << endl; | 
|---|
|  | 941 | Log() << Verbose(0) << "n - change molecule's name" << endl; | 
|---|
|  | 942 | Log() << Verbose(0) << "N - give molecules filename" << endl; | 
|---|
|  | 943 | Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl; | 
|---|
|  | 944 | Log() << Verbose(0) << "r - remove a molecule" << endl; | 
|---|
|  | 945 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 946 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 947 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [1907a7] | 948 | cin >> choice; | 
|---|
|  | 949 |  | 
|---|
|  | 950 | switch (choice) { | 
|---|
|  | 951 | default: | 
|---|
| [e138de] | 952 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [1907a7] | 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]; | 
|---|
| [e138de] | 962 | Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; | 
|---|
| [63f06e] | 963 | mol = new molecule(periode); | 
|---|
|  | 964 | do { | 
|---|
| [e138de] | 965 | Log() << Verbose(0) << "Enter file name: "; | 
|---|
| [63f06e] | 966 | cin >> filename; | 
|---|
|  | 967 | } while (!mol->AddXYZFile(filename)); | 
|---|
|  | 968 | mol->SetNameFromFilename(filename); | 
|---|
|  | 969 | // center at set box dimensions | 
|---|
| [e138de] | 970 | mol->CenterEdge(¢er); | 
|---|
| [63f06e] | 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 { | 
|---|
| [e138de] | 985 | Log() << Verbose(0) << "Enter index of molecule: "; | 
|---|
| [63f06e] | 986 | cin >> nr; | 
|---|
|  | 987 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 988 | } while (mol == NULL); | 
|---|
| [e138de] | 989 | Log() << Verbose(0) << "Enter name: "; | 
|---|
| [63f06e] | 990 | cin >> filename; | 
|---|
|  | 991 | strcpy(mol->name, filename); | 
|---|
|  | 992 | } | 
|---|
| [1907a7] | 993 | break; | 
|---|
|  | 994 |  | 
|---|
|  | 995 | case 'N': | 
|---|
| [63f06e] | 996 | { | 
|---|
|  | 997 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 998 | do { | 
|---|
| [e138de] | 999 | Log() << Verbose(0) << "Enter index of molecule: "; | 
|---|
| [63f06e] | 1000 | cin >> nr; | 
|---|
|  | 1001 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 1002 | } while (mol == NULL); | 
|---|
| [e138de] | 1003 | Log() << Verbose(0) << "Enter name: "; | 
|---|
| [63f06e] | 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 { | 
|---|
| [e138de] | 1014 | Log() << Verbose(0) << "Enter index of molecule: "; | 
|---|
| [63f06e] | 1015 | cin >> nr; | 
|---|
|  | 1016 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 1017 | } while (mol == NULL); | 
|---|
| [e138de] | 1018 | Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; | 
|---|
| [63f06e] | 1019 | do { | 
|---|
| [e138de] | 1020 | Log() << Verbose(0) << "Enter file name: "; | 
|---|
| [63f06e] | 1021 | cin >> filename; | 
|---|
|  | 1022 | } while (!mol->AddXYZFile(filename)); | 
|---|
|  | 1023 | mol->SetNameFromFilename(filename); | 
|---|
|  | 1024 | } | 
|---|
| [1907a7] | 1025 | break; | 
|---|
|  | 1026 |  | 
|---|
|  | 1027 | case 'r': | 
|---|
| [e138de] | 1028 | Log() << Verbose(0) << "Enter index of molecule: "; | 
|---|
| [1907a7] | 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 |  | 
|---|
| [e138de] | 1051 | Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl; | 
|---|
|  | 1052 | Log() << Verbose(0) << "a - simple add of one molecule to another" << endl; | 
|---|
|  | 1053 | Log() << Verbose(0) << "e - embedding merge of two molecules" << endl; | 
|---|
|  | 1054 | Log() << Verbose(0) << "m - multi-merge of all molecules" << endl; | 
|---|
|  | 1055 | Log() << Verbose(0) << "s - scatter merge of two molecules" << endl; | 
|---|
|  | 1056 | Log() << Verbose(0) << "t - simple merge of two molecules" << endl; | 
|---|
|  | 1057 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 1058 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 1059 | Log() << Verbose(0) << "INPUT: "; | 
|---|
| [1907a7] | 1060 | cin >> choice; | 
|---|
|  | 1061 |  | 
|---|
|  | 1062 | switch (choice) { | 
|---|
|  | 1063 | default: | 
|---|
| [e138de] | 1064 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
| [1907a7] | 1065 | break; | 
|---|
|  | 1066 |  | 
|---|
| [63f06e] | 1067 | case 'a': | 
|---|
|  | 1068 | { | 
|---|
|  | 1069 | int src, dest; | 
|---|
|  | 1070 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 1071 | { | 
|---|
|  | 1072 | do { | 
|---|
| [e138de] | 1073 | Log() << Verbose(0) << "Enter index of destination molecule: "; | 
|---|
| [63f06e] | 1074 | cin >> dest; | 
|---|
|  | 1075 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 1076 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 1077 | do { | 
|---|
| [e138de] | 1078 | Log() << Verbose(0) << "Enter index of source molecule to add from: "; | 
|---|
| [63f06e] | 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 { | 
|---|
| [e138de] | 1093 | Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): "; | 
|---|
| [f7f7a4] | 1094 | cin >> src; | 
|---|
|  | 1095 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 1096 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 1097 | do { | 
|---|
| [e138de] | 1098 | Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): "; | 
|---|
| [f7f7a4] | 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 { | 
|---|
| [e138de] | 1112 | Log() << Verbose(0) << "Enter index of molecule to merge into: "; | 
|---|
| [63f06e] | 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': | 
|---|
| [e138de] | 1129 | Log() << 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 { | 
|---|
| [e138de] | 1138 | Log() << Verbose(0) << "Enter index of destination molecule: "; | 
|---|
| [63f06e] | 1139 | cin >> dest; | 
|---|
|  | 1140 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 1141 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 1142 | do { | 
|---|
| [e138de] | 1143 | Log() << Verbose(0) << "Enter index of source molecule to merge into: "; | 
|---|
| [63f06e] | 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 { | 
|---|
| [e138de] | 1172 | eLog() << Verbose(0) << "I don't have anything to test on ... "; | 
|---|
| [e359a8] | 1173 | performCriticalExit(); | 
|---|
| [1907a7] | 1174 | return; | 
|---|
|  | 1175 | } | 
|---|
|  | 1176 | atom *Walker = mol->start; | 
|---|
| [6ac7ee] | 1177 |  | 
|---|
| [042f82] | 1178 | // generate some KeySets | 
|---|
| [e138de] | 1179 | Log() << Verbose(0) << "Generating KeySets." << endl; | 
|---|
| [042f82] | 1180 | KeySet TestSets[mol->AtomCount+1]; | 
|---|
|  | 1181 | i=1; | 
|---|
|  | 1182 | while (Walker->next != mol->end) { | 
|---|
|  | 1183 | Walker = Walker->next; | 
|---|
|  | 1184 | for (int j=0;j<i;j++) { | 
|---|
|  | 1185 | TestSets[j].insert(Walker->nr); | 
|---|
|  | 1186 | } | 
|---|
|  | 1187 | i++; | 
|---|
|  | 1188 | } | 
|---|
| [e138de] | 1189 | Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl; | 
|---|
| [042f82] | 1190 | KeySetTestPair test; | 
|---|
|  | 1191 | test = TestSets[mol->AtomCount-1].insert(Walker->nr); | 
|---|
|  | 1192 | if (test.second) { | 
|---|
| [e138de] | 1193 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
| [042f82] | 1194 | } else { | 
|---|
| [e138de] | 1195 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl; | 
|---|
| [042f82] | 1196 | } | 
|---|
|  | 1197 | TestSets[mol->AtomCount].insert(mol->end->previous->nr); | 
|---|
|  | 1198 | TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr); | 
|---|
|  | 1199 |  | 
|---|
|  | 1200 | // constructing Graph structure | 
|---|
| [e138de] | 1201 | Log() << Verbose(0) << "Generating Subgraph class." << endl; | 
|---|
| [042f82] | 1202 | Graph Subgraphs; | 
|---|
|  | 1203 |  | 
|---|
|  | 1204 | // insert KeySets into Subgraphs | 
|---|
| [e138de] | 1205 | Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl; | 
|---|
| [042f82] | 1206 | for (int j=0;j<mol->AtomCount;j++) { | 
|---|
|  | 1207 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1208 | } | 
|---|
| [e138de] | 1209 | Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl; | 
|---|
| [042f82] | 1210 | GraphTestPair test2; | 
|---|
|  | 1211 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1212 | if (test2.second) { | 
|---|
| [e138de] | 1213 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
| [042f82] | 1214 | } else { | 
|---|
| [e138de] | 1215 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl; | 
|---|
| [042f82] | 1216 | } | 
|---|
|  | 1217 |  | 
|---|
|  | 1218 | // show graphs | 
|---|
| [e138de] | 1219 | Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl; | 
|---|
| [042f82] | 1220 | Graph::iterator A = Subgraphs.begin(); | 
|---|
|  | 1221 | while (A !=  Subgraphs.end()) { | 
|---|
| [e138de] | 1222 | Log() << Verbose(0) << (*A).second.first << ": "; | 
|---|
| [042f82] | 1223 | KeySet::iterator key = (*A).first.begin(); | 
|---|
|  | 1224 | comp = -1; | 
|---|
|  | 1225 | while (key != (*A).first.end()) { | 
|---|
|  | 1226 | if ((*key) > comp) | 
|---|
| [e138de] | 1227 | Log() << Verbose(0) << (*key) << " "; | 
|---|
| [042f82] | 1228 | else | 
|---|
| [e138de] | 1229 | Log() << Verbose(0) << (*key) << "! "; | 
|---|
| [042f82] | 1230 | comp = (*key); | 
|---|
|  | 1231 | key++; | 
|---|
|  | 1232 | } | 
|---|
| [e138de] | 1233 | Log() << Verbose(0) << endl; | 
|---|
| [042f82] | 1234 | A++; | 
|---|
|  | 1235 | } | 
|---|
|  | 1236 | delete(mol); | 
|---|
| [14de469] | 1237 | }; | 
|---|
|  | 1238 |  | 
|---|
| [dbe929] | 1239 | /** Tries given filename or standard on saving the config file. | 
|---|
|  | 1240 | * \param *ConfigFileName name of file | 
|---|
|  | 1241 | * \param *configuration pointer to configuration structure with all the values | 
|---|
|  | 1242 | * \param *periode pointer to periodentafel structure with all the elements | 
|---|
| [1907a7] | 1243 | * \param *molecules list of molecules structure with all the atoms and coordinates | 
|---|
| [dbe929] | 1244 | */ | 
|---|
| [1907a7] | 1245 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules) | 
|---|
| [dbe929] | 1246 | { | 
|---|
| [042f82] | 1247 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1248 | ofstream output; | 
|---|
|  | 1249 | molecule *mol = new molecule(periode); | 
|---|
| [6a7f78c] | 1250 | mol->SetNameFromFilename(ConfigFileName); | 
|---|
| [042f82] | 1251 |  | 
|---|
| [568be7] | 1252 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
| [717e0c] | 1253 | eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; | 
|---|
| [568be7] | 1254 | } | 
|---|
|  | 1255 |  | 
|---|
|  | 1256 |  | 
|---|
|  | 1257 | // first save as PDB data | 
|---|
|  | 1258 | if (ConfigFileName != NULL) | 
|---|
|  | 1259 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1260 | if (output == NULL) | 
|---|
|  | 1261 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1262 | Log() << Verbose(0) << "Saving as pdb input "; | 
|---|
|  | 1263 | if (configuration->SavePDB(filename, molecules)) | 
|---|
|  | 1264 | Log() << Verbose(0) << "done." << endl; | 
|---|
|  | 1265 | else | 
|---|
|  | 1266 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1267 |  | 
|---|
|  | 1268 | // then save as tremolo data file | 
|---|
|  | 1269 | if (ConfigFileName != NULL) | 
|---|
|  | 1270 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1271 | if (output == NULL) | 
|---|
|  | 1272 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1273 | Log() << Verbose(0) << "Saving as tremolo data input "; | 
|---|
|  | 1274 | if (configuration->SaveTREMOLO(filename, molecules)) | 
|---|
|  | 1275 | Log() << Verbose(0) << "done." << endl; | 
|---|
|  | 1276 | else | 
|---|
|  | 1277 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1278 |  | 
|---|
| [437922] | 1279 | // translate each to its center and merge all molecules in MoleculeListClass into this molecule | 
|---|
| [042f82] | 1280 | int N = molecules->ListOfMolecules.size(); | 
|---|
| [ae38fb] | 1281 | int *src = new int[N]; | 
|---|
| [042f82] | 1282 | N=0; | 
|---|
| [437922] | 1283 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { | 
|---|
| [042f82] | 1284 | src[N++] = (*ListRunner)->IndexNr; | 
|---|
| [437922] | 1285 | (*ListRunner)->Translate(&(*ListRunner)->Center); | 
|---|
|  | 1286 | } | 
|---|
| [042f82] | 1287 | molecules->SimpleMultiAdd(mol, src, N); | 
|---|
| [ae38fb] | 1288 | delete[](src); | 
|---|
| [357fba] | 1289 |  | 
|---|
| [437922] | 1290 | // ... and translate back | 
|---|
| [63f06e] | 1291 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { | 
|---|
|  | 1292 | (*ListRunner)->Center.Scale(-1.); | 
|---|
|  | 1293 | (*ListRunner)->Translate(&(*ListRunner)->Center); | 
|---|
|  | 1294 | (*ListRunner)->Center.Scale(-1.); | 
|---|
|  | 1295 | } | 
|---|
| [042f82] | 1296 |  | 
|---|
| [e138de] | 1297 | Log() << Verbose(0) << "Storing configuration ... " << endl; | 
|---|
| [042f82] | 1298 | // get correct valence orbitals | 
|---|
|  | 1299 | mol->CalculateOrbitals(*configuration); | 
|---|
|  | 1300 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble; | 
|---|
|  | 1301 | if (ConfigFileName != NULL) { // test the file name | 
|---|
| [437922] | 1302 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1303 | output.open(filename, ios::trunc); | 
|---|
| [042f82] | 1304 | } else if (strlen(configuration->configname) != 0) { | 
|---|
|  | 1305 | strcpy(filename, configuration->configname); | 
|---|
|  | 1306 | output.open(configuration->configname, ios::trunc); | 
|---|
|  | 1307 | } else { | 
|---|
|  | 1308 | strcpy(filename, DEFAULTCONFIG); | 
|---|
|  | 1309 | output.open(DEFAULTCONFIG, ios::trunc); | 
|---|
|  | 1310 | } | 
|---|
|  | 1311 | output.close(); | 
|---|
|  | 1312 | output.clear(); | 
|---|
| [e138de] | 1313 | Log() << Verbose(0) << "Saving of config file "; | 
|---|
| [042f82] | 1314 | if (configuration->Save(filename, periode, mol)) | 
|---|
| [e138de] | 1315 | Log() << Verbose(0) << "successful." << endl; | 
|---|
| [042f82] | 1316 | else | 
|---|
| [e138de] | 1317 | Log() << Verbose(0) << "failed." << endl; | 
|---|
| [042f82] | 1318 |  | 
|---|
|  | 1319 | // and save to xyz file | 
|---|
|  | 1320 | if (ConfigFileName != NULL) { | 
|---|
|  | 1321 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1322 | strcat(filename, ".xyz"); | 
|---|
|  | 1323 | output.open(filename, ios::trunc); | 
|---|
|  | 1324 | } | 
|---|
|  | 1325 | if (output == NULL) { | 
|---|
|  | 1326 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1327 | strcat(filename, ".xyz"); | 
|---|
|  | 1328 | output.open(filename, ios::trunc); | 
|---|
|  | 1329 | } | 
|---|
| [e138de] | 1330 | Log() << Verbose(0) << "Saving of XYZ file "; | 
|---|
| [042f82] | 1331 | if (mol->MDSteps <= 1) { | 
|---|
|  | 1332 | if (mol->OutputXYZ(&output)) | 
|---|
| [e138de] | 1333 | Log() << Verbose(0) << "successful." << endl; | 
|---|
| [042f82] | 1334 | else | 
|---|
| [e138de] | 1335 | Log() << Verbose(0) << "failed." << endl; | 
|---|
| [042f82] | 1336 | } else { | 
|---|
|  | 1337 | if (mol->OutputTrajectoriesXYZ(&output)) | 
|---|
| [e138de] | 1338 | Log() << Verbose(0) << "successful." << endl; | 
|---|
| [042f82] | 1339 | else | 
|---|
| [e138de] | 1340 | Log() << Verbose(0) << "failed." << endl; | 
|---|
| [042f82] | 1341 | } | 
|---|
|  | 1342 | output.close(); | 
|---|
|  | 1343 | output.clear(); | 
|---|
|  | 1344 |  | 
|---|
|  | 1345 | // and save as MPQC configuration | 
|---|
|  | 1346 | if (ConfigFileName != NULL) | 
|---|
|  | 1347 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1348 | if (output == NULL) | 
|---|
|  | 1349 | strcpy(filename,"main_pcp_linux"); | 
|---|
| [e138de] | 1350 | Log() << Verbose(0) << "Saving as mpqc input "; | 
|---|
| [042f82] | 1351 | if (configuration->SaveMPQC(filename, mol)) | 
|---|
| [e138de] | 1352 | Log() << Verbose(0) << "done." << endl; | 
|---|
| [042f82] | 1353 | else | 
|---|
| [e138de] | 1354 | Log() << Verbose(0) << "failed." << endl; | 
|---|
| [042f82] | 1355 |  | 
|---|
|  | 1356 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
| [717e0c] | 1357 | eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; | 
|---|
| [042f82] | 1358 | } | 
|---|
| [568be7] | 1359 |  | 
|---|
| [042f82] | 1360 | delete(mol); | 
|---|
| [dbe929] | 1361 | }; | 
|---|
|  | 1362 |  | 
|---|
| [ca2b83] | 1363 | /** Parses the command line options. | 
|---|
|  | 1364 | * \param argc argument count | 
|---|
|  | 1365 | * \param **argv arguments array | 
|---|
| [1907a7] | 1366 | * \param *molecules list of molecules structure | 
|---|
| [ca2b83] | 1367 | * \param *periode elements structure | 
|---|
|  | 1368 | * \param configuration config file structure | 
|---|
|  | 1369 | * \param *ConfigFileName pointer to config file name in **argv | 
|---|
| [d7d29c] | 1370 | * \param *PathToDatabases pointer to db's path in **argv | 
|---|
| [ca2b83] | 1371 | * \return exit code (0 - successful, all else - something's wrong) | 
|---|
|  | 1372 | */ | 
|---|
| [989bf6] | 1373 | static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName) | 
|---|
| [14de469] | 1374 | { | 
|---|
| [042f82] | 1375 | Vector x,y,z,n;  // coordinates for absolute point in cell volume | 
|---|
|  | 1376 | double *factor; // unit factor if desired | 
|---|
|  | 1377 | ifstream test; | 
|---|
|  | 1378 | ofstream output; | 
|---|
|  | 1379 | string line; | 
|---|
|  | 1380 | atom *first; | 
|---|
|  | 1381 | bool SaveFlag = false; | 
|---|
|  | 1382 | int ExitFlag = 0; | 
|---|
|  | 1383 | int j; | 
|---|
|  | 1384 | double volume = 0.; | 
|---|
| [f1cccd] | 1385 | enum ConfigStatus configPresent = absent; | 
|---|
| [042f82] | 1386 | clock_t start,end; | 
|---|
|  | 1387 | int argptr; | 
|---|
| [b6d8a9] | 1388 | molecule *mol = NULL; | 
|---|
| [6a7f78c] | 1389 | string BondGraphFileName("\n"); | 
|---|
| [717e0c] | 1390 | int verbosity = 0; | 
|---|
| [989bf6] | 1391 | strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1); | 
|---|
| [6ac7ee] | 1392 |  | 
|---|
| [042f82] | 1393 | if (argc > 1) { // config file specified as option | 
|---|
|  | 1394 | // 1. : Parse options that just set variables or print help | 
|---|
|  | 1395 | argptr = 1; | 
|---|
|  | 1396 | do { | 
|---|
|  | 1397 | if (argv[argptr][0] == '-') { | 
|---|
| [e138de] | 1398 | Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n"; | 
|---|
| [042f82] | 1399 | argptr++; | 
|---|
|  | 1400 | switch(argv[argptr-1][1]) { | 
|---|
|  | 1401 | case 'h': | 
|---|
|  | 1402 | case 'H': | 
|---|
|  | 1403 | case '?': | 
|---|
| [e138de] | 1404 | Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl; | 
|---|
|  | 1405 | Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl; | 
|---|
|  | 1406 | Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl; | 
|---|
|  | 1407 | Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl; | 
|---|
|  | 1408 | Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl; | 
|---|
|  | 1409 | Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl; | 
|---|
|  | 1410 | Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl; | 
|---|
|  | 1411 | Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl; | 
|---|
| [3930eb] | 1412 | Log() << Verbose(0) << "\t-C <Z> <output> <bin output>\tPair Correlation analysis." << endl; | 
|---|
| [e138de] | 1413 | Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl; | 
|---|
|  | 1414 | Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl; | 
|---|
|  | 1415 | Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl; | 
|---|
|  | 1416 | Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl; | 
|---|
|  | 1417 | Log() << Verbose(0) << "\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; | 
|---|
| [3930eb] | 1418 | Log() << Verbose(0) << "\t-F\tFilling Box with water molecules." << endl; | 
|---|
| [e138de] | 1419 | Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl; | 
|---|
|  | 1420 | Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl; | 
|---|
| [3930eb] | 1421 | Log() << Verbose(0) << "\t-I\t Dissect current system of molecules into a set of disconnected (subgraphs of) molecules." << endl; | 
|---|
| [e138de] | 1422 | Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl; | 
|---|
|  | 1423 | Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl; | 
|---|
|  | 1424 | Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl; | 
|---|
|  | 1425 | Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl; | 
|---|
|  | 1426 | Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl; | 
|---|
|  | 1427 | Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl; | 
|---|
|  | 1428 | Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl; | 
|---|
|  | 1429 | Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl; | 
|---|
|  | 1430 | Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl; | 
|---|
|  | 1431 | Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl; | 
|---|
|  | 1432 | Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl; | 
|---|
|  | 1433 | Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl; | 
|---|
|  | 1434 | Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl; | 
|---|
|  | 1435 | Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl; | 
|---|
|  | 1436 | Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl; | 
|---|
|  | 1437 | Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl; | 
|---|
| [717e0c] | 1438 | Log() << Verbose(0) << "\t-v\t\tsets verbosity (more is more)." << endl; | 
|---|
|  | 1439 | Log() << Verbose(0) << "\t-V\t\tGives version information." << endl; | 
|---|
| [e138de] | 1440 | Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl; | 
|---|
| [042f82] | 1441 | return (1); | 
|---|
|  | 1442 | break; | 
|---|
|  | 1443 | case 'v': | 
|---|
| [717e0c] | 1444 | while (argv[argptr-1][verbosity+1] == 'v') { | 
|---|
|  | 1445 | verbosity++; | 
|---|
|  | 1446 | } | 
|---|
|  | 1447 | setVerbosity(verbosity); | 
|---|
|  | 1448 | Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl; | 
|---|
|  | 1449 | break; | 
|---|
| [042f82] | 1450 | case 'V': | 
|---|
| [e138de] | 1451 | Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl; | 
|---|
|  | 1452 | Log() << Verbose(0) << "Build your own molecule position set." << endl; | 
|---|
| [042f82] | 1453 | return (1); | 
|---|
|  | 1454 | break; | 
|---|
|  | 1455 | case 'e': | 
|---|
|  | 1456 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [e138de] | 1457 | eLog() << Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl; | 
|---|
| [e359a8] | 1458 | performCriticalExit(); | 
|---|
| [042f82] | 1459 | } else { | 
|---|
| [e138de] | 1460 | Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl; | 
|---|
| [042f82] | 1461 | strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1); | 
|---|
|  | 1462 | argptr+=1; | 
|---|
|  | 1463 | } | 
|---|
|  | 1464 | break; | 
|---|
| [b21a64] | 1465 | case 'g': | 
|---|
|  | 1466 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
| [e138de] | 1467 | eLog() << Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl; | 
|---|
| [e359a8] | 1468 | performCriticalExit(); | 
|---|
| [b21a64] | 1469 | } else { | 
|---|
|  | 1470 | BondGraphFileName = argv[argptr]; | 
|---|
| [e138de] | 1471 | Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl; | 
|---|
| [b21a64] | 1472 | argptr+=1; | 
|---|
|  | 1473 | } | 
|---|
|  | 1474 | break; | 
|---|
| [042f82] | 1475 | case 'n': | 
|---|
| [e138de] | 1476 | Log() << Verbose(0) << "I won't parse trajectories." << endl; | 
|---|
| [042f82] | 1477 | configuration.FastParsing = true; | 
|---|
|  | 1478 | break; | 
|---|
|  | 1479 | default:   // no match? Step on | 
|---|
|  | 1480 | argptr++; | 
|---|
|  | 1481 | break; | 
|---|
|  | 1482 | } | 
|---|
|  | 1483 | } else | 
|---|
|  | 1484 | argptr++; | 
|---|
|  | 1485 | } while (argptr < argc); | 
|---|
|  | 1486 |  | 
|---|
| [b21a64] | 1487 | // 3a. Parse the element database | 
|---|
| [042f82] | 1488 | if (periode->LoadPeriodentafel(configuration.databasepath)) { | 
|---|
| [e138de] | 1489 | Log() << Verbose(0) << "Element list loaded successfully." << endl; | 
|---|
|  | 1490 | //periode->Output(); | 
|---|
| [042f82] | 1491 | } else { | 
|---|
| [e138de] | 1492 | Log() << Verbose(0) << "Element list loading failed." << endl; | 
|---|
| [042f82] | 1493 | return 1; | 
|---|
|  | 1494 | } | 
|---|
| [34e0013] | 1495 | // 3b. Find config file name and parse if possible, also BondGraphFileName | 
|---|
| [042f82] | 1496 | if (argv[1][0] != '-') { | 
|---|
| [b6d8a9] | 1497 | // simply create a new molecule, wherein the config file is loaded and the manipulation takes place | 
|---|
| [e138de] | 1498 | Log() << Verbose(0) << "Config file given." << endl; | 
|---|
| [042f82] | 1499 | test.open(argv[1], ios::in); | 
|---|
|  | 1500 | if (test == NULL) { | 
|---|
|  | 1501 | //return (1); | 
|---|
|  | 1502 | output.open(argv[1], ios::out); | 
|---|
|  | 1503 | if (output == NULL) { | 
|---|
| [e138de] | 1504 | Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl; | 
|---|
| [f1cccd] | 1505 | configPresent = absent; | 
|---|
| [042f82] | 1506 | } else { | 
|---|
| [e138de] | 1507 | Log() << Verbose(0) << "Empty configuration file." << endl; | 
|---|
| [042f82] | 1508 | ConfigFileName = argv[1]; | 
|---|
| [f1cccd] | 1509 | configPresent = empty; | 
|---|
| [042f82] | 1510 | output.close(); | 
|---|
|  | 1511 | } | 
|---|
|  | 1512 | } else { | 
|---|
|  | 1513 | test.close(); | 
|---|
|  | 1514 | ConfigFileName = argv[1]; | 
|---|
| [e138de] | 1515 | Log() << Verbose(1) << "Specified config file found, parsing ... "; | 
|---|
| [fa649a] | 1516 | switch (configuration.TestSyntax(ConfigFileName, periode)) { | 
|---|
| [042f82] | 1517 | case 1: | 
|---|
| [e138de] | 1518 | Log() << Verbose(0) << "new syntax." << endl; | 
|---|
| [fa649a] | 1519 | configuration.Load(ConfigFileName, BondGraphFileName, periode, molecules); | 
|---|
| [f1cccd] | 1520 | configPresent = present; | 
|---|
| [042f82] | 1521 | break; | 
|---|
|  | 1522 | case 0: | 
|---|
| [e138de] | 1523 | Log() << Verbose(0) << "old syntax." << endl; | 
|---|
| [fa649a] | 1524 | configuration.LoadOld(ConfigFileName, BondGraphFileName, periode, molecules); | 
|---|
| [f1cccd] | 1525 | configPresent = present; | 
|---|
| [042f82] | 1526 | break; | 
|---|
|  | 1527 | default: | 
|---|
| [e138de] | 1528 | Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl; | 
|---|
| [f1cccd] | 1529 | configPresent = empty; | 
|---|
| [042f82] | 1530 | } | 
|---|
|  | 1531 | } | 
|---|
|  | 1532 | } else | 
|---|
| [f1cccd] | 1533 | configPresent = absent; | 
|---|
| [fa649a] | 1534 | // set mol to first active molecule | 
|---|
|  | 1535 | if (molecules->ListOfMolecules.size() != 0) { | 
|---|
|  | 1536 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 1537 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 1538 | mol = *ListRunner; | 
|---|
|  | 1539 | break; | 
|---|
|  | 1540 | } | 
|---|
|  | 1541 | } | 
|---|
|  | 1542 | if (mol == NULL) { | 
|---|
|  | 1543 | mol = new molecule(periode); | 
|---|
|  | 1544 | mol->ActiveFlag = true; | 
|---|
| [6a7f78c] | 1545 | if (ConfigFileName != NULL) | 
|---|
|  | 1546 | mol->SetNameFromFilename(ConfigFileName); | 
|---|
| [fa649a] | 1547 | molecules->insert(mol); | 
|---|
|  | 1548 | } | 
|---|
| [6a7f78c] | 1549 | if (configuration.BG == NULL) { | 
|---|
|  | 1550 | configuration.BG = new BondGraph(configuration.GetIsAngstroem()); | 
|---|
|  | 1551 | if ((BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) { | 
|---|
|  | 1552 | Log() << Verbose(0) << "Bond length table loaded successfully." << endl; | 
|---|
|  | 1553 | } else { | 
|---|
|  | 1554 | eLog() << Verbose(1) << "Bond length table loading failed." << endl; | 
|---|
|  | 1555 | } | 
|---|
|  | 1556 | } | 
|---|
| [fa649a] | 1557 |  | 
|---|
| [042f82] | 1558 | // 4. parse again through options, now for those depending on elements db and config presence | 
|---|
|  | 1559 | argptr = 1; | 
|---|
|  | 1560 | do { | 
|---|
| [e138de] | 1561 | Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl; | 
|---|
| [042f82] | 1562 | if (argv[argptr][0] == '-') { | 
|---|
|  | 1563 | argptr++; | 
|---|
| [f1cccd] | 1564 | if ((configPresent == present) || (configPresent == empty)) { | 
|---|
| [042f82] | 1565 | switch(argv[argptr-1][1]) { | 
|---|
|  | 1566 | case 'p': | 
|---|
| [ebcade] | 1567 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1568 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1569 | ExitFlag = 255; | 
|---|
| [e138de] | 1570 | eLog() << Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl; | 
|---|
| [e359a8] | 1571 | performCriticalExit(); | 
|---|
| [042f82] | 1572 | } else { | 
|---|
|  | 1573 | SaveFlag = true; | 
|---|
| [e138de] | 1574 | Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl; | 
|---|
| [042f82] | 1575 | if (!mol->AddXYZFile(argv[argptr])) | 
|---|
| [e138de] | 1576 | Log() << Verbose(2) << "File not found." << endl; | 
|---|
| [042f82] | 1577 | else { | 
|---|
| [e138de] | 1578 | Log() << Verbose(2) << "File found and parsed." << endl; | 
|---|
| [f1cccd] | 1579 | configPresent = present; | 
|---|
| [042f82] | 1580 | } | 
|---|
|  | 1581 | } | 
|---|
|  | 1582 | break; | 
|---|
|  | 1583 | case 'a': | 
|---|
| [ebcade] | 1584 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [09048c] | 1585 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) { | 
|---|
| [042f82] | 1586 | ExitFlag = 255; | 
|---|
| [e138de] | 1587 | eLog() << Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl; | 
|---|
| [e359a8] | 1588 | performCriticalExit(); | 
|---|
| [042f82] | 1589 | } else { | 
|---|
|  | 1590 | SaveFlag = true; | 
|---|
| [e138de] | 1591 | Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), "; | 
|---|
| [042f82] | 1592 | first = new atom; | 
|---|
|  | 1593 | first->type = periode->FindElement(atoi(argv[argptr])); | 
|---|
|  | 1594 | if (first->type != NULL) | 
|---|
| [e138de] | 1595 | Log() << Verbose(2) << "found element " << first->type->name << endl; | 
|---|
| [042f82] | 1596 | for (int i=NDIM;i--;) | 
|---|
|  | 1597 | first->x.x[i] = atof(argv[argptr+1+i]); | 
|---|
|  | 1598 | if (first->type != NULL) { | 
|---|
|  | 1599 | mol->AddAtom(first);  // add to molecule | 
|---|
| [f1cccd] | 1600 | if ((configPresent == empty) && (mol->AtomCount != 0)) | 
|---|
|  | 1601 | configPresent = present; | 
|---|
| [042f82] | 1602 | } else | 
|---|
| [e138de] | 1603 | eLog() << Verbose(1) << "Could not find the specified element." << endl; | 
|---|
| [042f82] | 1604 | argptr+=4; | 
|---|
|  | 1605 | } | 
|---|
|  | 1606 | break; | 
|---|
|  | 1607 | default:   // no match? Don't step on (this is done in next switch's default) | 
|---|
|  | 1608 | break; | 
|---|
|  | 1609 | } | 
|---|
|  | 1610 | } | 
|---|
| [f1cccd] | 1611 | if (configPresent == present) { | 
|---|
| [042f82] | 1612 | switch(argv[argptr-1][1]) { | 
|---|
| [f3278b] | 1613 | case 'M': | 
|---|
| [042f82] | 1614 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1615 | ExitFlag = 255; | 
|---|
| [e138de] | 1616 | eLog() << Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl; | 
|---|
| [e359a8] | 1617 | performCriticalExit(); | 
|---|
| [042f82] | 1618 | } else { | 
|---|
|  | 1619 | configuration.basis = argv[argptr]; | 
|---|
| [e138de] | 1620 | Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl; | 
|---|
| [042f82] | 1621 | argptr+=1; | 
|---|
|  | 1622 | } | 
|---|
|  | 1623 | break; | 
|---|
|  | 1624 | case 'D': | 
|---|
| [ebcade] | 1625 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1626 | { | 
|---|
| [e138de] | 1627 | Log() << Verbose(1) << "Depth-First-Search Analysis." << endl; | 
|---|
| [042f82] | 1628 | MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis | 
|---|
|  | 1629 | int *MinimumRingSize = new int[mol->AtomCount]; | 
|---|
|  | 1630 | atom ***ListOfLocalAtoms = NULL; | 
|---|
|  | 1631 | class StackClass<bond *> *BackEdgeStack = NULL; | 
|---|
|  | 1632 | class StackClass<bond *> *LocalBackEdgeStack = NULL; | 
|---|
| [e138de] | 1633 | mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 1634 | Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack); | 
|---|
| [042f82] | 1635 | if (Subgraphs != NULL) { | 
|---|
| [7218f8] | 1636 | int FragmentCounter = 0; | 
|---|
| [042f82] | 1637 | while (Subgraphs->next != NULL) { | 
|---|
|  | 1638 | Subgraphs = Subgraphs->next; | 
|---|
| [e138de] | 1639 | Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms | 
|---|
| [042f82] | 1640 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount); | 
|---|
| [e138de] | 1641 | Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack); | 
|---|
|  | 1642 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize); | 
|---|
| [042f82] | 1643 | delete(LocalBackEdgeStack); | 
|---|
|  | 1644 | delete(Subgraphs->previous); | 
|---|
| [7218f8] | 1645 | FragmentCounter++; | 
|---|
| [042f82] | 1646 | } | 
|---|
|  | 1647 | delete(Subgraphs); | 
|---|
|  | 1648 | for (int i=0;i<FragmentCounter;i++) | 
|---|
| [7218f8] | 1649 | Free(&ListOfLocalAtoms[i]); | 
|---|
| [b66c22] | 1650 | Free(&ListOfLocalAtoms); | 
|---|
| [042f82] | 1651 | } | 
|---|
|  | 1652 | delete(BackEdgeStack); | 
|---|
|  | 1653 | delete[](MinimumRingSize); | 
|---|
|  | 1654 | } | 
|---|
|  | 1655 | //argptr+=1; | 
|---|
|  | 1656 | break; | 
|---|
| [3930eb] | 1657 | case 'I': | 
|---|
|  | 1658 | Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl; | 
|---|
|  | 1659 | // @TODO rather do the dissection afterwards | 
|---|
|  | 1660 | molecules->DissectMoleculeIntoConnectedSubgraphs(mol,&configuration); | 
|---|
|  | 1661 | mol = NULL; | 
|---|
|  | 1662 | if (molecules->ListOfMolecules.size() != 0) { | 
|---|
|  | 1663 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 1664 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 1665 | mol = *ListRunner; | 
|---|
|  | 1666 | break; | 
|---|
|  | 1667 | } | 
|---|
|  | 1668 | } | 
|---|
|  | 1669 | if (mol == NULL) { | 
|---|
|  | 1670 | mol = *(molecules->ListOfMolecules.begin()); | 
|---|
|  | 1671 | mol->ActiveFlag = true; | 
|---|
|  | 1672 | } | 
|---|
|  | 1673 | break; | 
|---|
| [db6bf74] | 1674 | case 'C': | 
|---|
|  | 1675 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f4e1f5] | 1676 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr][0] == '-') || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-')) { | 
|---|
| [db6bf74] | 1677 | ExitFlag = 255; | 
|---|
| [e138de] | 1678 | eLog() << Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C <Z> <output> <bin output>" << endl; | 
|---|
| [e359a8] | 1679 | performCriticalExit(); | 
|---|
| [db6bf74] | 1680 | } else { | 
|---|
| [09048c] | 1681 | ofstream output(argv[argptr+1]); | 
|---|
|  | 1682 | ofstream binoutput(argv[argptr+2]); | 
|---|
| [db6bf74] | 1683 | const double radius = 5.; | 
|---|
| [09048c] | 1684 |  | 
|---|
|  | 1685 | // get the boundary | 
|---|
| [f4e1f5] | 1686 | class molecule *Boundary = NULL; | 
|---|
| [776b64] | 1687 | class Tesselation *TesselStruct = NULL; | 
|---|
|  | 1688 | const LinkedCell *LCList = NULL; | 
|---|
| [f4e1f5] | 1689 | // find biggest molecule | 
|---|
| [a5551b] | 1690 | int counter  = 0; | 
|---|
| [f4e1f5] | 1691 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { | 
|---|
|  | 1692 | if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) { | 
|---|
|  | 1693 | Boundary = *BigFinder; | 
|---|
|  | 1694 | } | 
|---|
| [a5551b] | 1695 | counter++; | 
|---|
|  | 1696 | } | 
|---|
|  | 1697 | bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives"); | 
|---|
|  | 1698 | counter = 0; | 
|---|
|  | 1699 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { | 
|---|
| [3930eb] | 1700 | Actives[counter++] = (*BigFinder)->ActiveFlag; | 
|---|
| [a5551b] | 1701 | (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true; | 
|---|
| [f4e1f5] | 1702 | } | 
|---|
| [776b64] | 1703 | LCList = new LinkedCell(Boundary, 2.*radius); | 
|---|
| [f4e1f5] | 1704 | element *elemental = periode->FindElement((const int) atoi(argv[argptr])); | 
|---|
| [e138de] | 1705 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL); | 
|---|
| [7ea9e6] | 1706 | int ranges[NDIM] = {1,1,1}; | 
|---|
| [e138de] | 1707 | CorrelationToSurfaceMap *surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges ); | 
|---|
|  | 1708 | BinPairMap *binmap = BinData( surfacemap, 0.5, 0., 0. ); | 
|---|
| [db6bf74] | 1709 | OutputCorrelation ( &binoutput, binmap ); | 
|---|
|  | 1710 | output.close(); | 
|---|
|  | 1711 | binoutput.close(); | 
|---|
| [a5551b] | 1712 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) | 
|---|
| [3930eb] | 1713 | (*BigFinder)->ActiveFlag = Actives[counter++]; | 
|---|
| [a5551b] | 1714 | Free(&Actives); | 
|---|
| [776b64] | 1715 | delete(LCList); | 
|---|
|  | 1716 | delete(TesselStruct); | 
|---|
| [09048c] | 1717 | argptr+=3; | 
|---|
| [db6bf74] | 1718 | } | 
|---|
|  | 1719 | break; | 
|---|
| [042f82] | 1720 | case 'E': | 
|---|
| [ebcade] | 1721 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1722 | if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) { | 
|---|
|  | 1723 | ExitFlag = 255; | 
|---|
| [e138de] | 1724 | eLog() << Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl; | 
|---|
| [e359a8] | 1725 | performCriticalExit(); | 
|---|
| [042f82] | 1726 | } else { | 
|---|
|  | 1727 | SaveFlag = true; | 
|---|
| [e138de] | 1728 | Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl; | 
|---|
| [042f82] | 1729 | first = mol->FindAtom(atoi(argv[argptr])); | 
|---|
|  | 1730 | first->type = periode->FindElement(atoi(argv[argptr+1])); | 
|---|
|  | 1731 | argptr+=2; | 
|---|
|  | 1732 | } | 
|---|
|  | 1733 | break; | 
|---|
| [9f97c5] | 1734 | case 'F': | 
|---|
| [ebcade] | 1735 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [3930eb] | 1736 | if (argptr+6 >=argc) { | 
|---|
| [9f97c5] | 1737 | ExitFlag = 255; | 
|---|
| [3930eb] | 1738 | eLog() << Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>" << endl; | 
|---|
| [e359a8] | 1739 | performCriticalExit(); | 
|---|
| [9f97c5] | 1740 | } else { | 
|---|
|  | 1741 | SaveFlag = true; | 
|---|
| [e138de] | 1742 | Log() << Verbose(1) << "Filling Box with water molecules." << endl; | 
|---|
| [9f97c5] | 1743 | // construct water molecule | 
|---|
|  | 1744 | molecule *filler = new molecule(periode);; | 
|---|
|  | 1745 | molecule *Filling = NULL; | 
|---|
|  | 1746 | atom *second = NULL, *third = NULL; | 
|---|
|  | 1747 | first = new atom(); | 
|---|
| [3930eb] | 1748 | first->type = periode->FindElement(5); | 
|---|
|  | 1749 | first->x.Zero(); | 
|---|
| [9f97c5] | 1750 | filler->AddAtom(first); | 
|---|
| [3930eb] | 1751 | //                first = new atom(); | 
|---|
|  | 1752 | //                first->type = periode->FindElement(1); | 
|---|
|  | 1753 | //                first->x.Init(0.441, -0.143, 0.); | 
|---|
|  | 1754 | //                filler->AddAtom(first); | 
|---|
|  | 1755 | //                second = new atom(); | 
|---|
|  | 1756 | //                second->type = periode->FindElement(1); | 
|---|
|  | 1757 | //                second->x.Init(-0.464, 1.137, 0.0); | 
|---|
|  | 1758 | //                filler->AddAtom(second); | 
|---|
|  | 1759 | //                third = new atom(); | 
|---|
|  | 1760 | //                third->type = periode->FindElement(8); | 
|---|
|  | 1761 | //                third->x.Init(-0.464, 0.177, 0.); | 
|---|
|  | 1762 | //                filler->AddAtom(third); | 
|---|
|  | 1763 | //                filler->AddBond(first, third, 1); | 
|---|
|  | 1764 | //                filler->AddBond(second, third, 1); | 
|---|
| [9f97c5] | 1765 | // call routine | 
|---|
|  | 1766 | double distance[NDIM]; | 
|---|
|  | 1767 | for (int i=0;i<NDIM;i++) | 
|---|
|  | 1768 | distance[i] = atof(argv[argptr+i]); | 
|---|
| [3930eb] | 1769 | Filling = FillBoxWithMolecule(molecules, filler, configuration, distance, atof(argv[argptr+3]), atof(argv[argptr+4]), atof(argv[argptr+5]), atoi(argv[argptr+6])); | 
|---|
| [9f97c5] | 1770 | if (Filling != NULL) { | 
|---|
| [3930eb] | 1771 | Filling->ActiveFlag = false; | 
|---|
| [9f97c5] | 1772 | molecules->insert(Filling); | 
|---|
|  | 1773 | } | 
|---|
|  | 1774 | delete(filler); | 
|---|
|  | 1775 | argptr+=6; | 
|---|
|  | 1776 | } | 
|---|
|  | 1777 | break; | 
|---|
| [042f82] | 1778 | case 'A': | 
|---|
| [ebcade] | 1779 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1780 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1781 | ExitFlag =255; | 
|---|
| [e138de] | 1782 | eLog() << Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl; | 
|---|
| [e359a8] | 1783 | performCriticalExit(); | 
|---|
| [042f82] | 1784 | } else { | 
|---|
| [e138de] | 1785 | Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl; | 
|---|
| [042f82] | 1786 | ifstream *input = new ifstream(argv[argptr]); | 
|---|
| [e138de] | 1787 | mol->CreateAdjacencyListFromDbondFile(input); | 
|---|
| [042f82] | 1788 | input->close(); | 
|---|
|  | 1789 | argptr+=1; | 
|---|
|  | 1790 | } | 
|---|
|  | 1791 | break; | 
|---|
|  | 1792 | case 'N': | 
|---|
| [ebcade] | 1793 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1794 | if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){ | 
|---|
|  | 1795 | ExitFlag = 255; | 
|---|
| [e138de] | 1796 | eLog() << Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl; | 
|---|
| [e359a8] | 1797 | performCriticalExit(); | 
|---|
| [042f82] | 1798 | } else { | 
|---|
| [776b64] | 1799 | class Tesselation *T = NULL; | 
|---|
|  | 1800 | const LinkedCell *LCList = NULL; | 
|---|
| [9a0dc8] | 1801 | molecule * Boundary = NULL; | 
|---|
|  | 1802 | //string filename(argv[argptr+1]); | 
|---|
|  | 1803 | //filename.append(".csv"); | 
|---|
|  | 1804 | Log() << Verbose(0) << "Evaluating non-convex envelope of biggest molecule."; | 
|---|
| [e138de] | 1805 | Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl; | 
|---|
| [9a0dc8] | 1806 | // find biggest molecule | 
|---|
|  | 1807 | int counter  = 0; | 
|---|
|  | 1808 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) { | 
|---|
|  | 1809 | (*BigFinder)->CountAtoms(); | 
|---|
|  | 1810 | if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) { | 
|---|
|  | 1811 | Boundary = *BigFinder; | 
|---|
|  | 1812 | } | 
|---|
|  | 1813 | counter++; | 
|---|
|  | 1814 | } | 
|---|
|  | 1815 | Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl; | 
|---|
| [f7f7a4] | 1816 | start = clock(); | 
|---|
| [9a0dc8] | 1817 | LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.); | 
|---|
| [4fc93f] | 1818 | if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1])) | 
|---|
|  | 1819 | ExitFlag = 255; | 
|---|
| [e138de] | 1820 | //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str()); | 
|---|
| [f7f7a4] | 1821 | end = clock(); | 
|---|
| [e138de] | 1822 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
| [776b64] | 1823 | delete(LCList); | 
|---|
| [f67b6e] | 1824 | delete(T); | 
|---|
| [042f82] | 1825 | argptr+=2; | 
|---|
|  | 1826 | } | 
|---|
|  | 1827 | break; | 
|---|
|  | 1828 | case 'S': | 
|---|
| [ebcade] | 1829 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1830 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1831 | ExitFlag = 255; | 
|---|
| [e138de] | 1832 | eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl; | 
|---|
| [e359a8] | 1833 | performCriticalExit(); | 
|---|
| [042f82] | 1834 | } else { | 
|---|
| [e138de] | 1835 | Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl; | 
|---|
| [042f82] | 1836 | ofstream *output = new ofstream(argv[argptr], ios::trunc); | 
|---|
| [e138de] | 1837 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) | 
|---|
|  | 1838 | Log() << Verbose(2) << "File could not be written." << endl; | 
|---|
| [042f82] | 1839 | else | 
|---|
| [e138de] | 1840 | Log() << Verbose(2) << "File stored." << endl; | 
|---|
| [042f82] | 1841 | output->close(); | 
|---|
|  | 1842 | delete(output); | 
|---|
|  | 1843 | argptr+=1; | 
|---|
|  | 1844 | } | 
|---|
|  | 1845 | break; | 
|---|
| [85bac0] | 1846 | case 'L': | 
|---|
| [ebcade] | 1847 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f7f7a4] | 1848 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1849 | ExitFlag = 255; | 
|---|
| [e138de] | 1850 | eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl; | 
|---|
| [e359a8] | 1851 | performCriticalExit(); | 
|---|
| [f7f7a4] | 1852 | } else { | 
|---|
|  | 1853 | SaveFlag = true; | 
|---|
| [e138de] | 1854 | Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl; | 
|---|
| [f7f7a4] | 1855 | if (atoi(argv[argptr+3]) == 1) | 
|---|
| [e138de] | 1856 | Log() << Verbose(1) << "Using Identity for the permutation map." << endl; | 
|---|
|  | 1857 | if (!mol->LinearInterpolationBetweenConfiguration(atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false) | 
|---|
|  | 1858 | Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl; | 
|---|
| [f7f7a4] | 1859 | else | 
|---|
| [e138de] | 1860 | Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl; | 
|---|
| [f7f7a4] | 1861 | argptr+=4; | 
|---|
|  | 1862 | } | 
|---|
| [85bac0] | 1863 | break; | 
|---|
| [042f82] | 1864 | case 'P': | 
|---|
| [ebcade] | 1865 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1866 | if ((argptr >= argc) || (argv[argptr][0] == '-')) { | 
|---|
|  | 1867 | ExitFlag = 255; | 
|---|
| [e138de] | 1868 | eLog() << Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl; | 
|---|
| [e359a8] | 1869 | performCriticalExit(); | 
|---|
| [042f82] | 1870 | } else { | 
|---|
|  | 1871 | SaveFlag = true; | 
|---|
| [e138de] | 1872 | Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl; | 
|---|
|  | 1873 | if (!mol->VerletForceIntegration(argv[argptr], configuration)) | 
|---|
|  | 1874 | Log() << Verbose(2) << "File not found." << endl; | 
|---|
| [042f82] | 1875 | else | 
|---|
| [e138de] | 1876 | Log() << Verbose(2) << "File found and parsed." << endl; | 
|---|
| [042f82] | 1877 | argptr+=1; | 
|---|
|  | 1878 | } | 
|---|
|  | 1879 | break; | 
|---|
| [a5b2c3a] | 1880 | case 'R': | 
|---|
| [ebcade] | 1881 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 1882 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])))  { | 
|---|
| [a5b2c3a] | 1883 | ExitFlag = 255; | 
|---|
| [e138de] | 1884 | eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl; | 
|---|
| [e359a8] | 1885 | performCriticalExit(); | 
|---|
| [a5b2c3a] | 1886 | } else { | 
|---|
|  | 1887 | SaveFlag = true; | 
|---|
| [e138de] | 1888 | Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl; | 
|---|
| [a5b2c3a] | 1889 | double tmp1 = atof(argv[argptr+1]); | 
|---|
|  | 1890 | atom *third = mol->FindAtom(atoi(argv[argptr])); | 
|---|
|  | 1891 | atom *first = mol->start; | 
|---|
|  | 1892 | if ((third != NULL) && (first != mol->end)) { | 
|---|
|  | 1893 | atom *second = first->next; | 
|---|
|  | 1894 | while(second != mol->end) { | 
|---|
|  | 1895 | first = second; | 
|---|
|  | 1896 | second = first->next; | 
|---|
|  | 1897 | if (first->x.DistanceSquared((const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ... | 
|---|
|  | 1898 | mol->RemoveAtom(first); | 
|---|
|  | 1899 | } | 
|---|
|  | 1900 | } else { | 
|---|
| [717e0c] | 1901 | eLog() << Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl; | 
|---|
| [a5b2c3a] | 1902 | } | 
|---|
|  | 1903 | argptr+=2; | 
|---|
|  | 1904 | } | 
|---|
|  | 1905 | break; | 
|---|
| [042f82] | 1906 | case 't': | 
|---|
| [ebcade] | 1907 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [09048c] | 1908 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [042f82] | 1909 | ExitFlag = 255; | 
|---|
| [e138de] | 1910 | eLog() << Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl; | 
|---|
| [e359a8] | 1911 | performCriticalExit(); | 
|---|
| [042f82] | 1912 | } else { | 
|---|
| [ebcade] | 1913 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 1914 | SaveFlag = true; | 
|---|
| [e138de] | 1915 | Log() << Verbose(1) << "Translating all ions by given vector." << endl; | 
|---|
| [042f82] | 1916 | for (int i=NDIM;i--;) | 
|---|
|  | 1917 | x.x[i] = atof(argv[argptr+i]); | 
|---|
|  | 1918 | mol->Translate((const Vector *)&x); | 
|---|
|  | 1919 | argptr+=3; | 
|---|
|  | 1920 | } | 
|---|
| [f7f7a4] | 1921 | break; | 
|---|
| [21c017] | 1922 | case 'T': | 
|---|
| [ebcade] | 1923 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [09048c] | 1924 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [21c017] | 1925 | ExitFlag = 255; | 
|---|
| [e138de] | 1926 | eLog() << Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl; | 
|---|
| [e359a8] | 1927 | performCriticalExit(); | 
|---|
| [21c017] | 1928 | } else { | 
|---|
| [ebcade] | 1929 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [21c017] | 1930 | SaveFlag = true; | 
|---|
| [e138de] | 1931 | Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl; | 
|---|
| [21c017] | 1932 | for (int i=NDIM;i--;) | 
|---|
|  | 1933 | x.x[i] = atof(argv[argptr+i]); | 
|---|
|  | 1934 | mol->TranslatePeriodically((const Vector *)&x); | 
|---|
|  | 1935 | argptr+=3; | 
|---|
|  | 1936 | } | 
|---|
|  | 1937 | break; | 
|---|
| [042f82] | 1938 | case 's': | 
|---|
| [ebcade] | 1939 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [09048c] | 1940 | if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [042f82] | 1941 | ExitFlag = 255; | 
|---|
| [e138de] | 1942 | eLog() << Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl; | 
|---|
| [e359a8] | 1943 | performCriticalExit(); | 
|---|
| [042f82] | 1944 | } else { | 
|---|
|  | 1945 | SaveFlag = true; | 
|---|
|  | 1946 | j = -1; | 
|---|
| [e138de] | 1947 | Log() << Verbose(1) << "Scaling all ion positions by factor." << endl; | 
|---|
| [042f82] | 1948 | factor = new double[NDIM]; | 
|---|
|  | 1949 | factor[0] = atof(argv[argptr]); | 
|---|
| [09048c] | 1950 | factor[1] = atof(argv[argptr+1]); | 
|---|
|  | 1951 | factor[2] = atof(argv[argptr+2]); | 
|---|
| [776b64] | 1952 | mol->Scale((const double ** const)&factor); | 
|---|
| [042f82] | 1953 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 1954 | j += i+1; | 
|---|
|  | 1955 | x.x[i] = atof(argv[NDIM+i]); | 
|---|
|  | 1956 | mol->cell_size[j]*=factor[i]; | 
|---|
|  | 1957 | } | 
|---|
|  | 1958 | delete[](factor); | 
|---|
| [09048c] | 1959 | argptr+=3; | 
|---|
| [042f82] | 1960 | } | 
|---|
|  | 1961 | break; | 
|---|
|  | 1962 | case 'b': | 
|---|
| [ebcade] | 1963 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 1964 | 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] | 1965 | ExitFlag = 255; | 
|---|
| [e138de] | 1966 | eLog() << Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl; | 
|---|
| [e359a8] | 1967 | performCriticalExit(); | 
|---|
| [042f82] | 1968 | } else { | 
|---|
|  | 1969 | SaveFlag = true; | 
|---|
| [a8b9d61] | 1970 | j = -1; | 
|---|
| [e138de] | 1971 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
| [042f82] | 1972 | for (int i=0;i<6;i++) { | 
|---|
|  | 1973 | mol->cell_size[i] = atof(argv[argptr+i]); | 
|---|
|  | 1974 | } | 
|---|
|  | 1975 | // center | 
|---|
| [e138de] | 1976 | mol->CenterInBox(); | 
|---|
| [21c017] | 1977 | argptr+=6; | 
|---|
| [042f82] | 1978 | } | 
|---|
|  | 1979 | break; | 
|---|
| [f3278b] | 1980 | case 'B': | 
|---|
| [ebcade] | 1981 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 1982 | 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] | 1983 | ExitFlag = 255; | 
|---|
| [e138de] | 1984 | eLog() << Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl; | 
|---|
| [e359a8] | 1985 | performCriticalExit(); | 
|---|
| [f3278b] | 1986 | } else { | 
|---|
|  | 1987 | SaveFlag = true; | 
|---|
|  | 1988 | j = -1; | 
|---|
| [e138de] | 1989 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
| [f3278b] | 1990 | for (int i=0;i<6;i++) { | 
|---|
|  | 1991 | mol->cell_size[i] = atof(argv[argptr+i]); | 
|---|
|  | 1992 | } | 
|---|
|  | 1993 | // center | 
|---|
| [e138de] | 1994 | mol->BoundInBox(); | 
|---|
| [f3278b] | 1995 | argptr+=6; | 
|---|
|  | 1996 | } | 
|---|
|  | 1997 | break; | 
|---|
| [042f82] | 1998 | case 'c': | 
|---|
| [ebcade] | 1999 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2000 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [042f82] | 2001 | ExitFlag = 255; | 
|---|
| [e138de] | 2002 | eLog() << Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl; | 
|---|
| [e359a8] | 2003 | performCriticalExit(); | 
|---|
| [042f82] | 2004 | } else { | 
|---|
|  | 2005 | SaveFlag = true; | 
|---|
|  | 2006 | j = -1; | 
|---|
| [e138de] | 2007 | Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl; | 
|---|
| [042f82] | 2008 | // make every coordinate positive | 
|---|
| [e138de] | 2009 | mol->CenterEdge(&x); | 
|---|
| [042f82] | 2010 | // update Box of atoms by boundary | 
|---|
|  | 2011 | mol->SetBoxDimension(&x); | 
|---|
|  | 2012 | // translate each coordinate by boundary | 
|---|
|  | 2013 | j=-1; | 
|---|
|  | 2014 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 2015 | j += i+1; | 
|---|
| [36ec71] | 2016 | x.x[i] = atof(argv[argptr+i]); | 
|---|
| [042f82] | 2017 | mol->cell_size[j] += x.x[i]*2.; | 
|---|
|  | 2018 | } | 
|---|
|  | 2019 | mol->Translate((const Vector *)&x); | 
|---|
| [21c017] | 2020 | argptr+=3; | 
|---|
| [042f82] | 2021 | } | 
|---|
|  | 2022 | break; | 
|---|
|  | 2023 | case 'O': | 
|---|
| [ebcade] | 2024 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 2025 | SaveFlag = true; | 
|---|
| [e138de] | 2026 | Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl; | 
|---|
| [36ec71] | 2027 | x.Zero(); | 
|---|
| [e138de] | 2028 | mol->CenterEdge(&x); | 
|---|
| [042f82] | 2029 | mol->SetBoxDimension(&x); | 
|---|
| [21c017] | 2030 | argptr+=0; | 
|---|
| [042f82] | 2031 | break; | 
|---|
|  | 2032 | case 'r': | 
|---|
| [ebcade] | 2033 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2034 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])))  { | 
|---|
|  | 2035 | ExitFlag = 255; | 
|---|
| [e138de] | 2036 | eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl; | 
|---|
| [e359a8] | 2037 | performCriticalExit(); | 
|---|
| [ebcade] | 2038 | } else { | 
|---|
|  | 2039 | SaveFlag = true; | 
|---|
| [e138de] | 2040 | Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl; | 
|---|
| [ebcade] | 2041 | atom *first = mol->FindAtom(atoi(argv[argptr])); | 
|---|
|  | 2042 | mol->RemoveAtom(first); | 
|---|
|  | 2043 | argptr+=1; | 
|---|
|  | 2044 | } | 
|---|
| [042f82] | 2045 | break; | 
|---|
|  | 2046 | case 'f': | 
|---|
| [ebcade] | 2047 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2048 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) { | 
|---|
| [042f82] | 2049 | ExitFlag = 255; | 
|---|
| [e138de] | 2050 | eLog() << Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl; | 
|---|
| [e359a8] | 2051 | performCriticalExit(); | 
|---|
| [042f82] | 2052 | } else { | 
|---|
| [e138de] | 2053 | Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl; | 
|---|
|  | 2054 | Log() << Verbose(0) << "Creating connection matrix..." << endl; | 
|---|
| [042f82] | 2055 | start = clock(); | 
|---|
| [e138de] | 2056 | mol->CreateAdjacencyList(atof(argv[argptr++]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 2057 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; | 
|---|
| [042f82] | 2058 | if (mol->first->next != mol->last) { | 
|---|
| [e138de] | 2059 | ExitFlag = mol->FragmentMolecule(atoi(argv[argptr]), &configuration); | 
|---|
| [042f82] | 2060 | } | 
|---|
|  | 2061 | end = clock(); | 
|---|
| [e138de] | 2062 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
| [042f82] | 2063 | argptr+=2; | 
|---|
|  | 2064 | } | 
|---|
|  | 2065 | break; | 
|---|
|  | 2066 | case 'm': | 
|---|
| [ebcade] | 2067 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [042f82] | 2068 | j = atoi(argv[argptr++]); | 
|---|
|  | 2069 | if ((j<0) || (j>1)) { | 
|---|
| [717e0c] | 2070 | eLog() << Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl; | 
|---|
| [042f82] | 2071 | j = 0; | 
|---|
|  | 2072 | } | 
|---|
|  | 2073 | if (j) { | 
|---|
|  | 2074 | SaveFlag = true; | 
|---|
| [e138de] | 2075 | Log() << Verbose(0) << "Converting to prinicipal axis system." << endl; | 
|---|
| [042f82] | 2076 | } else | 
|---|
| [e138de] | 2077 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl; | 
|---|
|  | 2078 | mol->PrincipalAxisSystem((bool)j); | 
|---|
| [042f82] | 2079 | break; | 
|---|
|  | 2080 | case 'o': | 
|---|
| [ebcade] | 2081 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
| [f7f7a4] | 2082 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){ | 
|---|
| [042f82] | 2083 | ExitFlag = 255; | 
|---|
| [e138de] | 2084 | eLog() << Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl; | 
|---|
| [e359a8] | 2085 | performCriticalExit(); | 
|---|
| [042f82] | 2086 | } else { | 
|---|
| [776b64] | 2087 | class Tesselation *TesselStruct = NULL; | 
|---|
|  | 2088 | const LinkedCell *LCList = NULL; | 
|---|
| [e138de] | 2089 | Log() << Verbose(0) << "Evaluating volume of the convex envelope."; | 
|---|
|  | 2090 | Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl; | 
|---|
|  | 2091 | Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl; | 
|---|
| [776b64] | 2092 | LCList = new LinkedCell(mol, 10.); | 
|---|
| [e138de] | 2093 | //FindConvexBorder(mol, LCList, argv[argptr]); | 
|---|
|  | 2094 | FindNonConvexBorder(mol, TesselStruct, LCList, 5., argv[argptr+1]); | 
|---|
|  | 2095 | //                RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]); | 
|---|
|  | 2096 | double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, argv[argptr]); | 
|---|
|  | 2097 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, &configuration); | 
|---|
|  | 2098 | Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl; | 
|---|
|  | 2099 | Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl; | 
|---|
| [776b64] | 2100 | delete(TesselStruct); | 
|---|
|  | 2101 | delete(LCList); | 
|---|
| [f7f7a4] | 2102 | argptr+=2; | 
|---|
| [042f82] | 2103 | } | 
|---|
|  | 2104 | break; | 
|---|
|  | 2105 | case 'U': | 
|---|
| [ebcade] | 2106 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2107 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) { | 
|---|
| [042f82] | 2108 | ExitFlag = 255; | 
|---|
| [e138de] | 2109 | eLog() << Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl; | 
|---|
| [e359a8] | 2110 | performCriticalExit(); | 
|---|
| [042f82] | 2111 | } else { | 
|---|
|  | 2112 | volume = atof(argv[argptr++]); | 
|---|
| [e138de] | 2113 | Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl; | 
|---|
| [042f82] | 2114 | } | 
|---|
|  | 2115 | case 'u': | 
|---|
| [ebcade] | 2116 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2117 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) { | 
|---|
| [042f82] | 2118 | if (volume != -1) | 
|---|
|  | 2119 | ExitFlag = 255; | 
|---|
| [482373] | 2120 | eLog() << Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl; | 
|---|
| [e359a8] | 2121 | performCriticalExit(); | 
|---|
| [042f82] | 2122 | } else { | 
|---|
|  | 2123 | double density; | 
|---|
|  | 2124 | SaveFlag = true; | 
|---|
| [e138de] | 2125 | Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water."; | 
|---|
| [042f82] | 2126 | density = atof(argv[argptr++]); | 
|---|
|  | 2127 | if (density < 1.0) { | 
|---|
| [e359a8] | 2128 | eLog() << Verbose(1) << "Density must be greater than 1.0g/cm^3 !" << endl; | 
|---|
| [042f82] | 2129 | density = 1.3; | 
|---|
|  | 2130 | } | 
|---|
|  | 2131 | //                for(int i=0;i<NDIM;i++) { | 
|---|
|  | 2132 | //                  repetition[i] = atoi(argv[argptr++]); | 
|---|
|  | 2133 | //                  if (repetition[i] < 1) | 
|---|
| [717e0c] | 2134 | //                    eLog() << Verbose(1) << "repetition value must be greater 1!" << endl; | 
|---|
| [042f82] | 2135 | //                  repetition[i] = 1; | 
|---|
|  | 2136 | //                } | 
|---|
| [e138de] | 2137 | PrepareClustersinWater(&configuration, mol, volume, density);  // if volume == 0, will calculate from ConvexEnvelope | 
|---|
| [042f82] | 2138 | } | 
|---|
|  | 2139 | break; | 
|---|
|  | 2140 | case 'd': | 
|---|
| [ebcade] | 2141 | if (ExitFlag == 0) ExitFlag = 1; | 
|---|
|  | 2142 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) { | 
|---|
| [042f82] | 2143 | ExitFlag = 255; | 
|---|
| [e138de] | 2144 | eLog() << Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl; | 
|---|
| [e359a8] | 2145 | performCriticalExit(); | 
|---|
| [042f82] | 2146 | } else { | 
|---|
|  | 2147 | SaveFlag = true; | 
|---|
|  | 2148 | for (int axis = 1; axis <= NDIM; axis++) { | 
|---|
|  | 2149 | int faktor = atoi(argv[argptr++]); | 
|---|
|  | 2150 | int count; | 
|---|
|  | 2151 | element ** Elements; | 
|---|
|  | 2152 | Vector ** vectors; | 
|---|
|  | 2153 | if (faktor < 1) { | 
|---|
| [717e0c] | 2154 | eLog() << Verbose(1) << "Repetition factor mus be greater than 1!" << endl; | 
|---|
| [042f82] | 2155 | faktor = 1; | 
|---|
|  | 2156 | } | 
|---|
| [e138de] | 2157 | mol->CountAtoms();  // recount atoms | 
|---|
| [042f82] | 2158 | if (mol->AtomCount != 0) {  // if there is more than none | 
|---|
|  | 2159 | count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand | 
|---|
|  | 2160 | Elements = new element *[count]; | 
|---|
|  | 2161 | vectors = new Vector *[count]; | 
|---|
|  | 2162 | j = 0; | 
|---|
|  | 2163 | first = mol->start; | 
|---|
|  | 2164 | while (first->next != mol->end) {  // make a list of all atoms with coordinates and element | 
|---|
|  | 2165 | first = first->next; | 
|---|
|  | 2166 | Elements[j] = first->type; | 
|---|
|  | 2167 | vectors[j] = &first->x; | 
|---|
|  | 2168 | j++; | 
|---|
|  | 2169 | } | 
|---|
|  | 2170 | if (count != j) | 
|---|
| [717e0c] | 2171 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl; | 
|---|
| [042f82] | 2172 | x.Zero(); | 
|---|
|  | 2173 | y.Zero(); | 
|---|
|  | 2174 | 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 | 
|---|
|  | 2175 | for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times | 
|---|
|  | 2176 | x.AddVector(&y); // per factor one cell width further | 
|---|
|  | 2177 | for (int k=count;k--;) { // go through every atom of the original cell | 
|---|
|  | 2178 | first = new atom(); // create a new body | 
|---|
|  | 2179 | first->x.CopyVector(vectors[k]);  // use coordinate of original atom | 
|---|
|  | 2180 | first->x.AddVector(&x);      // translate the coordinates | 
|---|
|  | 2181 | first->type = Elements[k];  // insert original element | 
|---|
|  | 2182 | mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) | 
|---|
|  | 2183 | } | 
|---|
|  | 2184 | } | 
|---|
|  | 2185 | // free memory | 
|---|
|  | 2186 | delete[](Elements); | 
|---|
|  | 2187 | delete[](vectors); | 
|---|
|  | 2188 | // correct cell size | 
|---|
|  | 2189 | if (axis < 0) { // if sign was negative, we have to translate everything | 
|---|
|  | 2190 | x.Zero(); | 
|---|
|  | 2191 | x.AddVector(&y); | 
|---|
|  | 2192 | x.Scale(-(faktor-1)); | 
|---|
|  | 2193 | mol->Translate(&x); | 
|---|
|  | 2194 | } | 
|---|
|  | 2195 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; | 
|---|
|  | 2196 | } | 
|---|
|  | 2197 | } | 
|---|
|  | 2198 | } | 
|---|
|  | 2199 | break; | 
|---|
|  | 2200 | default:   // no match? Step on | 
|---|
|  | 2201 | if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step! | 
|---|
|  | 2202 | argptr++; | 
|---|
|  | 2203 | break; | 
|---|
|  | 2204 | } | 
|---|
|  | 2205 | } | 
|---|
|  | 2206 | } else argptr++; | 
|---|
|  | 2207 | } while (argptr < argc); | 
|---|
|  | 2208 | if (SaveFlag) | 
|---|
|  | 2209 | SaveConfig(ConfigFileName, &configuration, periode, molecules); | 
|---|
|  | 2210 | } else {  // no arguments, hence scan the elements db | 
|---|
|  | 2211 | if (periode->LoadPeriodentafel(configuration.databasepath)) | 
|---|
| [e138de] | 2212 | Log() << Verbose(0) << "Element list loaded successfully." << endl; | 
|---|
| [042f82] | 2213 | else | 
|---|
| [e138de] | 2214 | Log() << Verbose(0) << "Element list loading failed." << endl; | 
|---|
| [042f82] | 2215 | configuration.RetrieveConfigPathAndName("main_pcp_linux"); | 
|---|
|  | 2216 | } | 
|---|
|  | 2217 | return(ExitFlag); | 
|---|
| [ca2b83] | 2218 | }; | 
|---|
|  | 2219 |  | 
|---|
|  | 2220 | /********************************************** Main routine **************************************/ | 
|---|
| [14de469] | 2221 |  | 
|---|
| [ca2b83] | 2222 | int main(int argc, char **argv) | 
|---|
|  | 2223 | { | 
|---|
| [042f82] | 2224 | periodentafel *periode = new periodentafel; // and a period table of all elements | 
|---|
|  | 2225 | MoleculeListClass *molecules = new MoleculeListClass;  // list of all molecules | 
|---|
|  | 2226 | molecule *mol = NULL; | 
|---|
| [db6bf74] | 2227 | config *configuration = new config; | 
|---|
| [042f82] | 2228 | char choice;  // menu choice char | 
|---|
|  | 2229 | Vector x,y,z,n;  // coordinates for absolute point in cell volume | 
|---|
|  | 2230 | ifstream test; | 
|---|
|  | 2231 | ofstream output; | 
|---|
|  | 2232 | string line; | 
|---|
|  | 2233 | char *ConfigFileName = NULL; | 
|---|
| [437922] | 2234 | int j; | 
|---|
| [042f82] | 2235 |  | 
|---|
| [a8eb4a] | 2236 | cout << ESPACKVersion << endl; | 
|---|
|  | 2237 |  | 
|---|
| [717e0c] | 2238 | setVerbosity(0); | 
|---|
| [e138de] | 2239 |  | 
|---|
| [042f82] | 2240 | // =========================== PARSE COMMAND LINE OPTIONS ==================================== | 
|---|
| [db6bf74] | 2241 | j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName); | 
|---|
| [042f82] | 2242 | switch(j) { | 
|---|
| [b6d8a9] | 2243 | case 255:  // something went wrong | 
|---|
| [c26f44] | 2244 | case 2:  // just for -f option | 
|---|
| [7218f8] | 2245 | case 1:  // just for -v and -h options | 
|---|
| [c26f44] | 2246 | delete(molecules); // also free's all molecules contained | 
|---|
|  | 2247 | delete(periode); | 
|---|
| [7218f8] | 2248 | delete(configuration); | 
|---|
| [e138de] | 2249 | Log() << Verbose(0) <<  "Maximum of allocated memory: " | 
|---|
| [c26f44] | 2250 | << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; | 
|---|
| [e138de] | 2251 | Log() << Verbose(0) <<  "Remaining non-freed memory: " | 
|---|
| [c26f44] | 2252 | << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; | 
|---|
| [7218f8] | 2253 | MemoryUsageObserver::getInstance()->purgeInstance(); | 
|---|
| [1614174] | 2254 | logger::purgeInstance(); | 
|---|
|  | 2255 | errorLogger::purgeInstance(); | 
|---|
| [7218f8] | 2256 | return (j == 1 ? 0 : j); | 
|---|
| [042f82] | 2257 | default: | 
|---|
|  | 2258 | break; | 
|---|
|  | 2259 | } | 
|---|
|  | 2260 |  | 
|---|
|  | 2261 | // General stuff | 
|---|
|  | 2262 | if (molecules->ListOfMolecules.size() == 0) { | 
|---|
| [1907a7] | 2263 | mol = new molecule(periode); | 
|---|
|  | 2264 | if (mol->cell_size[0] == 0.) { | 
|---|
| [e138de] | 2265 | Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl; | 
|---|
| [1907a7] | 2266 | for (int i=0;i<6;i++) { | 
|---|
| [e138de] | 2267 | Log() << Verbose(1) << "Cell size" << i << ": "; | 
|---|
| [1907a7] | 2268 | cin >> mol->cell_size[i]; | 
|---|
|  | 2269 | } | 
|---|
|  | 2270 | } | 
|---|
| [7218f8] | 2271 | mol->ActiveFlag = true; | 
|---|
| [1907a7] | 2272 | molecules->insert(mol); | 
|---|
| [042f82] | 2273 | } | 
|---|
| [6ac7ee] | 2274 |  | 
|---|
| [042f82] | 2275 | // =========================== START INTERACTIVE SESSION ==================================== | 
|---|
| [6ac7ee] | 2276 |  | 
|---|
| [042f82] | 2277 | // now the main construction loop | 
|---|
| [e138de] | 2278 | Log() << Verbose(0) << endl << "Now comes the real construction..." << endl; | 
|---|
| [042f82] | 2279 | do { | 
|---|
| [e138de] | 2280 | Log() << Verbose(0) << endl << endl; | 
|---|
|  | 2281 | Log() << Verbose(0) << "============Molecule list=======================" << endl; | 
|---|
| [042f82] | 2282 | molecules->Enumerate((ofstream *)&cout); | 
|---|
| [e138de] | 2283 | Log() << Verbose(0) << "============Menu===============================" << endl; | 
|---|
|  | 2284 | Log() << Verbose(0) << "a - set molecule (in)active" << endl; | 
|---|
|  | 2285 | Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl; | 
|---|
|  | 2286 | Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl; | 
|---|
|  | 2287 | Log() << Verbose(0) << "M - Merge molecules" << endl; | 
|---|
|  | 2288 | Log() << Verbose(0) << "m - manipulate atoms" << endl; | 
|---|
|  | 2289 | Log() << Verbose(0) << "-----------------------------------------------" << endl; | 
|---|
|  | 2290 | Log() << Verbose(0) << "c - edit the current configuration" << endl; | 
|---|
|  | 2291 | Log() << Verbose(0) << "-----------------------------------------------" << endl; | 
|---|
|  | 2292 | Log() << Verbose(0) << "s - save current setup to config file" << endl; | 
|---|
|  | 2293 | Log() << Verbose(0) << "T - call the current test routine" << endl; | 
|---|
|  | 2294 | Log() << Verbose(0) << "q - quit" << endl; | 
|---|
|  | 2295 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 2296 | Log() << Verbose(0) << "Input: "; | 
|---|
| [1907a7] | 2297 | cin >> choice; | 
|---|
| [6ac7ee] | 2298 |  | 
|---|
| [042f82] | 2299 | switch (choice) { | 
|---|
|  | 2300 | case 'a':  // (in)activate molecule | 
|---|
| [1907a7] | 2301 | { | 
|---|
| [e138de] | 2302 | Log() << Verbose(0) << "Enter index of molecule: "; | 
|---|
| [1907a7] | 2303 | cin >> j; | 
|---|
| [63f06e] | 2304 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 2305 | if ((*ListRunner)->IndexNr == j) | 
|---|
|  | 2306 | (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag; | 
|---|
| [1907a7] | 2307 | } | 
|---|
| [042f82] | 2308 | break; | 
|---|
| [1907a7] | 2309 |  | 
|---|
| [042f82] | 2310 | case 'c': // edit each field of the configuration | 
|---|
| [db6bf74] | 2311 | configuration->Edit(); | 
|---|
| [042f82] | 2312 | break; | 
|---|
| [6ac7ee] | 2313 |  | 
|---|
| [ca3ccc] | 2314 | case 'e': // create molecule | 
|---|
|  | 2315 | EditMolecules(periode, molecules); | 
|---|
|  | 2316 | break; | 
|---|
|  | 2317 |  | 
|---|
| [1907a7] | 2318 | case 'g': // manipulate molecules | 
|---|
| [db6bf74] | 2319 | ManipulateMolecules(periode, molecules, configuration); | 
|---|
| [1907a7] | 2320 | break; | 
|---|
| [6ac7ee] | 2321 |  | 
|---|
| [1907a7] | 2322 | case 'M':  // merge molecules | 
|---|
|  | 2323 | MergeMolecules(periode, molecules); | 
|---|
|  | 2324 | break; | 
|---|
| [6ac7ee] | 2325 |  | 
|---|
| [1907a7] | 2326 | case 'm': // manipulate atoms | 
|---|
| [db6bf74] | 2327 | ManipulateAtoms(periode, molecules, configuration); | 
|---|
| [1907a7] | 2328 | break; | 
|---|
| [6ac7ee] | 2329 |  | 
|---|
| [042f82] | 2330 | case 'q': // quit | 
|---|
|  | 2331 | break; | 
|---|
| [6ac7ee] | 2332 |  | 
|---|
| [042f82] | 2333 | case 's': // save to config file | 
|---|
| [db6bf74] | 2334 | SaveConfig(ConfigFileName, configuration, periode, molecules); | 
|---|
| [042f82] | 2335 | break; | 
|---|
| [6ac7ee] | 2336 |  | 
|---|
| [042f82] | 2337 | case 'T': | 
|---|
|  | 2338 | testroutine(molecules); | 
|---|
|  | 2339 | break; | 
|---|
| [6ac7ee] | 2340 |  | 
|---|
| [042f82] | 2341 | default: | 
|---|
|  | 2342 | break; | 
|---|
|  | 2343 | }; | 
|---|
|  | 2344 | } while (choice != 'q'); | 
|---|
|  | 2345 |  | 
|---|
|  | 2346 | // save element data base | 
|---|
| [db6bf74] | 2347 | if (periode->StorePeriodentafel(configuration->databasepath)) //ElementsFileName | 
|---|
| [e138de] | 2348 | Log() << Verbose(0) << "Saving of elements.db successful." << endl; | 
|---|
| [042f82] | 2349 | else | 
|---|
| [e138de] | 2350 | Log() << Verbose(0) << "Saving of elements.db failed." << endl; | 
|---|
| [042f82] | 2351 |  | 
|---|
|  | 2352 | delete(molecules); // also free's all molecules contained | 
|---|
|  | 2353 | delete(periode); | 
|---|
| [db6bf74] | 2354 | delete(configuration); | 
|---|
| [b66c22] | 2355 |  | 
|---|
| [e138de] | 2356 | Log() << Verbose(0) <<  "Maximum of allocated memory: " | 
|---|
| [b66c22] | 2357 | << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl; | 
|---|
| [e138de] | 2358 | Log() << Verbose(0) <<  "Remaining non-freed memory: " | 
|---|
| [b66c22] | 2359 | << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl; | 
|---|
| [db6bf74] | 2360 | MemoryUsageObserver::purgeInstance(); | 
|---|
| [1614174] | 2361 | logger::purgeInstance(); | 
|---|
|  | 2362 | errorLogger::purgeInstance(); | 
|---|
| [b66c22] | 2363 |  | 
|---|
| [042f82] | 2364 | return (0); | 
|---|
| [14de469] | 2365 | } | 
|---|
|  | 2366 |  | 
|---|
|  | 2367 | /********************************************** E N D **************************************************/ | 
|---|