| [85bc8e] | 1 | /** \file menu.cpp | 
|---|
|  | 2 | * The class in this file is responsible for displaying the menu and enabling choices. | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * This class is currently being refactored. Functions were copied from builder.cpp and are | 
|---|
|  | 5 | * to be imported into the menu class. | 
|---|
|  | 6 | * | 
|---|
|  | 7 | */ | 
|---|
|  | 8 |  | 
|---|
|  | 9 | #include "menu.hpp" | 
|---|
|  | 10 | #include "analysis_correlation.hpp" | 
|---|
|  | 11 | #include "atom.hpp" | 
|---|
|  | 12 | #include "bond.hpp" | 
|---|
|  | 13 | #include "bondgraph.hpp" | 
|---|
|  | 14 | #include "boundary.hpp" | 
|---|
|  | 15 | #include "config.hpp" | 
|---|
|  | 16 | #include "element.hpp" | 
|---|
|  | 17 | #include "ellipsoid.hpp" | 
|---|
|  | 18 | #include "helpers.hpp" | 
|---|
|  | 19 | #include "leastsquaremin.hpp" | 
|---|
|  | 20 | #include "linkedcell.hpp" | 
|---|
|  | 21 | #include "log.hpp" | 
|---|
|  | 22 | #include "memoryusageobserverunittest.hpp" | 
|---|
|  | 23 | #include "molecule.hpp" | 
|---|
|  | 24 | #include "periodentafel.hpp" | 
|---|
|  | 25 |  | 
|---|
| [65b6e0] | 26 | #include "Menu/Menu.hpp" | 
|---|
|  | 27 | #include "Menu/TextMenu.hpp" | 
|---|
|  | 28 | #include "Menu/ActionMenuItem.hpp" | 
|---|
|  | 29 | #include "Menu/SeperatorItem.hpp" | 
|---|
| [9d8609] | 30 | #include "Menu/DisplayMenuItem.hpp" | 
|---|
| [096214] | 31 | #include "Menu/SubMenuItem.hpp" | 
|---|
| [65b6e0] | 32 | #include "Actions/MethodAction.hpp" | 
|---|
| [9d8609] | 33 | #include "Views/StreamStringView.hpp" | 
|---|
|  | 34 | #include "Views/MethodStringView.hpp" | 
|---|
| [65b6e0] | 35 |  | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include <boost/bind.hpp> | 
|---|
|  | 38 |  | 
|---|
| [85bc8e] | 39 | /* copied methods for refactoring */ | 
|---|
|  | 40 | /*TODO: Move these methods inside menu class | 
|---|
|  | 41 | * and restructure menu class*/ | 
|---|
|  | 42 |  | 
|---|
|  | 43 | /********************************************* Subsubmenu routine ************************************/ | 
|---|
|  | 44 |  | 
|---|
|  | 45 | /** Submenu for adding atoms to the molecule. | 
|---|
|  | 46 | * \param *periode periodentafel | 
|---|
|  | 47 | * \param *molecule molecules with atoms | 
|---|
|  | 48 | */ | 
|---|
| [65b6e0] | 49 | void oldmenu::AddAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [85bc8e] | 50 | { | 
|---|
|  | 51 | atom *first, *second, *third, *fourth; | 
|---|
|  | 52 | Vector **atoms; | 
|---|
|  | 53 | Vector x,y,z,n;  // coordinates for absolute point in cell volume | 
|---|
|  | 54 | double a,b,c; | 
|---|
|  | 55 | char choice;  // menu choice char | 
|---|
|  | 56 | bool valid; | 
|---|
|  | 57 |  | 
|---|
|  | 58 | Log() << Verbose(0) << "===========ADD ATOM============================" << endl; | 
|---|
|  | 59 | Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl; | 
|---|
|  | 60 | Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl; | 
|---|
|  | 61 | Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl; | 
|---|
|  | 62 | Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl; | 
|---|
|  | 63 | Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl; | 
|---|
|  | 64 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 65 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 66 | Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl; | 
|---|
|  | 67 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 68 | cin >> choice; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | switch (choice) { | 
|---|
|  | 71 | default: | 
|---|
|  | 72 | eLog() << Verbose(2) << "Not a valid choice." << endl; | 
|---|
|  | 73 | break; | 
|---|
|  | 74 | case 'a': // absolute coordinates of atom | 
|---|
|  | 75 | Log() << Verbose(0) << "Enter absolute coordinates." << endl; | 
|---|
|  | 76 | first = new atom; | 
|---|
|  | 77 | first->x.AskPosition(mol->cell_size, false); | 
|---|
|  | 78 | first->type = periode->AskElement();  // give type | 
|---|
|  | 79 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 80 | break; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | case 'b': // relative coordinates of atom wrt to reference point | 
|---|
|  | 83 | first = new atom; | 
|---|
|  | 84 | valid = true; | 
|---|
|  | 85 | do { | 
|---|
|  | 86 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
|  | 87 | Log() << Verbose(0) << "Enter reference coordinates." << endl; | 
|---|
|  | 88 | x.AskPosition(mol->cell_size, true); | 
|---|
|  | 89 | Log() << Verbose(0) << "Enter relative coordinates." << endl; | 
|---|
|  | 90 | first->x.AskPosition(mol->cell_size, false); | 
|---|
|  | 91 | first->x.AddVector((const Vector *)&x); | 
|---|
|  | 92 | Log() << Verbose(0) << "\n"; | 
|---|
|  | 93 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 94 | first->type = periode->AskElement();  // give type | 
|---|
|  | 95 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 96 | break; | 
|---|
|  | 97 |  | 
|---|
|  | 98 | case 'c': // relative coordinates of atom wrt to already placed atom | 
|---|
|  | 99 | first = new atom; | 
|---|
|  | 100 | valid = true; | 
|---|
|  | 101 | do { | 
|---|
|  | 102 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
|  | 103 | second = mol->AskAtom("Enter atom number: "); | 
|---|
|  | 104 | Log() << Verbose(0) << "Enter relative coordinates." << endl; | 
|---|
|  | 105 | first->x.AskPosition(mol->cell_size, false); | 
|---|
|  | 106 | for (int i=NDIM;i--;) { | 
|---|
|  | 107 | first->x.x[i] += second->x.x[i]; | 
|---|
|  | 108 | } | 
|---|
|  | 109 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 110 | first->type = periode->AskElement();  // give type | 
|---|
|  | 111 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 112 | break; | 
|---|
|  | 113 |  | 
|---|
|  | 114 | case 'd': // two atoms, two angles and a distance | 
|---|
|  | 115 | first = new atom; | 
|---|
|  | 116 | valid = true; | 
|---|
|  | 117 | do { | 
|---|
|  | 118 | if (!valid) { | 
|---|
|  | 119 | eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl; | 
|---|
|  | 120 | } | 
|---|
|  | 121 | Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl; | 
|---|
|  | 122 | second = mol->AskAtom("Enter central atom: "); | 
|---|
|  | 123 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): "); | 
|---|
|  | 124 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): "); | 
|---|
|  | 125 | a = ask_value("Enter distance between central (first) and new atom: "); | 
|---|
|  | 126 | b = ask_value("Enter angle between new, first and second atom (degrees): "); | 
|---|
|  | 127 | b *= M_PI/180.; | 
|---|
|  | 128 | bound(&b, 0., 2.*M_PI); | 
|---|
|  | 129 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): "); | 
|---|
|  | 130 | c *= M_PI/180.; | 
|---|
|  | 131 | bound(&c, -M_PI, M_PI); | 
|---|
|  | 132 | Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl; | 
|---|
|  | 133 | /* | 
|---|
|  | 134 | second->Output(1,1,(ofstream *)&cout); | 
|---|
|  | 135 | third->Output(1,2,(ofstream *)&cout); | 
|---|
|  | 136 | fourth->Output(1,3,(ofstream *)&cout); | 
|---|
|  | 137 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x); | 
|---|
|  | 138 | x.Copyvector(&second->x); | 
|---|
|  | 139 | x.SubtractVector(&third->x); | 
|---|
|  | 140 | x.Copyvector(&fourth->x); | 
|---|
|  | 141 | x.SubtractVector(&third->x); | 
|---|
|  | 142 |  | 
|---|
|  | 143 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) { | 
|---|
|  | 144 | Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl; | 
|---|
|  | 145 | continue; | 
|---|
|  | 146 | } | 
|---|
|  | 147 | Log() << Verbose(0) << "resulting relative coordinates: "; | 
|---|
|  | 148 | z.Output(); | 
|---|
|  | 149 | Log() << Verbose(0) << endl; | 
|---|
|  | 150 | */ | 
|---|
|  | 151 | // calc axis vector | 
|---|
|  | 152 | x.CopyVector(&second->x); | 
|---|
|  | 153 | x.SubtractVector(&third->x); | 
|---|
|  | 154 | x.Normalize(); | 
|---|
|  | 155 | Log() << Verbose(0) << "x: ", | 
|---|
|  | 156 | x.Output(); | 
|---|
|  | 157 | Log() << Verbose(0) << endl; | 
|---|
|  | 158 | z.MakeNormalVector(&second->x,&third->x,&fourth->x); | 
|---|
|  | 159 | Log() << Verbose(0) << "z: ", | 
|---|
|  | 160 | z.Output(); | 
|---|
|  | 161 | Log() << Verbose(0) << endl; | 
|---|
|  | 162 | y.MakeNormalVector(&x,&z); | 
|---|
|  | 163 | Log() << Verbose(0) << "y: ", | 
|---|
|  | 164 | y.Output(); | 
|---|
|  | 165 | Log() << Verbose(0) << endl; | 
|---|
|  | 166 |  | 
|---|
|  | 167 | // rotate vector around first angle | 
|---|
|  | 168 | first->x.CopyVector(&x); | 
|---|
|  | 169 | first->x.RotateVector(&z,b - M_PI); | 
|---|
|  | 170 | Log() << Verbose(0) << "Rotated vector: ", | 
|---|
|  | 171 | first->x.Output(); | 
|---|
|  | 172 | Log() << Verbose(0) << endl; | 
|---|
|  | 173 | // remove the projection onto the rotation plane of the second angle | 
|---|
|  | 174 | n.CopyVector(&y); | 
|---|
|  | 175 | n.Scale(first->x.ScalarProduct(&y)); | 
|---|
|  | 176 | Log() << Verbose(0) << "N1: ", | 
|---|
|  | 177 | n.Output(); | 
|---|
|  | 178 | Log() << Verbose(0) << endl; | 
|---|
|  | 179 | first->x.SubtractVector(&n); | 
|---|
|  | 180 | Log() << Verbose(0) << "Subtracted vector: ", | 
|---|
|  | 181 | first->x.Output(); | 
|---|
|  | 182 | Log() << Verbose(0) << endl; | 
|---|
|  | 183 | n.CopyVector(&z); | 
|---|
|  | 184 | n.Scale(first->x.ScalarProduct(&z)); | 
|---|
|  | 185 | Log() << Verbose(0) << "N2: ", | 
|---|
|  | 186 | n.Output(); | 
|---|
|  | 187 | Log() << Verbose(0) << endl; | 
|---|
|  | 188 | first->x.SubtractVector(&n); | 
|---|
|  | 189 | Log() << Verbose(0) << "2nd subtracted vector: ", | 
|---|
|  | 190 | first->x.Output(); | 
|---|
|  | 191 | Log() << Verbose(0) << endl; | 
|---|
|  | 192 |  | 
|---|
|  | 193 | // rotate another vector around second angle | 
|---|
|  | 194 | n.CopyVector(&y); | 
|---|
|  | 195 | n.RotateVector(&x,c - M_PI); | 
|---|
|  | 196 | Log() << Verbose(0) << "2nd Rotated vector: ", | 
|---|
|  | 197 | n.Output(); | 
|---|
|  | 198 | Log() << Verbose(0) << endl; | 
|---|
|  | 199 |  | 
|---|
|  | 200 | // add the two linear independent vectors | 
|---|
|  | 201 | first->x.AddVector(&n); | 
|---|
|  | 202 | first->x.Normalize(); | 
|---|
|  | 203 | first->x.Scale(a); | 
|---|
|  | 204 | first->x.AddVector(&second->x); | 
|---|
|  | 205 |  | 
|---|
|  | 206 | Log() << Verbose(0) << "resulting coordinates: "; | 
|---|
|  | 207 | first->x.Output(); | 
|---|
|  | 208 | Log() << Verbose(0) << endl; | 
|---|
|  | 209 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 210 | first->type = periode->AskElement();  // give type | 
|---|
|  | 211 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 212 | break; | 
|---|
|  | 213 |  | 
|---|
|  | 214 | case 'e': // least square distance position to a set of atoms | 
|---|
|  | 215 | first = new atom; | 
|---|
|  | 216 | atoms = new (Vector*[128]); | 
|---|
|  | 217 | valid = true; | 
|---|
|  | 218 | for(int i=128;i--;) | 
|---|
|  | 219 | atoms[i] = NULL; | 
|---|
|  | 220 | int i=0, j=0; | 
|---|
|  | 221 | Log() << Verbose(0) << "Now we need at least three molecules.\n"; | 
|---|
|  | 222 | do { | 
|---|
|  | 223 | Log() << Verbose(0) << "Enter " << i+1 << "th atom: "; | 
|---|
|  | 224 | cin >> j; | 
|---|
|  | 225 | if (j != -1) { | 
|---|
|  | 226 | second = mol->FindAtom(j); | 
|---|
|  | 227 | atoms[i++] = &(second->x); | 
|---|
|  | 228 | } | 
|---|
|  | 229 | } while ((j != -1) && (i<128)); | 
|---|
|  | 230 | if (i >= 2) { | 
|---|
|  | 231 | first->x.LSQdistance((const Vector **)atoms, i); | 
|---|
|  | 232 |  | 
|---|
|  | 233 | first->x.Output(); | 
|---|
|  | 234 | first->type = periode->AskElement();  // give type | 
|---|
|  | 235 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 236 | } else { | 
|---|
|  | 237 | delete first; | 
|---|
|  | 238 | Log() << Verbose(0) << "Please enter at least two vectors!\n"; | 
|---|
|  | 239 | } | 
|---|
|  | 240 | break; | 
|---|
|  | 241 | }; | 
|---|
|  | 242 | }; | 
|---|
|  | 243 |  | 
|---|
|  | 244 | /** Submenu for centering the atoms in the molecule. | 
|---|
|  | 245 | * \param *mol molecule with all the atoms | 
|---|
|  | 246 | */ | 
|---|
| [65b6e0] | 247 | void oldmenu::CenterAtoms(molecule *mol) | 
|---|
| [85bc8e] | 248 | { | 
|---|
|  | 249 | Vector x, y, helper; | 
|---|
|  | 250 | char choice;  // menu choice char | 
|---|
|  | 251 |  | 
|---|
|  | 252 | Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl; | 
|---|
|  | 253 | Log() << Verbose(0) << " a - on origin" << endl; | 
|---|
|  | 254 | Log() << Verbose(0) << " b - on center of gravity" << endl; | 
|---|
|  | 255 | Log() << Verbose(0) << " c - within box with additional boundary" << endl; | 
|---|
|  | 256 | Log() << Verbose(0) << " d - within given simulation box" << endl; | 
|---|
|  | 257 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 258 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 259 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 260 | cin >> choice; | 
|---|
|  | 261 |  | 
|---|
|  | 262 | switch (choice) { | 
|---|
|  | 263 | default: | 
|---|
|  | 264 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 265 | break; | 
|---|
|  | 266 | case 'a': | 
|---|
|  | 267 | Log() << Verbose(0) << "Centering atoms in config file on origin." << endl; | 
|---|
|  | 268 | mol->CenterOrigin(); | 
|---|
|  | 269 | break; | 
|---|
|  | 270 | case 'b': | 
|---|
|  | 271 | Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl; | 
|---|
|  | 272 | mol->CenterPeriodic(); | 
|---|
|  | 273 | break; | 
|---|
|  | 274 | case 'c': | 
|---|
|  | 275 | Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl; | 
|---|
|  | 276 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 277 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
|  | 278 | cin >> y.x[i]; | 
|---|
|  | 279 | } | 
|---|
|  | 280 | mol->CenterEdge(&x);  // make every coordinate positive | 
|---|
|  | 281 | mol->Center.AddVector(&y); // translate by boundary | 
|---|
|  | 282 | helper.CopyVector(&y); | 
|---|
|  | 283 | helper.Scale(2.); | 
|---|
|  | 284 | helper.AddVector(&x); | 
|---|
|  | 285 | mol->SetBoxDimension(&helper);  // update Box of atoms by boundary | 
|---|
|  | 286 | break; | 
|---|
|  | 287 | case 'd': | 
|---|
|  | 288 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
|  | 289 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 290 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
|  | 291 | cin >> x.x[i]; | 
|---|
|  | 292 | } | 
|---|
|  | 293 | // update Box of atoms by boundary | 
|---|
|  | 294 | mol->SetBoxDimension(&x); | 
|---|
|  | 295 | // center | 
|---|
|  | 296 | mol->CenterInBox(); | 
|---|
|  | 297 | break; | 
|---|
|  | 298 | } | 
|---|
|  | 299 | }; | 
|---|
|  | 300 |  | 
|---|
|  | 301 | /** Submenu for aligning the atoms in the molecule. | 
|---|
|  | 302 | * \param *periode periodentafel | 
|---|
|  | 303 | * \param *mol molecule with all the atoms | 
|---|
|  | 304 | */ | 
|---|
| [65b6e0] | 305 | void oldmenu::AlignAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [85bc8e] | 306 | { | 
|---|
|  | 307 | atom *first, *second, *third; | 
|---|
|  | 308 | Vector x,n; | 
|---|
|  | 309 | char choice;  // menu choice char | 
|---|
|  | 310 |  | 
|---|
|  | 311 | Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl; | 
|---|
|  | 312 | Log() << Verbose(0) << " a - state three atoms defining align plane" << endl; | 
|---|
|  | 313 | Log() << Verbose(0) << " b - state alignment vector" << endl; | 
|---|
|  | 314 | Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl; | 
|---|
|  | 315 | Log() << Verbose(0) << " d - align automatically by least square fit" << endl; | 
|---|
|  | 316 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 317 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 318 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 319 | cin >> choice; | 
|---|
|  | 320 |  | 
|---|
|  | 321 | switch (choice) { | 
|---|
|  | 322 | default: | 
|---|
|  | 323 | case 'a': // three atoms defining mirror plane | 
|---|
|  | 324 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 325 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 326 | third = mol->AskAtom("Enter third atom: "); | 
|---|
|  | 327 |  | 
|---|
|  | 328 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x); | 
|---|
|  | 329 | break; | 
|---|
|  | 330 | case 'b': // normal vector of mirror plane | 
|---|
|  | 331 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; | 
|---|
|  | 332 | n.AskPosition(mol->cell_size,0); | 
|---|
|  | 333 | n.Normalize(); | 
|---|
|  | 334 | break; | 
|---|
|  | 335 | case 'c': // three atoms defining mirror plane | 
|---|
|  | 336 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 337 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 338 |  | 
|---|
|  | 339 | n.CopyVector((const Vector *)&first->x); | 
|---|
|  | 340 | n.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 341 | n.Normalize(); | 
|---|
|  | 342 | break; | 
|---|
|  | 343 | case 'd': | 
|---|
|  | 344 | char shorthand[4]; | 
|---|
|  | 345 | Vector a; | 
|---|
|  | 346 | struct lsq_params param; | 
|---|
|  | 347 | do { | 
|---|
|  | 348 | fprintf(stdout, "Enter the element of atoms to be chosen: "); | 
|---|
|  | 349 | fscanf(stdin, "%3s", shorthand); | 
|---|
|  | 350 | } while ((param.type = periode->FindElement(shorthand)) == NULL); | 
|---|
|  | 351 | Log() << Verbose(0) << "Element is " << param.type->name << endl; | 
|---|
|  | 352 | mol->GetAlignvector(¶m); | 
|---|
|  | 353 | for (int i=NDIM;i--;) { | 
|---|
|  | 354 | x.x[i] = gsl_vector_get(param.x,i); | 
|---|
|  | 355 | n.x[i] = gsl_vector_get(param.x,i+NDIM); | 
|---|
|  | 356 | } | 
|---|
|  | 357 | gsl_vector_free(param.x); | 
|---|
|  | 358 | Log() << Verbose(0) << "Offset vector: "; | 
|---|
|  | 359 | x.Output(); | 
|---|
|  | 360 | Log() << Verbose(0) << endl; | 
|---|
|  | 361 | n.Normalize(); | 
|---|
|  | 362 | break; | 
|---|
|  | 363 | }; | 
|---|
|  | 364 | Log() << Verbose(0) << "Alignment vector: "; | 
|---|
|  | 365 | n.Output(); | 
|---|
|  | 366 | Log() << Verbose(0) << endl; | 
|---|
|  | 367 | mol->Align(&n); | 
|---|
|  | 368 | }; | 
|---|
|  | 369 |  | 
|---|
|  | 370 | /** Submenu for mirroring the atoms in the molecule. | 
|---|
|  | 371 | * \param *mol molecule with all the atoms | 
|---|
|  | 372 | */ | 
|---|
| [65b6e0] | 373 | void oldmenu::MirrorAtoms(molecule *mol) | 
|---|
| [85bc8e] | 374 | { | 
|---|
|  | 375 | atom *first, *second, *third; | 
|---|
|  | 376 | Vector n; | 
|---|
|  | 377 | char choice;  // menu choice char | 
|---|
|  | 378 |  | 
|---|
|  | 379 | Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl; | 
|---|
|  | 380 | Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl; | 
|---|
|  | 381 | Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl; | 
|---|
|  | 382 | Log() << Verbose(0) << " c - state two atoms in normal direction" << endl; | 
|---|
|  | 383 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 384 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 385 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 386 | cin >> choice; | 
|---|
|  | 387 |  | 
|---|
|  | 388 | switch (choice) { | 
|---|
|  | 389 | default: | 
|---|
|  | 390 | case 'a': // three atoms defining mirror plane | 
|---|
|  | 391 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 392 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 393 | third = mol->AskAtom("Enter third atom: "); | 
|---|
|  | 394 |  | 
|---|
|  | 395 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x); | 
|---|
|  | 396 | break; | 
|---|
|  | 397 | case 'b': // normal vector of mirror plane | 
|---|
|  | 398 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl; | 
|---|
|  | 399 | n.AskPosition(mol->cell_size,0); | 
|---|
|  | 400 | n.Normalize(); | 
|---|
|  | 401 | break; | 
|---|
|  | 402 | case 'c': // three atoms defining mirror plane | 
|---|
|  | 403 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 404 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 405 |  | 
|---|
|  | 406 | n.CopyVector((const Vector *)&first->x); | 
|---|
|  | 407 | n.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 408 | n.Normalize(); | 
|---|
|  | 409 | break; | 
|---|
|  | 410 | }; | 
|---|
|  | 411 | Log() << Verbose(0) << "Normal vector: "; | 
|---|
|  | 412 | n.Output(); | 
|---|
|  | 413 | Log() << Verbose(0) << endl; | 
|---|
|  | 414 | mol->Mirror((const Vector *)&n); | 
|---|
|  | 415 | }; | 
|---|
|  | 416 |  | 
|---|
|  | 417 | /** Submenu for removing the atoms from the molecule. | 
|---|
|  | 418 | * \param *mol molecule with all the atoms | 
|---|
|  | 419 | */ | 
|---|
| [65b6e0] | 420 | void oldmenu::RemoveAtoms(molecule *mol) | 
|---|
| [85bc8e] | 421 | { | 
|---|
|  | 422 | atom *first, *second; | 
|---|
|  | 423 | int axis; | 
|---|
|  | 424 | double tmp1, tmp2; | 
|---|
|  | 425 | char choice;  // menu choice char | 
|---|
|  | 426 |  | 
|---|
|  | 427 | Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl; | 
|---|
|  | 428 | Log() << Verbose(0) << " a - state atom for removal by number" << endl; | 
|---|
|  | 429 | Log() << Verbose(0) << " b - keep only in radius around atom" << endl; | 
|---|
|  | 430 | Log() << Verbose(0) << " c - remove this with one axis greater value" << endl; | 
|---|
|  | 431 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 432 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 433 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 434 | cin >> choice; | 
|---|
|  | 435 |  | 
|---|
|  | 436 | switch (choice) { | 
|---|
|  | 437 | default: | 
|---|
|  | 438 | case 'a': | 
|---|
|  | 439 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: "))) | 
|---|
|  | 440 | Log() << Verbose(1) << "Atom removed." << endl; | 
|---|
|  | 441 | else | 
|---|
|  | 442 | Log() << Verbose(1) << "Atom not found." << endl; | 
|---|
|  | 443 | break; | 
|---|
|  | 444 | case 'b': | 
|---|
|  | 445 | second = mol->AskAtom("Enter number of atom as reference point: "); | 
|---|
|  | 446 | Log() << Verbose(0) << "Enter radius: "; | 
|---|
|  | 447 | cin >> tmp1; | 
|---|
|  | 448 | first = mol->start; | 
|---|
|  | 449 | second = first->next; | 
|---|
|  | 450 | while(second != mol->end) { | 
|---|
|  | 451 | first = second; | 
|---|
|  | 452 | second = first->next; | 
|---|
|  | 453 | if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ... | 
|---|
|  | 454 | mol->RemoveAtom(first); | 
|---|
|  | 455 | } | 
|---|
|  | 456 | break; | 
|---|
|  | 457 | case 'c': | 
|---|
|  | 458 | Log() << Verbose(0) << "Which axis is it: "; | 
|---|
|  | 459 | cin >> axis; | 
|---|
|  | 460 | Log() << Verbose(0) << "Lower boundary: "; | 
|---|
|  | 461 | cin >> tmp1; | 
|---|
|  | 462 | Log() << Verbose(0) << "Upper boundary: "; | 
|---|
|  | 463 | cin >> tmp2; | 
|---|
|  | 464 | first = mol->start; | 
|---|
|  | 465 | second = first->next; | 
|---|
|  | 466 | while(second != mol->end) { | 
|---|
|  | 467 | first = second; | 
|---|
|  | 468 | second = first->next; | 
|---|
|  | 469 | if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ... | 
|---|
|  | 470 | //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl; | 
|---|
|  | 471 | mol->RemoveAtom(first); | 
|---|
|  | 472 | } | 
|---|
|  | 473 | } | 
|---|
|  | 474 | break; | 
|---|
|  | 475 | }; | 
|---|
|  | 476 | //mol->Output(); | 
|---|
|  | 477 | choice = 'r'; | 
|---|
|  | 478 | }; | 
|---|
|  | 479 |  | 
|---|
|  | 480 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
|  | 481 | * \param *periode periodentafel | 
|---|
|  | 482 | * \param *mol molecule with all the atoms | 
|---|
|  | 483 | */ | 
|---|
| [65b6e0] | 484 | void oldmenu::MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration) | 
|---|
| [85bc8e] | 485 | { | 
|---|
|  | 486 | atom *first, *second, *third; | 
|---|
|  | 487 | Vector x,y; | 
|---|
|  | 488 | double min[256], tmp1, tmp2, tmp3; | 
|---|
|  | 489 | int Z; | 
|---|
|  | 490 | char choice;  // menu choice char | 
|---|
|  | 491 |  | 
|---|
|  | 492 | Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl; | 
|---|
|  | 493 | Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl; | 
|---|
|  | 494 | Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl; | 
|---|
|  | 495 | Log() << Verbose(0) << " c - calculate bond angle" << endl; | 
|---|
|  | 496 | Log() << Verbose(0) << " d - calculate principal axis of the system" << endl; | 
|---|
|  | 497 | Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl; | 
|---|
|  | 498 | Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl; | 
|---|
|  | 499 | Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl; | 
|---|
|  | 500 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 501 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 502 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 503 | cin >> choice; | 
|---|
|  | 504 |  | 
|---|
|  | 505 | switch(choice) { | 
|---|
|  | 506 | default: | 
|---|
|  | 507 | Log() << Verbose(1) << "Not a valid choice." << endl; | 
|---|
|  | 508 | break; | 
|---|
|  | 509 | case 'a': | 
|---|
|  | 510 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 511 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
|  | 512 | min[i] = 0.; | 
|---|
|  | 513 |  | 
|---|
|  | 514 | second = mol->start; | 
|---|
|  | 515 | while ((second->next != mol->end)) { | 
|---|
|  | 516 | second = second->next; // advance | 
|---|
|  | 517 | Z = second->type->Z; | 
|---|
|  | 518 | tmp1 = 0.; | 
|---|
|  | 519 | if (first != second) { | 
|---|
|  | 520 | x.CopyVector((const Vector *)&first->x); | 
|---|
|  | 521 | x.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 522 | tmp1 = x.Norm(); | 
|---|
|  | 523 | } | 
|---|
|  | 524 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1; | 
|---|
|  | 525 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl; | 
|---|
|  | 526 | } | 
|---|
|  | 527 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
|  | 528 | 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; | 
|---|
|  | 529 | break; | 
|---|
|  | 530 |  | 
|---|
|  | 531 | case 'b': | 
|---|
|  | 532 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 533 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 534 | for (int i=NDIM;i--;) | 
|---|
|  | 535 | min[i] = 0.; | 
|---|
|  | 536 | x.CopyVector((const Vector *)&first->x); | 
|---|
|  | 537 | x.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 538 | tmp1 = x.Norm(); | 
|---|
|  | 539 | Log() << Verbose(1) << "Distance vector is "; | 
|---|
|  | 540 | x.Output(); | 
|---|
|  | 541 | Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl; | 
|---|
|  | 542 | break; | 
|---|
|  | 543 |  | 
|---|
|  | 544 | case 'c': | 
|---|
|  | 545 | Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl; | 
|---|
|  | 546 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 547 | second = mol->AskAtom("Enter central atom: "); | 
|---|
|  | 548 | third  = mol->AskAtom("Enter last atom: "); | 
|---|
|  | 549 | tmp1 = tmp2 = tmp3 = 0.; | 
|---|
|  | 550 | x.CopyVector((const Vector *)&first->x); | 
|---|
|  | 551 | x.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 552 | y.CopyVector((const Vector *)&third->x); | 
|---|
|  | 553 | y.SubtractVector((const Vector *)&second->x); | 
|---|
|  | 554 | Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": "; | 
|---|
|  | 555 | Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; | 
|---|
|  | 556 | break; | 
|---|
|  | 557 | case 'd': | 
|---|
|  | 558 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl; | 
|---|
|  | 559 | Log() << Verbose(0) << "Shall we rotate? [0/1]: "; | 
|---|
|  | 560 | cin >> Z; | 
|---|
|  | 561 | if ((Z >=0) && (Z <=1)) | 
|---|
|  | 562 | mol->PrincipalAxisSystem((bool)Z); | 
|---|
|  | 563 | else | 
|---|
|  | 564 | mol->PrincipalAxisSystem(false); | 
|---|
|  | 565 | break; | 
|---|
|  | 566 | case 'e': | 
|---|
|  | 567 | { | 
|---|
|  | 568 | Log() << Verbose(0) << "Evaluating volume of the convex envelope."; | 
|---|
|  | 569 | class Tesselation *TesselStruct = NULL; | 
|---|
|  | 570 | const LinkedCell *LCList = NULL; | 
|---|
|  | 571 | LCList = new LinkedCell(mol, 10.); | 
|---|
|  | 572 | FindConvexBorder(mol, TesselStruct, LCList, NULL); | 
|---|
|  | 573 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration); | 
|---|
|  | 574 | Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\ | 
|---|
|  | 575 | delete(LCList); | 
|---|
|  | 576 | delete(TesselStruct); | 
|---|
|  | 577 | } | 
|---|
|  | 578 | break; | 
|---|
|  | 579 | case 'f': | 
|---|
|  | 580 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps); | 
|---|
|  | 581 | break; | 
|---|
|  | 582 | case 'g': | 
|---|
|  | 583 | { | 
|---|
|  | 584 | char filename[255]; | 
|---|
|  | 585 | Log() << Verbose(0) << "Please enter filename: " << endl; | 
|---|
|  | 586 | cin >> filename; | 
|---|
|  | 587 | Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl; | 
|---|
|  | 588 | ofstream *output = new ofstream(filename, ios::trunc); | 
|---|
|  | 589 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) | 
|---|
|  | 590 | Log() << Verbose(2) << "File could not be written." << endl; | 
|---|
|  | 591 | else | 
|---|
|  | 592 | Log() << Verbose(2) << "File stored." << endl; | 
|---|
|  | 593 | output->close(); | 
|---|
|  | 594 | delete(output); | 
|---|
|  | 595 | } | 
|---|
|  | 596 | break; | 
|---|
|  | 597 | } | 
|---|
|  | 598 | }; | 
|---|
|  | 599 |  | 
|---|
|  | 600 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
|  | 601 | * \param *mol molecule with all the atoms | 
|---|
|  | 602 | * \param *configuration configuration structure for the to be written config files of all fragments | 
|---|
|  | 603 | */ | 
|---|
| [65b6e0] | 604 | void oldmenu::FragmentAtoms(molecule *mol, config *configuration) | 
|---|
| [85bc8e] | 605 | { | 
|---|
|  | 606 | int Order1; | 
|---|
|  | 607 | clock_t start, end; | 
|---|
|  | 608 |  | 
|---|
|  | 609 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; | 
|---|
|  | 610 | Log() << Verbose(0) << "What's the desired bond order: "; | 
|---|
|  | 611 | cin >> Order1; | 
|---|
|  | 612 | if (mol->first->next != mol->last) {  // there are bonds | 
|---|
|  | 613 | start = clock(); | 
|---|
|  | 614 | mol->FragmentMolecule(Order1, configuration); | 
|---|
|  | 615 | end = clock(); | 
|---|
|  | 616 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
|  | 617 | } else | 
|---|
|  | 618 | Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl; | 
|---|
|  | 619 | }; | 
|---|
|  | 620 |  | 
|---|
|  | 621 | /********************************************** Submenu routine **************************************/ | 
|---|
|  | 622 |  | 
|---|
|  | 623 | /** Submenu for manipulating atoms. | 
|---|
|  | 624 | * \param *periode periodentafel | 
|---|
|  | 625 | * \param *molecules list of molecules whose atoms are to be manipulated | 
|---|
|  | 626 | */ | 
|---|
| [65b6e0] | 627 | void oldmenu::ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration) | 
|---|
| [85bc8e] | 628 | { | 
|---|
|  | 629 | atom *first, *second; | 
|---|
|  | 630 | molecule *mol = NULL; | 
|---|
|  | 631 | Vector x,y,z,n; // coordinates for absolute point in cell volume | 
|---|
|  | 632 | double *factor; // unit factor if desired | 
|---|
|  | 633 | double bond, minBond; | 
|---|
|  | 634 | char choice;  // menu choice char | 
|---|
|  | 635 | bool valid; | 
|---|
|  | 636 |  | 
|---|
|  | 637 | Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl; | 
|---|
|  | 638 | Log() << Verbose(0) << "a - add an atom" << endl; | 
|---|
|  | 639 | Log() << Verbose(0) << "r - remove an atom" << endl; | 
|---|
|  | 640 | Log() << Verbose(0) << "b - scale a bond between atoms" << endl; | 
|---|
|  | 641 | Log() << Verbose(0) << "u - change an atoms element" << endl; | 
|---|
|  | 642 | Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl; | 
|---|
|  | 643 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 644 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 645 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
|  | 646 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
|  | 647 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 648 | cin >> choice; | 
|---|
|  | 649 |  | 
|---|
|  | 650 | switch (choice) { | 
|---|
|  | 651 | default: | 
|---|
|  | 652 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 653 | break; | 
|---|
|  | 654 |  | 
|---|
|  | 655 | case 'a': // add atom | 
|---|
|  | 656 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 657 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 658 | mol = *ListRunner; | 
|---|
|  | 659 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 660 | AddAtoms(periode, mol); | 
|---|
|  | 661 | } | 
|---|
|  | 662 | break; | 
|---|
|  | 663 |  | 
|---|
|  | 664 | case 'b': // scale a bond | 
|---|
|  | 665 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 666 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 667 | mol = *ListRunner; | 
|---|
|  | 668 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 669 | Log() << Verbose(0) << "Scaling bond length between two atoms." << endl; | 
|---|
|  | 670 | first = mol->AskAtom("Enter first (fixed) atom: "); | 
|---|
|  | 671 | second = mol->AskAtom("Enter second (shifting) atom: "); | 
|---|
|  | 672 | minBond = 0.; | 
|---|
|  | 673 | for (int i=NDIM;i--;) | 
|---|
|  | 674 | minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]); | 
|---|
|  | 675 | minBond = sqrt(minBond); | 
|---|
|  | 676 | Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl; | 
|---|
|  | 677 | Log() << Verbose(0) << "Enter new bond length [a.u.]: "; | 
|---|
|  | 678 | cin >> bond; | 
|---|
|  | 679 | for (int i=NDIM;i--;) { | 
|---|
|  | 680 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond); | 
|---|
|  | 681 | } | 
|---|
|  | 682 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; | 
|---|
|  | 683 | //second->Output(second->type->No, 1); | 
|---|
|  | 684 | } | 
|---|
|  | 685 | break; | 
|---|
|  | 686 |  | 
|---|
|  | 687 | case 'c': // unit scaling of the metric | 
|---|
|  | 688 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 689 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 690 | mol = *ListRunner; | 
|---|
|  | 691 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 692 | Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl; | 
|---|
|  | 693 | Log() << Verbose(0) << "Enter three factors: "; | 
|---|
|  | 694 | factor = new double[NDIM]; | 
|---|
|  | 695 | cin >> factor[0]; | 
|---|
|  | 696 | cin >> factor[1]; | 
|---|
|  | 697 | cin >> factor[2]; | 
|---|
|  | 698 | valid = true; | 
|---|
|  | 699 | mol->Scale((const double ** const)&factor); | 
|---|
|  | 700 | delete[](factor); | 
|---|
|  | 701 | } | 
|---|
|  | 702 | break; | 
|---|
|  | 703 |  | 
|---|
|  | 704 | case 'l': // measure distances or angles | 
|---|
|  | 705 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 706 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 707 | mol = *ListRunner; | 
|---|
|  | 708 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 709 | MeasureAtoms(periode, mol, configuration); | 
|---|
|  | 710 | } | 
|---|
|  | 711 | break; | 
|---|
|  | 712 |  | 
|---|
|  | 713 | case 'r': // remove atom | 
|---|
|  | 714 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 715 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 716 | mol = *ListRunner; | 
|---|
|  | 717 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 718 | RemoveAtoms(mol); | 
|---|
|  | 719 | } | 
|---|
|  | 720 | break; | 
|---|
|  | 721 |  | 
|---|
|  | 722 | case 'u': // change an atom's element | 
|---|
|  | 723 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 724 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 725 | int Z; | 
|---|
|  | 726 | mol = *ListRunner; | 
|---|
|  | 727 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 728 | first = NULL; | 
|---|
|  | 729 | do { | 
|---|
|  | 730 | Log() << Verbose(0) << "Change the element of which atom: "; | 
|---|
|  | 731 | cin >> Z; | 
|---|
|  | 732 | } while ((first = mol->FindAtom(Z)) == NULL); | 
|---|
|  | 733 | Log() << Verbose(0) << "New element by atomic number Z: "; | 
|---|
|  | 734 | cin >> Z; | 
|---|
|  | 735 | first->type = periode->FindElement(Z); | 
|---|
|  | 736 | Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl; | 
|---|
|  | 737 | } | 
|---|
|  | 738 | break; | 
|---|
|  | 739 | } | 
|---|
|  | 740 | }; | 
|---|
|  | 741 |  | 
|---|
|  | 742 | /** Submenu for manipulating molecules. | 
|---|
|  | 743 | * \param *periode periodentafel | 
|---|
|  | 744 | * \param *molecules list of molecule to manipulate | 
|---|
|  | 745 | */ | 
|---|
| [65b6e0] | 746 | void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration) | 
|---|
| [85bc8e] | 747 | { | 
|---|
|  | 748 | atom *first = NULL; | 
|---|
|  | 749 | Vector x,y,z,n; // coordinates for absolute point in cell volume | 
|---|
|  | 750 | int j, axis, count, faktor; | 
|---|
|  | 751 | char choice;  // menu choice char | 
|---|
|  | 752 | molecule *mol = NULL; | 
|---|
|  | 753 | element **Elements; | 
|---|
|  | 754 | Vector **vectors; | 
|---|
|  | 755 | MoleculeLeafClass *Subgraphs = NULL; | 
|---|
|  | 756 |  | 
|---|
|  | 757 | Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl; | 
|---|
|  | 758 | Log() << Verbose(0) << "c - scale by unit transformation" << endl; | 
|---|
|  | 759 | Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl; | 
|---|
|  | 760 | Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl; | 
|---|
|  | 761 | Log() << Verbose(0) << "g - center atoms in box" << endl; | 
|---|
|  | 762 | Log() << Verbose(0) << "i - realign molecule" << endl; | 
|---|
|  | 763 | Log() << Verbose(0) << "m - mirror all molecules" << endl; | 
|---|
|  | 764 | Log() << Verbose(0) << "o - create connection matrix" << endl; | 
|---|
|  | 765 | Log() << Verbose(0) << "t - translate molecule by vector" << endl; | 
|---|
|  | 766 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 767 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 768 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
|  | 769 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
|  | 770 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 771 | cin >> choice; | 
|---|
|  | 772 |  | 
|---|
|  | 773 | switch (choice) { | 
|---|
|  | 774 | default: | 
|---|
|  | 775 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 776 | break; | 
|---|
|  | 777 |  | 
|---|
|  | 778 | case 'd': // duplicate the periodic cell along a given axis, given times | 
|---|
|  | 779 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 780 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 781 | mol = *ListRunner; | 
|---|
|  | 782 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 783 | Log() << Verbose(0) << "State the axis [(+-)123]: "; | 
|---|
|  | 784 | cin >> axis; | 
|---|
|  | 785 | Log() << Verbose(0) << "State the factor: "; | 
|---|
|  | 786 | cin >> faktor; | 
|---|
|  | 787 |  | 
|---|
|  | 788 | mol->CountAtoms(); // recount atoms | 
|---|
|  | 789 | if (mol->AtomCount != 0) {  // if there is more than none | 
|---|
|  | 790 | count = mol->AtomCount;  // is changed becausing of adding, thus has to be stored away beforehand | 
|---|
|  | 791 | Elements = new element *[count]; | 
|---|
|  | 792 | vectors = new Vector *[count]; | 
|---|
|  | 793 | j = 0; | 
|---|
|  | 794 | first = mol->start; | 
|---|
|  | 795 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element | 
|---|
|  | 796 | first = first->next; | 
|---|
|  | 797 | Elements[j] = first->type; | 
|---|
|  | 798 | vectors[j] = &first->x; | 
|---|
|  | 799 | j++; | 
|---|
|  | 800 | } | 
|---|
|  | 801 | if (count != j) | 
|---|
|  | 802 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl; | 
|---|
|  | 803 | x.Zero(); | 
|---|
|  | 804 | y.Zero(); | 
|---|
|  | 805 | 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 | 
|---|
|  | 806 | for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times | 
|---|
|  | 807 | x.AddVector(&y); // per factor one cell width further | 
|---|
|  | 808 | for (int k=count;k--;) { // go through every atom of the original cell | 
|---|
|  | 809 | first = new atom(); // create a new body | 
|---|
|  | 810 | first->x.CopyVector(vectors[k]);  // use coordinate of original atom | 
|---|
|  | 811 | first->x.AddVector(&x);     // translate the coordinates | 
|---|
|  | 812 | first->type = Elements[k];  // insert original element | 
|---|
|  | 813 | mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) | 
|---|
|  | 814 | } | 
|---|
|  | 815 | } | 
|---|
|  | 816 | if (mol->first->next != mol->last) // if connect matrix is present already, redo it | 
|---|
|  | 817 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 818 | // free memory | 
|---|
|  | 819 | delete[](Elements); | 
|---|
|  | 820 | delete[](vectors); | 
|---|
|  | 821 | // correct cell size | 
|---|
|  | 822 | if (axis < 0) { // if sign was negative, we have to translate everything | 
|---|
|  | 823 | x.Zero(); | 
|---|
|  | 824 | x.AddVector(&y); | 
|---|
|  | 825 | x.Scale(-(faktor-1)); | 
|---|
|  | 826 | mol->Translate(&x); | 
|---|
|  | 827 | } | 
|---|
|  | 828 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; | 
|---|
|  | 829 | } | 
|---|
|  | 830 | } | 
|---|
|  | 831 | break; | 
|---|
|  | 832 |  | 
|---|
|  | 833 | case 'f': | 
|---|
|  | 834 | FragmentAtoms(mol, configuration); | 
|---|
|  | 835 | break; | 
|---|
|  | 836 |  | 
|---|
|  | 837 | case 'g': // center the atoms | 
|---|
|  | 838 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 839 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 840 | mol = *ListRunner; | 
|---|
|  | 841 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 842 | CenterAtoms(mol); | 
|---|
|  | 843 | } | 
|---|
|  | 844 | break; | 
|---|
|  | 845 |  | 
|---|
|  | 846 | case 'i': // align all atoms | 
|---|
|  | 847 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 848 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 849 | mol = *ListRunner; | 
|---|
|  | 850 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 851 | AlignAtoms(periode, mol); | 
|---|
|  | 852 | } | 
|---|
|  | 853 | break; | 
|---|
|  | 854 |  | 
|---|
|  | 855 | case 'm': // mirror atoms along a given axis | 
|---|
|  | 856 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 857 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 858 | mol = *ListRunner; | 
|---|
|  | 859 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 860 | MirrorAtoms(mol); | 
|---|
|  | 861 | } | 
|---|
|  | 862 | break; | 
|---|
|  | 863 |  | 
|---|
|  | 864 | case 'o': // create the connection matrix | 
|---|
|  | 865 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 866 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 867 | mol = *ListRunner; | 
|---|
|  | 868 | double bonddistance; | 
|---|
|  | 869 | clock_t start,end; | 
|---|
|  | 870 | Log() << Verbose(0) << "What's the maximum bond distance: "; | 
|---|
|  | 871 | cin >> bonddistance; | 
|---|
|  | 872 | start = clock(); | 
|---|
|  | 873 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 874 | end = clock(); | 
|---|
|  | 875 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
|  | 876 | } | 
|---|
|  | 877 | break; | 
|---|
|  | 878 |  | 
|---|
|  | 879 | case 't': // translate all atoms | 
|---|
|  | 880 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 881 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 882 | mol = *ListRunner; | 
|---|
|  | 883 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 884 | Log() << Verbose(0) << "Enter translation vector." << endl; | 
|---|
|  | 885 | x.AskPosition(mol->cell_size,0); | 
|---|
|  | 886 | mol->Center.AddVector((const Vector *)&x); | 
|---|
|  | 887 | } | 
|---|
|  | 888 | break; | 
|---|
|  | 889 | } | 
|---|
|  | 890 | // Free all | 
|---|
|  | 891 | if (Subgraphs != NULL) {  // free disconnected subgraph list of DFS analysis was performed | 
|---|
|  | 892 | while (Subgraphs->next != NULL) { | 
|---|
|  | 893 | Subgraphs = Subgraphs->next; | 
|---|
|  | 894 | delete(Subgraphs->previous); | 
|---|
|  | 895 | } | 
|---|
|  | 896 | delete(Subgraphs); | 
|---|
|  | 897 | } | 
|---|
|  | 898 | }; | 
|---|
|  | 899 |  | 
|---|
|  | 900 |  | 
|---|
| [1020f0] | 901 | void oldmenu::createNewMolecule(periodentafel *periode,MoleculeListClass *molecules) { | 
|---|
| [477bb2] | 902 | molecules->createNewMolecule(periode); | 
|---|
| [1020f0] | 903 | }; | 
|---|
|  | 904 |  | 
|---|
|  | 905 | void oldmenu::loadFromXYZ(periodentafel *periode,MoleculeListClass *molecules){ | 
|---|
| [477bb2] | 906 | molecules->loadFromXYZ(periode); | 
|---|
| [1020f0] | 907 | } | 
|---|
|  | 908 |  | 
|---|
|  | 909 | void oldmenu::changeName(MoleculeListClass *molecules){ | 
|---|
| [477bb2] | 910 | molecules->changeName(); | 
|---|
| [1020f0] | 911 | } | 
|---|
|  | 912 |  | 
|---|
|  | 913 | void oldmenu::setMoleculeFilename(MoleculeListClass *molecules) { | 
|---|
| [477bb2] | 914 | molecules->setMoleculeFilename(); | 
|---|
| [1020f0] | 915 | } | 
|---|
|  | 916 |  | 
|---|
|  | 917 | void oldmenu::parseXYZIntoMolecule(MoleculeListClass *molecules){ | 
|---|
| [477bb2] | 918 | molecules->parseXYZIntoMolecule(); | 
|---|
| [1020f0] | 919 | }; | 
|---|
|  | 920 |  | 
|---|
|  | 921 | void oldmenu::eraseMolecule(MoleculeListClass *molecules){ | 
|---|
| [477bb2] | 922 | molecules->eraseMolecule(); | 
|---|
| [1020f0] | 923 | }; | 
|---|
|  | 924 |  | 
|---|
| [85bc8e] | 925 | /** Submenu for merging molecules. | 
|---|
|  | 926 | * \param *periode periodentafel | 
|---|
|  | 927 | * \param *molecules list of molecules to add to | 
|---|
|  | 928 | */ | 
|---|
| [65b6e0] | 929 | void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules) | 
|---|
| [85bc8e] | 930 | { | 
|---|
|  | 931 | char choice;  // menu choice char | 
|---|
|  | 932 |  | 
|---|
|  | 933 | Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl; | 
|---|
|  | 934 | Log() << Verbose(0) << "a - simple add of one molecule to another" << endl; | 
|---|
|  | 935 | Log() << Verbose(0) << "e - embedding merge of two molecules" << endl; | 
|---|
|  | 936 | Log() << Verbose(0) << "m - multi-merge of all molecules" << endl; | 
|---|
|  | 937 | Log() << Verbose(0) << "s - scatter merge of two molecules" << endl; | 
|---|
|  | 938 | Log() << Verbose(0) << "t - simple merge of two molecules" << endl; | 
|---|
|  | 939 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 940 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 941 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 942 | cin >> choice; | 
|---|
|  | 943 |  | 
|---|
|  | 944 | switch (choice) { | 
|---|
|  | 945 | default: | 
|---|
|  | 946 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 947 | break; | 
|---|
|  | 948 |  | 
|---|
|  | 949 | case 'a': | 
|---|
|  | 950 | { | 
|---|
|  | 951 | int src, dest; | 
|---|
|  | 952 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 953 | { | 
|---|
|  | 954 | do { | 
|---|
|  | 955 | Log() << Verbose(0) << "Enter index of destination molecule: "; | 
|---|
|  | 956 | cin >> dest; | 
|---|
|  | 957 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 958 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 959 | do { | 
|---|
|  | 960 | Log() << Verbose(0) << "Enter index of source molecule to add from: "; | 
|---|
|  | 961 | cin >> src; | 
|---|
|  | 962 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 963 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 964 | if ((src != -1) && (dest != -1)) | 
|---|
|  | 965 | molecules->SimpleAdd(srcmol, destmol); | 
|---|
|  | 966 | } | 
|---|
|  | 967 | } | 
|---|
|  | 968 | break; | 
|---|
|  | 969 |  | 
|---|
|  | 970 | case 'e': | 
|---|
|  | 971 | { | 
|---|
|  | 972 | int src, dest; | 
|---|
|  | 973 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 974 | do { | 
|---|
|  | 975 | Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): "; | 
|---|
|  | 976 | cin >> src; | 
|---|
|  | 977 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 978 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 979 | do { | 
|---|
|  | 980 | Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): "; | 
|---|
|  | 981 | cin >> dest; | 
|---|
|  | 982 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 983 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 984 | if ((src != -1) && (dest != -1)) | 
|---|
|  | 985 | molecules->EmbedMerge(destmol, srcmol); | 
|---|
|  | 986 | } | 
|---|
|  | 987 | break; | 
|---|
|  | 988 |  | 
|---|
|  | 989 | case 'm': | 
|---|
|  | 990 | { | 
|---|
|  | 991 | int nr; | 
|---|
|  | 992 | molecule *mol = NULL; | 
|---|
|  | 993 | do { | 
|---|
|  | 994 | Log() << Verbose(0) << "Enter index of molecule to merge into: "; | 
|---|
|  | 995 | cin >> nr; | 
|---|
|  | 996 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 997 | } while ((mol == NULL) && (nr != -1)); | 
|---|
|  | 998 | if (nr != -1) { | 
|---|
|  | 999 | int N = molecules->ListOfMolecules.size()-1; | 
|---|
|  | 1000 | int *src = new int(N); | 
|---|
|  | 1001 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 1002 | if ((*ListRunner)->IndexNr != nr) | 
|---|
|  | 1003 | src[N++] = (*ListRunner)->IndexNr; | 
|---|
|  | 1004 | molecules->SimpleMultiMerge(mol, src, N); | 
|---|
|  | 1005 | delete[](src); | 
|---|
|  | 1006 | } | 
|---|
|  | 1007 | } | 
|---|
|  | 1008 | break; | 
|---|
|  | 1009 |  | 
|---|
|  | 1010 | case 's': | 
|---|
|  | 1011 | Log() << Verbose(0) << "Not implemented yet." << endl; | 
|---|
|  | 1012 | break; | 
|---|
|  | 1013 |  | 
|---|
|  | 1014 | case 't': | 
|---|
|  | 1015 | { | 
|---|
|  | 1016 | int src, dest; | 
|---|
|  | 1017 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 1018 | { | 
|---|
|  | 1019 | do { | 
|---|
|  | 1020 | Log() << Verbose(0) << "Enter index of destination molecule: "; | 
|---|
|  | 1021 | cin >> dest; | 
|---|
|  | 1022 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 1023 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 1024 | do { | 
|---|
|  | 1025 | Log() << Verbose(0) << "Enter index of source molecule to merge into: "; | 
|---|
|  | 1026 | cin >> src; | 
|---|
|  | 1027 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 1028 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 1029 | if ((src != -1) && (dest != -1)) | 
|---|
|  | 1030 | molecules->SimpleMerge(srcmol, destmol); | 
|---|
|  | 1031 | } | 
|---|
|  | 1032 | } | 
|---|
|  | 1033 | break; | 
|---|
|  | 1034 | } | 
|---|
|  | 1035 | }; | 
|---|
|  | 1036 |  | 
|---|
|  | 1037 |  | 
|---|
|  | 1038 | /********************************************** Test routine **************************************/ | 
|---|
|  | 1039 |  | 
|---|
|  | 1040 | /** Is called always as option 'T' in the menu. | 
|---|
|  | 1041 | * \param *molecules list of molecules | 
|---|
|  | 1042 | */ | 
|---|
| [65b6e0] | 1043 | void oldmenu::testroutine(MoleculeListClass *molecules) | 
|---|
| [85bc8e] | 1044 | { | 
|---|
|  | 1045 | // the current test routine checks the functionality of the KeySet&Graph concept: | 
|---|
|  | 1046 | // We want to have a multiindex (the KeySet) describing a unique subgraph | 
|---|
|  | 1047 | int i, comp, counter=0; | 
|---|
|  | 1048 |  | 
|---|
|  | 1049 | // create a clone | 
|---|
|  | 1050 | molecule *mol = NULL; | 
|---|
|  | 1051 | if (molecules->ListOfMolecules.size() != 0) // clone | 
|---|
|  | 1052 | mol = (molecules->ListOfMolecules.front())->CopyMolecule(); | 
|---|
|  | 1053 | else { | 
|---|
|  | 1054 | eLog() << Verbose(0) << "I don't have anything to test on ... "; | 
|---|
|  | 1055 | performCriticalExit(); | 
|---|
|  | 1056 | return; | 
|---|
|  | 1057 | } | 
|---|
|  | 1058 | atom *Walker = mol->start; | 
|---|
|  | 1059 |  | 
|---|
|  | 1060 | // generate some KeySets | 
|---|
|  | 1061 | Log() << Verbose(0) << "Generating KeySets." << endl; | 
|---|
|  | 1062 | KeySet TestSets[mol->AtomCount+1]; | 
|---|
|  | 1063 | i=1; | 
|---|
|  | 1064 | while (Walker->next != mol->end) { | 
|---|
|  | 1065 | Walker = Walker->next; | 
|---|
|  | 1066 | for (int j=0;j<i;j++) { | 
|---|
|  | 1067 | TestSets[j].insert(Walker->nr); | 
|---|
|  | 1068 | } | 
|---|
|  | 1069 | i++; | 
|---|
|  | 1070 | } | 
|---|
|  | 1071 | Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl; | 
|---|
|  | 1072 | KeySetTestPair test; | 
|---|
|  | 1073 | test = TestSets[mol->AtomCount-1].insert(Walker->nr); | 
|---|
|  | 1074 | if (test.second) { | 
|---|
|  | 1075 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
|  | 1076 | } else { | 
|---|
|  | 1077 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl; | 
|---|
|  | 1078 | } | 
|---|
|  | 1079 | TestSets[mol->AtomCount].insert(mol->end->previous->nr); | 
|---|
|  | 1080 | TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr); | 
|---|
|  | 1081 |  | 
|---|
|  | 1082 | // constructing Graph structure | 
|---|
|  | 1083 | Log() << Verbose(0) << "Generating Subgraph class." << endl; | 
|---|
|  | 1084 | Graph Subgraphs; | 
|---|
|  | 1085 |  | 
|---|
|  | 1086 | // insert KeySets into Subgraphs | 
|---|
|  | 1087 | Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl; | 
|---|
|  | 1088 | for (int j=0;j<mol->AtomCount;j++) { | 
|---|
|  | 1089 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1090 | } | 
|---|
|  | 1091 | Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl; | 
|---|
|  | 1092 | GraphTestPair test2; | 
|---|
|  | 1093 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1094 | if (test2.second) { | 
|---|
|  | 1095 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
|  | 1096 | } else { | 
|---|
|  | 1097 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl; | 
|---|
|  | 1098 | } | 
|---|
|  | 1099 |  | 
|---|
|  | 1100 | // show graphs | 
|---|
|  | 1101 | Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl; | 
|---|
|  | 1102 | Graph::iterator A = Subgraphs.begin(); | 
|---|
|  | 1103 | while (A !=  Subgraphs.end()) { | 
|---|
|  | 1104 | Log() << Verbose(0) << (*A).second.first << ": "; | 
|---|
|  | 1105 | KeySet::iterator key = (*A).first.begin(); | 
|---|
|  | 1106 | comp = -1; | 
|---|
|  | 1107 | while (key != (*A).first.end()) { | 
|---|
|  | 1108 | if ((*key) > comp) | 
|---|
|  | 1109 | Log() << Verbose(0) << (*key) << " "; | 
|---|
|  | 1110 | else | 
|---|
|  | 1111 | Log() << Verbose(0) << (*key) << "! "; | 
|---|
|  | 1112 | comp = (*key); | 
|---|
|  | 1113 | key++; | 
|---|
|  | 1114 | } | 
|---|
|  | 1115 | Log() << Verbose(0) << endl; | 
|---|
|  | 1116 | A++; | 
|---|
|  | 1117 | } | 
|---|
|  | 1118 | delete(mol); | 
|---|
|  | 1119 | }; | 
|---|
|  | 1120 |  | 
|---|
| [65b6e0] | 1121 | oldmenu::oldmenu() | 
|---|
| [85bc8e] | 1122 | { | 
|---|
|  | 1123 | // TODO Auto-generated constructor stub | 
|---|
|  | 1124 | } | 
|---|
|  | 1125 |  | 
|---|
| [65b6e0] | 1126 | oldmenu::~oldmenu() | 
|---|
| [85bc8e] | 1127 | { | 
|---|
|  | 1128 | // TODO Auto-generated destructor stub | 
|---|
|  | 1129 | } | 
|---|
|  | 1130 |  | 
|---|
| [21c246] | 1131 | void oldmenu::notImplementedYet() { | 
|---|
|  | 1132 | Log() << Verbose(0) << "This method has not yet been moved to an appropriate class." << endl; | 
|---|
|  | 1133 | } | 
|---|
|  | 1134 |  | 
|---|
| [65b6e0] | 1135 | void oldmenu::perform(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName) | 
|---|
| [85bc8e] | 1136 | { | 
|---|
| [7c6f73] | 1137 |  | 
|---|
|  | 1138 | // build the main menu | 
|---|
| [65b6e0] | 1139 | TextMenu *main_menu = new TextMenu(Log() << Verbose(0), "Main Menu"); | 
|---|
|  | 1140 |  | 
|---|
| [9d8609] | 1141 | StringView *moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1)); | 
|---|
| [835a0f] | 1142 | new DisplayMenuItem(main_menu,moleculeView,"Molecule List"); | 
|---|
| [9d8609] | 1143 |  | 
|---|
|  | 1144 | new SeperatorItem(main_menu); | 
|---|
|  | 1145 |  | 
|---|
| [77675f] | 1146 | Action *setMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::flipChosen,molecules)); | 
|---|
| [21c246] | 1147 | new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction); | 
|---|
|  | 1148 |  | 
|---|
| [096214] | 1149 | TextMenu *edit_molecules_menu = new TextMenu(Log() << Verbose(0), "Edit Molecules"); | 
|---|
|  | 1150 | new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,edit_molecules_menu); | 
|---|
| [21c246] | 1151 |  | 
|---|
| [1fa107] | 1152 | Action *manipulateMoleculeAction = new MethodAction(boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration)); | 
|---|
| [21c246] | 1153 | new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction); | 
|---|
|  | 1154 |  | 
|---|
| [1fa107] | 1155 | Action *mergeMoleculeAction = new MethodAction(boost::bind(&oldmenu::MergeMolecules,this,periode, molecules)); | 
|---|
| [21c246] | 1156 | new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction); | 
|---|
|  | 1157 |  | 
|---|
| [1fa107] | 1158 | Action *manipulateAtomsAction = new MethodAction(boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration)); | 
|---|
| [21c246] | 1159 | new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction); | 
|---|
| [65b6e0] | 1160 |  | 
|---|
|  | 1161 | new SeperatorItem(main_menu); | 
|---|
| [21c246] | 1162 |  | 
|---|
| [1fa107] | 1163 | Action *editConfigAction = new MethodAction(boost::bind(&config::Edit,configuration)); | 
|---|
| [21c246] | 1164 | new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction); | 
|---|
|  | 1165 |  | 
|---|
| [65b6e0] | 1166 | new SeperatorItem(main_menu); | 
|---|
|  | 1167 |  | 
|---|
| [1fa107] | 1168 | Action *saveConfigAction = new MethodAction(boost::bind(&oldmenu::SaveConfig,this,ConfigFileName, configuration, periode, molecules)); | 
|---|
| [21c246] | 1169 | new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction); | 
|---|
| [65b6e0] | 1170 |  | 
|---|
| [1fa107] | 1171 | Action *doTestAction = new MethodAction(boost::bind(&oldmenu::testroutine,this,molecules)); | 
|---|
| [21c246] | 1172 | new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction); | 
|---|
|  | 1173 |  | 
|---|
| [1fa107] | 1174 | Action *quitAction = new MethodAction(boost::bind(&TextMenu::doQuit,main_menu)); | 
|---|
| [21c246] | 1175 | new ActionMenuItem('q',"quit",main_menu,quitAction); | 
|---|
| [65b6e0] | 1176 |  | 
|---|
| [096214] | 1177 | // build the EditMoleculesMenu | 
|---|
|  | 1178 | Action *createMoleculeAction = new MethodAction(boost::bind(&oldmenu::createNewMolecule,this,periode,molecules)); | 
|---|
|  | 1179 | new ActionMenuItem('c',"create new molecule",edit_molecules_menu,createMoleculeAction); | 
|---|
|  | 1180 |  | 
|---|
|  | 1181 | Action *loadMoleculeAction = new MethodAction(boost::bind(&oldmenu::loadFromXYZ,this,periode,molecules)); | 
|---|
|  | 1182 | new ActionMenuItem('l',"load molecule from xyz file",edit_molecules_menu,loadMoleculeAction); | 
|---|
|  | 1183 |  | 
|---|
|  | 1184 | Action *changeFilenameAction = new MethodAction(boost::bind(&oldmenu::changeName,this,molecules)); | 
|---|
|  | 1185 | new ActionMenuItem('n',"change molecule's name",edit_molecules_menu,changeFilenameAction); | 
|---|
|  | 1186 |  | 
|---|
|  | 1187 | Action *giveFilenameAction = new MethodAction(boost::bind(&oldmenu::setMoleculeFilename,this,molecules)); | 
|---|
|  | 1188 | new ActionMenuItem('N',"give molecules filename",edit_molecules_menu,giveFilenameAction); | 
|---|
|  | 1189 |  | 
|---|
|  | 1190 | Action *parseAtomsAction = new MethodAction(boost::bind(&oldmenu::parseXYZIntoMolecule,this,molecules)); | 
|---|
|  | 1191 | new ActionMenuItem('p',"parse atoms in xyz file into molecule",edit_molecules_menu,parseAtomsAction); | 
|---|
|  | 1192 |  | 
|---|
|  | 1193 | Action *eraseMoleculeAction = new MethodAction(boost::bind(&oldmenu::eraseMolecule,this,molecules)); | 
|---|
|  | 1194 | new ActionMenuItem('r',"remove a molecule",edit_molecules_menu,eraseMoleculeAction); | 
|---|
|  | 1195 |  | 
|---|
|  | 1196 | Action *returnAction = new MethodAction(boost::bind(&TextMenu::doQuit,edit_molecules_menu)); | 
|---|
|  | 1197 | MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",edit_molecules_menu,returnAction); | 
|---|
|  | 1198 |  | 
|---|
|  | 1199 | edit_molecules_menu->addDefault(returnItem); | 
|---|
| [65b6e0] | 1200 |  | 
|---|
|  | 1201 | main_menu->display(); | 
|---|
|  | 1202 |  | 
|---|
|  | 1203 |  | 
|---|
| [096214] | 1204 | delete main_menu; | 
|---|
|  | 1205 |  | 
|---|
|  | 1206 | // delete all actions and views contained in Menu | 
|---|
|  | 1207 | // TODO: find a better way to handle this | 
|---|
|  | 1208 |  | 
|---|
| [a306a2] | 1209 | delete moleculeView; | 
|---|
|  | 1210 |  | 
|---|
| [21c246] | 1211 | delete setMoleculeAction; | 
|---|
|  | 1212 | delete manipulateMoleculeAction; | 
|---|
|  | 1213 | delete mergeMoleculeAction; | 
|---|
|  | 1214 | delete manipulateAtomsAction; | 
|---|
|  | 1215 | delete editConfigAction; | 
|---|
|  | 1216 | delete saveConfigAction; | 
|---|
|  | 1217 | delete doTestAction; | 
|---|
|  | 1218 | delete quitAction; | 
|---|
| [65b6e0] | 1219 |  | 
|---|
| [096214] | 1220 | delete createMoleculeAction; | 
|---|
|  | 1221 | delete loadMoleculeAction; | 
|---|
|  | 1222 | delete changeFilenameAction; | 
|---|
|  | 1223 | delete giveFilenameAction; | 
|---|
|  | 1224 | delete parseAtomsAction; | 
|---|
|  | 1225 | delete eraseMoleculeAction; | 
|---|
|  | 1226 | delete returnAction; | 
|---|
| [85bc8e] | 1227 | }; | 
|---|
|  | 1228 |  | 
|---|
|  | 1229 | /** Tries given filename or standard on saving the config file. | 
|---|
|  | 1230 | * \param *ConfigFileName name of file | 
|---|
|  | 1231 | * \param *configuration pointer to configuration structure with all the values | 
|---|
|  | 1232 | * \param *periode pointer to periodentafel structure with all the elements | 
|---|
|  | 1233 | * \param *molecules list of molecules structure with all the atoms and coordinates | 
|---|
|  | 1234 | */ | 
|---|
| [65b6e0] | 1235 | void oldmenu::SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules) | 
|---|
| [85bc8e] | 1236 | { | 
|---|
|  | 1237 | char filename[MAXSTRINGSIZE]; | 
|---|
|  | 1238 | ofstream output; | 
|---|
|  | 1239 | molecule *mol = new molecule(periode); | 
|---|
|  | 1240 |  | 
|---|
|  | 1241 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
|  | 1242 | eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; | 
|---|
|  | 1243 | } | 
|---|
|  | 1244 |  | 
|---|
|  | 1245 |  | 
|---|
|  | 1246 | // first save as PDB data | 
|---|
|  | 1247 | if (ConfigFileName != NULL) | 
|---|
|  | 1248 | strcpy(filename, ConfigFileName); | 
|---|
| [992a54] | 1249 | else | 
|---|
| [85bc8e] | 1250 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1251 | Log() << Verbose(0) << "Saving as pdb input "; | 
|---|
|  | 1252 | if (configuration->SavePDB(filename, molecules)) | 
|---|
|  | 1253 | Log() << Verbose(0) << "done." << endl; | 
|---|
|  | 1254 | else | 
|---|
|  | 1255 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1256 |  | 
|---|
|  | 1257 | // then save as tremolo data file | 
|---|
|  | 1258 | if (ConfigFileName != NULL) | 
|---|
|  | 1259 | strcpy(filename, ConfigFileName); | 
|---|
| [992a54] | 1260 | else | 
|---|
| [85bc8e] | 1261 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1262 | Log() << Verbose(0) << "Saving as tremolo data input "; | 
|---|
|  | 1263 | if (configuration->SaveTREMOLO(filename, molecules)) | 
|---|
|  | 1264 | Log() << Verbose(0) << "done." << endl; | 
|---|
|  | 1265 | else | 
|---|
|  | 1266 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1267 |  | 
|---|
|  | 1268 | // translate each to its center and merge all molecules in MoleculeListClass into this molecule | 
|---|
|  | 1269 | int N = molecules->ListOfMolecules.size(); | 
|---|
|  | 1270 | int *src = new int[N]; | 
|---|
|  | 1271 | N=0; | 
|---|
|  | 1272 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { | 
|---|
|  | 1273 | src[N++] = (*ListRunner)->IndexNr; | 
|---|
|  | 1274 | (*ListRunner)->Translate(&(*ListRunner)->Center); | 
|---|
|  | 1275 | } | 
|---|
|  | 1276 | molecules->SimpleMultiAdd(mol, src, N); | 
|---|
|  | 1277 | delete[](src); | 
|---|
|  | 1278 |  | 
|---|
|  | 1279 | // ... and translate back | 
|---|
|  | 1280 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) { | 
|---|
|  | 1281 | (*ListRunner)->Center.Scale(-1.); | 
|---|
|  | 1282 | (*ListRunner)->Translate(&(*ListRunner)->Center); | 
|---|
|  | 1283 | (*ListRunner)->Center.Scale(-1.); | 
|---|
|  | 1284 | } | 
|---|
|  | 1285 |  | 
|---|
|  | 1286 | Log() << Verbose(0) << "Storing configuration ... " << endl; | 
|---|
|  | 1287 | // get correct valence orbitals | 
|---|
|  | 1288 | mol->CalculateOrbitals(*configuration); | 
|---|
|  | 1289 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble; | 
|---|
|  | 1290 | if (ConfigFileName != NULL) { // test the file name | 
|---|
|  | 1291 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1292 | output.open(filename, ios::trunc); | 
|---|
|  | 1293 | } else if (strlen(configuration->configname) != 0) { | 
|---|
|  | 1294 | strcpy(filename, configuration->configname); | 
|---|
|  | 1295 | output.open(configuration->configname, ios::trunc); | 
|---|
|  | 1296 | } else { | 
|---|
|  | 1297 | strcpy(filename, DEFAULTCONFIG); | 
|---|
|  | 1298 | output.open(DEFAULTCONFIG, ios::trunc); | 
|---|
|  | 1299 | } | 
|---|
|  | 1300 | output.close(); | 
|---|
|  | 1301 | output.clear(); | 
|---|
|  | 1302 | Log() << Verbose(0) << "Saving of config file "; | 
|---|
|  | 1303 | if (configuration->Save(filename, periode, mol)) | 
|---|
|  | 1304 | Log() << Verbose(0) << "successful." << endl; | 
|---|
|  | 1305 | else | 
|---|
|  | 1306 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1307 |  | 
|---|
|  | 1308 | // and save to xyz file | 
|---|
|  | 1309 | if (ConfigFileName != NULL) { | 
|---|
|  | 1310 | strcpy(filename, ConfigFileName); | 
|---|
|  | 1311 | strcat(filename, ".xyz"); | 
|---|
|  | 1312 | output.open(filename, ios::trunc); | 
|---|
|  | 1313 | } | 
|---|
| [992a54] | 1314 | else { | 
|---|
| [85bc8e] | 1315 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1316 | strcat(filename, ".xyz"); | 
|---|
|  | 1317 | output.open(filename, ios::trunc); | 
|---|
|  | 1318 | } | 
|---|
|  | 1319 | Log() << Verbose(0) << "Saving of XYZ file "; | 
|---|
|  | 1320 | if (mol->MDSteps <= 1) { | 
|---|
|  | 1321 | if (mol->OutputXYZ(&output)) | 
|---|
|  | 1322 | Log() << Verbose(0) << "successful." << endl; | 
|---|
|  | 1323 | else | 
|---|
|  | 1324 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1325 | } else { | 
|---|
|  | 1326 | if (mol->OutputTrajectoriesXYZ(&output)) | 
|---|
|  | 1327 | Log() << Verbose(0) << "successful." << endl; | 
|---|
|  | 1328 | else | 
|---|
|  | 1329 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1330 | } | 
|---|
|  | 1331 | output.close(); | 
|---|
|  | 1332 | output.clear(); | 
|---|
|  | 1333 |  | 
|---|
|  | 1334 | // and save as MPQC configuration | 
|---|
|  | 1335 | if (ConfigFileName != NULL) | 
|---|
|  | 1336 | strcpy(filename, ConfigFileName); | 
|---|
| [992a54] | 1337 | else | 
|---|
| [85bc8e] | 1338 | strcpy(filename,"main_pcp_linux"); | 
|---|
|  | 1339 | Log() << Verbose(0) << "Saving as mpqc input "; | 
|---|
|  | 1340 | if (configuration->SaveMPQC(filename, mol)) | 
|---|
|  | 1341 | Log() << Verbose(0) << "done." << endl; | 
|---|
|  | 1342 | else | 
|---|
|  | 1343 | Log() << Verbose(0) << "failed." << endl; | 
|---|
|  | 1344 |  | 
|---|
|  | 1345 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) { | 
|---|
|  | 1346 | eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl; | 
|---|
|  | 1347 | } | 
|---|
|  | 1348 |  | 
|---|
|  | 1349 | delete(mol); | 
|---|
|  | 1350 | }; | 
|---|