| [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 |  | 
|---|
| [442218] | 9 | #include "Legacy/oldmenu.hpp" | 
|---|
| [85bc8e] | 10 | #include "analysis_correlation.hpp" | 
|---|
| [46d958] | 11 | #include "World.hpp" | 
|---|
| [85bc8e] | 12 | #include "atom.hpp" | 
|---|
|  | 13 | #include "bond.hpp" | 
|---|
|  | 14 | #include "bondgraph.hpp" | 
|---|
|  | 15 | #include "boundary.hpp" | 
|---|
|  | 16 | #include "config.hpp" | 
|---|
|  | 17 | #include "element.hpp" | 
|---|
|  | 18 | #include "ellipsoid.hpp" | 
|---|
|  | 19 | #include "helpers.hpp" | 
|---|
|  | 20 | #include "leastsquaremin.hpp" | 
|---|
|  | 21 | #include "linkedcell.hpp" | 
|---|
|  | 22 | #include "log.hpp" | 
|---|
|  | 23 | #include "memoryusageobserverunittest.hpp" | 
|---|
|  | 24 | #include "molecule.hpp" | 
|---|
|  | 25 | #include "periodentafel.hpp" | 
|---|
| [0a4f7f] | 26 | #include "vector_ops.hpp" | 
|---|
|  | 27 | #include "Plane.hpp" | 
|---|
| [85bc8e] | 28 |  | 
|---|
| [29a4cc] | 29 | #include "UIElements/UIFactory.hpp" | 
|---|
|  | 30 | #include "UIElements/Dialog.hpp" | 
|---|
| [65b6e0] | 31 | #include "Menu/Menu.hpp" | 
|---|
|  | 32 | #include "Menu/TextMenu.hpp" | 
|---|
|  | 33 | #include "Menu/ActionMenuItem.hpp" | 
|---|
|  | 34 | #include "Menu/SeperatorItem.hpp" | 
|---|
| [9d8609] | 35 | #include "Menu/DisplayMenuItem.hpp" | 
|---|
| [096214] | 36 | #include "Menu/SubMenuItem.hpp" | 
|---|
| [97ebf8] | 37 | #include "Actions/MapOfActions.hpp" | 
|---|
| [65b6e0] | 38 | #include "Actions/MethodAction.hpp" | 
|---|
| [3e026a] | 39 | #include "Actions/ErrorAction.hpp" | 
|---|
| [9d8609] | 40 | #include "Views/StreamStringView.hpp" | 
|---|
|  | 41 | #include "Views/MethodStringView.hpp" | 
|---|
| [65b6e0] | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 | #include <boost/bind.hpp> | 
|---|
|  | 45 |  | 
|---|
| [85bc8e] | 46 | /* copied methods for refactoring */ | 
|---|
|  | 47 | /*TODO: Move these methods inside menu class | 
|---|
|  | 48 | * and restructure menu class*/ | 
|---|
|  | 49 |  | 
|---|
|  | 50 | /********************************************* Subsubmenu routine ************************************/ | 
|---|
|  | 51 |  | 
|---|
|  | 52 | /** Submenu for adding atoms to the molecule. | 
|---|
|  | 53 | * \param *periode periodentafel | 
|---|
|  | 54 | * \param *molecule molecules with atoms | 
|---|
|  | 55 | */ | 
|---|
| [65b6e0] | 56 | void oldmenu::AddAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [85bc8e] | 57 | { | 
|---|
|  | 58 | atom *first, *second, *third, *fourth; | 
|---|
|  | 59 | Vector **atoms; | 
|---|
|  | 60 | Vector x,y,z,n;  // coordinates for absolute point in cell volume | 
|---|
|  | 61 | double a,b,c; | 
|---|
|  | 62 | char choice;  // menu choice char | 
|---|
|  | 63 | bool valid; | 
|---|
| [8cbb97] | 64 | bool aborted; | 
|---|
| [85bc8e] | 65 |  | 
|---|
|  | 66 | Log() << Verbose(0) << "===========ADD ATOM============================" << endl; | 
|---|
|  | 67 | Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl; | 
|---|
|  | 68 | Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl; | 
|---|
|  | 69 | Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl; | 
|---|
|  | 70 | Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl; | 
|---|
|  | 71 | Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl; | 
|---|
|  | 72 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 73 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 74 | Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl; | 
|---|
|  | 75 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 76 | cin >> choice; | 
|---|
|  | 77 |  | 
|---|
|  | 78 | switch (choice) { | 
|---|
|  | 79 | default: | 
|---|
|  | 80 | eLog() << Verbose(2) << "Not a valid choice." << endl; | 
|---|
|  | 81 | break; | 
|---|
|  | 82 | case 'a': // absolute coordinates of atom | 
|---|
| [0a4f7f] | 83 | { | 
|---|
|  | 84 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [23b547] | 85 | first = World::getInstance().createAtom(); | 
|---|
| [8cbb97] | 86 | dialog->queryVector("Please enter coordinates: ",&first->x,World::getInstance().getDomain(), false); | 
|---|
|  | 87 | dialog->queryElement("Please choose element: ",&first->type); | 
|---|
| [0a4f7f] | 88 | if(dialog->display()){ | 
|---|
|  | 89 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 90 | } | 
|---|
|  | 91 | else{ | 
|---|
|  | 92 | World::getInstance().destroyAtom(first); | 
|---|
|  | 93 | } | 
|---|
|  | 94 | } | 
|---|
|  | 95 | break; | 
|---|
| [85bc8e] | 96 |  | 
|---|
|  | 97 | case 'b': // relative coordinates of atom wrt to reference point | 
|---|
| [23b547] | 98 | first = World::getInstance().createAtom(); | 
|---|
| [85bc8e] | 99 | valid = true; | 
|---|
| [8cbb97] | 100 | aborted = false; | 
|---|
| [85bc8e] | 101 | do { | 
|---|
|  | 102 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
| [8cbb97] | 103 | auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog()); | 
|---|
|  | 104 | dialog->queryVector("Enter reference coordinates.",&x,World::getInstance().getDomain(), true); | 
|---|
|  | 105 | dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false); | 
|---|
|  | 106 | if((aborted = !dialog->display())){ | 
|---|
|  | 107 | continue; | 
|---|
|  | 108 | } | 
|---|
| [273382] | 109 | first->x += x; | 
|---|
| [8cbb97] | 110 | } while (!aborted && !(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 111 | if(!aborted){ | 
|---|
|  | 112 | first->type = periode->AskElement();  // give type | 
|---|
|  | 113 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 114 | } | 
|---|
|  | 115 | else{ | 
|---|
|  | 116 | World::getInstance().destroyAtom(first); | 
|---|
|  | 117 | } | 
|---|
| [85bc8e] | 118 | break; | 
|---|
|  | 119 |  | 
|---|
|  | 120 | case 'c': // relative coordinates of atom wrt to already placed atom | 
|---|
| [0a4f7f] | 121 | { | 
|---|
| [23b547] | 122 | first = World::getInstance().createAtom(); | 
|---|
| [85bc8e] | 123 | valid = true; | 
|---|
|  | 124 | do { | 
|---|
|  | 125 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl; | 
|---|
| [8cbb97] | 126 | auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog()); | 
|---|
| [85bc8e] | 127 | second = mol->AskAtom("Enter atom number: "); | 
|---|
| [8cbb97] | 128 | dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false); | 
|---|
| [0a4f7f] | 129 | dialog->display(); | 
|---|
| [85bc8e] | 130 | for (int i=NDIM;i--;) { | 
|---|
| [0a4f7f] | 131 | first->x[i] += second->x[i]; | 
|---|
| [85bc8e] | 132 | } | 
|---|
|  | 133 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 134 | first->type = periode->AskElement();  // give type | 
|---|
|  | 135 | mol->AddAtom(first);  // add to molecule | 
|---|
| [0a4f7f] | 136 | } | 
|---|
|  | 137 | break; | 
|---|
| [85bc8e] | 138 |  | 
|---|
|  | 139 | case 'd': // two atoms, two angles and a distance | 
|---|
| [23b547] | 140 | first = World::getInstance().createAtom(); | 
|---|
| [85bc8e] | 141 | valid = true; | 
|---|
|  | 142 | do { | 
|---|
|  | 143 | if (!valid) { | 
|---|
|  | 144 | eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl; | 
|---|
|  | 145 | } | 
|---|
|  | 146 | Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl; | 
|---|
|  | 147 | second = mol->AskAtom("Enter central atom: "); | 
|---|
|  | 148 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): "); | 
|---|
|  | 149 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): "); | 
|---|
|  | 150 | a = ask_value("Enter distance between central (first) and new atom: "); | 
|---|
|  | 151 | b = ask_value("Enter angle between new, first and second atom (degrees): "); | 
|---|
|  | 152 | b *= M_PI/180.; | 
|---|
|  | 153 | bound(&b, 0., 2.*M_PI); | 
|---|
|  | 154 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): "); | 
|---|
|  | 155 | c *= M_PI/180.; | 
|---|
|  | 156 | bound(&c, -M_PI, M_PI); | 
|---|
|  | 157 | Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl; | 
|---|
|  | 158 | /* | 
|---|
|  | 159 | second->Output(1,1,(ofstream *)&cout); | 
|---|
|  | 160 | third->Output(1,2,(ofstream *)&cout); | 
|---|
|  | 161 | fourth->Output(1,3,(ofstream *)&cout); | 
|---|
|  | 162 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x); | 
|---|
|  | 163 | x.Copyvector(&second->x); | 
|---|
|  | 164 | x.SubtractVector(&third->x); | 
|---|
|  | 165 | x.Copyvector(&fourth->x); | 
|---|
|  | 166 | x.SubtractVector(&third->x); | 
|---|
|  | 167 |  | 
|---|
|  | 168 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) { | 
|---|
|  | 169 | Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl; | 
|---|
|  | 170 | continue; | 
|---|
|  | 171 | } | 
|---|
|  | 172 | Log() << Verbose(0) << "resulting relative coordinates: "; | 
|---|
|  | 173 | z.Output(); | 
|---|
|  | 174 | Log() << Verbose(0) << endl; | 
|---|
|  | 175 | */ | 
|---|
|  | 176 | // calc axis vector | 
|---|
| [273382] | 177 | x= second->x - third->x; | 
|---|
| [85bc8e] | 178 | x.Normalize(); | 
|---|
| [0a4f7f] | 179 | Log() << Verbose(0) << "x: " << x << endl; | 
|---|
|  | 180 | z = Plane(second->x,third->x,fourth->x).getNormal(); | 
|---|
|  | 181 | Log() << Verbose(0) << "z: " << z << endl; | 
|---|
|  | 182 | y = Plane(x,z,0).getNormal(); | 
|---|
|  | 183 | Log() << Verbose(0) << "y: " << y << endl; | 
|---|
| [85bc8e] | 184 |  | 
|---|
|  | 185 | // rotate vector around first angle | 
|---|
| [273382] | 186 | first->x = x; | 
|---|
| [0a4f7f] | 187 | first->x = RotateVector(first->x,z,b - M_PI); | 
|---|
|  | 188 | Log() << Verbose(0) << "Rotated vector: " << first->x << endl, | 
|---|
| [85bc8e] | 189 | // remove the projection onto the rotation plane of the second angle | 
|---|
| [273382] | 190 | n = y; | 
|---|
|  | 191 | n.Scale(first->x.ScalarProduct(y)); | 
|---|
| [0a4f7f] | 192 | Log() << Verbose(0) << "N1: " << n << endl; | 
|---|
| [273382] | 193 | first->x -= n; | 
|---|
| [0a4f7f] | 194 | Log() << Verbose(0) << "Subtracted vector: " << first->x << endl; | 
|---|
| [273382] | 195 | n = z; | 
|---|
|  | 196 | n.Scale(first->x.ScalarProduct(z)); | 
|---|
| [0a4f7f] | 197 | Log() << Verbose(0) << "N2: " << n << endl; | 
|---|
| [273382] | 198 | first->x -= n; | 
|---|
| [0a4f7f] | 199 | Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl; | 
|---|
| [85bc8e] | 200 |  | 
|---|
|  | 201 | // rotate another vector around second angle | 
|---|
| [273382] | 202 | n = y; | 
|---|
| [0a4f7f] | 203 | n = RotateVector(n,x,c - M_PI); | 
|---|
|  | 204 | Log() << Verbose(0) << "2nd Rotated vector: " << n << endl; | 
|---|
| [85bc8e] | 205 |  | 
|---|
|  | 206 | // add the two linear independent vectors | 
|---|
| [273382] | 207 | first->x += n; | 
|---|
| [85bc8e] | 208 | first->x.Normalize(); | 
|---|
|  | 209 | first->x.Scale(a); | 
|---|
| [273382] | 210 | first->x += second->x; | 
|---|
| [85bc8e] | 211 |  | 
|---|
| [0a4f7f] | 212 | Log() << Verbose(0) << "resulting coordinates: " << first->x << endl; | 
|---|
| [85bc8e] | 213 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x))); | 
|---|
|  | 214 | first->type = periode->AskElement();  // give type | 
|---|
|  | 215 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 216 | break; | 
|---|
|  | 217 |  | 
|---|
|  | 218 | case 'e': // least square distance position to a set of atoms | 
|---|
| [23b547] | 219 | first = World::getInstance().createAtom(); | 
|---|
| [85bc8e] | 220 | atoms = new (Vector*[128]); | 
|---|
|  | 221 | valid = true; | 
|---|
|  | 222 | for(int i=128;i--;) | 
|---|
|  | 223 | atoms[i] = NULL; | 
|---|
|  | 224 | int i=0, j=0; | 
|---|
|  | 225 | Log() << Verbose(0) << "Now we need at least three molecules.\n"; | 
|---|
|  | 226 | do { | 
|---|
|  | 227 | Log() << Verbose(0) << "Enter " << i+1 << "th atom: "; | 
|---|
|  | 228 | cin >> j; | 
|---|
|  | 229 | if (j != -1) { | 
|---|
|  | 230 | second = mol->FindAtom(j); | 
|---|
|  | 231 | atoms[i++] = &(second->x); | 
|---|
|  | 232 | } | 
|---|
|  | 233 | } while ((j != -1) && (i<128)); | 
|---|
|  | 234 | if (i >= 2) { | 
|---|
| [0a4f7f] | 235 | LSQdistance(first->x,(const Vector **)atoms, i); | 
|---|
| [85bc8e] | 236 |  | 
|---|
| [0a4f7f] | 237 | Log() << Verbose(0) << first->x; | 
|---|
| [85bc8e] | 238 | first->type = periode->AskElement();  // give type | 
|---|
|  | 239 | mol->AddAtom(first);  // add to molecule | 
|---|
|  | 240 | } else { | 
|---|
| [23b547] | 241 | World::getInstance().destroyAtom(first); | 
|---|
| [85bc8e] | 242 | Log() << Verbose(0) << "Please enter at least two vectors!\n"; | 
|---|
|  | 243 | } | 
|---|
|  | 244 | break; | 
|---|
|  | 245 | }; | 
|---|
|  | 246 | }; | 
|---|
|  | 247 |  | 
|---|
|  | 248 | /** Submenu for centering the atoms in the molecule. | 
|---|
|  | 249 | * \param *mol molecule with all the atoms | 
|---|
|  | 250 | */ | 
|---|
| [65b6e0] | 251 | void oldmenu::CenterAtoms(molecule *mol) | 
|---|
| [85bc8e] | 252 | { | 
|---|
|  | 253 | Vector x, y, helper; | 
|---|
|  | 254 | char choice;  // menu choice char | 
|---|
|  | 255 |  | 
|---|
|  | 256 | Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl; | 
|---|
|  | 257 | Log() << Verbose(0) << " a - on origin" << endl; | 
|---|
|  | 258 | Log() << Verbose(0) << " b - on center of gravity" << endl; | 
|---|
|  | 259 | Log() << Verbose(0) << " c - within box with additional boundary" << endl; | 
|---|
|  | 260 | Log() << Verbose(0) << " d - within given simulation box" << endl; | 
|---|
|  | 261 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 262 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 263 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 264 | cin >> choice; | 
|---|
|  | 265 |  | 
|---|
|  | 266 | switch (choice) { | 
|---|
|  | 267 | default: | 
|---|
|  | 268 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 269 | break; | 
|---|
|  | 270 | case 'a': | 
|---|
|  | 271 | Log() << Verbose(0) << "Centering atoms in config file on origin." << endl; | 
|---|
|  | 272 | mol->CenterOrigin(); | 
|---|
|  | 273 | break; | 
|---|
|  | 274 | case 'b': | 
|---|
|  | 275 | Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl; | 
|---|
|  | 276 | mol->CenterPeriodic(); | 
|---|
|  | 277 | break; | 
|---|
|  | 278 | case 'c': | 
|---|
|  | 279 | Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl; | 
|---|
|  | 280 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 281 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [0a4f7f] | 282 | cin >> y[i]; | 
|---|
| [85bc8e] | 283 | } | 
|---|
|  | 284 | mol->CenterEdge(&x);  // make every coordinate positive | 
|---|
| [273382] | 285 | mol->Center += y; // translate by boundary | 
|---|
|  | 286 | helper = (2*y)+x; | 
|---|
| [85bc8e] | 287 | mol->SetBoxDimension(&helper);  // update Box of atoms by boundary | 
|---|
|  | 288 | break; | 
|---|
|  | 289 | case 'd': | 
|---|
|  | 290 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl; | 
|---|
|  | 291 | for (int i=0;i<NDIM;i++) { | 
|---|
|  | 292 | Log() << Verbose(0) << "Enter axis " << i << " boundary: "; | 
|---|
| [0a4f7f] | 293 | cin >> x[i]; | 
|---|
| [85bc8e] | 294 | } | 
|---|
|  | 295 | // update Box of atoms by boundary | 
|---|
|  | 296 | mol->SetBoxDimension(&x); | 
|---|
|  | 297 | // center | 
|---|
|  | 298 | mol->CenterInBox(); | 
|---|
|  | 299 | break; | 
|---|
|  | 300 | } | 
|---|
|  | 301 | }; | 
|---|
|  | 302 |  | 
|---|
|  | 303 | /** Submenu for aligning the atoms in the molecule. | 
|---|
|  | 304 | * \param *periode periodentafel | 
|---|
|  | 305 | * \param *mol molecule with all the atoms | 
|---|
|  | 306 | */ | 
|---|
| [65b6e0] | 307 | void oldmenu::AlignAtoms(periodentafel *periode, molecule *mol) | 
|---|
| [85bc8e] | 308 | { | 
|---|
|  | 309 | atom *first, *second, *third; | 
|---|
|  | 310 | Vector x,n; | 
|---|
|  | 311 | char choice;  // menu choice char | 
|---|
|  | 312 |  | 
|---|
|  | 313 | Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl; | 
|---|
|  | 314 | Log() << Verbose(0) << " a - state three atoms defining align plane" << endl; | 
|---|
|  | 315 | Log() << Verbose(0) << " b - state alignment vector" << endl; | 
|---|
|  | 316 | Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl; | 
|---|
|  | 317 | Log() << Verbose(0) << " d - align automatically by least square fit" << endl; | 
|---|
|  | 318 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 319 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 320 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 321 | cin >> choice; | 
|---|
|  | 322 |  | 
|---|
|  | 323 | switch (choice) { | 
|---|
|  | 324 | default: | 
|---|
|  | 325 | case 'a': // three atoms defining mirror plane | 
|---|
|  | 326 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 327 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 328 | third = mol->AskAtom("Enter third atom: "); | 
|---|
|  | 329 |  | 
|---|
| [0a4f7f] | 330 | n = Plane(first->x,second->x,third->x).getNormal(); | 
|---|
| [85bc8e] | 331 | break; | 
|---|
|  | 332 | case 'b': // normal vector of mirror plane | 
|---|
| [0a4f7f] | 333 | { | 
|---|
|  | 334 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [8cbb97] | 335 | dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false); | 
|---|
| [0a4f7f] | 336 | dialog->display(); | 
|---|
|  | 337 | delete dialog; | 
|---|
| [85bc8e] | 338 | n.Normalize(); | 
|---|
| [0a4f7f] | 339 | } | 
|---|
|  | 340 | break; | 
|---|
|  | 341 |  | 
|---|
| [85bc8e] | 342 | case 'c': // three atoms defining mirror plane | 
|---|
|  | 343 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 344 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 345 |  | 
|---|
| [273382] | 346 | n = first->x - second->x; | 
|---|
| [85bc8e] | 347 | n.Normalize(); | 
|---|
|  | 348 | break; | 
|---|
|  | 349 | case 'd': | 
|---|
|  | 350 | char shorthand[4]; | 
|---|
|  | 351 | Vector a; | 
|---|
|  | 352 | struct lsq_params param; | 
|---|
|  | 353 | do { | 
|---|
|  | 354 | fprintf(stdout, "Enter the element of atoms to be chosen: "); | 
|---|
|  | 355 | fscanf(stdin, "%3s", shorthand); | 
|---|
|  | 356 | } while ((param.type = periode->FindElement(shorthand)) == NULL); | 
|---|
|  | 357 | Log() << Verbose(0) << "Element is " << param.type->name << endl; | 
|---|
|  | 358 | mol->GetAlignvector(¶m); | 
|---|
|  | 359 | for (int i=NDIM;i--;) { | 
|---|
| [0a4f7f] | 360 | x[i] = gsl_vector_get(param.x,i); | 
|---|
|  | 361 | n[i] = gsl_vector_get(param.x,i+NDIM); | 
|---|
| [85bc8e] | 362 | } | 
|---|
|  | 363 | gsl_vector_free(param.x); | 
|---|
| [0a4f7f] | 364 | Log() << Verbose(0) << "Offset vector: " << x << endl; | 
|---|
| [85bc8e] | 365 | n.Normalize(); | 
|---|
|  | 366 | break; | 
|---|
|  | 367 | }; | 
|---|
| [0a4f7f] | 368 | Log() << Verbose(0) << "Alignment vector: " << n << endl; | 
|---|
| [85bc8e] | 369 | mol->Align(&n); | 
|---|
|  | 370 | }; | 
|---|
|  | 371 |  | 
|---|
|  | 372 | /** Submenu for mirroring the atoms in the molecule. | 
|---|
|  | 373 | * \param *mol molecule with all the atoms | 
|---|
|  | 374 | */ | 
|---|
| [65b6e0] | 375 | void oldmenu::MirrorAtoms(molecule *mol) | 
|---|
| [85bc8e] | 376 | { | 
|---|
|  | 377 | atom *first, *second, *third; | 
|---|
|  | 378 | Vector n; | 
|---|
|  | 379 | char choice;  // menu choice char | 
|---|
|  | 380 |  | 
|---|
|  | 381 | Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl; | 
|---|
|  | 382 | Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl; | 
|---|
|  | 383 | Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl; | 
|---|
|  | 384 | Log() << Verbose(0) << " c - state two atoms in normal direction" << endl; | 
|---|
|  | 385 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 386 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 387 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 388 | cin >> choice; | 
|---|
|  | 389 |  | 
|---|
|  | 390 | switch (choice) { | 
|---|
|  | 391 | default: | 
|---|
|  | 392 | case 'a': // three atoms defining mirror plane | 
|---|
|  | 393 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 394 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 395 | third = mol->AskAtom("Enter third atom: "); | 
|---|
|  | 396 |  | 
|---|
| [0a4f7f] | 397 | n = Plane(first->x,second->x,third->x).getNormal(); | 
|---|
| [85bc8e] | 398 | break; | 
|---|
|  | 399 | case 'b': // normal vector of mirror plane | 
|---|
| [0a4f7f] | 400 | { | 
|---|
|  | 401 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [8cbb97] | 402 | dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false); | 
|---|
| [0a4f7f] | 403 | dialog->display(); | 
|---|
|  | 404 | delete dialog; | 
|---|
| [85bc8e] | 405 | n.Normalize(); | 
|---|
| [0a4f7f] | 406 | } | 
|---|
|  | 407 | break; | 
|---|
|  | 408 |  | 
|---|
| [85bc8e] | 409 | case 'c': // three atoms defining mirror plane | 
|---|
|  | 410 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 411 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 412 |  | 
|---|
| [273382] | 413 | n = first->x - second->x; | 
|---|
| [85bc8e] | 414 | n.Normalize(); | 
|---|
|  | 415 | break; | 
|---|
|  | 416 | }; | 
|---|
| [0a4f7f] | 417 | Log() << Verbose(0) << "Normal vector: " << n << endl; | 
|---|
| [85bc8e] | 418 | mol->Mirror((const Vector *)&n); | 
|---|
|  | 419 | }; | 
|---|
|  | 420 |  | 
|---|
|  | 421 | /** Submenu for removing the atoms from the molecule. | 
|---|
|  | 422 | * \param *mol molecule with all the atoms | 
|---|
|  | 423 | */ | 
|---|
| [65b6e0] | 424 | void oldmenu::RemoveAtoms(molecule *mol) | 
|---|
| [85bc8e] | 425 | { | 
|---|
| [f2bb0f] | 426 | atom *second; | 
|---|
| [85bc8e] | 427 | int axis; | 
|---|
|  | 428 | double tmp1, tmp2; | 
|---|
|  | 429 | char choice;  // menu choice char | 
|---|
|  | 430 |  | 
|---|
|  | 431 | Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl; | 
|---|
|  | 432 | Log() << Verbose(0) << " a - state atom for removal by number" << endl; | 
|---|
|  | 433 | Log() << Verbose(0) << " b - keep only in radius around atom" << endl; | 
|---|
|  | 434 | Log() << Verbose(0) << " c - remove this with one axis greater value" << endl; | 
|---|
|  | 435 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 436 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 437 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 438 | cin >> choice; | 
|---|
|  | 439 |  | 
|---|
|  | 440 | switch (choice) { | 
|---|
|  | 441 | default: | 
|---|
|  | 442 | case 'a': | 
|---|
|  | 443 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: "))) | 
|---|
|  | 444 | Log() << Verbose(1) << "Atom removed." << endl; | 
|---|
|  | 445 | else | 
|---|
|  | 446 | Log() << Verbose(1) << "Atom not found." << endl; | 
|---|
|  | 447 | break; | 
|---|
|  | 448 | case 'b': | 
|---|
| [9879f6] | 449 | { | 
|---|
|  | 450 | second = mol->AskAtom("Enter number of atom as reference point: "); | 
|---|
|  | 451 | Log() << Verbose(0) << "Enter radius: "; | 
|---|
|  | 452 | cin >> tmp1; | 
|---|
|  | 453 | molecule::iterator runner; | 
|---|
|  | 454 | for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) { | 
|---|
|  | 455 | runner = iter++; | 
|---|
| [a7b761b] | 456 | if ((*runner)->x.DistanceSquared((*runner)->x) > tmp1*tmp1) // distance to first above radius ... | 
|---|
| [9879f6] | 457 | mol->RemoveAtom((*runner)); | 
|---|
|  | 458 | } | 
|---|
| [85bc8e] | 459 | } | 
|---|
|  | 460 | break; | 
|---|
|  | 461 | case 'c': | 
|---|
|  | 462 | Log() << Verbose(0) << "Which axis is it: "; | 
|---|
|  | 463 | cin >> axis; | 
|---|
|  | 464 | Log() << Verbose(0) << "Lower boundary: "; | 
|---|
|  | 465 | cin >> tmp1; | 
|---|
|  | 466 | Log() << Verbose(0) << "Upper boundary: "; | 
|---|
|  | 467 | cin >> tmp2; | 
|---|
| [9879f6] | 468 | molecule::iterator runner; | 
|---|
|  | 469 | for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) { | 
|---|
|  | 470 | runner = iter++; | 
|---|
| [a7b761b] | 471 | if (((*runner)->x[axis] < tmp1) || ((*runner)->x[axis] > tmp2)) {// out of boundary ... | 
|---|
| [9879f6] | 472 | //Log() << Verbose(0) << "Atom " << *(*runner) << " with " << (*runner)->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl; | 
|---|
|  | 473 | mol->RemoveAtom((*runner)); | 
|---|
| [85bc8e] | 474 | } | 
|---|
|  | 475 | } | 
|---|
|  | 476 | break; | 
|---|
|  | 477 | }; | 
|---|
|  | 478 | //mol->Output(); | 
|---|
|  | 479 | choice = 'r'; | 
|---|
|  | 480 | }; | 
|---|
|  | 481 |  | 
|---|
|  | 482 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
|  | 483 | * \param *periode periodentafel | 
|---|
|  | 484 | * \param *mol molecule with all the atoms | 
|---|
|  | 485 | */ | 
|---|
| [65b6e0] | 486 | void oldmenu::MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration) | 
|---|
| [85bc8e] | 487 | { | 
|---|
|  | 488 | atom *first, *second, *third; | 
|---|
|  | 489 | Vector x,y; | 
|---|
|  | 490 | double min[256], tmp1, tmp2, tmp3; | 
|---|
|  | 491 | int Z; | 
|---|
|  | 492 | char choice;  // menu choice char | 
|---|
|  | 493 |  | 
|---|
|  | 494 | Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl; | 
|---|
|  | 495 | Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl; | 
|---|
|  | 496 | Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl; | 
|---|
|  | 497 | Log() << Verbose(0) << " c - calculate bond angle" << endl; | 
|---|
|  | 498 | Log() << Verbose(0) << " d - calculate principal axis of the system" << endl; | 
|---|
|  | 499 | Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl; | 
|---|
|  | 500 | Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl; | 
|---|
|  | 501 | Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl; | 
|---|
|  | 502 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 503 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 504 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 505 | cin >> choice; | 
|---|
|  | 506 |  | 
|---|
|  | 507 | switch(choice) { | 
|---|
|  | 508 | default: | 
|---|
|  | 509 | Log() << Verbose(1) << "Not a valid choice." << endl; | 
|---|
|  | 510 | break; | 
|---|
|  | 511 | case 'a': | 
|---|
|  | 512 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 513 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
|  | 514 | min[i] = 0.; | 
|---|
|  | 515 |  | 
|---|
| [9879f6] | 516 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { | 
|---|
|  | 517 | Z = (*iter)->type->Z; | 
|---|
| [85bc8e] | 518 | tmp1 = 0.; | 
|---|
| [9879f6] | 519 | if (first != (*iter)) { | 
|---|
| [a7b761b] | 520 | x = first->x - (*iter)->x; | 
|---|
| [85bc8e] | 521 | tmp1 = x.Norm(); | 
|---|
|  | 522 | } | 
|---|
|  | 523 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1; | 
|---|
| [9879f6] | 524 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << ((*iter)->nr << ": " << tmp1 << " a.u." << endl; | 
|---|
| [85bc8e] | 525 | } | 
|---|
|  | 526 | for (int i=MAX_ELEMENTS;i--;) | 
|---|
|  | 527 | 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; | 
|---|
|  | 528 | break; | 
|---|
|  | 529 |  | 
|---|
|  | 530 | case 'b': | 
|---|
|  | 531 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 532 | second = mol->AskAtom("Enter second atom: "); | 
|---|
|  | 533 | for (int i=NDIM;i--;) | 
|---|
|  | 534 | min[i] = 0.; | 
|---|
| [273382] | 535 | x = first->x - second->x; | 
|---|
| [85bc8e] | 536 | tmp1 = x.Norm(); | 
|---|
| [0a4f7f] | 537 | Log() << Verbose(1) << "Distance vector is " << x << "." << "/n" | 
|---|
|  | 538 | << "Norm of distance is " << tmp1 << "." << endl; | 
|---|
| [85bc8e] | 539 | break; | 
|---|
|  | 540 |  | 
|---|
|  | 541 | case 'c': | 
|---|
|  | 542 | Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl; | 
|---|
|  | 543 | first = mol->AskAtom("Enter first atom: "); | 
|---|
|  | 544 | second = mol->AskAtom("Enter central atom: "); | 
|---|
|  | 545 | third  = mol->AskAtom("Enter last atom: "); | 
|---|
|  | 546 | tmp1 = tmp2 = tmp3 = 0.; | 
|---|
| [273382] | 547 | x = first->x - second->x; | 
|---|
|  | 548 | y = third->x - second->x; | 
|---|
| [85bc8e] | 549 | Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": "; | 
|---|
| [273382] | 550 | Log() << Verbose(0) << (acos(x.ScalarProduct(y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; | 
|---|
| [85bc8e] | 551 | break; | 
|---|
|  | 552 | case 'd': | 
|---|
|  | 553 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl; | 
|---|
|  | 554 | Log() << Verbose(0) << "Shall we rotate? [0/1]: "; | 
|---|
|  | 555 | cin >> Z; | 
|---|
|  | 556 | if ((Z >=0) && (Z <=1)) | 
|---|
|  | 557 | mol->PrincipalAxisSystem((bool)Z); | 
|---|
|  | 558 | else | 
|---|
|  | 559 | mol->PrincipalAxisSystem(false); | 
|---|
|  | 560 | break; | 
|---|
|  | 561 | case 'e': | 
|---|
|  | 562 | { | 
|---|
|  | 563 | Log() << Verbose(0) << "Evaluating volume of the convex envelope."; | 
|---|
|  | 564 | class Tesselation *TesselStruct = NULL; | 
|---|
|  | 565 | const LinkedCell *LCList = NULL; | 
|---|
|  | 566 | LCList = new LinkedCell(mol, 10.); | 
|---|
|  | 567 | FindConvexBorder(mol, TesselStruct, LCList, NULL); | 
|---|
|  | 568 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration); | 
|---|
|  | 569 | Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\ | 
|---|
|  | 570 | delete(LCList); | 
|---|
|  | 571 | delete(TesselStruct); | 
|---|
|  | 572 | } | 
|---|
|  | 573 | break; | 
|---|
|  | 574 | case 'f': | 
|---|
|  | 575 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps); | 
|---|
|  | 576 | break; | 
|---|
|  | 577 | case 'g': | 
|---|
|  | 578 | { | 
|---|
|  | 579 | char filename[255]; | 
|---|
|  | 580 | Log() << Verbose(0) << "Please enter filename: " << endl; | 
|---|
|  | 581 | cin >> filename; | 
|---|
|  | 582 | Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl; | 
|---|
|  | 583 | ofstream *output = new ofstream(filename, ios::trunc); | 
|---|
|  | 584 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps)) | 
|---|
|  | 585 | Log() << Verbose(2) << "File could not be written." << endl; | 
|---|
|  | 586 | else | 
|---|
|  | 587 | Log() << Verbose(2) << "File stored." << endl; | 
|---|
|  | 588 | output->close(); | 
|---|
|  | 589 | delete(output); | 
|---|
|  | 590 | } | 
|---|
|  | 591 | break; | 
|---|
|  | 592 | } | 
|---|
|  | 593 | }; | 
|---|
|  | 594 |  | 
|---|
|  | 595 | /** Submenu for measuring out the atoms in the molecule. | 
|---|
|  | 596 | * \param *mol molecule with all the atoms | 
|---|
|  | 597 | * \param *configuration configuration structure for the to be written config files of all fragments | 
|---|
|  | 598 | */ | 
|---|
| [65b6e0] | 599 | void oldmenu::FragmentAtoms(molecule *mol, config *configuration) | 
|---|
| [85bc8e] | 600 | { | 
|---|
|  | 601 | int Order1; | 
|---|
|  | 602 | clock_t start, end; | 
|---|
|  | 603 |  | 
|---|
|  | 604 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl; | 
|---|
|  | 605 | Log() << Verbose(0) << "What's the desired bond order: "; | 
|---|
|  | 606 | cin >> Order1; | 
|---|
| [e08c46] | 607 | if (mol->hasBondStructure()) { | 
|---|
| [85bc8e] | 608 | start = clock(); | 
|---|
|  | 609 | mol->FragmentMolecule(Order1, configuration); | 
|---|
|  | 610 | end = clock(); | 
|---|
|  | 611 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
|  | 612 | } else | 
|---|
|  | 613 | Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl; | 
|---|
|  | 614 | }; | 
|---|
|  | 615 |  | 
|---|
|  | 616 | /********************************************** Submenu routine **************************************/ | 
|---|
|  | 617 |  | 
|---|
|  | 618 | /** Submenu for manipulating atoms. | 
|---|
|  | 619 | * \param *periode periodentafel | 
|---|
|  | 620 | * \param *molecules list of molecules whose atoms are to be manipulated | 
|---|
|  | 621 | */ | 
|---|
| [65b6e0] | 622 | void oldmenu::ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration) | 
|---|
| [85bc8e] | 623 | { | 
|---|
|  | 624 | atom *first, *second; | 
|---|
|  | 625 | molecule *mol = NULL; | 
|---|
|  | 626 | Vector x,y,z,n; // coordinates for absolute point in cell volume | 
|---|
|  | 627 | double *factor; // unit factor if desired | 
|---|
|  | 628 | double bond, minBond; | 
|---|
|  | 629 | char choice;  // menu choice char | 
|---|
|  | 630 | bool valid; | 
|---|
|  | 631 |  | 
|---|
|  | 632 | Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl; | 
|---|
|  | 633 | Log() << Verbose(0) << "a - add an atom" << endl; | 
|---|
|  | 634 | Log() << Verbose(0) << "r - remove an atom" << endl; | 
|---|
|  | 635 | Log() << Verbose(0) << "b - scale a bond between atoms" << endl; | 
|---|
|  | 636 | Log() << Verbose(0) << "u - change an atoms element" << endl; | 
|---|
|  | 637 | Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl; | 
|---|
|  | 638 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 639 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 640 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
|  | 641 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
|  | 642 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 643 | cin >> choice; | 
|---|
|  | 644 |  | 
|---|
|  | 645 | switch (choice) { | 
|---|
|  | 646 | default: | 
|---|
|  | 647 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 648 | break; | 
|---|
|  | 649 |  | 
|---|
|  | 650 | case 'a': // add atom | 
|---|
|  | 651 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 652 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 653 | mol = *ListRunner; | 
|---|
|  | 654 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 655 | AddAtoms(periode, mol); | 
|---|
|  | 656 | } | 
|---|
|  | 657 | break; | 
|---|
|  | 658 |  | 
|---|
|  | 659 | case 'b': // scale a bond | 
|---|
|  | 660 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 661 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 662 | mol = *ListRunner; | 
|---|
|  | 663 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 664 | Log() << Verbose(0) << "Scaling bond length between two atoms." << endl; | 
|---|
|  | 665 | first = mol->AskAtom("Enter first (fixed) atom: "); | 
|---|
|  | 666 | second = mol->AskAtom("Enter second (shifting) atom: "); | 
|---|
|  | 667 | minBond = 0.; | 
|---|
|  | 668 | for (int i=NDIM;i--;) | 
|---|
| [0a4f7f] | 669 | minBond += (first->x[i]-second->x[i])*(first->x[i] - second->x[i]); | 
|---|
| [85bc8e] | 670 | minBond = sqrt(minBond); | 
|---|
|  | 671 | Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl; | 
|---|
|  | 672 | Log() << Verbose(0) << "Enter new bond length [a.u.]: "; | 
|---|
|  | 673 | cin >> bond; | 
|---|
|  | 674 | for (int i=NDIM;i--;) { | 
|---|
| [0a4f7f] | 675 | second->x[i] -= (second->x[i]-first->x[i])/minBond*(minBond-bond); | 
|---|
| [85bc8e] | 676 | } | 
|---|
|  | 677 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: "; | 
|---|
|  | 678 | //second->Output(second->type->No, 1); | 
|---|
|  | 679 | } | 
|---|
|  | 680 | break; | 
|---|
|  | 681 |  | 
|---|
|  | 682 | case 'c': // unit scaling of the metric | 
|---|
|  | 683 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 684 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 685 | mol = *ListRunner; | 
|---|
|  | 686 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 687 | Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl; | 
|---|
|  | 688 | Log() << Verbose(0) << "Enter three factors: "; | 
|---|
|  | 689 | factor = new double[NDIM]; | 
|---|
|  | 690 | cin >> factor[0]; | 
|---|
|  | 691 | cin >> factor[1]; | 
|---|
|  | 692 | cin >> factor[2]; | 
|---|
|  | 693 | valid = true; | 
|---|
|  | 694 | mol->Scale((const double ** const)&factor); | 
|---|
|  | 695 | delete[](factor); | 
|---|
|  | 696 | } | 
|---|
|  | 697 | break; | 
|---|
|  | 698 |  | 
|---|
|  | 699 | case 'l': // measure distances or angles | 
|---|
|  | 700 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 701 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 702 | mol = *ListRunner; | 
|---|
|  | 703 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 704 | MeasureAtoms(periode, mol, configuration); | 
|---|
|  | 705 | } | 
|---|
|  | 706 | break; | 
|---|
|  | 707 |  | 
|---|
|  | 708 | case 'r': // remove atom | 
|---|
|  | 709 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 710 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 711 | mol = *ListRunner; | 
|---|
|  | 712 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 713 | RemoveAtoms(mol); | 
|---|
|  | 714 | } | 
|---|
|  | 715 | break; | 
|---|
|  | 716 |  | 
|---|
|  | 717 | case 'u': // change an atom's element | 
|---|
|  | 718 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 719 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 720 | int Z; | 
|---|
|  | 721 | mol = *ListRunner; | 
|---|
|  | 722 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 723 | first = NULL; | 
|---|
|  | 724 | do { | 
|---|
|  | 725 | Log() << Verbose(0) << "Change the element of which atom: "; | 
|---|
|  | 726 | cin >> Z; | 
|---|
|  | 727 | } while ((first = mol->FindAtom(Z)) == NULL); | 
|---|
|  | 728 | Log() << Verbose(0) << "New element by atomic number Z: "; | 
|---|
|  | 729 | cin >> Z; | 
|---|
| [f16a4b] | 730 | first->setType(Z); | 
|---|
| [85bc8e] | 731 | Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl; | 
|---|
|  | 732 | } | 
|---|
|  | 733 | break; | 
|---|
|  | 734 | } | 
|---|
|  | 735 | }; | 
|---|
|  | 736 |  | 
|---|
| [820a42] | 737 | void oldmenu::duplicateCell(MoleculeListClass *molecules, config *configuration) { | 
|---|
|  | 738 | molecule *mol = NULL; | 
|---|
|  | 739 | int axis,faktor,count,j; | 
|---|
|  | 740 | atom *first = NULL; | 
|---|
| [ead4e6] | 741 | const element **Elements; | 
|---|
| [820a42] | 742 | Vector x,y; | 
|---|
|  | 743 | Vector **vectors; | 
|---|
|  | 744 |  | 
|---|
|  | 745 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 746 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 747 | mol = *ListRunner; | 
|---|
|  | 748 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 749 | Log() << Verbose(0) << "State the axis [(+-)123]: "; | 
|---|
|  | 750 | cin >> axis; | 
|---|
|  | 751 | Log() << Verbose(0) << "State the factor: "; | 
|---|
|  | 752 | cin >> faktor; | 
|---|
| [ea7176] | 753 | if (mol->getAtomCount() != 0) {  // if there is more than none | 
|---|
|  | 754 | count = mol->getAtomCount();  // is changed becausing of adding, thus has to be stored away beforehand | 
|---|
| [ead4e6] | 755 | Elements = new const element *[count]; | 
|---|
| [820a42] | 756 | vectors = new Vector *[count]; | 
|---|
|  | 757 | j = 0; | 
|---|
| [9879f6] | 758 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { | 
|---|
|  | 759 | Elements[j] = (*iter)->type; | 
|---|
|  | 760 | vectors[j] = &(*iter)->x; | 
|---|
| [820a42] | 761 | j++; | 
|---|
|  | 762 | } | 
|---|
|  | 763 | if (count != j) | 
|---|
|  | 764 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl; | 
|---|
|  | 765 | x.Zero(); | 
|---|
|  | 766 | y.Zero(); | 
|---|
| [8cbb97] | 767 | y[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude | 
|---|
| [820a42] | 768 | for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times | 
|---|
| [273382] | 769 | x += y; // per factor one cell width further | 
|---|
| [820a42] | 770 | for (int k=count;k--;) { // go through every atom of the original cell | 
|---|
| [23b547] | 771 | first = World::getInstance().createAtom(); // create a new body | 
|---|
| [273382] | 772 | first->x = (*vectors[k]) + x;  // use coordinate of original atom | 
|---|
| [820a42] | 773 | first->type = Elements[k];  // insert original element | 
|---|
|  | 774 | mol->AddAtom(first);        // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) | 
|---|
|  | 775 | } | 
|---|
|  | 776 | } | 
|---|
| [e08c46] | 777 | if (mol->hasBondStructure()) | 
|---|
| [820a42] | 778 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 779 | // free memory | 
|---|
|  | 780 | delete[](Elements); | 
|---|
|  | 781 | delete[](vectors); | 
|---|
|  | 782 | // correct cell size | 
|---|
|  | 783 | if (axis < 0) { // if sign was negative, we have to translate everything | 
|---|
| [273382] | 784 | x = y; | 
|---|
| [820a42] | 785 | x.Scale(-(faktor-1)); | 
|---|
|  | 786 | mol->Translate(&x); | 
|---|
|  | 787 | } | 
|---|
| [5f612ee] | 788 | World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor; | 
|---|
| [820a42] | 789 | } | 
|---|
|  | 790 | } | 
|---|
|  | 791 | } | 
|---|
|  | 792 |  | 
|---|
| [85bc8e] | 793 | /** Submenu for manipulating molecules. | 
|---|
|  | 794 | * \param *periode periodentafel | 
|---|
|  | 795 | * \param *molecules list of molecule to manipulate | 
|---|
|  | 796 | */ | 
|---|
| [65b6e0] | 797 | void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration) | 
|---|
| [85bc8e] | 798 | { | 
|---|
|  | 799 | Vector x,y,z,n; // coordinates for absolute point in cell volume | 
|---|
|  | 800 | char choice;  // menu choice char | 
|---|
|  | 801 | molecule *mol = NULL; | 
|---|
|  | 802 | MoleculeLeafClass *Subgraphs = NULL; | 
|---|
|  | 803 |  | 
|---|
|  | 804 | Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl; | 
|---|
|  | 805 | Log() << Verbose(0) << "c - scale by unit transformation" << endl; | 
|---|
|  | 806 | Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl; | 
|---|
|  | 807 | Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl; | 
|---|
|  | 808 | Log() << Verbose(0) << "g - center atoms in box" << endl; | 
|---|
|  | 809 | Log() << Verbose(0) << "i - realign molecule" << endl; | 
|---|
|  | 810 | Log() << Verbose(0) << "m - mirror all molecules" << endl; | 
|---|
|  | 811 | Log() << Verbose(0) << "o - create connection matrix" << endl; | 
|---|
|  | 812 | Log() << Verbose(0) << "t - translate molecule by vector" << endl; | 
|---|
|  | 813 | Log() << Verbose(0) << "all else - go back" << endl; | 
|---|
|  | 814 | Log() << Verbose(0) << "===============================================" << endl; | 
|---|
|  | 815 | if (molecules->NumberOfActiveMolecules() > 1) | 
|---|
|  | 816 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl; | 
|---|
|  | 817 | Log() << Verbose(0) << "INPUT: "; | 
|---|
|  | 818 | cin >> choice; | 
|---|
|  | 819 |  | 
|---|
|  | 820 | switch (choice) { | 
|---|
|  | 821 | default: | 
|---|
|  | 822 | Log() << Verbose(0) << "Not a valid choice." << endl; | 
|---|
|  | 823 | break; | 
|---|
|  | 824 |  | 
|---|
|  | 825 | case 'd': // duplicate the periodic cell along a given axis, given times | 
|---|
| [820a42] | 826 | duplicateCell(molecules, configuration); | 
|---|
| [85bc8e] | 827 | break; | 
|---|
|  | 828 |  | 
|---|
|  | 829 | case 'f': | 
|---|
|  | 830 | FragmentAtoms(mol, configuration); | 
|---|
|  | 831 | break; | 
|---|
|  | 832 |  | 
|---|
|  | 833 | case 'g': // center the atoms | 
|---|
|  | 834 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 835 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 836 | mol = *ListRunner; | 
|---|
|  | 837 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 838 | CenterAtoms(mol); | 
|---|
|  | 839 | } | 
|---|
|  | 840 | break; | 
|---|
|  | 841 |  | 
|---|
|  | 842 | case 'i': // align all atoms | 
|---|
|  | 843 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 844 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 845 | mol = *ListRunner; | 
|---|
|  | 846 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 847 | AlignAtoms(periode, mol); | 
|---|
|  | 848 | } | 
|---|
|  | 849 | break; | 
|---|
|  | 850 |  | 
|---|
|  | 851 | case 'm': // mirror atoms along a given axis | 
|---|
|  | 852 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 853 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 854 | mol = *ListRunner; | 
|---|
|  | 855 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
|  | 856 | MirrorAtoms(mol); | 
|---|
|  | 857 | } | 
|---|
|  | 858 | break; | 
|---|
|  | 859 |  | 
|---|
|  | 860 | case 'o': // create the connection matrix | 
|---|
|  | 861 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 862 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 863 | mol = *ListRunner; | 
|---|
|  | 864 | double bonddistance; | 
|---|
|  | 865 | clock_t start,end; | 
|---|
|  | 866 | Log() << Verbose(0) << "What's the maximum bond distance: "; | 
|---|
|  | 867 | cin >> bonddistance; | 
|---|
|  | 868 | start = clock(); | 
|---|
|  | 869 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL); | 
|---|
|  | 870 | end = clock(); | 
|---|
|  | 871 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl; | 
|---|
|  | 872 | } | 
|---|
|  | 873 | break; | 
|---|
|  | 874 |  | 
|---|
|  | 875 | case 't': // translate all atoms | 
|---|
|  | 876 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 877 | if ((*ListRunner)->ActiveFlag) { | 
|---|
|  | 878 | mol = *ListRunner; | 
|---|
|  | 879 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl; | 
|---|
| [0a4f7f] | 880 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [8cbb97] | 881 | dialog->queryVector("Enter translation vector.",&x,World::getInstance().getDomain(),false); | 
|---|
|  | 882 | if(dialog->display()){ | 
|---|
|  | 883 | mol->Center += x; | 
|---|
|  | 884 | } | 
|---|
| [0a4f7f] | 885 | delete dialog; | 
|---|
| [85bc8e] | 886 | } | 
|---|
|  | 887 | break; | 
|---|
|  | 888 | } | 
|---|
|  | 889 | // Free all | 
|---|
|  | 890 | if (Subgraphs != NULL) {  // free disconnected subgraph list of DFS analysis was performed | 
|---|
|  | 891 | while (Subgraphs->next != NULL) { | 
|---|
|  | 892 | Subgraphs = Subgraphs->next; | 
|---|
|  | 893 | delete(Subgraphs->previous); | 
|---|
|  | 894 | } | 
|---|
|  | 895 | delete(Subgraphs); | 
|---|
|  | 896 | } | 
|---|
|  | 897 | }; | 
|---|
|  | 898 |  | 
|---|
|  | 899 |  | 
|---|
| [820a42] | 900 | void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) { | 
|---|
|  | 901 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
| [d7940e] | 902 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [97ebf8] | 903 | dialog->queryMolecule("molecule-by-id",&destmol, MapOfActions::getInstance().getDescription("molecule-by-id")); | 
|---|
|  | 904 | dialog->queryMolecule("molecule-by-id",&srcmol, MapOfActions::getInstance().getDescription("molecule-by-id")); | 
|---|
| [29a4cc] | 905 | if(dialog->display()) { | 
|---|
|  | 906 | molecules->SimpleAdd(srcmol, destmol); | 
|---|
|  | 907 | } | 
|---|
|  | 908 | else { | 
|---|
| [8927ae] | 909 | Log() << Verbose(0) << "Adding of molecules canceled" << endl; | 
|---|
| [820a42] | 910 | } | 
|---|
| [8927ae] | 911 | delete dialog; | 
|---|
| [820a42] | 912 | } | 
|---|
|  | 913 |  | 
|---|
|  | 914 | void oldmenu::embeddMolecules(MoleculeListClass *molecules) { | 
|---|
|  | 915 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
| [d7940e] | 916 | Dialog *dialog = UIFactory::getInstance().makeDialog(); | 
|---|
| [97ebf8] | 917 | dialog->queryMolecule("molecule-by-id",&destmol, MapOfActions::getInstance().getDescription("molecule-by-id")); | 
|---|
|  | 918 | dialog->queryMolecule("molecule-by-id",&srcmol, MapOfActions::getInstance().getDescription("molecule-by-id")); | 
|---|
| [8927ae] | 919 | if(dialog->display()) { | 
|---|
| [820a42] | 920 | molecules->EmbedMerge(destmol, srcmol); | 
|---|
| [8927ae] | 921 | } | 
|---|
|  | 922 | else { | 
|---|
|  | 923 | Log() << Verbose(0) << "embedding of molecules canceled" << endl; | 
|---|
|  | 924 | } | 
|---|
|  | 925 |  | 
|---|
|  | 926 |  | 
|---|
| [820a42] | 927 | } | 
|---|
|  | 928 |  | 
|---|
|  | 929 | void oldmenu::multiMergeMolecules(MoleculeListClass *molecules) { | 
|---|
|  | 930 | int nr; | 
|---|
|  | 931 | molecule *mol = NULL; | 
|---|
|  | 932 | do { | 
|---|
|  | 933 | Log() << Verbose(0) << "Enter index of molecule to merge into: "; | 
|---|
|  | 934 | cin >> nr; | 
|---|
|  | 935 | mol = molecules->ReturnIndex(nr); | 
|---|
|  | 936 | } while ((mol == NULL) && (nr != -1)); | 
|---|
|  | 937 | if (nr != -1) { | 
|---|
|  | 938 | int N = molecules->ListOfMolecules.size()-1; | 
|---|
|  | 939 | int *src = new int(N); | 
|---|
|  | 940 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) | 
|---|
|  | 941 | if ((*ListRunner)->IndexNr != nr) | 
|---|
|  | 942 | src[N++] = (*ListRunner)->IndexNr; | 
|---|
|  | 943 | molecules->SimpleMultiMerge(mol, src, N); | 
|---|
|  | 944 | delete[](src); | 
|---|
|  | 945 | } | 
|---|
|  | 946 | } | 
|---|
|  | 947 |  | 
|---|
|  | 948 | void oldmenu::simpleMergeMolecules(MoleculeListClass *molecules) { | 
|---|
|  | 949 | int src, dest; | 
|---|
|  | 950 | molecule *srcmol = NULL, *destmol = NULL; | 
|---|
|  | 951 | { | 
|---|
|  | 952 | do { | 
|---|
|  | 953 | Log() << Verbose(0) << "Enter index of destination molecule: "; | 
|---|
|  | 954 | cin >> dest; | 
|---|
|  | 955 | destmol = molecules->ReturnIndex(dest); | 
|---|
|  | 956 | } while ((destmol == NULL) && (dest != -1)); | 
|---|
|  | 957 | do { | 
|---|
|  | 958 | Log() << Verbose(0) << "Enter index of source molecule to merge into: "; | 
|---|
|  | 959 | cin >> src; | 
|---|
|  | 960 | srcmol = molecules->ReturnIndex(src); | 
|---|
|  | 961 | } while ((srcmol == NULL) && (src != -1)); | 
|---|
|  | 962 | if ((src != -1) && (dest != -1)) | 
|---|
|  | 963 | molecules->SimpleMerge(srcmol, destmol); | 
|---|
|  | 964 | } | 
|---|
|  | 965 | } | 
|---|
|  | 966 |  | 
|---|
| [85bc8e] | 967 | /** Submenu for merging molecules. | 
|---|
|  | 968 | * \param *periode periodentafel | 
|---|
|  | 969 | * \param *molecules list of molecules to add to | 
|---|
|  | 970 | */ | 
|---|
| [65b6e0] | 971 | void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules) | 
|---|
| [85bc8e] | 972 | { | 
|---|
| [3e026a] | 973 | TextMenu *MergeMoleculesMenu = new TextMenu(Log() << Verbose(0), "Merge Molecules"); | 
|---|
| [85bc8e] | 974 |  | 
|---|
| [cc04b7] | 975 | Action *simpleAddAction = new MethodAction("simpleAddAction",boost::bind(&oldmenu::SimpleAddMolecules,this,molecules),false); | 
|---|
| [3e026a] | 976 | new ActionMenuItem('a',"simple add of one molecule to another",MergeMoleculesMenu,simpleAddAction); | 
|---|
| [85bc8e] | 977 |  | 
|---|
| [cc04b7] | 978 | Action *embeddAction = new MethodAction("embeddAction",boost::bind(&oldmenu::embeddMolecules,this,molecules),false); | 
|---|
| [3e026a] | 979 | new ActionMenuItem('e',"embedding merge of two molecules",MergeMoleculesMenu,embeddAction); | 
|---|
| [85bc8e] | 980 |  | 
|---|
| [cc04b7] | 981 | Action *multiMergeAction = new MethodAction("multiMergeAction",boost::bind(&oldmenu::multiMergeMolecules,this,molecules),false); | 
|---|
| [3e026a] | 982 | new ActionMenuItem('m',"multi-merge of all molecules",MergeMoleculesMenu,multiMergeAction); | 
|---|
| [85bc8e] | 983 |  | 
|---|
| [cc04b7] | 984 | Action *scatterMergeAction = new ErrorAction("scatterMergeAction","Not Implemented yet",false); | 
|---|
| [3e026a] | 985 | new ActionMenuItem('s',"scatter merge of two molecules",MergeMoleculesMenu,scatterMergeAction); | 
|---|
| [85bc8e] | 986 |  | 
|---|
| [cc04b7] | 987 | Action *simpleMergeAction = new MethodAction("simpleMergeAction",boost::bind(&oldmenu::simpleMergeMolecules,this,molecules),false); | 
|---|
| [3e026a] | 988 | new ActionMenuItem('t',"simple merge of two molecules",MergeMoleculesMenu,simpleMergeAction); | 
|---|
| [85bc8e] | 989 |  | 
|---|
| [cc04b7] | 990 | Action *returnAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,MergeMoleculesMenu),false); | 
|---|
| [3e026a] | 991 | MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",MergeMoleculesMenu,returnAction); | 
|---|
| [85bc8e] | 992 |  | 
|---|
| [3e026a] | 993 | MergeMoleculesMenu->addDefault(returnItem); | 
|---|
|  | 994 |  | 
|---|
|  | 995 | MergeMoleculesMenu->display(); | 
|---|
| [85bc8e] | 996 | }; | 
|---|
|  | 997 |  | 
|---|
|  | 998 |  | 
|---|
|  | 999 | /********************************************** Test routine **************************************/ | 
|---|
|  | 1000 |  | 
|---|
|  | 1001 | /** Is called always as option 'T' in the menu. | 
|---|
|  | 1002 | * \param *molecules list of molecules | 
|---|
|  | 1003 | */ | 
|---|
| [65b6e0] | 1004 | void oldmenu::testroutine(MoleculeListClass *molecules) | 
|---|
| [85bc8e] | 1005 | { | 
|---|
|  | 1006 | // the current test routine checks the functionality of the KeySet&Graph concept: | 
|---|
|  | 1007 | // We want to have a multiindex (the KeySet) describing a unique subgraph | 
|---|
|  | 1008 | int i, comp, counter=0; | 
|---|
|  | 1009 |  | 
|---|
|  | 1010 | // create a clone | 
|---|
|  | 1011 | molecule *mol = NULL; | 
|---|
|  | 1012 | if (molecules->ListOfMolecules.size() != 0) // clone | 
|---|
|  | 1013 | mol = (molecules->ListOfMolecules.front())->CopyMolecule(); | 
|---|
|  | 1014 | else { | 
|---|
|  | 1015 | eLog() << Verbose(0) << "I don't have anything to test on ... "; | 
|---|
|  | 1016 | performCriticalExit(); | 
|---|
|  | 1017 | return; | 
|---|
|  | 1018 | } | 
|---|
|  | 1019 |  | 
|---|
|  | 1020 | // generate some KeySets | 
|---|
|  | 1021 | Log() << Verbose(0) << "Generating KeySets." << endl; | 
|---|
| [ea7176] | 1022 | KeySet TestSets[mol->getAtomCount()+1]; | 
|---|
| [85bc8e] | 1023 | i=1; | 
|---|
| [9879f6] | 1024 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) { | 
|---|
| [85bc8e] | 1025 | for (int j=0;j<i;j++) { | 
|---|
| [9879f6] | 1026 | TestSets[j].insert((*iter)->nr); | 
|---|
| [85bc8e] | 1027 | } | 
|---|
|  | 1028 | i++; | 
|---|
|  | 1029 | } | 
|---|
|  | 1030 | Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl; | 
|---|
|  | 1031 | KeySetTestPair test; | 
|---|
| [9879f6] | 1032 | molecule::const_iterator iter = mol->begin(); | 
|---|
|  | 1033 | if (iter != mol->end()) { | 
|---|
| [ea7176] | 1034 | test = TestSets[mol->getAtomCount()-1].insert((*iter)->nr); | 
|---|
| [9879f6] | 1035 | if (test.second) { | 
|---|
|  | 1036 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
|  | 1037 | } else { | 
|---|
|  | 1038 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl; | 
|---|
|  | 1039 | } | 
|---|
| [85bc8e] | 1040 | } else { | 
|---|
| [9879f6] | 1041 | eLog() << Verbose(1) << "No atoms to test double insertion." << endl; | 
|---|
| [85bc8e] | 1042 | } | 
|---|
|  | 1043 |  | 
|---|
|  | 1044 | // constructing Graph structure | 
|---|
|  | 1045 | Log() << Verbose(0) << "Generating Subgraph class." << endl; | 
|---|
|  | 1046 | Graph Subgraphs; | 
|---|
|  | 1047 |  | 
|---|
|  | 1048 | // insert KeySets into Subgraphs | 
|---|
|  | 1049 | Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl; | 
|---|
| [ea7176] | 1050 | for (int j=0;j<mol->getAtomCount();j++) { | 
|---|
| [85bc8e] | 1051 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.))); | 
|---|
|  | 1052 | } | 
|---|
|  | 1053 | Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl; | 
|---|
|  | 1054 | GraphTestPair test2; | 
|---|
| [ea7176] | 1055 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.))); | 
|---|
| [85bc8e] | 1056 | if (test2.second) { | 
|---|
|  | 1057 | Log() << Verbose(1) << "Insertion worked?!" << endl; | 
|---|
|  | 1058 | } else { | 
|---|
|  | 1059 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl; | 
|---|
|  | 1060 | } | 
|---|
|  | 1061 |  | 
|---|
|  | 1062 | // show graphs | 
|---|
|  | 1063 | Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl; | 
|---|
|  | 1064 | Graph::iterator A = Subgraphs.begin(); | 
|---|
|  | 1065 | while (A !=  Subgraphs.end()) { | 
|---|
|  | 1066 | Log() << Verbose(0) << (*A).second.first << ": "; | 
|---|
|  | 1067 | KeySet::iterator key = (*A).first.begin(); | 
|---|
|  | 1068 | comp = -1; | 
|---|
|  | 1069 | while (key != (*A).first.end()) { | 
|---|
|  | 1070 | if ((*key) > comp) | 
|---|
|  | 1071 | Log() << Verbose(0) << (*key) << " "; | 
|---|
|  | 1072 | else | 
|---|
|  | 1073 | Log() << Verbose(0) << (*key) << "! "; | 
|---|
|  | 1074 | comp = (*key); | 
|---|
|  | 1075 | key++; | 
|---|
|  | 1076 | } | 
|---|
|  | 1077 | Log() << Verbose(0) << endl; | 
|---|
|  | 1078 | A++; | 
|---|
|  | 1079 | } | 
|---|
| [23b547] | 1080 | World::getInstance().destroyMolecule(mol); | 
|---|
| [85bc8e] | 1081 | }; | 
|---|
|  | 1082 |  | 
|---|
| [65b6e0] | 1083 | oldmenu::oldmenu() | 
|---|
| [85bc8e] | 1084 | { | 
|---|
|  | 1085 | // TODO Auto-generated constructor stub | 
|---|
|  | 1086 | } | 
|---|
|  | 1087 |  | 
|---|
| [65b6e0] | 1088 | oldmenu::~oldmenu() | 
|---|
| [85bc8e] | 1089 | { | 
|---|
|  | 1090 | // TODO Auto-generated destructor stub | 
|---|
|  | 1091 | } | 
|---|