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