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