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