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