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