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