| 1 | /** \file builder.cpp
|
|---|
| 2 | *
|
|---|
| 3 | * By stating absolute positions or binding angles and distances atomic positions of a molecule can be constructed.
|
|---|
| 4 | * The output is the complete configuration file for PCP for direct use.
|
|---|
| 5 | * Features:
|
|---|
| 6 | * -# Atomic data is retrieved from a file, if not found requested and stored there for later re-use
|
|---|
| 7 | * -# step-by-step construction of the molecule beginning either at a centre of with a certain atom
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /*! \mainpage Molecuilder - a molecular set builder
|
|---|
| 12 | *
|
|---|
| 13 | * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
|
|---|
| 14 | *
|
|---|
| 15 | * \section about About the Program
|
|---|
| 16 | *
|
|---|
| 17 | * Molecuilder is a short program, written in C++, that enables the construction of a coordinate set for the
|
|---|
| 18 | * atoms making up an molecule by the successive statement of binding angles and distances and referencing to
|
|---|
| 19 | * already constructed atoms.
|
|---|
| 20 | *
|
|---|
| 21 | * A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
|
|---|
| 22 | * molecular dynamics implementation.
|
|---|
| 23 | *
|
|---|
| 24 | * \section install Installation
|
|---|
| 25 | *
|
|---|
| 26 | * Installation should without problems succeed as follows:
|
|---|
| 27 | * -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
|
|---|
| 28 | * -# make
|
|---|
| 29 | * -# make install
|
|---|
| 30 | *
|
|---|
| 31 | * Further useful commands are
|
|---|
| 32 | * -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
|
|---|
| 33 | * -# make doxygen-doc: Creates these html pages out of the documented source
|
|---|
| 34 | *
|
|---|
| 35 | * \section run Running
|
|---|
| 36 | *
|
|---|
| 37 | * The program can be executed by running: ./molecuilder
|
|---|
| 38 | *
|
|---|
| 39 | * Note, that it uses a database, called "elements.db", in the executable's directory. If the file is not found,
|
|---|
| 40 | * it is created and any given data on elements of the periodic table will be stored therein and re-used on
|
|---|
| 41 | * later re-execution.
|
|---|
| 42 | *
|
|---|
| 43 | * \section ref References
|
|---|
| 44 | *
|
|---|
| 45 | * For the special configuration file format, see the documentation of pcp.
|
|---|
| 46 | *
|
|---|
| 47 | */
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | #include <boost/bind.hpp>
|
|---|
| 51 |
|
|---|
| 52 | using namespace std;
|
|---|
| 53 |
|
|---|
| 54 | #include <cstring>
|
|---|
| 55 |
|
|---|
| 56 | #include "analysis_correlation.hpp"
|
|---|
| 57 | #include "atom.hpp"
|
|---|
| 58 | #include "bond.hpp"
|
|---|
| 59 | #include "bondgraph.hpp"
|
|---|
| 60 | #include "boundary.hpp"
|
|---|
| 61 | #include "config.hpp"
|
|---|
| 62 | #include "element.hpp"
|
|---|
| 63 | #include "ellipsoid.hpp"
|
|---|
| 64 | #include "helpers.hpp"
|
|---|
| 65 | #include "leastsquaremin.hpp"
|
|---|
| 66 | #include "linkedcell.hpp"
|
|---|
| 67 | #include "log.hpp"
|
|---|
| 68 | #include "memoryusageobserverunittest.hpp"
|
|---|
| 69 | #include "molecule.hpp"
|
|---|
| 70 | #include "periodentafel.hpp"
|
|---|
| 71 | #include "UIElements/UIFactory.hpp"
|
|---|
| 72 | #include "UIElements/MainWindow.hpp"
|
|---|
| 73 | #include "UIElements/Dialog.hpp"
|
|---|
| 74 | #include "Menu/ActionMenuItem.hpp"
|
|---|
| 75 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 76 | #include "Actions/MethodAction.hpp"
|
|---|
| 77 | #include "Actions/small_actions.hpp"
|
|---|
| 78 | #include "version.h"
|
|---|
| 79 |
|
|---|
| 80 | /********************************************* Subsubmenu routine ************************************/
|
|---|
| 81 | #if 0
|
|---|
| 82 | /** Submenu for adding atoms to the molecule.
|
|---|
| 83 | * \param *periode periodentafel
|
|---|
| 84 | * \param *molecule molecules with atoms
|
|---|
| 85 | */
|
|---|
| 86 | static void AddAtoms(periodentafel *periode, molecule *mol)
|
|---|
| 87 | {
|
|---|
| 88 | atom *first, *second, *third, *fourth;
|
|---|
| 89 | Vector **atoms;
|
|---|
| 90 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
|---|
| 91 | double a,b,c;
|
|---|
| 92 | char choice; // menu choice char
|
|---|
| 93 | bool valid;
|
|---|
| 94 |
|
|---|
| 95 | Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
|
|---|
| 96 | Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl;
|
|---|
| 97 | Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
|
|---|
| 98 | Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
|
|---|
| 99 | Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
|
|---|
| 100 | Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
|
|---|
| 101 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 102 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 103 | Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
|
|---|
| 104 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 105 | cin >> choice;
|
|---|
| 106 |
|
|---|
| 107 | switch (choice) {
|
|---|
| 108 | default:
|
|---|
| 109 | eLog() << Verbose(2) << "Not a valid choice." << endl;
|
|---|
| 110 | break;
|
|---|
| 111 | case 'a': // absolute coordinates of atom
|
|---|
| 112 | Log() << Verbose(0) << "Enter absolute coordinates." << endl;
|
|---|
| 113 | first = new atom;
|
|---|
| 114 | first->x.AskPosition(mol->cell_size, false);
|
|---|
| 115 | first->type = periode->AskElement(); // give type
|
|---|
| 116 | mol->AddAtom(first); // add to molecule
|
|---|
| 117 | break;
|
|---|
| 118 |
|
|---|
| 119 | case 'b': // relative coordinates of atom wrt to reference point
|
|---|
| 120 | first = new atom;
|
|---|
| 121 | valid = true;
|
|---|
| 122 | do {
|
|---|
| 123 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
|
|---|
| 124 | Log() << Verbose(0) << "Enter reference coordinates." << endl;
|
|---|
| 125 | x.AskPosition(mol->cell_size, true);
|
|---|
| 126 | Log() << Verbose(0) << "Enter relative coordinates." << endl;
|
|---|
| 127 | first->x.AskPosition(mol->cell_size, false);
|
|---|
| 128 | first->x.AddVector((const Vector *)&x);
|
|---|
| 129 | Log() << Verbose(0) << "\n";
|
|---|
| 130 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
|---|
| 131 | first->type = periode->AskElement(); // give type
|
|---|
| 132 | mol->AddAtom(first); // add to molecule
|
|---|
| 133 | break;
|
|---|
| 134 |
|
|---|
| 135 | case 'c': // relative coordinates of atom wrt to already placed atom
|
|---|
| 136 | first = new atom;
|
|---|
| 137 | valid = true;
|
|---|
| 138 | do {
|
|---|
| 139 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
|
|---|
| 140 | second = mol->AskAtom("Enter atom number: ");
|
|---|
| 141 | Log() << Verbose(0) << "Enter relative coordinates." << endl;
|
|---|
| 142 | first->x.AskPosition(mol->cell_size, false);
|
|---|
| 143 | for (int i=NDIM;i--;) {
|
|---|
| 144 | first->x.x[i] += second->x.x[i];
|
|---|
| 145 | }
|
|---|
| 146 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
|---|
| 147 | first->type = periode->AskElement(); // give type
|
|---|
| 148 | mol->AddAtom(first); // add to molecule
|
|---|
| 149 | break;
|
|---|
| 150 |
|
|---|
| 151 | case 'd': // two atoms, two angles and a distance
|
|---|
| 152 | first = new atom;
|
|---|
| 153 | valid = true;
|
|---|
| 154 | do {
|
|---|
| 155 | if (!valid) {
|
|---|
| 156 | eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl;
|
|---|
| 157 | }
|
|---|
| 158 | Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
|
|---|
| 159 | second = mol->AskAtom("Enter central atom: ");
|
|---|
| 160 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
|
|---|
| 161 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
|
|---|
| 162 | a = ask_value("Enter distance between central (first) and new atom: ");
|
|---|
| 163 | b = ask_value("Enter angle between new, first and second atom (degrees): ");
|
|---|
| 164 | b *= M_PI/180.;
|
|---|
| 165 | bound(&b, 0., 2.*M_PI);
|
|---|
| 166 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
|
|---|
| 167 | c *= M_PI/180.;
|
|---|
| 168 | bound(&c, -M_PI, M_PI);
|
|---|
| 169 | Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
|
|---|
| 170 | /*
|
|---|
| 171 | second->Output(1,1,(ofstream *)&cout);
|
|---|
| 172 | third->Output(1,2,(ofstream *)&cout);
|
|---|
| 173 | fourth->Output(1,3,(ofstream *)&cout);
|
|---|
| 174 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
|
|---|
| 175 | x.Copyvector(&second->x);
|
|---|
| 176 | x.SubtractVector(&third->x);
|
|---|
| 177 | x.Copyvector(&fourth->x);
|
|---|
| 178 | x.SubtractVector(&third->x);
|
|---|
| 179 |
|
|---|
| 180 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
|
|---|
| 181 | Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
|
|---|
| 182 | continue;
|
|---|
| 183 | }
|
|---|
| 184 | Log() << Verbose(0) << "resulting relative coordinates: ";
|
|---|
| 185 | z.Output();
|
|---|
| 186 | Log() << Verbose(0) << endl;
|
|---|
| 187 | */
|
|---|
| 188 | // calc axis vector
|
|---|
| 189 | x.CopyVector(&second->x);
|
|---|
| 190 | x.SubtractVector(&third->x);
|
|---|
| 191 | x.Normalize();
|
|---|
| 192 | Log() << Verbose(0) << "x: ",
|
|---|
| 193 | x.Output();
|
|---|
| 194 | Log() << Verbose(0) << endl;
|
|---|
| 195 | z.MakeNormalVector(&second->x,&third->x,&fourth->x);
|
|---|
| 196 | Log() << Verbose(0) << "z: ",
|
|---|
| 197 | z.Output();
|
|---|
| 198 | Log() << Verbose(0) << endl;
|
|---|
| 199 | y.MakeNormalVector(&x,&z);
|
|---|
| 200 | Log() << Verbose(0) << "y: ",
|
|---|
| 201 | y.Output();
|
|---|
| 202 | Log() << Verbose(0) << endl;
|
|---|
| 203 |
|
|---|
| 204 | // rotate vector around first angle
|
|---|
| 205 | first->x.CopyVector(&x);
|
|---|
| 206 | first->x.RotateVector(&z,b - M_PI);
|
|---|
| 207 | Log() << Verbose(0) << "Rotated vector: ",
|
|---|
| 208 | first->x.Output();
|
|---|
| 209 | Log() << Verbose(0) << endl;
|
|---|
| 210 | // remove the projection onto the rotation plane of the second angle
|
|---|
| 211 | n.CopyVector(&y);
|
|---|
| 212 | n.Scale(first->x.ScalarProduct(&y));
|
|---|
| 213 | Log() << Verbose(0) << "N1: ",
|
|---|
| 214 | n.Output();
|
|---|
| 215 | Log() << Verbose(0) << endl;
|
|---|
| 216 | first->x.SubtractVector(&n);
|
|---|
| 217 | Log() << Verbose(0) << "Subtracted vector: ",
|
|---|
| 218 | first->x.Output();
|
|---|
| 219 | Log() << Verbose(0) << endl;
|
|---|
| 220 | n.CopyVector(&z);
|
|---|
| 221 | n.Scale(first->x.ScalarProduct(&z));
|
|---|
| 222 | Log() << Verbose(0) << "N2: ",
|
|---|
| 223 | n.Output();
|
|---|
| 224 | Log() << Verbose(0) << endl;
|
|---|
| 225 | first->x.SubtractVector(&n);
|
|---|
| 226 | Log() << Verbose(0) << "2nd subtracted vector: ",
|
|---|
| 227 | first->x.Output();
|
|---|
| 228 | Log() << Verbose(0) << endl;
|
|---|
| 229 |
|
|---|
| 230 | // rotate another vector around second angle
|
|---|
| 231 | n.CopyVector(&y);
|
|---|
| 232 | n.RotateVector(&x,c - M_PI);
|
|---|
| 233 | Log() << Verbose(0) << "2nd Rotated vector: ",
|
|---|
| 234 | n.Output();
|
|---|
| 235 | Log() << Verbose(0) << endl;
|
|---|
| 236 |
|
|---|
| 237 | // add the two linear independent vectors
|
|---|
| 238 | first->x.AddVector(&n);
|
|---|
| 239 | first->x.Normalize();
|
|---|
| 240 | first->x.Scale(a);
|
|---|
| 241 | first->x.AddVector(&second->x);
|
|---|
| 242 |
|
|---|
| 243 | Log() << Verbose(0) << "resulting coordinates: ";
|
|---|
| 244 | first->x.Output();
|
|---|
| 245 | Log() << Verbose(0) << endl;
|
|---|
| 246 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
|---|
| 247 | first->type = periode->AskElement(); // give type
|
|---|
| 248 | mol->AddAtom(first); // add to molecule
|
|---|
| 249 | break;
|
|---|
| 250 |
|
|---|
| 251 | case 'e': // least square distance position to a set of atoms
|
|---|
| 252 | first = new atom;
|
|---|
| 253 | atoms = new (Vector*[128]);
|
|---|
| 254 | valid = true;
|
|---|
| 255 | for(int i=128;i--;)
|
|---|
| 256 | atoms[i] = NULL;
|
|---|
| 257 | int i=0, j=0;
|
|---|
| 258 | Log() << Verbose(0) << "Now we need at least three molecules.\n";
|
|---|
| 259 | do {
|
|---|
| 260 | Log() << Verbose(0) << "Enter " << i+1 << "th atom: ";
|
|---|
| 261 | cin >> j;
|
|---|
| 262 | if (j != -1) {
|
|---|
| 263 | second = mol->FindAtom(j);
|
|---|
| 264 | atoms[i++] = &(second->x);
|
|---|
| 265 | }
|
|---|
| 266 | } while ((j != -1) && (i<128));
|
|---|
| 267 | if (i >= 2) {
|
|---|
| 268 | first->x.LSQdistance((const Vector **)atoms, i);
|
|---|
| 269 | first->x.Output();
|
|---|
| 270 | first->type = periode->AskElement(); // give type
|
|---|
| 271 | mol->AddAtom(first); // add to molecule
|
|---|
| 272 | } else {
|
|---|
| 273 | delete first;
|
|---|
| 274 | Log() << Verbose(0) << "Please enter at least two vectors!\n";
|
|---|
| 275 | }
|
|---|
| 276 | break;
|
|---|
| 277 | };
|
|---|
| 278 | };
|
|---|
| 279 |
|
|---|
| 280 | /** Submenu for centering the atoms in the molecule.
|
|---|
| 281 | * \param *mol molecule with all the atoms
|
|---|
| 282 | */
|
|---|
| 283 | static void CenterAtoms(molecule *mol)
|
|---|
| 284 | {
|
|---|
| 285 | Vector x, y, helper;
|
|---|
| 286 | char choice; // menu choice char
|
|---|
| 287 |
|
|---|
| 288 | Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
|
|---|
| 289 | Log() << Verbose(0) << " a - on origin" << endl;
|
|---|
| 290 | Log() << Verbose(0) << " b - on center of gravity" << endl;
|
|---|
| 291 | Log() << Verbose(0) << " c - within box with additional boundary" << endl;
|
|---|
| 292 | Log() << Verbose(0) << " d - within given simulation box" << endl;
|
|---|
| 293 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 294 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 295 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 296 | cin >> choice;
|
|---|
| 297 |
|
|---|
| 298 | switch (choice) {
|
|---|
| 299 | default:
|
|---|
| 300 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
|---|
| 301 | break;
|
|---|
| 302 | case 'a':
|
|---|
| 303 | Log() << Verbose(0) << "Centering atoms in config file on origin." << endl;
|
|---|
| 304 | mol->CenterOrigin();
|
|---|
| 305 | break;
|
|---|
| 306 | case 'b':
|
|---|
| 307 | Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
|
|---|
| 308 | mol->CenterPeriodic();
|
|---|
| 309 | break;
|
|---|
| 310 | case 'c':
|
|---|
| 311 | Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
|
|---|
| 312 | for (int i=0;i<NDIM;i++) {
|
|---|
| 313 | Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
|
|---|
| 314 | cin >> y.x[i];
|
|---|
| 315 | }
|
|---|
| 316 | mol->CenterEdge(&x); // make every coordinate positive
|
|---|
| 317 | mol->Center.AddVector(&y); // translate by boundary
|
|---|
| 318 | helper.CopyVector(&y);
|
|---|
| 319 | helper.Scale(2.);
|
|---|
| 320 | helper.AddVector(&x);
|
|---|
| 321 | mol->SetBoxDimension(&helper); // update Box of atoms by boundary
|
|---|
| 322 | break;
|
|---|
| 323 | case 'd':
|
|---|
| 324 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
|---|
| 325 | for (int i=0;i<NDIM;i++) {
|
|---|
| 326 | Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
|
|---|
| 327 | cin >> x.x[i];
|
|---|
| 328 | }
|
|---|
| 329 | // update Box of atoms by boundary
|
|---|
| 330 | mol->SetBoxDimension(&x);
|
|---|
| 331 | // center
|
|---|
| 332 | mol->CenterInBox();
|
|---|
| 333 | break;
|
|---|
| 334 | }
|
|---|
| 335 | };
|
|---|
| 336 |
|
|---|
| 337 | /** Submenu for aligning the atoms in the molecule.
|
|---|
| 338 | * \param *periode periodentafel
|
|---|
| 339 | * \param *mol molecule with all the atoms
|
|---|
| 340 | */
|
|---|
| 341 | static void AlignAtoms(periodentafel *periode, molecule *mol)
|
|---|
| 342 | {
|
|---|
| 343 | atom *first, *second, *third;
|
|---|
| 344 | Vector x,n;
|
|---|
| 345 | char choice; // menu choice char
|
|---|
| 346 |
|
|---|
| 347 | Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
|
|---|
| 348 | Log() << Verbose(0) << " a - state three atoms defining align plane" << endl;
|
|---|
| 349 | Log() << Verbose(0) << " b - state alignment vector" << endl;
|
|---|
| 350 | Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl;
|
|---|
| 351 | Log() << Verbose(0) << " d - align automatically by least square fit" << endl;
|
|---|
| 352 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 353 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 354 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 355 | cin >> choice;
|
|---|
| 356 |
|
|---|
| 357 | switch (choice) {
|
|---|
| 358 | default:
|
|---|
| 359 | case 'a': // three atoms defining mirror plane
|
|---|
| 360 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 361 | second = mol->AskAtom("Enter second atom: ");
|
|---|
| 362 | third = mol->AskAtom("Enter third atom: ");
|
|---|
| 363 |
|
|---|
| 364 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
|---|
| 365 | break;
|
|---|
| 366 | case 'b': // normal vector of mirror plane
|
|---|
| 367 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
|
|---|
| 368 | n.AskPosition(mol->cell_size,0);
|
|---|
| 369 | n.Normalize();
|
|---|
| 370 | break;
|
|---|
| 371 | case 'c': // three atoms defining mirror plane
|
|---|
| 372 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 373 | second = mol->AskAtom("Enter second atom: ");
|
|---|
| 374 |
|
|---|
| 375 | n.CopyVector((const Vector *)&first->x);
|
|---|
| 376 | n.SubtractVector((const Vector *)&second->x);
|
|---|
| 377 | n.Normalize();
|
|---|
| 378 | break;
|
|---|
| 379 | case 'd':
|
|---|
| 380 | char shorthand[4];
|
|---|
| 381 | Vector a;
|
|---|
| 382 | struct lsq_params param;
|
|---|
| 383 | do {
|
|---|
| 384 | fprintf(stdout, "Enter the element of atoms to be chosen: ");
|
|---|
| 385 | fscanf(stdin, "%3s", shorthand);
|
|---|
| 386 | } while ((param.type = periode->FindElement(shorthand)) == NULL);
|
|---|
| 387 | Log() << Verbose(0) << "Element is " << param.type->name << endl;
|
|---|
| 388 | mol->GetAlignvector(¶m);
|
|---|
| 389 | for (int i=NDIM;i--;) {
|
|---|
| 390 | x.x[i] = gsl_vector_get(param.x,i);
|
|---|
| 391 | n.x[i] = gsl_vector_get(param.x,i+NDIM);
|
|---|
| 392 | }
|
|---|
| 393 | gsl_vector_free(param.x);
|
|---|
| 394 | Log() << Verbose(0) << "Offset vector: ";
|
|---|
| 395 | x.Output();
|
|---|
| 396 | Log() << Verbose(0) << endl;
|
|---|
| 397 | n.Normalize();
|
|---|
| 398 | break;
|
|---|
| 399 | };
|
|---|
| 400 | Log() << Verbose(0) << "Alignment vector: ";
|
|---|
| 401 | n.Output();
|
|---|
| 402 | Log() << Verbose(0) << endl;
|
|---|
| 403 | mol->Align(&n);
|
|---|
| 404 | };
|
|---|
| 405 |
|
|---|
| 406 | /** Submenu for mirroring the atoms in the molecule.
|
|---|
| 407 | * \param *mol molecule with all the atoms
|
|---|
| 408 | */
|
|---|
| 409 | static void MirrorAtoms(molecule *mol)
|
|---|
| 410 | {
|
|---|
| 411 | atom *first, *second, *third;
|
|---|
| 412 | Vector n;
|
|---|
| 413 | char choice; // menu choice char
|
|---|
| 414 |
|
|---|
| 415 | Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
|
|---|
| 416 | Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
|
|---|
| 417 | Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl;
|
|---|
| 418 | Log() << Verbose(0) << " c - state two atoms in normal direction" << endl;
|
|---|
| 419 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 420 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 421 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 422 | cin >> choice;
|
|---|
| 423 |
|
|---|
| 424 | switch (choice) {
|
|---|
| 425 | default:
|
|---|
| 426 | case 'a': // three atoms defining mirror plane
|
|---|
| 427 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 428 | second = mol->AskAtom("Enter second atom: ");
|
|---|
| 429 | third = mol->AskAtom("Enter third atom: ");
|
|---|
| 430 |
|
|---|
| 431 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
|---|
| 432 | break;
|
|---|
| 433 | case 'b': // normal vector of mirror plane
|
|---|
| 434 | Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
|
|---|
| 435 | n.AskPosition(mol->cell_size,0);
|
|---|
| 436 | n.Normalize();
|
|---|
| 437 | break;
|
|---|
| 438 | case 'c': // three atoms defining mirror plane
|
|---|
| 439 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 440 | second = mol->AskAtom("Enter second atom: ");
|
|---|
| 441 |
|
|---|
| 442 | n.CopyVector((const Vector *)&first->x);
|
|---|
| 443 | n.SubtractVector((const Vector *)&second->x);
|
|---|
| 444 | n.Normalize();
|
|---|
| 445 | break;
|
|---|
| 446 | };
|
|---|
| 447 | Log() << Verbose(0) << "Normal vector: ";
|
|---|
| 448 | n.Output();
|
|---|
| 449 | Log() << Verbose(0) << endl;
|
|---|
| 450 | mol->Mirror((const Vector *)&n);
|
|---|
| 451 | };
|
|---|
| 452 |
|
|---|
| 453 | /** Submenu for removing the atoms from the molecule.
|
|---|
| 454 | * \param *mol molecule with all the atoms
|
|---|
| 455 | */
|
|---|
| 456 | static void RemoveAtoms(molecule *mol)
|
|---|
| 457 | {
|
|---|
| 458 | atom *first, *second;
|
|---|
| 459 | int axis;
|
|---|
| 460 | double tmp1, tmp2;
|
|---|
| 461 | char choice; // menu choice char
|
|---|
| 462 |
|
|---|
| 463 | Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
|
|---|
| 464 | Log() << Verbose(0) << " a - state atom for removal by number" << endl;
|
|---|
| 465 | Log() << Verbose(0) << " b - keep only in radius around atom" << endl;
|
|---|
| 466 | Log() << Verbose(0) << " c - remove this with one axis greater value" << endl;
|
|---|
| 467 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 468 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 469 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 470 | cin >> choice;
|
|---|
| 471 |
|
|---|
| 472 | switch (choice) {
|
|---|
| 473 | default:
|
|---|
| 474 | case 'a':
|
|---|
| 475 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
|
|---|
| 476 | Log() << Verbose(1) << "Atom removed." << endl;
|
|---|
| 477 | else
|
|---|
| 478 | Log() << Verbose(1) << "Atom not found." << endl;
|
|---|
| 479 | break;
|
|---|
| 480 | case 'b':
|
|---|
| 481 | second = mol->AskAtom("Enter number of atom as reference point: ");
|
|---|
| 482 | Log() << Verbose(0) << "Enter radius: ";
|
|---|
| 483 | cin >> tmp1;
|
|---|
| 484 | first = mol->start;
|
|---|
| 485 | second = first->next;
|
|---|
| 486 | while(second != mol->end) {
|
|---|
| 487 | first = second;
|
|---|
| 488 | second = first->next;
|
|---|
| 489 | if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
|
|---|
| 490 | mol->RemoveAtom(first);
|
|---|
| 491 | }
|
|---|
| 492 | break;
|
|---|
| 493 | case 'c':
|
|---|
| 494 | Log() << Verbose(0) << "Which axis is it: ";
|
|---|
| 495 | cin >> axis;
|
|---|
| 496 | Log() << Verbose(0) << "Lower boundary: ";
|
|---|
| 497 | cin >> tmp1;
|
|---|
| 498 | Log() << Verbose(0) << "Upper boundary: ";
|
|---|
| 499 | cin >> tmp2;
|
|---|
| 500 | first = mol->start;
|
|---|
| 501 | second = first->next;
|
|---|
| 502 | while(second != mol->end) {
|
|---|
| 503 | first = second;
|
|---|
| 504 | second = first->next;
|
|---|
| 505 | if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
|
|---|
| 506 | //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
|
|---|
| 507 | mol->RemoveAtom(first);
|
|---|
| 508 | }
|
|---|
| 509 | }
|
|---|
| 510 | break;
|
|---|
| 511 | };
|
|---|
| 512 | //mol->Output();
|
|---|
| 513 | choice = 'r';
|
|---|
| 514 | };
|
|---|
| 515 |
|
|---|
| 516 | /** Submenu for measuring out the atoms in the molecule.
|
|---|
| 517 | * \param *periode periodentafel
|
|---|
| 518 | * \param *mol molecule with all the atoms
|
|---|
| 519 | */
|
|---|
| 520 | static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
|
|---|
| 521 | {
|
|---|
| 522 | atom *first, *second, *third;
|
|---|
| 523 | Vector x,y;
|
|---|
| 524 | double min[256], tmp1, tmp2, tmp3;
|
|---|
| 525 | int Z;
|
|---|
| 526 | char choice; // menu choice char
|
|---|
| 527 |
|
|---|
| 528 | Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
|
|---|
| 529 | Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
|
|---|
| 530 | Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl;
|
|---|
| 531 | Log() << Verbose(0) << " c - calculate bond angle" << endl;
|
|---|
| 532 | Log() << Verbose(0) << " d - calculate principal axis of the system" << endl;
|
|---|
| 533 | Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
|
|---|
| 534 | Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl;
|
|---|
| 535 | Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
|
|---|
| 536 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 537 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 538 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 539 | cin >> choice;
|
|---|
| 540 |
|
|---|
| 541 | switch(choice) {
|
|---|
| 542 | default:
|
|---|
| 543 | Log() << Verbose(1) << "Not a valid choice." << endl;
|
|---|
| 544 | break;
|
|---|
| 545 | case 'a':
|
|---|
| 546 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 547 | for (int i=MAX_ELEMENTS;i--;)
|
|---|
| 548 | min[i] = 0.;
|
|---|
| 549 |
|
|---|
| 550 | second = mol->start;
|
|---|
| 551 | while ((second->next != mol->end)) {
|
|---|
| 552 | second = second->next; // advance
|
|---|
| 553 | Z = second->type->Z;
|
|---|
| 554 | tmp1 = 0.;
|
|---|
| 555 | if (first != second) {
|
|---|
| 556 | x.CopyVector((const Vector *)&first->x);
|
|---|
| 557 | x.SubtractVector((const Vector *)&second->x);
|
|---|
| 558 | tmp1 = x.Norm();
|
|---|
| 559 | }
|
|---|
| 560 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
|
|---|
| 561 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
|
|---|
| 562 | }
|
|---|
| 563 | for (int i=MAX_ELEMENTS;i--;)
|
|---|
| 564 | 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;
|
|---|
| 565 | break;
|
|---|
| 566 |
|
|---|
| 567 | case 'b':
|
|---|
| 568 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 569 | second = mol->AskAtom("Enter second atom: ");
|
|---|
| 570 | for (int i=NDIM;i--;)
|
|---|
| 571 | min[i] = 0.;
|
|---|
| 572 | x.CopyVector((const Vector *)&first->x);
|
|---|
| 573 | x.SubtractVector((const Vector *)&second->x);
|
|---|
| 574 | tmp1 = x.Norm();
|
|---|
| 575 | Log() << Verbose(1) << "Distance vector is ";
|
|---|
| 576 | x.Output();
|
|---|
| 577 | Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
|
|---|
| 578 | break;
|
|---|
| 579 |
|
|---|
| 580 | case 'c':
|
|---|
| 581 | Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
|
|---|
| 582 | first = mol->AskAtom("Enter first atom: ");
|
|---|
| 583 | second = mol->AskAtom("Enter central atom: ");
|
|---|
| 584 | third = mol->AskAtom("Enter last atom: ");
|
|---|
| 585 | tmp1 = tmp2 = tmp3 = 0.;
|
|---|
| 586 | x.CopyVector((const Vector *)&first->x);
|
|---|
| 587 | x.SubtractVector((const Vector *)&second->x);
|
|---|
| 588 | y.CopyVector((const Vector *)&third->x);
|
|---|
| 589 | y.SubtractVector((const Vector *)&second->x);
|
|---|
| 590 | Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
|---|
| 591 | Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
|
|---|
| 592 | break;
|
|---|
| 593 | case 'd':
|
|---|
| 594 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
|---|
| 595 | Log() << Verbose(0) << "Shall we rotate? [0/1]: ";
|
|---|
| 596 | cin >> Z;
|
|---|
| 597 | if ((Z >=0) && (Z <=1))
|
|---|
| 598 | mol->PrincipalAxisSystem((bool)Z);
|
|---|
| 599 | else
|
|---|
| 600 | mol->PrincipalAxisSystem(false);
|
|---|
| 601 | break;
|
|---|
| 602 | case 'e':
|
|---|
| 603 | {
|
|---|
| 604 | Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
|
|---|
| 605 | class Tesselation *TesselStruct = NULL;
|
|---|
| 606 | const LinkedCell *LCList = NULL;
|
|---|
| 607 | LCList = new LinkedCell(mol, 10.);
|
|---|
| 608 | FindConvexBorder(mol, TesselStruct, LCList, NULL);
|
|---|
| 609 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
|
|---|
| 610 | Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\
|
|---|
| 611 | delete(LCList);
|
|---|
| 612 | delete(TesselStruct);
|
|---|
| 613 | }
|
|---|
| 614 | break;
|
|---|
| 615 | case 'f':
|
|---|
| 616 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
|
|---|
| 617 | break;
|
|---|
| 618 | case 'g':
|
|---|
| 619 | {
|
|---|
| 620 | char filename[255];
|
|---|
| 621 | Log() << Verbose(0) << "Please enter filename: " << endl;
|
|---|
| 622 | cin >> filename;
|
|---|
| 623 | Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
|
|---|
| 624 | ofstream *output = new ofstream(filename, ios::trunc);
|
|---|
| 625 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
|
|---|
| 626 | Log() << Verbose(2) << "File could not be written." << endl;
|
|---|
| 627 | else
|
|---|
| 628 | Log() << Verbose(2) << "File stored." << endl;
|
|---|
| 629 | output->close();
|
|---|
| 630 | delete(output);
|
|---|
| 631 | }
|
|---|
| 632 | break;
|
|---|
| 633 | }
|
|---|
| 634 | };
|
|---|
| 635 |
|
|---|
| 636 | /** Submenu for measuring out the atoms in the molecule.
|
|---|
| 637 | * \param *mol molecule with all the atoms
|
|---|
| 638 | * \param *configuration configuration structure for the to be written config files of all fragments
|
|---|
| 639 | */
|
|---|
| 640 | static void FragmentAtoms(molecule *mol, config *configuration)
|
|---|
| 641 | {
|
|---|
| 642 | int Order1;
|
|---|
| 643 | clock_t start, end;
|
|---|
| 644 |
|
|---|
| 645 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
|---|
| 646 | Log() << Verbose(0) << "What's the desired bond order: ";
|
|---|
| 647 | cin >> Order1;
|
|---|
| 648 | if (mol->first->next != mol->last) { // there are bonds
|
|---|
| 649 | start = clock();
|
|---|
| 650 | mol->FragmentMolecule(Order1, configuration);
|
|---|
| 651 | end = clock();
|
|---|
| 652 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
|---|
| 653 | } else
|
|---|
| 654 | Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
|
|---|
| 655 | };
|
|---|
| 656 |
|
|---|
| 657 | /********************************************** Submenu routine **************************************/
|
|---|
| 658 |
|
|---|
| 659 | /** Submenu for manipulating atoms.
|
|---|
| 660 | * \param *periode periodentafel
|
|---|
| 661 | * \param *molecules list of molecules whose atoms are to be manipulated
|
|---|
| 662 | */
|
|---|
| 663 | static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
|---|
| 664 | {
|
|---|
| 665 | atom *first, *second;
|
|---|
| 666 | molecule *mol = NULL;
|
|---|
| 667 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
|---|
| 668 | double *factor; // unit factor if desired
|
|---|
| 669 | double bond, minBond;
|
|---|
| 670 | char choice; // menu choice char
|
|---|
| 671 | bool valid;
|
|---|
| 672 |
|
|---|
| 673 | Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
|
|---|
| 674 | Log() << Verbose(0) << "a - add an atom" << endl;
|
|---|
| 675 | Log() << Verbose(0) << "r - remove an atom" << endl;
|
|---|
| 676 | Log() << Verbose(0) << "b - scale a bond between atoms" << endl;
|
|---|
| 677 | Log() << Verbose(0) << "u - change an atoms element" << endl;
|
|---|
| 678 | Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
|
|---|
| 679 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 680 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 681 | if (molecules->NumberOfActiveMolecules() > 1)
|
|---|
| 682 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
|
|---|
| 683 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 684 | cin >> choice;
|
|---|
| 685 |
|
|---|
| 686 | switch (choice) {
|
|---|
| 687 | default:
|
|---|
| 688 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
|---|
| 689 | break;
|
|---|
| 690 |
|
|---|
| 691 | case 'a': // add atom
|
|---|
| 692 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 693 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 694 | mol = *ListRunner;
|
|---|
| 695 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 696 | AddAtoms(periode, mol);
|
|---|
| 697 | }
|
|---|
| 698 | break;
|
|---|
| 699 |
|
|---|
| 700 | case 'b': // scale a bond
|
|---|
| 701 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 702 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 703 | mol = *ListRunner;
|
|---|
| 704 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 705 | Log() << Verbose(0) << "Scaling bond length between two atoms." << endl;
|
|---|
| 706 | first = mol->AskAtom("Enter first (fixed) atom: ");
|
|---|
| 707 | second = mol->AskAtom("Enter second (shifting) atom: ");
|
|---|
| 708 | minBond = 0.;
|
|---|
| 709 | for (int i=NDIM;i--;)
|
|---|
| 710 | minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
|
|---|
| 711 | minBond = sqrt(minBond);
|
|---|
| 712 | Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
|
|---|
| 713 | Log() << Verbose(0) << "Enter new bond length [a.u.]: ";
|
|---|
| 714 | cin >> bond;
|
|---|
| 715 | for (int i=NDIM;i--;) {
|
|---|
| 716 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
|
|---|
| 717 | }
|
|---|
| 718 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
|
|---|
| 719 | //second->Output(second->type->No, 1);
|
|---|
| 720 | }
|
|---|
| 721 | break;
|
|---|
| 722 |
|
|---|
| 723 | case 'c': // unit scaling of the metric
|
|---|
| 724 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 725 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 726 | mol = *ListRunner;
|
|---|
| 727 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 728 | Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
|
|---|
| 729 | Log() << Verbose(0) << "Enter three factors: ";
|
|---|
| 730 | factor = new double[NDIM];
|
|---|
| 731 | cin >> factor[0];
|
|---|
| 732 | cin >> factor[1];
|
|---|
| 733 | cin >> factor[2];
|
|---|
| 734 | valid = true;
|
|---|
| 735 | mol->Scale((const double ** const)&factor);
|
|---|
| 736 | delete[](factor);
|
|---|
| 737 | }
|
|---|
| 738 | break;
|
|---|
| 739 |
|
|---|
| 740 | case 'l': // measure distances or angles
|
|---|
| 741 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 742 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 743 | mol = *ListRunner;
|
|---|
| 744 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 745 | MeasureAtoms(periode, mol, configuration);
|
|---|
| 746 | }
|
|---|
| 747 | break;
|
|---|
| 748 |
|
|---|
| 749 | case 'r': // remove atom
|
|---|
| 750 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 751 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 752 | mol = *ListRunner;
|
|---|
| 753 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 754 | RemoveAtoms(mol);
|
|---|
| 755 | }
|
|---|
| 756 | break;
|
|---|
| 757 |
|
|---|
| 758 | case 'u': // change an atom's element
|
|---|
| 759 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 760 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 761 | int Z;
|
|---|
| 762 | mol = *ListRunner;
|
|---|
| 763 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 764 | first = NULL;
|
|---|
| 765 | do {
|
|---|
| 766 | Log() << Verbose(0) << "Change the element of which atom: ";
|
|---|
| 767 | cin >> Z;
|
|---|
| 768 | } while ((first = mol->FindAtom(Z)) == NULL);
|
|---|
| 769 | Log() << Verbose(0) << "New element by atomic number Z: ";
|
|---|
| 770 | cin >> Z;
|
|---|
| 771 | first->type = periode->FindElement(Z);
|
|---|
| 772 | Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
|
|---|
| 773 | }
|
|---|
| 774 | break;
|
|---|
| 775 | }
|
|---|
| 776 | };
|
|---|
| 777 |
|
|---|
| 778 | /** Submenu for manipulating molecules.
|
|---|
| 779 | * \param *periode periodentafel
|
|---|
| 780 | * \param *molecules list of molecule to manipulate
|
|---|
| 781 | */
|
|---|
| 782 | static void ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
|---|
| 783 | {
|
|---|
| 784 | atom *first = NULL;
|
|---|
| 785 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
|---|
| 786 | int j, axis, count, faktor;
|
|---|
| 787 | char choice; // menu choice char
|
|---|
| 788 | molecule *mol = NULL;
|
|---|
| 789 | element **Elements;
|
|---|
| 790 | Vector **vectors;
|
|---|
| 791 | MoleculeLeafClass *Subgraphs = NULL;
|
|---|
| 792 |
|
|---|
| 793 | Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
|
|---|
| 794 | Log() << Verbose(0) << "c - scale by unit transformation" << endl;
|
|---|
| 795 | Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
|
|---|
| 796 | Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
|
|---|
| 797 | Log() << Verbose(0) << "g - center atoms in box" << endl;
|
|---|
| 798 | Log() << Verbose(0) << "i - realign molecule" << endl;
|
|---|
| 799 | Log() << Verbose(0) << "m - mirror all molecules" << endl;
|
|---|
| 800 | Log() << Verbose(0) << "o - create connection matrix" << endl;
|
|---|
| 801 | Log() << Verbose(0) << "t - translate molecule by vector" << endl;
|
|---|
| 802 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 803 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 804 | if (molecules->NumberOfActiveMolecules() > 1)
|
|---|
| 805 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
|
|---|
| 806 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 807 | cin >> choice;
|
|---|
| 808 |
|
|---|
| 809 | switch (choice) {
|
|---|
| 810 | default:
|
|---|
| 811 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
|---|
| 812 | break;
|
|---|
| 813 |
|
|---|
| 814 | case 'd': // duplicate the periodic cell along a given axis, given times
|
|---|
| 815 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 816 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 817 | mol = *ListRunner;
|
|---|
| 818 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 819 | Log() << Verbose(0) << "State the axis [(+-)123]: ";
|
|---|
| 820 | cin >> axis;
|
|---|
| 821 | Log() << Verbose(0) << "State the factor: ";
|
|---|
| 822 | cin >> faktor;
|
|---|
| 823 |
|
|---|
| 824 | mol->CountAtoms(); // recount atoms
|
|---|
| 825 | if (mol->AtomCount != 0) { // if there is more than none
|
|---|
| 826 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
|---|
| 827 | Elements = new element *[count];
|
|---|
| 828 | vectors = new Vector *[count];
|
|---|
| 829 | j = 0;
|
|---|
| 830 | first = mol->start;
|
|---|
| 831 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
|---|
| 832 | first = first->next;
|
|---|
| 833 | Elements[j] = first->type;
|
|---|
| 834 | vectors[j] = &first->x;
|
|---|
| 835 | j++;
|
|---|
| 836 | }
|
|---|
| 837 | if (count != j)
|
|---|
| 838 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
|---|
| 839 | x.Zero();
|
|---|
| 840 | y.Zero();
|
|---|
| 841 | 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
|
|---|
| 842 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
|---|
| 843 | x.AddVector(&y); // per factor one cell width further
|
|---|
| 844 | for (int k=count;k--;) { // go through every atom of the original cell
|
|---|
| 845 | first = new atom(); // create a new body
|
|---|
| 846 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
|---|
| 847 | first->x.AddVector(&x); // translate the coordinates
|
|---|
| 848 | first->type = Elements[k]; // insert original element
|
|---|
| 849 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
|---|
| 850 | }
|
|---|
| 851 | }
|
|---|
| 852 | if (mol->first->next != mol->last) // if connect matrix is present already, redo it
|
|---|
| 853 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
|---|
| 854 | // free memory
|
|---|
| 855 | delete[](Elements);
|
|---|
| 856 | delete[](vectors);
|
|---|
| 857 | // correct cell size
|
|---|
| 858 | if (axis < 0) { // if sign was negative, we have to translate everything
|
|---|
| 859 | x.Zero();
|
|---|
| 860 | x.AddVector(&y);
|
|---|
| 861 | x.Scale(-(faktor-1));
|
|---|
| 862 | mol->Translate(&x);
|
|---|
| 863 | }
|
|---|
| 864 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
|---|
| 865 | }
|
|---|
| 866 | }
|
|---|
| 867 | break;
|
|---|
| 868 |
|
|---|
| 869 | case 'f':
|
|---|
| 870 | FragmentAtoms(mol, configuration);
|
|---|
| 871 | break;
|
|---|
| 872 |
|
|---|
| 873 | case 'g': // center the atoms
|
|---|
| 874 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 875 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 876 | mol = *ListRunner;
|
|---|
| 877 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 878 | CenterAtoms(mol);
|
|---|
| 879 | }
|
|---|
| 880 | break;
|
|---|
| 881 |
|
|---|
| 882 | case 'i': // align all atoms
|
|---|
| 883 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 884 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 885 | mol = *ListRunner;
|
|---|
| 886 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 887 | AlignAtoms(periode, mol);
|
|---|
| 888 | }
|
|---|
| 889 | break;
|
|---|
| 890 |
|
|---|
| 891 | case 'm': // mirror atoms along a given axis
|
|---|
| 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 | MirrorAtoms(mol);
|
|---|
| 897 | }
|
|---|
| 898 | break;
|
|---|
| 899 |
|
|---|
| 900 | case 'o': // create the connection matrix
|
|---|
| 901 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 902 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 903 | mol = *ListRunner;
|
|---|
| 904 | double bonddistance;
|
|---|
| 905 | clock_t start,end;
|
|---|
| 906 | Log() << Verbose(0) << "What's the maximum bond distance: ";
|
|---|
| 907 | cin >> bonddistance;
|
|---|
| 908 | start = clock();
|
|---|
| 909 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
|---|
| 910 | end = clock();
|
|---|
| 911 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
|---|
| 912 | }
|
|---|
| 913 | break;
|
|---|
| 914 |
|
|---|
| 915 | case 't': // translate all atoms
|
|---|
| 916 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 917 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 918 | mol = *ListRunner;
|
|---|
| 919 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
|---|
| 920 | Log() << Verbose(0) << "Enter translation vector." << endl;
|
|---|
| 921 | x.AskPosition(mol->cell_size,0);
|
|---|
| 922 | mol->Center.AddVector((const Vector *)&x);
|
|---|
| 923 | }
|
|---|
| 924 | break;
|
|---|
| 925 | }
|
|---|
| 926 | // Free all
|
|---|
| 927 | if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
|
|---|
| 928 | while (Subgraphs->next != NULL) {
|
|---|
| 929 | Subgraphs = Subgraphs->next;
|
|---|
| 930 | delete(Subgraphs->previous);
|
|---|
| 931 | }
|
|---|
| 932 | delete(Subgraphs);
|
|---|
| 933 | }
|
|---|
| 934 | };
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 | /** Submenu for creating new molecules.
|
|---|
| 938 | * \param *periode periodentafel
|
|---|
| 939 | * \param *molecules list of molecules to add to
|
|---|
| 940 | */
|
|---|
| 941 | static void EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
|
|---|
| 942 | {
|
|---|
| 943 | char choice; // menu choice char
|
|---|
| 944 | Vector center;
|
|---|
| 945 | int nr, count;
|
|---|
| 946 | molecule *mol = NULL;
|
|---|
| 947 |
|
|---|
| 948 | Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
|
|---|
| 949 | Log() << Verbose(0) << "c - create new molecule" << endl;
|
|---|
| 950 | Log() << Verbose(0) << "l - load molecule from xyz file" << endl;
|
|---|
| 951 | Log() << Verbose(0) << "n - change molecule's name" << endl;
|
|---|
| 952 | Log() << Verbose(0) << "N - give molecules filename" << endl;
|
|---|
| 953 | Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
|
|---|
| 954 | Log() << Verbose(0) << "r - remove a molecule" << endl;
|
|---|
| 955 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 956 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 957 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 958 | cin >> choice;
|
|---|
| 959 |
|
|---|
| 960 | switch (choice) {
|
|---|
| 961 | default:
|
|---|
| 962 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
|---|
| 963 | break;
|
|---|
| 964 | case 'c':
|
|---|
| 965 | mol = new molecule(periode);
|
|---|
| 966 | molecules->insert(mol);
|
|---|
| 967 | break;
|
|---|
| 968 |
|
|---|
| 969 | case 'l': // load from XYZ file
|
|---|
| 970 | {
|
|---|
| 971 | char filename[MAXSTRINGSIZE];
|
|---|
| 972 | Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
|
|---|
| 973 | mol = new molecule(periode);
|
|---|
| 974 | do {
|
|---|
| 975 | Log() << Verbose(0) << "Enter file name: ";
|
|---|
| 976 | cin >> filename;
|
|---|
| 977 | } while (!mol->AddXYZFile(filename));
|
|---|
| 978 | mol->SetNameFromFilename(filename);
|
|---|
| 979 | // center at set box dimensions
|
|---|
| 980 | mol->CenterEdge(¢er);
|
|---|
| 981 | mol->cell_size[0] = center.x[0];
|
|---|
| 982 | mol->cell_size[1] = 0;
|
|---|
| 983 | mol->cell_size[2] = center.x[1];
|
|---|
| 984 | mol->cell_size[3] = 0;
|
|---|
| 985 | mol->cell_size[4] = 0;
|
|---|
| 986 | mol->cell_size[5] = center.x[2];
|
|---|
| 987 | molecules->insert(mol);
|
|---|
| 988 | }
|
|---|
| 989 | break;
|
|---|
| 990 |
|
|---|
| 991 | case 'n':
|
|---|
| 992 | {
|
|---|
| 993 | char filename[MAXSTRINGSIZE];
|
|---|
| 994 | do {
|
|---|
| 995 | Log() << Verbose(0) << "Enter index of molecule: ";
|
|---|
| 996 | cin >> nr;
|
|---|
| 997 | mol = molecules->ReturnIndex(nr);
|
|---|
| 998 | } while (mol == NULL);
|
|---|
| 999 | Log() << Verbose(0) << "Enter name: ";
|
|---|
| 1000 | cin >> filename;
|
|---|
| 1001 | strcpy(mol->name, filename);
|
|---|
| 1002 | }
|
|---|
| 1003 | break;
|
|---|
| 1004 |
|
|---|
| 1005 | case 'N':
|
|---|
| 1006 | {
|
|---|
| 1007 | char filename[MAXSTRINGSIZE];
|
|---|
| 1008 | do {
|
|---|
| 1009 | Log() << Verbose(0) << "Enter index of molecule: ";
|
|---|
| 1010 | cin >> nr;
|
|---|
| 1011 | mol = molecules->ReturnIndex(nr);
|
|---|
| 1012 | } while (mol == NULL);
|
|---|
| 1013 | Log() << Verbose(0) << "Enter name: ";
|
|---|
| 1014 | cin >> filename;
|
|---|
| 1015 | mol->SetNameFromFilename(filename);
|
|---|
| 1016 | }
|
|---|
| 1017 | break;
|
|---|
| 1018 |
|
|---|
| 1019 | case 'p': // parse XYZ file
|
|---|
| 1020 | {
|
|---|
| 1021 | char filename[MAXSTRINGSIZE];
|
|---|
| 1022 | mol = NULL;
|
|---|
| 1023 | do {
|
|---|
| 1024 | Log() << Verbose(0) << "Enter index of molecule: ";
|
|---|
| 1025 | cin >> nr;
|
|---|
| 1026 | mol = molecules->ReturnIndex(nr);
|
|---|
| 1027 | } while (mol == NULL);
|
|---|
| 1028 | Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
|
|---|
| 1029 | do {
|
|---|
| 1030 | Log() << Verbose(0) << "Enter file name: ";
|
|---|
| 1031 | cin >> filename;
|
|---|
| 1032 | } while (!mol->AddXYZFile(filename));
|
|---|
| 1033 | mol->SetNameFromFilename(filename);
|
|---|
| 1034 | }
|
|---|
| 1035 | break;
|
|---|
| 1036 |
|
|---|
| 1037 | case 'r':
|
|---|
| 1038 | Log() << Verbose(0) << "Enter index of molecule: ";
|
|---|
| 1039 | cin >> nr;
|
|---|
| 1040 | count = 1;
|
|---|
| 1041 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 1042 | if (nr == (*ListRunner)->IndexNr) {
|
|---|
| 1043 | mol = *ListRunner;
|
|---|
| 1044 | molecules->ListOfMolecules.erase(ListRunner);
|
|---|
| 1045 | delete(mol);
|
|---|
| 1046 | break;
|
|---|
| 1047 | }
|
|---|
| 1048 | break;
|
|---|
| 1049 | }
|
|---|
| 1050 | };
|
|---|
| 1051 |
|
|---|
| 1052 |
|
|---|
| 1053 | /** Submenu for merging molecules.
|
|---|
| 1054 | * \param *periode periodentafel
|
|---|
| 1055 | * \param *molecules list of molecules to add to
|
|---|
| 1056 | */
|
|---|
| 1057 | static void MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
|
|---|
| 1058 | {
|
|---|
| 1059 | char choice; // menu choice char
|
|---|
| 1060 |
|
|---|
| 1061 | Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
|
|---|
| 1062 | Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
|
|---|
| 1063 | Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
|
|---|
| 1064 | Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
|
|---|
| 1065 | Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
|
|---|
| 1066 | Log() << Verbose(0) << "t - simple merge of two molecules" << endl;
|
|---|
| 1067 | Log() << Verbose(0) << "all else - go back" << endl;
|
|---|
| 1068 | Log() << Verbose(0) << "===============================================" << endl;
|
|---|
| 1069 | Log() << Verbose(0) << "INPUT: ";
|
|---|
| 1070 | cin >> choice;
|
|---|
| 1071 |
|
|---|
| 1072 | switch (choice) {
|
|---|
| 1073 | default:
|
|---|
| 1074 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
|---|
| 1075 | break;
|
|---|
| 1076 |
|
|---|
| 1077 | case 'a':
|
|---|
| 1078 | {
|
|---|
| 1079 | int src, dest;
|
|---|
| 1080 | molecule *srcmol = NULL, *destmol = NULL;
|
|---|
| 1081 | {
|
|---|
| 1082 | do {
|
|---|
| 1083 | Log() << Verbose(0) << "Enter index of destination molecule: ";
|
|---|
| 1084 | cin >> dest;
|
|---|
| 1085 | destmol = molecules->ReturnIndex(dest);
|
|---|
| 1086 | } while ((destmol == NULL) && (dest != -1));
|
|---|
| 1087 | do {
|
|---|
| 1088 | Log() << Verbose(0) << "Enter index of source molecule to add from: ";
|
|---|
| 1089 | cin >> src;
|
|---|
| 1090 | srcmol = molecules->ReturnIndex(src);
|
|---|
| 1091 | } while ((srcmol == NULL) && (src != -1));
|
|---|
| 1092 | if ((src != -1) && (dest != -1))
|
|---|
| 1093 | molecules->SimpleAdd(srcmol, destmol);
|
|---|
| 1094 | }
|
|---|
| 1095 | }
|
|---|
| 1096 | break;
|
|---|
| 1097 |
|
|---|
| 1098 | case 'e':
|
|---|
| 1099 | {
|
|---|
| 1100 | int src, dest;
|
|---|
| 1101 | molecule *srcmol = NULL, *destmol = NULL;
|
|---|
| 1102 | do {
|
|---|
| 1103 | Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
|
|---|
| 1104 | cin >> src;
|
|---|
| 1105 | srcmol = molecules->ReturnIndex(src);
|
|---|
| 1106 | } while ((srcmol == NULL) && (src != -1));
|
|---|
| 1107 | do {
|
|---|
| 1108 | Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
|
|---|
| 1109 | cin >> dest;
|
|---|
| 1110 | destmol = molecules->ReturnIndex(dest);
|
|---|
| 1111 | } while ((destmol == NULL) && (dest != -1));
|
|---|
| 1112 | if ((src != -1) && (dest != -1))
|
|---|
| 1113 | molecules->EmbedMerge(destmol, srcmol);
|
|---|
| 1114 | }
|
|---|
| 1115 | break;
|
|---|
| 1116 |
|
|---|
| 1117 | case 'm':
|
|---|
| 1118 | {
|
|---|
| 1119 | int nr;
|
|---|
| 1120 | molecule *mol = NULL;
|
|---|
| 1121 | do {
|
|---|
| 1122 | Log() << Verbose(0) << "Enter index of molecule to merge into: ";
|
|---|
| 1123 | cin >> nr;
|
|---|
| 1124 | mol = molecules->ReturnIndex(nr);
|
|---|
| 1125 | } while ((mol == NULL) && (nr != -1));
|
|---|
| 1126 | if (nr != -1) {
|
|---|
| 1127 | int N = molecules->ListOfMolecules.size()-1;
|
|---|
| 1128 | int *src = new int(N);
|
|---|
| 1129 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 1130 | if ((*ListRunner)->IndexNr != nr)
|
|---|
| 1131 | src[N++] = (*ListRunner)->IndexNr;
|
|---|
| 1132 | molecules->SimpleMultiMerge(mol, src, N);
|
|---|
| 1133 | delete[](src);
|
|---|
| 1134 | }
|
|---|
| 1135 | }
|
|---|
| 1136 | break;
|
|---|
| 1137 |
|
|---|
| 1138 | case 's':
|
|---|
| 1139 | Log() << Verbose(0) << "Not implemented yet." << endl;
|
|---|
| 1140 | break;
|
|---|
| 1141 |
|
|---|
| 1142 | case 't':
|
|---|
| 1143 | {
|
|---|
| 1144 | int src, dest;
|
|---|
| 1145 | molecule *srcmol = NULL, *destmol = NULL;
|
|---|
| 1146 | {
|
|---|
| 1147 | do {
|
|---|
| 1148 | Log() << Verbose(0) << "Enter index of destination molecule: ";
|
|---|
| 1149 | cin >> dest;
|
|---|
| 1150 | destmol = molecules->ReturnIndex(dest);
|
|---|
| 1151 | } while ((destmol == NULL) && (dest != -1));
|
|---|
| 1152 | do {
|
|---|
| 1153 | Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
|
|---|
| 1154 | cin >> src;
|
|---|
| 1155 | srcmol = molecules->ReturnIndex(src);
|
|---|
| 1156 | } while ((srcmol == NULL) && (src != -1));
|
|---|
| 1157 | if ((src != -1) && (dest != -1))
|
|---|
| 1158 | molecules->SimpleMerge(srcmol, destmol);
|
|---|
| 1159 | }
|
|---|
| 1160 | }
|
|---|
| 1161 | break;
|
|---|
| 1162 | }
|
|---|
| 1163 | };
|
|---|
| 1164 |
|
|---|
| 1165 | /********************************************** Test routine **************************************/
|
|---|
| 1166 |
|
|---|
| 1167 | /** Is called always as option 'T' in the menu.
|
|---|
| 1168 | * \param *molecules list of molecules
|
|---|
| 1169 | */
|
|---|
| 1170 | static void testroutine(MoleculeListClass *molecules)
|
|---|
| 1171 | {
|
|---|
| 1172 | // the current test routine checks the functionality of the KeySet&Graph concept:
|
|---|
| 1173 | // We want to have a multiindex (the KeySet) describing a unique subgraph
|
|---|
| 1174 | int i, comp, counter=0;
|
|---|
| 1175 |
|
|---|
| 1176 | // create a clone
|
|---|
| 1177 | molecule *mol = NULL;
|
|---|
| 1178 | if (molecules->ListOfMolecules.size() != 0) // clone
|
|---|
| 1179 | mol = (molecules->ListOfMolecules.front())->CopyMolecule();
|
|---|
| 1180 | else {
|
|---|
| 1181 | eLog() << Verbose(0) << "I don't have anything to test on ... ";
|
|---|
| 1182 | performCriticalExit();
|
|---|
| 1183 | return;
|
|---|
| 1184 | }
|
|---|
| 1185 | atom *Walker = mol->start;
|
|---|
| 1186 |
|
|---|
| 1187 | // generate some KeySets
|
|---|
| 1188 | Log() << Verbose(0) << "Generating KeySets." << endl;
|
|---|
| 1189 | KeySet TestSets[mol->AtomCount+1];
|
|---|
| 1190 | i=1;
|
|---|
| 1191 | while (Walker->next != mol->end) {
|
|---|
| 1192 | Walker = Walker->next;
|
|---|
| 1193 | for (int j=0;j<i;j++) {
|
|---|
| 1194 | TestSets[j].insert(Walker->nr);
|
|---|
| 1195 | }
|
|---|
| 1196 | i++;
|
|---|
| 1197 | }
|
|---|
| 1198 | Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
|
|---|
| 1199 | KeySetTestPair test;
|
|---|
| 1200 | test = TestSets[mol->AtomCount-1].insert(Walker->nr);
|
|---|
| 1201 | if (test.second) {
|
|---|
| 1202 | Log() << Verbose(1) << "Insertion worked?!" << endl;
|
|---|
| 1203 | } else {
|
|---|
| 1204 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
|
|---|
| 1205 | }
|
|---|
| 1206 | TestSets[mol->AtomCount].insert(mol->end->previous->nr);
|
|---|
| 1207 | TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
|
|---|
| 1208 |
|
|---|
| 1209 | // constructing Graph structure
|
|---|
| 1210 | Log() << Verbose(0) << "Generating Subgraph class." << endl;
|
|---|
| 1211 | Graph Subgraphs;
|
|---|
| 1212 |
|
|---|
| 1213 | // insert KeySets into Subgraphs
|
|---|
| 1214 | Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
|
|---|
| 1215 | for (int j=0;j<mol->AtomCount;j++) {
|
|---|
| 1216 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
|
|---|
| 1217 | }
|
|---|
| 1218 | Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
|
|---|
| 1219 | GraphTestPair test2;
|
|---|
| 1220 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
|
|---|
| 1221 | if (test2.second) {
|
|---|
| 1222 | Log() << Verbose(1) << "Insertion worked?!" << endl;
|
|---|
| 1223 | } else {
|
|---|
| 1224 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
|
|---|
| 1225 | }
|
|---|
| 1226 |
|
|---|
| 1227 | // show graphs
|
|---|
| 1228 | Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
|
|---|
| 1229 | Graph::iterator A = Subgraphs.begin();
|
|---|
| 1230 | while (A != Subgraphs.end()) {
|
|---|
| 1231 | Log() << Verbose(0) << (*A).second.first << ": ";
|
|---|
| 1232 | KeySet::iterator key = (*A).first.begin();
|
|---|
| 1233 | comp = -1;
|
|---|
| 1234 | while (key != (*A).first.end()) {
|
|---|
| 1235 | if ((*key) > comp)
|
|---|
| 1236 | Log() << Verbose(0) << (*key) << " ";
|
|---|
| 1237 | else
|
|---|
| 1238 | Log() << Verbose(0) << (*key) << "! ";
|
|---|
| 1239 | comp = (*key);
|
|---|
| 1240 | key++;
|
|---|
| 1241 | }
|
|---|
| 1242 | Log() << Verbose(0) << endl;
|
|---|
| 1243 | A++;
|
|---|
| 1244 | }
|
|---|
| 1245 | delete(mol);
|
|---|
| 1246 | };
|
|---|
| 1247 |
|
|---|
| 1248 | #endif
|
|---|
| 1249 |
|
|---|
| 1250 | /** Parses the command line options.
|
|---|
| 1251 | * \param argc argument count
|
|---|
| 1252 | * \param **argv arguments array
|
|---|
| 1253 | * \param *molecules list of molecules structure
|
|---|
| 1254 | * \param *periode elements structure
|
|---|
| 1255 | * \param configuration config file structure
|
|---|
| 1256 | * \param *ConfigFileName pointer to config file name in **argv
|
|---|
| 1257 | * \param *PathToDatabases pointer to db's path in **argv
|
|---|
| 1258 | * \return exit code (0 - successful, all else - something's wrong)
|
|---|
| 1259 | */
|
|---|
| 1260 | static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
|
|---|
| 1261 | config& configuration, char *&ConfigFileName)
|
|---|
| 1262 | {
|
|---|
| 1263 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
|---|
| 1264 | double *factor; // unit factor if desired
|
|---|
| 1265 | ifstream test;
|
|---|
| 1266 | ofstream output;
|
|---|
| 1267 | string line;
|
|---|
| 1268 | atom *first;
|
|---|
| 1269 | bool SaveFlag = false;
|
|---|
| 1270 | int ExitFlag = 0;
|
|---|
| 1271 | int j;
|
|---|
| 1272 | double volume = 0.;
|
|---|
| 1273 | enum ConfigStatus configPresent = absent;
|
|---|
| 1274 | clock_t start,end;
|
|---|
| 1275 | int argptr;
|
|---|
| 1276 | molecule *mol = NULL;
|
|---|
| 1277 | string BondGraphFileName("\n");
|
|---|
| 1278 | int verbosity = 0;
|
|---|
| 1279 | strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
|
|---|
| 1280 |
|
|---|
| 1281 | if (argc > 1) { // config file specified as option
|
|---|
| 1282 | // 1. : Parse options that just set variables or print help
|
|---|
| 1283 | argptr = 1;
|
|---|
| 1284 | do {
|
|---|
| 1285 | if (argv[argptr][0] == '-') {
|
|---|
| 1286 | Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
|
|---|
| 1287 | argptr++;
|
|---|
| 1288 | switch(argv[argptr-1][1]) {
|
|---|
| 1289 | case 'h':
|
|---|
| 1290 | case 'H':
|
|---|
| 1291 | case '?':
|
|---|
| 1292 | Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl;
|
|---|
| 1293 | Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
|
|---|
| 1294 | Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl;
|
|---|
| 1295 | Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
|
|---|
| 1296 | Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl;
|
|---|
| 1297 | Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
|
|---|
| 1298 | Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
|
|---|
| 1299 | Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
|
|---|
| 1300 | Log() << Verbose(0) << "\t-C <Z> <output> <bin output>\tPair Correlation analysis." << endl;
|
|---|
| 1301 | Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
|
|---|
| 1302 | Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
|
|---|
| 1303 | Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
|
|---|
| 1304 | Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
|
|---|
| 1305 | Log() << Verbose(0) << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl;
|
|---|
| 1306 | Log() << Verbose(0) << "\t-F <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl;
|
|---|
| 1307 | Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl;
|
|---|
| 1308 | Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl;
|
|---|
| 1309 | Log() << Verbose(0) << "\t-I\t Dissect current system of molecules into a set of disconnected (subgraphs of) molecules." << endl;
|
|---|
| 1310 | Log() << Verbose(0) << "\t-j\t<path> Store all bonds to file." << endl;
|
|---|
| 1311 | Log() << Verbose(0) << "\t-J\t<path> Store adjacency per atom to file." << endl;
|
|---|
| 1312 | Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl;
|
|---|
| 1313 | Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
|
|---|
| 1314 | Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl;
|
|---|
| 1315 | Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
|
|---|
| 1316 | Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl;
|
|---|
| 1317 | Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl;
|
|---|
| 1318 | Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl;
|
|---|
| 1319 | Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
|
|---|
| 1320 | Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
|
|---|
| 1321 | Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl;
|
|---|
| 1322 | Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl;
|
|---|
| 1323 | Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
|
|---|
| 1324 | Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl;
|
|---|
| 1325 | Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
|
|---|
| 1326 | Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl;
|
|---|
| 1327 | Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
|
|---|
| 1328 | Log() << Verbose(0) << "\t-v\t\tsets verbosity (more is more)." << endl;
|
|---|
| 1329 | Log() << Verbose(0) << "\t-V\t\tGives version information." << endl;
|
|---|
| 1330 | Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl;
|
|---|
| 1331 | return (1);
|
|---|
| 1332 | break;
|
|---|
| 1333 | case 'v':
|
|---|
| 1334 | while (argv[argptr-1][verbosity+1] == 'v') {
|
|---|
| 1335 | verbosity++;
|
|---|
| 1336 | }
|
|---|
| 1337 | setVerbosity(verbosity);
|
|---|
| 1338 | Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl;
|
|---|
| 1339 | break;
|
|---|
| 1340 | case 'V':
|
|---|
| 1341 | Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl;
|
|---|
| 1342 | Log() << Verbose(0) << "Build your own molecule position set." << endl;
|
|---|
| 1343 | return (1);
|
|---|
| 1344 | break;
|
|---|
| 1345 | case 'e':
|
|---|
| 1346 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1347 | eLog() << Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl;
|
|---|
| 1348 | performCriticalExit();
|
|---|
| 1349 | } else {
|
|---|
| 1350 | Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl;
|
|---|
| 1351 | strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1);
|
|---|
| 1352 | argptr+=1;
|
|---|
| 1353 | }
|
|---|
| 1354 | break;
|
|---|
| 1355 | case 'g':
|
|---|
| 1356 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1357 | eLog() << Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl;
|
|---|
| 1358 | performCriticalExit();
|
|---|
| 1359 | } else {
|
|---|
| 1360 | BondGraphFileName = argv[argptr];
|
|---|
| 1361 | Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl;
|
|---|
| 1362 | argptr+=1;
|
|---|
| 1363 | }
|
|---|
| 1364 | break;
|
|---|
| 1365 | case 'n':
|
|---|
| 1366 | Log() << Verbose(0) << "I won't parse trajectories." << endl;
|
|---|
| 1367 | configuration.FastParsing = true;
|
|---|
| 1368 | break;
|
|---|
| 1369 | default: // no match? Step on
|
|---|
| 1370 | argptr++;
|
|---|
| 1371 | break;
|
|---|
| 1372 | }
|
|---|
| 1373 | } else
|
|---|
| 1374 | argptr++;
|
|---|
| 1375 | } while (argptr < argc);
|
|---|
| 1376 |
|
|---|
| 1377 | // 3a. Parse the element database
|
|---|
| 1378 | if (periode->LoadPeriodentafel(configuration.databasepath)) {
|
|---|
| 1379 | Log() << Verbose(0) << "Element list loaded successfully." << endl;
|
|---|
| 1380 | //periode->Output();
|
|---|
| 1381 | } else {
|
|---|
| 1382 | Log() << Verbose(0) << "Element list loading failed." << endl;
|
|---|
| 1383 | return 1;
|
|---|
| 1384 | }
|
|---|
| 1385 | // 3b. Find config file name and parse if possible, also BondGraphFileName
|
|---|
| 1386 | if (argv[1][0] != '-') {
|
|---|
| 1387 | // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
|
|---|
| 1388 | Log() << Verbose(0) << "Config file given." << endl;
|
|---|
| 1389 | test.open(argv[1], ios::in);
|
|---|
| 1390 | if (test == NULL) {
|
|---|
| 1391 | //return (1);
|
|---|
| 1392 | output.open(argv[1], ios::out);
|
|---|
| 1393 | if (output == NULL) {
|
|---|
| 1394 | Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
|
|---|
| 1395 | configPresent = absent;
|
|---|
| 1396 | } else {
|
|---|
| 1397 | Log() << Verbose(0) << "Empty configuration file." << endl;
|
|---|
| 1398 | ConfigFileName = argv[1];
|
|---|
| 1399 | configPresent = empty;
|
|---|
| 1400 | output.close();
|
|---|
| 1401 | }
|
|---|
| 1402 | } else {
|
|---|
| 1403 | test.close();
|
|---|
| 1404 | ConfigFileName = argv[1];
|
|---|
| 1405 | Log() << Verbose(1) << "Specified config file found, parsing ... ";
|
|---|
| 1406 | switch (configuration.TestSyntax(ConfigFileName, periode)) {
|
|---|
| 1407 | case 1:
|
|---|
| 1408 | Log() << Verbose(0) << "new syntax." << endl;
|
|---|
| 1409 | configuration.Load(ConfigFileName, BondGraphFileName, periode, molecules);
|
|---|
| 1410 | configPresent = present;
|
|---|
| 1411 | break;
|
|---|
| 1412 | case 0:
|
|---|
| 1413 | Log() << Verbose(0) << "old syntax." << endl;
|
|---|
| 1414 | configuration.LoadOld(ConfigFileName, BondGraphFileName, periode, molecules);
|
|---|
| 1415 | configPresent = present;
|
|---|
| 1416 | break;
|
|---|
| 1417 | default:
|
|---|
| 1418 | Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl;
|
|---|
| 1419 | configPresent = empty;
|
|---|
| 1420 | }
|
|---|
| 1421 | }
|
|---|
| 1422 | } else
|
|---|
| 1423 | configPresent = absent;
|
|---|
| 1424 | // set mol to first active molecule
|
|---|
| 1425 | if (molecules->ListOfMolecules.size() != 0) {
|
|---|
| 1426 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 1427 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 1428 | mol = *ListRunner;
|
|---|
| 1429 | break;
|
|---|
| 1430 | }
|
|---|
| 1431 | }
|
|---|
| 1432 | if (mol == NULL) {
|
|---|
| 1433 | mol = new molecule(periode);
|
|---|
| 1434 | mol->ActiveFlag = true;
|
|---|
| 1435 | if (ConfigFileName != NULL)
|
|---|
| 1436 | mol->SetNameFromFilename(ConfigFileName);
|
|---|
| 1437 | molecules->insert(mol);
|
|---|
| 1438 | }
|
|---|
| 1439 | if (configuration.BG == NULL) {
|
|---|
| 1440 | configuration.BG = new BondGraph(configuration.GetIsAngstroem());
|
|---|
| 1441 | if ((!BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
|
|---|
| 1442 | Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
|
|---|
| 1443 | } else {
|
|---|
| 1444 | eLog() << Verbose(1) << "Bond length table loading failed." << endl;
|
|---|
| 1445 | }
|
|---|
| 1446 | }
|
|---|
| 1447 |
|
|---|
| 1448 | // 4. parse again through options, now for those depending on elements db and config presence
|
|---|
| 1449 | argptr = 1;
|
|---|
| 1450 | do {
|
|---|
| 1451 | Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl;
|
|---|
| 1452 | if (argv[argptr][0] == '-') {
|
|---|
| 1453 | argptr++;
|
|---|
| 1454 | if ((configPresent == present) || (configPresent == empty)) {
|
|---|
| 1455 | switch(argv[argptr-1][1]) {
|
|---|
| 1456 | case 'p':
|
|---|
| 1457 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1458 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1459 | ExitFlag = 255;
|
|---|
| 1460 | eLog() << Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl;
|
|---|
| 1461 | performCriticalExit();
|
|---|
| 1462 | } else {
|
|---|
| 1463 | SaveFlag = true;
|
|---|
| 1464 | Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl;
|
|---|
| 1465 | if (!mol->AddXYZFile(argv[argptr]))
|
|---|
| 1466 | Log() << Verbose(2) << "File not found." << endl;
|
|---|
| 1467 | else {
|
|---|
| 1468 | Log() << Verbose(2) << "File found and parsed." << endl;
|
|---|
| 1469 | configPresent = present;
|
|---|
| 1470 | }
|
|---|
| 1471 | }
|
|---|
| 1472 | break;
|
|---|
| 1473 | case 'a':
|
|---|
| 1474 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1475 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) {
|
|---|
| 1476 | ExitFlag = 255;
|
|---|
| 1477 | eLog() << Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl;
|
|---|
| 1478 | performCriticalExit();
|
|---|
| 1479 | } else {
|
|---|
| 1480 | SaveFlag = true;
|
|---|
| 1481 | Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
|
|---|
| 1482 | first = new atom;
|
|---|
| 1483 | first->type = periode->FindElement(atoi(argv[argptr]));
|
|---|
| 1484 | if (first->type != NULL)
|
|---|
| 1485 | Log() << Verbose(2) << "found element " << first->type->name << endl;
|
|---|
| 1486 | for (int i=NDIM;i--;)
|
|---|
| 1487 | first->x.x[i] = atof(argv[argptr+1+i]);
|
|---|
| 1488 | if (first->type != NULL) {
|
|---|
| 1489 | mol->AddAtom(first); // add to molecule
|
|---|
| 1490 | if ((configPresent == empty) && (mol->AtomCount != 0))
|
|---|
| 1491 | configPresent = present;
|
|---|
| 1492 | } else
|
|---|
| 1493 | eLog() << Verbose(1) << "Could not find the specified element." << endl;
|
|---|
| 1494 | argptr+=4;
|
|---|
| 1495 | }
|
|---|
| 1496 | break;
|
|---|
| 1497 | default: // no match? Don't step on (this is done in next switch's default)
|
|---|
| 1498 | break;
|
|---|
| 1499 | }
|
|---|
| 1500 | }
|
|---|
| 1501 | if (configPresent == present) {
|
|---|
| 1502 | switch(argv[argptr-1][1]) {
|
|---|
| 1503 | case 'M':
|
|---|
| 1504 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1505 | ExitFlag = 255;
|
|---|
| 1506 | eLog() << Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl;
|
|---|
| 1507 | performCriticalExit();
|
|---|
| 1508 | } else {
|
|---|
| 1509 | configuration.basis = argv[argptr];
|
|---|
| 1510 | Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl;
|
|---|
| 1511 | argptr+=1;
|
|---|
| 1512 | }
|
|---|
| 1513 | break;
|
|---|
| 1514 | case 'D':
|
|---|
| 1515 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1516 | {
|
|---|
| 1517 | Log() << Verbose(1) << "Depth-First-Search Analysis." << endl;
|
|---|
| 1518 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
|---|
| 1519 | int *MinimumRingSize = new int[mol->AtomCount];
|
|---|
| 1520 | atom ***ListOfLocalAtoms = NULL;
|
|---|
| 1521 | class StackClass<bond *> *BackEdgeStack = NULL;
|
|---|
| 1522 | class StackClass<bond *> *LocalBackEdgeStack = NULL;
|
|---|
| 1523 | mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
|---|
| 1524 | Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
|
|---|
| 1525 | if (Subgraphs != NULL) {
|
|---|
| 1526 | int FragmentCounter = 0;
|
|---|
| 1527 | while (Subgraphs->next != NULL) {
|
|---|
| 1528 | Subgraphs = Subgraphs->next;
|
|---|
| 1529 | Subgraphs->FillBondStructureFromReference(mol, FragmentCounter, ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms
|
|---|
| 1530 | LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
|
|---|
| 1531 | Subgraphs->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter], BackEdgeStack, LocalBackEdgeStack);
|
|---|
| 1532 | Subgraphs->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
|
|---|
| 1533 | delete(LocalBackEdgeStack);
|
|---|
| 1534 | delete(Subgraphs->previous);
|
|---|
| 1535 | FragmentCounter++;
|
|---|
| 1536 | }
|
|---|
| 1537 | delete(Subgraphs);
|
|---|
| 1538 | for (int i=0;i<FragmentCounter;i++)
|
|---|
| 1539 | Free(&ListOfLocalAtoms[i]);
|
|---|
| 1540 | Free(&ListOfLocalAtoms);
|
|---|
| 1541 | }
|
|---|
| 1542 | delete(BackEdgeStack);
|
|---|
| 1543 | delete[](MinimumRingSize);
|
|---|
| 1544 | }
|
|---|
| 1545 | //argptr+=1;
|
|---|
| 1546 | break;
|
|---|
| 1547 | case 'I':
|
|---|
| 1548 | Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl;
|
|---|
| 1549 | // @TODO rather do the dissection afterwards
|
|---|
| 1550 | molecules->DissectMoleculeIntoConnectedSubgraphs(periode, &configuration);
|
|---|
| 1551 | mol = NULL;
|
|---|
| 1552 | if (molecules->ListOfMolecules.size() != 0) {
|
|---|
| 1553 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
|---|
| 1554 | if ((*ListRunner)->ActiveFlag) {
|
|---|
| 1555 | mol = *ListRunner;
|
|---|
| 1556 | break;
|
|---|
| 1557 | }
|
|---|
| 1558 | }
|
|---|
| 1559 | if (mol == NULL) {
|
|---|
| 1560 | mol = *(molecules->ListOfMolecules.begin());
|
|---|
| 1561 | mol->ActiveFlag = true;
|
|---|
| 1562 | }
|
|---|
| 1563 | break;
|
|---|
| 1564 | case 'C':
|
|---|
| 1565 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1566 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr][0] == '-') || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-')) {
|
|---|
| 1567 | ExitFlag = 255;
|
|---|
| 1568 | eLog() << Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C <Z> <output> <bin output>" << endl;
|
|---|
| 1569 | performCriticalExit();
|
|---|
| 1570 | } else {
|
|---|
| 1571 | ofstream output(argv[argptr+1]);
|
|---|
| 1572 | ofstream binoutput(argv[argptr+2]);
|
|---|
| 1573 | const double radius = 5.;
|
|---|
| 1574 |
|
|---|
| 1575 | // get the boundary
|
|---|
| 1576 | class molecule *Boundary = NULL;
|
|---|
| 1577 | class Tesselation *TesselStruct = NULL;
|
|---|
| 1578 | const LinkedCell *LCList = NULL;
|
|---|
| 1579 | // find biggest molecule
|
|---|
| 1580 | int counter = 0;
|
|---|
| 1581 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
|---|
| 1582 | if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
|
|---|
| 1583 | Boundary = *BigFinder;
|
|---|
| 1584 | }
|
|---|
| 1585 | counter++;
|
|---|
| 1586 | }
|
|---|
| 1587 | bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives");
|
|---|
| 1588 | counter = 0;
|
|---|
| 1589 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
|---|
| 1590 | Actives[counter++] = (*BigFinder)->ActiveFlag;
|
|---|
| 1591 | (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
|
|---|
| 1592 | }
|
|---|
| 1593 | LCList = new LinkedCell(Boundary, 2.*radius);
|
|---|
| 1594 | element *elemental = periode->FindElement((const int) atoi(argv[argptr]));
|
|---|
| 1595 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
|
|---|
| 1596 | int ranges[NDIM] = {1,1,1};
|
|---|
| 1597 | CorrelationToSurfaceMap *surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges );
|
|---|
| 1598 | OutputCorrelationToSurface(&output, surfacemap);
|
|---|
| 1599 | BinPairMap *binmap = BinData( surfacemap, 0.5, 0., 20. );
|
|---|
| 1600 | OutputCorrelation ( &binoutput, binmap );
|
|---|
| 1601 | output.close();
|
|---|
| 1602 | binoutput.close();
|
|---|
| 1603 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++)
|
|---|
| 1604 | (*BigFinder)->ActiveFlag = Actives[counter++];
|
|---|
| 1605 | Free(&Actives);
|
|---|
| 1606 | delete(LCList);
|
|---|
| 1607 | delete(TesselStruct);
|
|---|
| 1608 | argptr+=3;
|
|---|
| 1609 | }
|
|---|
| 1610 | break;
|
|---|
| 1611 | case 'E':
|
|---|
| 1612 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1613 | if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
|
|---|
| 1614 | ExitFlag = 255;
|
|---|
| 1615 | eLog() << Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl;
|
|---|
| 1616 | performCriticalExit();
|
|---|
| 1617 | } else {
|
|---|
| 1618 | SaveFlag = true;
|
|---|
| 1619 | Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl;
|
|---|
| 1620 | first = mol->FindAtom(atoi(argv[argptr]));
|
|---|
| 1621 | first->type = periode->FindElement(atoi(argv[argptr+1]));
|
|---|
| 1622 | argptr+=2;
|
|---|
| 1623 | }
|
|---|
| 1624 | break;
|
|---|
| 1625 | case 'F':
|
|---|
| 1626 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1627 | if (argptr+6 >=argc) {
|
|---|
| 1628 | ExitFlag = 255;
|
|---|
| 1629 | eLog() << Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <boundary> <randatom> <randmol> <DoRotate>" << endl;
|
|---|
| 1630 | performCriticalExit();
|
|---|
| 1631 | } else {
|
|---|
| 1632 | SaveFlag = true;
|
|---|
| 1633 | Log() << Verbose(1) << "Filling Box with water molecules." << endl;
|
|---|
| 1634 | // construct water molecule
|
|---|
| 1635 | molecule *filler = new molecule(periode);
|
|---|
| 1636 | molecule *Filling = NULL;
|
|---|
| 1637 | atom *second = NULL, *third = NULL;
|
|---|
| 1638 | // first = new atom();
|
|---|
| 1639 | // first->type = periode->FindElement(5);
|
|---|
| 1640 | // first->x.Zero();
|
|---|
| 1641 | // filler->AddAtom(first);
|
|---|
| 1642 | first = new atom();
|
|---|
| 1643 | first->type = periode->FindElement(1);
|
|---|
| 1644 | first->x.Init(0.441, -0.143, 0.);
|
|---|
| 1645 | filler->AddAtom(first);
|
|---|
| 1646 | second = new atom();
|
|---|
| 1647 | second->type = periode->FindElement(1);
|
|---|
| 1648 | second->x.Init(-0.464, 1.137, 0.0);
|
|---|
| 1649 | filler->AddAtom(second);
|
|---|
| 1650 | third = new atom();
|
|---|
| 1651 | third->type = periode->FindElement(8);
|
|---|
| 1652 | third->x.Init(-0.464, 0.177, 0.);
|
|---|
| 1653 | filler->AddAtom(third);
|
|---|
| 1654 | filler->AddBond(first, third, 1);
|
|---|
| 1655 | filler->AddBond(second, third, 1);
|
|---|
| 1656 | // call routine
|
|---|
| 1657 | double distance[NDIM];
|
|---|
| 1658 | for (int i=0;i<NDIM;i++)
|
|---|
| 1659 | distance[i] = atof(argv[argptr+i]);
|
|---|
| 1660 | Filling = FillBoxWithMolecule(molecules, filler, configuration, distance, atof(argv[argptr+3]), atof(argv[argptr+4]), atof(argv[argptr+5]), atoi(argv[argptr+6]));
|
|---|
| 1661 | if (Filling != NULL) {
|
|---|
| 1662 | Filling->ActiveFlag = false;
|
|---|
| 1663 | molecules->insert(Filling);
|
|---|
| 1664 | }
|
|---|
| 1665 | delete(filler);
|
|---|
| 1666 | argptr+=6;
|
|---|
| 1667 | }
|
|---|
| 1668 | break;
|
|---|
| 1669 | case 'A':
|
|---|
| 1670 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1671 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1672 | ExitFlag =255;
|
|---|
| 1673 | eLog() << Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl;
|
|---|
| 1674 | performCriticalExit();
|
|---|
| 1675 | } else {
|
|---|
| 1676 | Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl;
|
|---|
| 1677 | ifstream *input = new ifstream(argv[argptr]);
|
|---|
| 1678 | mol->CreateAdjacencyListFromDbondFile(input);
|
|---|
| 1679 | input->close();
|
|---|
| 1680 | argptr+=1;
|
|---|
| 1681 | }
|
|---|
| 1682 | break;
|
|---|
| 1683 |
|
|---|
| 1684 | case 'J':
|
|---|
| 1685 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1686 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1687 | ExitFlag =255;
|
|---|
| 1688 | eLog() << Verbose(0) << "Missing path of adjacency file: -j <path>" << endl;
|
|---|
| 1689 | performCriticalExit();
|
|---|
| 1690 | } else {
|
|---|
| 1691 | Log() << Verbose(0) << "Storing adjacency to path " << argv[argptr] << "." << endl;
|
|---|
| 1692 | configuration.BG->ConstructBondGraph(mol);
|
|---|
| 1693 | mol->StoreAdjacencyToFile(argv[argptr]);
|
|---|
| 1694 | argptr+=1;
|
|---|
| 1695 | }
|
|---|
| 1696 | break;
|
|---|
| 1697 |
|
|---|
| 1698 | case 'j':
|
|---|
| 1699 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1700 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1701 | ExitFlag =255;
|
|---|
| 1702 | eLog() << Verbose(0) << "Missing path of bonds file: -j <path>" << endl;
|
|---|
| 1703 | performCriticalExit();
|
|---|
| 1704 | } else {
|
|---|
| 1705 | Log() << Verbose(0) << "Storing bonds to path " << argv[argptr] << "." << endl;
|
|---|
| 1706 | configuration.BG->ConstructBondGraph(mol);
|
|---|
| 1707 | mol->StoreBondsToFile(argv[argptr]);
|
|---|
| 1708 | argptr+=1;
|
|---|
| 1709 | }
|
|---|
| 1710 | break;
|
|---|
| 1711 |
|
|---|
| 1712 | case 'N':
|
|---|
| 1713 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1714 | if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
|
|---|
| 1715 | ExitFlag = 255;
|
|---|
| 1716 | eLog() << Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl;
|
|---|
| 1717 | performCriticalExit();
|
|---|
| 1718 | } else {
|
|---|
| 1719 | class Tesselation *T = NULL;
|
|---|
| 1720 | const LinkedCell *LCList = NULL;
|
|---|
| 1721 | molecule * Boundary = NULL;
|
|---|
| 1722 | //string filename(argv[argptr+1]);
|
|---|
| 1723 | //filename.append(".csv");
|
|---|
| 1724 | Log() << Verbose(0) << "Evaluating non-convex envelope of biggest molecule.";
|
|---|
| 1725 | Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl;
|
|---|
| 1726 | // find biggest molecule
|
|---|
| 1727 | int counter = 0;
|
|---|
| 1728 | for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
|
|---|
| 1729 | (*BigFinder)->CountAtoms();
|
|---|
| 1730 | if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
|
|---|
| 1731 | Boundary = *BigFinder;
|
|---|
| 1732 | }
|
|---|
| 1733 | counter++;
|
|---|
| 1734 | }
|
|---|
| 1735 | Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl;
|
|---|
| 1736 | start = clock();
|
|---|
| 1737 | LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.);
|
|---|
| 1738 | if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]))
|
|---|
| 1739 | ExitFlag = 255;
|
|---|
| 1740 | //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
|
|---|
| 1741 | end = clock();
|
|---|
| 1742 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
|---|
| 1743 | delete(LCList);
|
|---|
| 1744 | delete(T);
|
|---|
| 1745 | argptr+=2;
|
|---|
| 1746 | }
|
|---|
| 1747 | break;
|
|---|
| 1748 | case 'S':
|
|---|
| 1749 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1750 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1751 | ExitFlag = 255;
|
|---|
| 1752 | eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl;
|
|---|
| 1753 | performCriticalExit();
|
|---|
| 1754 | } else {
|
|---|
| 1755 | Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
|
|---|
| 1756 | ofstream *output = new ofstream(argv[argptr], ios::trunc);
|
|---|
| 1757 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
|
|---|
| 1758 | Log() << Verbose(2) << "File could not be written." << endl;
|
|---|
| 1759 | else
|
|---|
| 1760 | Log() << Verbose(2) << "File stored." << endl;
|
|---|
| 1761 | output->close();
|
|---|
| 1762 | delete(output);
|
|---|
| 1763 | argptr+=1;
|
|---|
| 1764 | }
|
|---|
| 1765 | break;
|
|---|
| 1766 | case 'L':
|
|---|
| 1767 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1768 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1769 | ExitFlag = 255;
|
|---|
| 1770 | eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl;
|
|---|
| 1771 | performCriticalExit();
|
|---|
| 1772 | } else {
|
|---|
| 1773 | SaveFlag = true;
|
|---|
| 1774 | Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl;
|
|---|
| 1775 | if (atoi(argv[argptr+3]) == 1)
|
|---|
| 1776 | Log() << Verbose(1) << "Using Identity for the permutation map." << endl;
|
|---|
| 1777 | if (!mol->LinearInterpolationBetweenConfiguration(atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false)
|
|---|
| 1778 | Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl;
|
|---|
| 1779 | else
|
|---|
| 1780 | Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl;
|
|---|
| 1781 | argptr+=4;
|
|---|
| 1782 | }
|
|---|
| 1783 | break;
|
|---|
| 1784 | case 'P':
|
|---|
| 1785 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1786 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
|---|
| 1787 | ExitFlag = 255;
|
|---|
| 1788 | eLog() << Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl;
|
|---|
| 1789 | performCriticalExit();
|
|---|
| 1790 | } else {
|
|---|
| 1791 | SaveFlag = true;
|
|---|
| 1792 | Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
|
|---|
| 1793 | if (!mol->VerletForceIntegration(argv[argptr], configuration))
|
|---|
| 1794 | Log() << Verbose(2) << "File not found." << endl;
|
|---|
| 1795 | else
|
|---|
| 1796 | Log() << Verbose(2) << "File found and parsed." << endl;
|
|---|
| 1797 | argptr+=1;
|
|---|
| 1798 | }
|
|---|
| 1799 | break;
|
|---|
| 1800 | case 'R':
|
|---|
| 1801 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1802 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
|
|---|
| 1803 | ExitFlag = 255;
|
|---|
| 1804 | eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl;
|
|---|
| 1805 | performCriticalExit();
|
|---|
| 1806 | } else {
|
|---|
| 1807 | SaveFlag = true;
|
|---|
| 1808 | Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl;
|
|---|
| 1809 | double tmp1 = atof(argv[argptr+1]);
|
|---|
| 1810 | atom *third = mol->FindAtom(atoi(argv[argptr]));
|
|---|
| 1811 | atom *first = mol->start;
|
|---|
| 1812 | if ((third != NULL) && (first != mol->end)) {
|
|---|
| 1813 | atom *second = first->next;
|
|---|
| 1814 | while(second != mol->end) {
|
|---|
| 1815 | first = second;
|
|---|
| 1816 | second = first->next;
|
|---|
| 1817 | if (first->x.DistanceSquared((const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...
|
|---|
| 1818 | mol->RemoveAtom(first);
|
|---|
| 1819 | }
|
|---|
| 1820 | } else {
|
|---|
| 1821 | eLog() << Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl;
|
|---|
| 1822 | }
|
|---|
| 1823 | argptr+=2;
|
|---|
| 1824 | }
|
|---|
| 1825 | break;
|
|---|
| 1826 | case 't':
|
|---|
| 1827 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1828 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
|---|
| 1829 | ExitFlag = 255;
|
|---|
| 1830 | eLog() << Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl;
|
|---|
| 1831 | performCriticalExit();
|
|---|
| 1832 | } else {
|
|---|
| 1833 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1834 | SaveFlag = true;
|
|---|
| 1835 | Log() << Verbose(1) << "Translating all ions by given vector." << endl;
|
|---|
| 1836 | for (int i=NDIM;i--;)
|
|---|
| 1837 | x.x[i] = atof(argv[argptr+i]);
|
|---|
| 1838 | mol->Translate((const Vector *)&x);
|
|---|
| 1839 | argptr+=3;
|
|---|
| 1840 | }
|
|---|
| 1841 | break;
|
|---|
| 1842 | case 'T':
|
|---|
| 1843 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1844 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
|---|
| 1845 | ExitFlag = 255;
|
|---|
| 1846 | eLog() << Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl;
|
|---|
| 1847 | performCriticalExit();
|
|---|
| 1848 | } else {
|
|---|
| 1849 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1850 | SaveFlag = true;
|
|---|
| 1851 | Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl;
|
|---|
| 1852 | for (int i=NDIM;i--;)
|
|---|
| 1853 | x.x[i] = atof(argv[argptr+i]);
|
|---|
| 1854 | mol->TranslatePeriodically((const Vector *)&x);
|
|---|
| 1855 | argptr+=3;
|
|---|
| 1856 | }
|
|---|
| 1857 | break;
|
|---|
| 1858 | case 's':
|
|---|
| 1859 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1860 | if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
|---|
| 1861 | ExitFlag = 255;
|
|---|
| 1862 | eLog() << Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl;
|
|---|
| 1863 | performCriticalExit();
|
|---|
| 1864 | } else {
|
|---|
| 1865 | SaveFlag = true;
|
|---|
| 1866 | j = -1;
|
|---|
| 1867 | Log() << Verbose(1) << "Scaling all ion positions by factor." << endl;
|
|---|
| 1868 | factor = new double[NDIM];
|
|---|
| 1869 | factor[0] = atof(argv[argptr]);
|
|---|
| 1870 | factor[1] = atof(argv[argptr+1]);
|
|---|
| 1871 | factor[2] = atof(argv[argptr+2]);
|
|---|
| 1872 | mol->Scale((const double ** const)&factor);
|
|---|
| 1873 | for (int i=0;i<NDIM;i++) {
|
|---|
| 1874 | j += i+1;
|
|---|
| 1875 | x.x[i] = atof(argv[NDIM+i]);
|
|---|
| 1876 | mol->cell_size[j]*=factor[i];
|
|---|
| 1877 | }
|
|---|
| 1878 | delete[](factor);
|
|---|
| 1879 | argptr+=3;
|
|---|
| 1880 | }
|
|---|
| 1881 | break;
|
|---|
| 1882 | case 'b':
|
|---|
| 1883 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1884 | if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
|
|---|
| 1885 | ExitFlag = 255;
|
|---|
| 1886 | eLog() << Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
|
|---|
| 1887 | performCriticalExit();
|
|---|
| 1888 | } else {
|
|---|
| 1889 | SaveFlag = true;
|
|---|
| 1890 | j = -1;
|
|---|
| 1891 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
|---|
| 1892 | for (int i=0;i<6;i++) {
|
|---|
| 1893 | mol->cell_size[i] = atof(argv[argptr+i]);
|
|---|
| 1894 | }
|
|---|
| 1895 | // center
|
|---|
| 1896 | mol->CenterInBox();
|
|---|
| 1897 | argptr+=6;
|
|---|
| 1898 | }
|
|---|
| 1899 | break;
|
|---|
| 1900 | case 'B':
|
|---|
| 1901 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1902 | if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
|
|---|
| 1903 | ExitFlag = 255;
|
|---|
| 1904 | eLog() << Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
|
|---|
| 1905 | performCriticalExit();
|
|---|
| 1906 | } else {
|
|---|
| 1907 | SaveFlag = true;
|
|---|
| 1908 | j = -1;
|
|---|
| 1909 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
|---|
| 1910 | for (int i=0;i<6;i++) {
|
|---|
| 1911 | mol->cell_size[i] = atof(argv[argptr+i]);
|
|---|
| 1912 | }
|
|---|
| 1913 | // center
|
|---|
| 1914 | mol->BoundInBox();
|
|---|
| 1915 | argptr+=6;
|
|---|
| 1916 | }
|
|---|
| 1917 | break;
|
|---|
| 1918 | case 'c':
|
|---|
| 1919 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1920 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
|---|
| 1921 | ExitFlag = 255;
|
|---|
| 1922 | eLog() << Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl;
|
|---|
| 1923 | performCriticalExit();
|
|---|
| 1924 | } else {
|
|---|
| 1925 | SaveFlag = true;
|
|---|
| 1926 | j = -1;
|
|---|
| 1927 | Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
|
|---|
| 1928 | // make every coordinate positive
|
|---|
| 1929 | mol->CenterEdge(&x);
|
|---|
| 1930 | // update Box of atoms by boundary
|
|---|
| 1931 | mol->SetBoxDimension(&x);
|
|---|
| 1932 | // translate each coordinate by boundary
|
|---|
| 1933 | j=-1;
|
|---|
| 1934 | for (int i=0;i<NDIM;i++) {
|
|---|
| 1935 | j += i+1;
|
|---|
| 1936 | x.x[i] = atof(argv[argptr+i]);
|
|---|
| 1937 | mol->cell_size[j] += x.x[i]*2.;
|
|---|
| 1938 | }
|
|---|
| 1939 | mol->Translate((const Vector *)&x);
|
|---|
| 1940 | argptr+=3;
|
|---|
| 1941 | }
|
|---|
| 1942 | break;
|
|---|
| 1943 | case 'O':
|
|---|
| 1944 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1945 | SaveFlag = true;
|
|---|
| 1946 | Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl;
|
|---|
| 1947 | x.Zero();
|
|---|
| 1948 | mol->CenterEdge(&x);
|
|---|
| 1949 | mol->SetBoxDimension(&x);
|
|---|
| 1950 | argptr+=0;
|
|---|
| 1951 | break;
|
|---|
| 1952 | case 'r':
|
|---|
| 1953 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1954 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr]))) {
|
|---|
| 1955 | ExitFlag = 255;
|
|---|
| 1956 | eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl;
|
|---|
| 1957 | performCriticalExit();
|
|---|
| 1958 | } else {
|
|---|
| 1959 | SaveFlag = true;
|
|---|
| 1960 | Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl;
|
|---|
| 1961 | atom *first = mol->FindAtom(atoi(argv[argptr]));
|
|---|
| 1962 | mol->RemoveAtom(first);
|
|---|
| 1963 | argptr+=1;
|
|---|
| 1964 | }
|
|---|
| 1965 | break;
|
|---|
| 1966 | case 'f':
|
|---|
| 1967 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1968 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
|
|---|
| 1969 | ExitFlag = 255;
|
|---|
| 1970 | eLog() << Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
|
|---|
| 1971 | performCriticalExit();
|
|---|
| 1972 | } else {
|
|---|
| 1973 | Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
|
|---|
| 1974 | Log() << Verbose(0) << "Creating connection matrix..." << endl;
|
|---|
| 1975 | start = clock();
|
|---|
| 1976 | mol->CreateAdjacencyList(atof(argv[argptr++]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
|---|
| 1977 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
|---|
| 1978 | if (mol->first->next != mol->last) {
|
|---|
| 1979 | ExitFlag = mol->FragmentMolecule(atoi(argv[argptr]), &configuration);
|
|---|
| 1980 | }
|
|---|
| 1981 | end = clock();
|
|---|
| 1982 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
|---|
| 1983 | argptr+=2;
|
|---|
| 1984 | }
|
|---|
| 1985 | break;
|
|---|
| 1986 | case 'm':
|
|---|
| 1987 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 1988 | j = atoi(argv[argptr++]);
|
|---|
| 1989 | if ((j<0) || (j>1)) {
|
|---|
| 1990 | eLog() << Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
|
|---|
| 1991 | j = 0;
|
|---|
| 1992 | }
|
|---|
| 1993 | if (j) {
|
|---|
| 1994 | SaveFlag = true;
|
|---|
| 1995 | Log() << Verbose(0) << "Converting to prinicipal axis system." << endl;
|
|---|
| 1996 | } else
|
|---|
| 1997 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
|---|
| 1998 | mol->PrincipalAxisSystem((bool)j);
|
|---|
| 1999 | break;
|
|---|
| 2000 | case 'o':
|
|---|
| 2001 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 2002 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
|
|---|
| 2003 | ExitFlag = 255;
|
|---|
| 2004 | eLog() << Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl;
|
|---|
| 2005 | performCriticalExit();
|
|---|
| 2006 | } else {
|
|---|
| 2007 | class Tesselation *TesselStruct = NULL;
|
|---|
| 2008 | const LinkedCell *LCList = NULL;
|
|---|
| 2009 | Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
|
|---|
| 2010 | Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl;
|
|---|
| 2011 | Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl;
|
|---|
| 2012 | LCList = new LinkedCell(mol, 10.);
|
|---|
| 2013 | //FindConvexBorder(mol, LCList, argv[argptr]);
|
|---|
| 2014 | FindNonConvexBorder(mol, TesselStruct, LCList, 5., argv[argptr+1]);
|
|---|
| 2015 | // RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]);
|
|---|
| 2016 | double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, argv[argptr]);
|
|---|
| 2017 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, &configuration);
|
|---|
| 2018 | Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 2019 | Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
|
|---|
| 2020 | delete(TesselStruct);
|
|---|
| 2021 | delete(LCList);
|
|---|
| 2022 | argptr+=2;
|
|---|
| 2023 | }
|
|---|
| 2024 | break;
|
|---|
| 2025 | case 'U':
|
|---|
| 2026 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 2027 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
|
|---|
| 2028 | ExitFlag = 255;
|
|---|
| 2029 | eLog() << Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl;
|
|---|
| 2030 | performCriticalExit();
|
|---|
| 2031 | } else {
|
|---|
| 2032 | volume = atof(argv[argptr++]);
|
|---|
| 2033 | Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
|
|---|
| 2034 | }
|
|---|
| 2035 | case 'u':
|
|---|
| 2036 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 2037 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
|
|---|
| 2038 | if (volume != -1)
|
|---|
| 2039 | ExitFlag = 255;
|
|---|
| 2040 | eLog() << Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl;
|
|---|
| 2041 | performCriticalExit();
|
|---|
| 2042 | } else {
|
|---|
| 2043 | double density;
|
|---|
| 2044 | SaveFlag = true;
|
|---|
| 2045 | Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
|
|---|
| 2046 | density = atof(argv[argptr++]);
|
|---|
| 2047 | if (density < 1.0) {
|
|---|
| 2048 | eLog() << Verbose(1) << "Density must be greater than 1.0g/cm^3 !" << endl;
|
|---|
| 2049 | density = 1.3;
|
|---|
| 2050 | }
|
|---|
| 2051 | // for(int i=0;i<NDIM;i++) {
|
|---|
| 2052 | // repetition[i] = atoi(argv[argptr++]);
|
|---|
| 2053 | // if (repetition[i] < 1)
|
|---|
| 2054 | // eLog() << Verbose(1) << "repetition value must be greater 1!" << endl;
|
|---|
| 2055 | // repetition[i] = 1;
|
|---|
| 2056 | // }
|
|---|
| 2057 | PrepareClustersinWater(&configuration, mol, volume, density); // if volume == 0, will calculate from ConvexEnvelope
|
|---|
| 2058 | }
|
|---|
| 2059 | break;
|
|---|
| 2060 | case 'd':
|
|---|
| 2061 | if (ExitFlag == 0) ExitFlag = 1;
|
|---|
| 2062 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
|---|
| 2063 | ExitFlag = 255;
|
|---|
| 2064 | eLog() << Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl;
|
|---|
| 2065 | performCriticalExit();
|
|---|
| 2066 | } else {
|
|---|
| 2067 | SaveFlag = true;
|
|---|
| 2068 | for (int axis = 1; axis <= NDIM; axis++) {
|
|---|
| 2069 | int faktor = atoi(argv[argptr++]);
|
|---|
| 2070 | int count;
|
|---|
| 2071 | element ** Elements;
|
|---|
| 2072 | Vector ** vectors;
|
|---|
| 2073 | if (faktor < 1) {
|
|---|
| 2074 | eLog() << Verbose(1) << "Repetition factor mus be greater than 1!" << endl;
|
|---|
| 2075 | faktor = 1;
|
|---|
| 2076 | }
|
|---|
| 2077 | mol->CountAtoms(); // recount atoms
|
|---|
| 2078 | if (mol->AtomCount != 0) { // if there is more than none
|
|---|
| 2079 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
|---|
| 2080 | Elements = new element *[count];
|
|---|
| 2081 | vectors = new Vector *[count];
|
|---|
| 2082 | j = 0;
|
|---|
| 2083 | first = mol->start;
|
|---|
| 2084 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
|---|
| 2085 | first = first->next;
|
|---|
| 2086 | Elements[j] = first->type;
|
|---|
| 2087 | vectors[j] = &first->x;
|
|---|
| 2088 | j++;
|
|---|
| 2089 | }
|
|---|
| 2090 | if (count != j)
|
|---|
| 2091 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
|---|
| 2092 | x.Zero();
|
|---|
| 2093 | y.Zero();
|
|---|
| 2094 | 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
|
|---|
| 2095 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
|---|
| 2096 | x.AddVector(&y); // per factor one cell width further
|
|---|
| 2097 | for (int k=count;k--;) { // go through every atom of the original cell
|
|---|
| 2098 | first = new atom(); // create a new body
|
|---|
| 2099 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
|---|
| 2100 | first->x.AddVector(&x); // translate the coordinates
|
|---|
| 2101 | first->type = Elements[k]; // insert original element
|
|---|
| 2102 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
|---|
| 2103 | }
|
|---|
| 2104 | }
|
|---|
| 2105 | // free memory
|
|---|
| 2106 | delete[](Elements);
|
|---|
| 2107 | delete[](vectors);
|
|---|
| 2108 | // correct cell size
|
|---|
| 2109 | if (axis < 0) { // if sign was negative, we have to translate everything
|
|---|
| 2110 | x.Zero();
|
|---|
| 2111 | x.AddVector(&y);
|
|---|
| 2112 | x.Scale(-(faktor-1));
|
|---|
| 2113 | mol->Translate(&x);
|
|---|
| 2114 | }
|
|---|
| 2115 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
|---|
| 2116 | }
|
|---|
| 2117 | }
|
|---|
| 2118 | }
|
|---|
| 2119 | break;
|
|---|
| 2120 | default: // no match? Step on
|
|---|
| 2121 | if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
|
|---|
| 2122 | argptr++;
|
|---|
| 2123 | break;
|
|---|
| 2124 | }
|
|---|
| 2125 | }
|
|---|
| 2126 | } else argptr++;
|
|---|
| 2127 | } while (argptr < argc);
|
|---|
| 2128 | if (SaveFlag)
|
|---|
| 2129 | configuration.SaveAll(ConfigFileName, periode, molecules);
|
|---|
| 2130 | } else { // no arguments, hence scan the elements db
|
|---|
| 2131 | if (periode->LoadPeriodentafel(configuration.databasepath))
|
|---|
| 2132 | Log() << Verbose(0) << "Element list loaded successfully." << endl;
|
|---|
| 2133 | else
|
|---|
| 2134 | Log() << Verbose(0) << "Element list loading failed." << endl;
|
|---|
| 2135 | configuration.RetrieveConfigPathAndName("main_pcp_linux");
|
|---|
| 2136 | }
|
|---|
| 2137 | return(ExitFlag);
|
|---|
| 2138 | };
|
|---|
| 2139 |
|
|---|
| 2140 | /***************************************** Functions used to build all menus **********************/
|
|---|
| 2141 |
|
|---|
| 2142 | void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
|
|---|
| 2143 | // build the EditMoleculesMenu
|
|---|
| 2144 | Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
|
|---|
| 2145 | new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
|
|---|
| 2146 |
|
|---|
| 2147 | Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
|
|---|
| 2148 | new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
|
|---|
| 2149 |
|
|---|
| 2150 | Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules);
|
|---|
| 2151 | new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
|
|---|
| 2152 |
|
|---|
| 2153 | Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
|
|---|
| 2154 | new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
|
|---|
| 2155 |
|
|---|
| 2156 | Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
|
|---|
| 2157 | new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
|
|---|
| 2158 |
|
|---|
| 2159 | Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
|
|---|
| 2160 | new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
|
|---|
| 2161 | }
|
|---|
| 2162 |
|
|---|
| 2163 |
|
|---|
| 2164 | /********************************************** Main routine **************************************/
|
|---|
| 2165 |
|
|---|
| 2166 | int main(int argc, char **argv)
|
|---|
| 2167 | {
|
|---|
| 2168 | periodentafel *periode = new periodentafel;
|
|---|
| 2169 | MoleculeListClass *molecules = new MoleculeListClass;
|
|---|
| 2170 | molecule *mol = NULL;
|
|---|
| 2171 | config *configuration = new config;
|
|---|
| 2172 | Vector x, y, z, n;
|
|---|
| 2173 | ifstream test;
|
|---|
| 2174 | ofstream output;
|
|---|
| 2175 | string line;
|
|---|
| 2176 | char *ConfigFileName = NULL;
|
|---|
| 2177 | int j;
|
|---|
| 2178 | setVerbosity(0);
|
|---|
| 2179 | /* structure of ParseCommandLineOptions will be refactored later */
|
|---|
| 2180 | j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);
|
|---|
| 2181 | switch (j){
|
|---|
| 2182 | case 255:
|
|---|
| 2183 | case 2:
|
|---|
| 2184 | case 1:
|
|---|
| 2185 | delete (molecules);
|
|---|
| 2186 | delete (periode);
|
|---|
| 2187 | delete (configuration);
|
|---|
| 2188 | Log() << Verbose(0) << "Maximum of allocated memory: " << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
|
|---|
| 2189 | Log() << Verbose(0) << "Remaining non-freed memory: " << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
|
|---|
| 2190 | MemoryUsageObserver::getInstance()->purgeInstance();
|
|---|
| 2191 | logger::purgeInstance();
|
|---|
| 2192 | errorLogger::purgeInstance();
|
|---|
| 2193 | return (j == 1 ? 0 : j);
|
|---|
| 2194 | default:
|
|---|
| 2195 | break;
|
|---|
| 2196 | }
|
|---|
| 2197 | if(molecules->ListOfMolecules.size() == 0){
|
|---|
| 2198 | mol = new molecule(periode);
|
|---|
| 2199 | if(mol->cell_size[0] == 0.){
|
|---|
| 2200 | Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
|
|---|
| 2201 | for(int i = 0;i < 6;i++){
|
|---|
| 2202 | Log() << Verbose(1) << "Cell size" << i << ": ";
|
|---|
| 2203 | cin >> mol->cell_size[i];
|
|---|
| 2204 | }
|
|---|
| 2205 | }
|
|---|
| 2206 |
|
|---|
| 2207 | mol->ActiveFlag = true;
|
|---|
| 2208 | molecules->insert(mol);
|
|---|
| 2209 | }
|
|---|
| 2210 |
|
|---|
| 2211 | {
|
|---|
| 2212 | cout << ESPACKVersion << endl;
|
|---|
| 2213 |
|
|---|
| 2214 | setVerbosity(0);
|
|---|
| 2215 |
|
|---|
| 2216 | menuPopulaters populaters;
|
|---|
| 2217 | populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu;
|
|---|
| 2218 |
|
|---|
| 2219 | UIFactory::makeUserInterface(UIFactory::Text);
|
|---|
| 2220 | MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,molecules, configuration, periode, ConfigFileName);
|
|---|
| 2221 | mainWindow->display();
|
|---|
| 2222 | delete mainWindow;
|
|---|
| 2223 | }
|
|---|
| 2224 |
|
|---|
| 2225 | if(periode->StorePeriodentafel(configuration->databasepath))
|
|---|
| 2226 | Log() << Verbose(0) << "Saving of elements.db successful." << endl;
|
|---|
| 2227 |
|
|---|
| 2228 | else
|
|---|
| 2229 | Log() << Verbose(0) << "Saving of elements.db failed." << endl;
|
|---|
| 2230 |
|
|---|
| 2231 | delete (molecules);
|
|---|
| 2232 | delete(periode);
|
|---|
| 2233 | delete(configuration);
|
|---|
| 2234 |
|
|---|
| 2235 |
|
|---|
| 2236 |
|
|---|
| 2237 | Log() << Verbose(0) << "Maximum of allocated memory: "
|
|---|
| 2238 | << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
|
|---|
| 2239 | Log() << Verbose(0) << "Remaining non-freed memory: "
|
|---|
| 2240 | << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
|
|---|
| 2241 | MemoryUsageObserver::purgeInstance();
|
|---|
| 2242 | logger::purgeInstance();
|
|---|
| 2243 | errorLogger::purgeInstance();
|
|---|
| 2244 | UIFactory::purgeInstance();
|
|---|
| 2245 | ActionRegistry::purgeRegistry();
|
|---|
| 2246 | return (0);
|
|---|
| 2247 | }
|
|---|
| 2248 |
|
|---|
| 2249 | /********************************************** E N D **************************************************/
|
|---|