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