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