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