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