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