[14de469] | 1 | /** \file builder.cpp
|
---|
| 2 | *
|
---|
| 3 | * By stating absolute positions or binding angles and distances atomic positions of a molecule can be constructed.
|
---|
| 4 | * The output is the complete configuration file for PCP for direct use.
|
---|
| 5 | * Features:
|
---|
| 6 | * -# Atomic data is retrieved from a file, if not found requested and stored there for later re-use
|
---|
| 7 | * -# step-by-step construction of the molecule beginning either at a centre of with a certain atom
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | /*! \mainpage Molecuilder - a molecular set builder
|
---|
| 12 | *
|
---|
| 13 | * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
|
---|
| 14 | *
|
---|
| 15 | * \section about About the Program
|
---|
| 16 | *
|
---|
| 17 | * Molecuilder is a short program, written in C++, that enables the construction of a coordinate set for the
|
---|
| 18 | * atoms making up an molecule by the successive statement of binding angles and distances and referencing to
|
---|
| 19 | * already constructed atoms.
|
---|
| 20 | *
|
---|
| 21 | * A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
|
---|
| 22 | * molecular dynamics implementation.
|
---|
| 23 | *
|
---|
| 24 | * \section install Installation
|
---|
| 25 | *
|
---|
| 26 | * Installation should without problems succeed as follows:
|
---|
| 27 | * -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
|
---|
| 28 | * -# make
|
---|
| 29 | * -# make install
|
---|
| 30 | *
|
---|
| 31 | * Further useful commands are
|
---|
| 32 | * -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
|
---|
| 33 | * -# make doxygen-doc: Creates these html pages out of the documented source
|
---|
| 34 | *
|
---|
| 35 | * \section run Running
|
---|
| 36 | *
|
---|
| 37 | * The program can be executed by running: ./molecuilder
|
---|
| 38 | *
|
---|
| 39 | * Note, that it uses a database, called "elements.db", in the executable's directory. If the file is not found,
|
---|
| 40 | * it is created and any given data on elements of the periodic table will be stored therein and re-used on
|
---|
| 41 | * later re-execution.
|
---|
| 42 | *
|
---|
| 43 | * \section ref References
|
---|
| 44 | *
|
---|
| 45 | * For the special configuration file format, see the documentation of pcp.
|
---|
| 46 | *
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | using namespace std;
|
---|
| 51 |
|
---|
| 52 | #include "helpers.hpp"
|
---|
| 53 | #include "molecules.hpp"
|
---|
[110ceb] | 54 | #include "boundary.hpp"
|
---|
[14de469] | 55 |
|
---|
| 56 | /********************************************** Submenu routine **************************************/
|
---|
| 57 |
|
---|
| 58 | /** Submenu for adding atoms to the molecule.
|
---|
| 59 | * \param *periode periodentafel
|
---|
| 60 | * \param *mol the molecule to add to
|
---|
| 61 | */
|
---|
[7f3b9d] | 62 | static void AddAtoms(periodentafel *periode, molecule *mol)
|
---|
[14de469] | 63 | {
|
---|
| 64 | atom *first, *second, *third, *fourth;
|
---|
[e9b8bb] | 65 | Vector **atoms;
|
---|
| 66 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
[14de469] | 67 | double a,b,c;
|
---|
| 68 | char choice; // menu choice char
|
---|
| 69 | bool valid;
|
---|
| 70 |
|
---|
| 71 | cout << Verbose(0) << "===========ADD ATOM============================" << endl;
|
---|
| 72 | cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
|
---|
| 73 | cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
|
---|
| 74 | cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
|
---|
| 75 | cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
|
---|
| 76 | cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
|
---|
| 77 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 78 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 79 | cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
|
---|
| 80 | cout << Verbose(0) << "INPUT: ";
|
---|
| 81 | cin >> choice;
|
---|
| 82 |
|
---|
| 83 | switch (choice) {
|
---|
| 84 | case 'a': // absolute coordinates of atom
|
---|
| 85 | cout << Verbose(0) << "Enter absolute coordinates." << endl;
|
---|
| 86 | first = new atom;
|
---|
| 87 | first->x.AskPosition(mol->cell_size, false);
|
---|
| 88 | first->type = periode->AskElement(); // give type
|
---|
| 89 | mol->AddAtom(first); // add to molecule
|
---|
| 90 | break;
|
---|
| 91 |
|
---|
| 92 | case 'b': // relative coordinates of atom wrt to reference point
|
---|
| 93 | first = new atom;
|
---|
| 94 | valid = true;
|
---|
| 95 | do {
|
---|
| 96 | if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
|
---|
| 97 | cout << Verbose(0) << "Enter reference coordinates." << endl;
|
---|
| 98 | x.AskPosition(mol->cell_size, true);
|
---|
| 99 | cout << Verbose(0) << "Enter relative coordinates." << endl;
|
---|
| 100 | first->x.AskPosition(mol->cell_size, false);
|
---|
[e9b8bb] | 101 | first->x.AddVector((const Vector *)&x);
|
---|
[14de469] | 102 | cout << Verbose(0) << "\n";
|
---|
[e9b8bb] | 103 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
[14de469] | 104 | first->type = periode->AskElement(); // give type
|
---|
| 105 | mol->AddAtom(first); // add to molecule
|
---|
| 106 | break;
|
---|
| 107 |
|
---|
| 108 | case 'c': // relative coordinates of atom wrt to already placed atom
|
---|
| 109 | first = new atom;
|
---|
| 110 | valid = true;
|
---|
| 111 | do {
|
---|
| 112 | if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
|
---|
| 113 | second = mol->AskAtom("Enter atom number: ");
|
---|
| 114 | cout << Verbose(0) << "Enter relative coordinates." << endl;
|
---|
| 115 | first->x.AskPosition(mol->cell_size, false);
|
---|
[7f3b9d] | 116 | for (int i=NDIM;i--;) {
|
---|
[14de469] | 117 | first->x.x[i] += second->x.x[i];
|
---|
| 118 | }
|
---|
[e9b8bb] | 119 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
[14de469] | 120 | first->type = periode->AskElement(); // give type
|
---|
| 121 | mol->AddAtom(first); // add to molecule
|
---|
| 122 | break;
|
---|
| 123 |
|
---|
| 124 | case 'd': // two atoms, two angles and a distance
|
---|
| 125 | first = new atom;
|
---|
| 126 | valid = true;
|
---|
| 127 | do {
|
---|
| 128 | if (!valid) {
|
---|
| 129 | cout << Verbose(0) << "Resulting coordinates out of cell - ";
|
---|
| 130 | first->x.Output((ofstream *)&cout);
|
---|
| 131 | cout << Verbose(0) << endl;
|
---|
| 132 | }
|
---|
| 133 | cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
|
---|
| 134 | second = mol->AskAtom("Enter central atom: ");
|
---|
| 135 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
|
---|
| 136 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
|
---|
| 137 | a = ask_value("Enter distance between central (first) and new atom: ");
|
---|
| 138 | b = ask_value("Enter angle between new, first and second atom (degrees): ");
|
---|
| 139 | b *= M_PI/180.;
|
---|
| 140 | bound(&b, 0., 2.*M_PI);
|
---|
| 141 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
|
---|
| 142 | c *= M_PI/180.;
|
---|
| 143 | bound(&c, -M_PI, M_PI);
|
---|
| 144 | cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
|
---|
| 145 | /*
|
---|
| 146 | second->Output(1,1,(ofstream *)&cout);
|
---|
| 147 | third->Output(1,2,(ofstream *)&cout);
|
---|
| 148 | fourth->Output(1,3,(ofstream *)&cout);
|
---|
[d7e30c] | 149 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
|
---|
| 150 | x.Copyvector(&second->x);
|
---|
[14de469] | 151 | x.SubtractVector(&third->x);
|
---|
[d7e30c] | 152 | x.Copyvector(&fourth->x);
|
---|
[14de469] | 153 | x.SubtractVector(&third->x);
|
---|
| 154 |
|
---|
| 155 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
|
---|
| 156 | cout << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
|
---|
| 157 | continue;
|
---|
| 158 | }
|
---|
| 159 | cout << Verbose(0) << "resulting relative coordinates: ";
|
---|
| 160 | z.Output((ofstream *)&cout);
|
---|
| 161 | cout << Verbose(0) << endl;
|
---|
| 162 | */
|
---|
| 163 | // calc axis vector
|
---|
| 164 | x.CopyVector(&second->x);
|
---|
| 165 | x.SubtractVector(&third->x);
|
---|
| 166 | x.Normalize();
|
---|
| 167 | cout << "x: ",
|
---|
| 168 | x.Output((ofstream *)&cout);
|
---|
| 169 | cout << endl;
|
---|
| 170 | z.MakeNormalVector(&second->x,&third->x,&fourth->x);
|
---|
| 171 | cout << "z: ",
|
---|
| 172 | z.Output((ofstream *)&cout);
|
---|
| 173 | cout << endl;
|
---|
| 174 | y.MakeNormalVector(&x,&z);
|
---|
| 175 | cout << "y: ",
|
---|
| 176 | y.Output((ofstream *)&cout);
|
---|
| 177 | cout << endl;
|
---|
| 178 |
|
---|
| 179 | // rotate vector around first angle
|
---|
| 180 | first->x.CopyVector(&x);
|
---|
| 181 | first->x.RotateVector(&z,b - M_PI);
|
---|
| 182 | cout << "Rotated vector: ",
|
---|
| 183 | first->x.Output((ofstream *)&cout);
|
---|
| 184 | cout << endl;
|
---|
| 185 | // remove the projection onto the rotation plane of the second angle
|
---|
| 186 | n.CopyVector(&y);
|
---|
| 187 | n.Scale(first->x.Projection(&y));
|
---|
| 188 | cout << "N1: ",
|
---|
| 189 | n.Output((ofstream *)&cout);
|
---|
| 190 | cout << endl;
|
---|
| 191 | first->x.SubtractVector(&n);
|
---|
| 192 | cout << "Subtracted vector: ",
|
---|
| 193 | first->x.Output((ofstream *)&cout);
|
---|
| 194 | cout << endl;
|
---|
| 195 | n.CopyVector(&z);
|
---|
| 196 | n.Scale(first->x.Projection(&z));
|
---|
| 197 | cout << "N2: ",
|
---|
| 198 | n.Output((ofstream *)&cout);
|
---|
| 199 | cout << endl;
|
---|
| 200 | first->x.SubtractVector(&n);
|
---|
| 201 | cout << "2nd subtracted vector: ",
|
---|
| 202 | first->x.Output((ofstream *)&cout);
|
---|
| 203 | cout << endl;
|
---|
| 204 |
|
---|
| 205 | // rotate another vector around second angle
|
---|
| 206 | n.CopyVector(&y);
|
---|
| 207 | n.RotateVector(&x,c - M_PI);
|
---|
| 208 | cout << "2nd Rotated vector: ",
|
---|
| 209 | n.Output((ofstream *)&cout);
|
---|
| 210 | cout << endl;
|
---|
| 211 |
|
---|
| 212 | // add the two linear independent vectors
|
---|
| 213 | first->x.AddVector(&n);
|
---|
| 214 | first->x.Normalize();
|
---|
| 215 | first->x.Scale(a);
|
---|
| 216 | first->x.AddVector(&second->x);
|
---|
| 217 |
|
---|
| 218 | cout << Verbose(0) << "resulting coordinates: ";
|
---|
| 219 | first->x.Output((ofstream *)&cout);
|
---|
| 220 | cout << Verbose(0) << endl;
|
---|
[e9b8bb] | 221 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
[14de469] | 222 | first->type = periode->AskElement(); // give type
|
---|
| 223 | mol->AddAtom(first); // add to molecule
|
---|
| 224 | break;
|
---|
| 225 |
|
---|
| 226 | case 'e': // least square distance position to a set of atoms
|
---|
| 227 | first = new atom;
|
---|
[e9b8bb] | 228 | atoms = new (Vector*[128]);
|
---|
[14de469] | 229 | valid = true;
|
---|
[7f3b9d] | 230 | for(int i=128;i--;)
|
---|
[14de469] | 231 | atoms[i] = NULL;
|
---|
| 232 | int i=0, j=0;
|
---|
| 233 | cout << Verbose(0) << "Now we need at least three molecules.\n";
|
---|
| 234 | do {
|
---|
| 235 | cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
|
---|
| 236 | cin >> j;
|
---|
| 237 | if (j != -1) {
|
---|
| 238 | second = mol->FindAtom(j);
|
---|
| 239 | atoms[i++] = &(second->x);
|
---|
| 240 | }
|
---|
| 241 | } while ((j != -1) && (i<128));
|
---|
| 242 | if (i >= 2) {
|
---|
| 243 | first->x.LSQdistance(atoms, i);
|
---|
| 244 |
|
---|
| 245 | first->x.Output((ofstream *)&cout);
|
---|
| 246 | first->type = periode->AskElement(); // give type
|
---|
| 247 | mol->AddAtom(first); // add to molecule
|
---|
| 248 | } else {
|
---|
| 249 | delete first;
|
---|
| 250 | cout << Verbose(0) << "Please enter at least two vectors!\n";
|
---|
| 251 | }
|
---|
| 252 | break;
|
---|
| 253 | };
|
---|
| 254 | };
|
---|
| 255 |
|
---|
| 256 | /** Submenu for centering the atoms in the molecule.
|
---|
| 257 | * \param *mol the molecule with all the atoms
|
---|
| 258 | */
|
---|
[7f3b9d] | 259 | static void CenterAtoms(molecule *mol)
|
---|
[14de469] | 260 | {
|
---|
[e9b8bb] | 261 | Vector x, y;
|
---|
[14de469] | 262 | char choice; // menu choice char
|
---|
| 263 |
|
---|
| 264 | cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
|
---|
| 265 | cout << Verbose(0) << " a - on origin" << endl;
|
---|
| 266 | cout << Verbose(0) << " b - on center of gravity" << endl;
|
---|
| 267 | cout << Verbose(0) << " c - within box with additional boundary" << endl;
|
---|
[ca2b83] | 268 | cout << Verbose(0) << " d - within given simulation box" << endl;
|
---|
[14de469] | 269 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 270 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 271 | cout << Verbose(0) << "INPUT: ";
|
---|
| 272 | cin >> choice;
|
---|
| 273 |
|
---|
| 274 | switch (choice) {
|
---|
| 275 | default:
|
---|
| 276 | cout << Verbose(0) << "Not a valid choice." << endl;
|
---|
| 277 | break;
|
---|
| 278 | case 'a':
|
---|
| 279 | cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
|
---|
| 280 | mol->CenterOrigin((ofstream *)&cout, &x);
|
---|
| 281 | break;
|
---|
| 282 | case 'b':
|
---|
| 283 | cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
|
---|
| 284 | mol->CenterGravity((ofstream *)&cout, &x);
|
---|
| 285 | break;
|
---|
| 286 | case 'c':
|
---|
| 287 | cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
|
---|
[7f3b9d] | 288 | for (int i=0;i<NDIM;i++) {
|
---|
[14de469] | 289 | cout << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
[ca2b83] | 290 | cin >> y.x[i];
|
---|
[14de469] | 291 | }
|
---|
| 292 | mol->CenterEdge((ofstream *)&cout, &x); // make every coordinate positive
|
---|
[ca2b83] | 293 | mol->Translate(&y); // translate by boundary
|
---|
| 294 | mol->SetBoxDimension(&(x+y*2)); // update Box of atoms by boundary
|
---|
| 295 | break;
|
---|
| 296 | case 'd':
|
---|
| 297 | cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
---|
[7f3b9d] | 298 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 299 | cout << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
| 300 | cin >> x.x[i];
|
---|
[14de469] | 301 | }
|
---|
[ca2b83] | 302 | // center
|
---|
| 303 | mol->CenterInBox((ofstream *)&cout, &x);
|
---|
| 304 | // update Box of atoms by boundary
|
---|
| 305 | mol->SetBoxDimension(&x);
|
---|
[14de469] | 306 | break;
|
---|
| 307 | }
|
---|
| 308 | };
|
---|
| 309 |
|
---|
| 310 | /** Submenu for aligning the atoms in the molecule.
|
---|
| 311 | * \param *periode periodentafel
|
---|
| 312 | * \param *mol the molecule with all the atoms
|
---|
| 313 | */
|
---|
[7f3b9d] | 314 | static void AlignAtoms(periodentafel *periode, molecule *mol)
|
---|
[14de469] | 315 | {
|
---|
| 316 | atom *first, *second, *third;
|
---|
[e9b8bb] | 317 | Vector x,n;
|
---|
[14de469] | 318 | char choice; // menu choice char
|
---|
| 319 |
|
---|
| 320 | cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
|
---|
| 321 | cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
|
---|
| 322 | cout << Verbose(0) << " b - state alignment vector" << endl;
|
---|
| 323 | cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
|
---|
| 324 | cout << Verbose(0) << " d - align automatically by least square fit" << endl;
|
---|
| 325 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 326 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 327 | cout << Verbose(0) << "INPUT: ";
|
---|
| 328 | cin >> choice;
|
---|
| 329 |
|
---|
| 330 | switch (choice) {
|
---|
| 331 | default:
|
---|
| 332 | case 'a': // three atoms defining mirror plane
|
---|
| 333 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 334 | second = mol->AskAtom("Enter second atom: ");
|
---|
| 335 | third = mol->AskAtom("Enter third atom: ");
|
---|
| 336 |
|
---|
[e9b8bb] | 337 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
---|
[14de469] | 338 | break;
|
---|
| 339 | case 'b': // normal vector of mirror plane
|
---|
| 340 | cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
|
---|
| 341 | n.AskPosition(mol->cell_size,0);
|
---|
| 342 | n.Normalize();
|
---|
| 343 | break;
|
---|
| 344 | case 'c': // three atoms defining mirror plane
|
---|
| 345 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 346 | second = mol->AskAtom("Enter second atom: ");
|
---|
| 347 |
|
---|
[e9b8bb] | 348 | n.CopyVector((const Vector *)&first->x);
|
---|
| 349 | n.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 350 | n.Normalize();
|
---|
| 351 | break;
|
---|
| 352 | case 'd':
|
---|
| 353 | char shorthand[4];
|
---|
[e9b8bb] | 354 | Vector a;
|
---|
[14de469] | 355 | struct lsq_params param;
|
---|
| 356 | do {
|
---|
| 357 | fprintf(stdout, "Enter the element of atoms to be chosen: ");
|
---|
| 358 | fscanf(stdin, "%3s", shorthand);
|
---|
| 359 | } while ((param.type = periode->FindElement(shorthand)) == NULL);
|
---|
| 360 | cout << Verbose(0) << "Element is " << param.type->name << endl;
|
---|
[d7e30c] | 361 | mol->GetAlignvector(¶m);
|
---|
[7f3b9d] | 362 | for (int i=NDIM;i--;) {
|
---|
[14de469] | 363 | x.x[i] = gsl_vector_get(param.x,i);
|
---|
[7f3b9d] | 364 | n.x[i] = gsl_vector_get(param.x,i+NDIM);
|
---|
[14de469] | 365 | }
|
---|
| 366 | gsl_vector_free(param.x);
|
---|
| 367 | cout << Verbose(0) << "Offset vector: ";
|
---|
| 368 | x.Output((ofstream *)&cout);
|
---|
| 369 | cout << Verbose(0) << endl;
|
---|
| 370 | n.Normalize();
|
---|
| 371 | break;
|
---|
| 372 | };
|
---|
| 373 | cout << Verbose(0) << "Alignment vector: ";
|
---|
| 374 | n.Output((ofstream *)&cout);
|
---|
| 375 | cout << Verbose(0) << endl;
|
---|
| 376 | mol->Align(&n);
|
---|
| 377 | };
|
---|
| 378 |
|
---|
| 379 | /** Submenu for mirroring the atoms in the molecule.
|
---|
| 380 | * \param *mol the molecule with all the atoms
|
---|
| 381 | */
|
---|
[7f3b9d] | 382 | static void MirrorAtoms(molecule *mol)
|
---|
[14de469] | 383 | {
|
---|
| 384 | atom *first, *second, *third;
|
---|
[e9b8bb] | 385 | Vector n;
|
---|
[14de469] | 386 | char choice; // menu choice char
|
---|
| 387 |
|
---|
| 388 | cout << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
|
---|
| 389 | cout << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
|
---|
| 390 | cout << Verbose(0) << " b - state normal vector of mirror plane" << endl;
|
---|
| 391 | cout << Verbose(0) << " c - state two atoms in normal direction" << endl;
|
---|
| 392 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 393 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 394 | cout << Verbose(0) << "INPUT: ";
|
---|
| 395 | cin >> choice;
|
---|
| 396 |
|
---|
| 397 | switch (choice) {
|
---|
| 398 | default:
|
---|
| 399 | case 'a': // three atoms defining mirror plane
|
---|
| 400 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 401 | second = mol->AskAtom("Enter second atom: ");
|
---|
| 402 | third = mol->AskAtom("Enter third atom: ");
|
---|
| 403 |
|
---|
[e9b8bb] | 404 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
---|
[14de469] | 405 | break;
|
---|
| 406 | case 'b': // normal vector of mirror plane
|
---|
| 407 | cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
|
---|
| 408 | n.AskPosition(mol->cell_size,0);
|
---|
| 409 | n.Normalize();
|
---|
| 410 | break;
|
---|
| 411 | case 'c': // three atoms defining mirror plane
|
---|
| 412 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 413 | second = mol->AskAtom("Enter second atom: ");
|
---|
| 414 |
|
---|
[e9b8bb] | 415 | n.CopyVector((const Vector *)&first->x);
|
---|
| 416 | n.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 417 | n.Normalize();
|
---|
| 418 | break;
|
---|
| 419 | };
|
---|
| 420 | cout << Verbose(0) << "Normal vector: ";
|
---|
| 421 | n.Output((ofstream *)&cout);
|
---|
| 422 | cout << Verbose(0) << endl;
|
---|
[e9b8bb] | 423 | mol->Mirror((const Vector *)&n);
|
---|
[14de469] | 424 | };
|
---|
| 425 |
|
---|
| 426 | /** Submenu for removing the atoms from the molecule.
|
---|
| 427 | * \param *mol the molecule with all the atoms
|
---|
| 428 | */
|
---|
[7f3b9d] | 429 | static void RemoveAtoms(molecule *mol)
|
---|
[14de469] | 430 | {
|
---|
| 431 | atom *first, *second;
|
---|
| 432 | int axis;
|
---|
| 433 | double tmp1, tmp2;
|
---|
| 434 | char choice; // menu choice char
|
---|
| 435 |
|
---|
| 436 | cout << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
|
---|
| 437 | cout << Verbose(0) << " a - state atom for removal by number" << endl;
|
---|
| 438 | cout << Verbose(0) << " b - keep only in radius around atom" << endl;
|
---|
| 439 | cout << Verbose(0) << " c - remove this with one axis greater value" << endl;
|
---|
| 440 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 441 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 442 | cout << Verbose(0) << "INPUT: ";
|
---|
| 443 | cin >> choice;
|
---|
| 444 |
|
---|
| 445 | switch (choice) {
|
---|
| 446 | default:
|
---|
| 447 | case 'a':
|
---|
| 448 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
|
---|
| 449 | cout << Verbose(1) << "Atom removed." << endl;
|
---|
| 450 | else
|
---|
| 451 | cout << Verbose(1) << "Atom not found." << endl;
|
---|
| 452 | break;
|
---|
| 453 | case 'b':
|
---|
| 454 | second = mol->AskAtom("Enter number of atom as reference point: ");
|
---|
| 455 | cout << Verbose(0) << "Enter radius: ";
|
---|
| 456 | cin >> tmp1;
|
---|
| 457 | first = mol->start;
|
---|
| 458 | while(first->next != mol->end) {
|
---|
| 459 | first = first->next;
|
---|
[e9b8bb] | 460 | if (first->x.Distance((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
|
---|
[14de469] | 461 | mol->RemoveAtom(first);
|
---|
| 462 | }
|
---|
| 463 | break;
|
---|
| 464 | case 'c':
|
---|
| 465 | cout << Verbose(0) << "Which axis is it: ";
|
---|
| 466 | cin >> axis;
|
---|
| 467 | cout << Verbose(0) << "Left inward boundary: ";
|
---|
| 468 | cin >> tmp1;
|
---|
| 469 | cout << Verbose(0) << "Right inward boundary: ";
|
---|
| 470 | cin >> tmp2;
|
---|
| 471 | first = mol->start;
|
---|
| 472 | while(first->next != mol->end) {
|
---|
| 473 | first = first->next;
|
---|
| 474 | if ((first->x.x[axis] > tmp2) || (first->x.x[axis] < tmp1)) // out of boundary ...
|
---|
| 475 | mol->RemoveAtom(first);
|
---|
| 476 | }
|
---|
| 477 | break;
|
---|
| 478 | };
|
---|
| 479 | //mol->Output((ofstream *)&cout);
|
---|
| 480 | choice = 'r';
|
---|
| 481 | };
|
---|
| 482 |
|
---|
| 483 | /** Submenu for measuring out the atoms in the molecule.
|
---|
| 484 | * \param *periode periodentafel
|
---|
| 485 | * \param *mol the molecule with all the atoms
|
---|
| 486 | */
|
---|
[d52ea1b] | 487 | static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
|
---|
[14de469] | 488 | {
|
---|
| 489 | atom *first, *second, *third;
|
---|
[e9b8bb] | 490 | Vector x,y;
|
---|
[14de469] | 491 | double min[256], tmp1, tmp2, tmp3;
|
---|
| 492 | int Z;
|
---|
| 493 | char choice; // menu choice char
|
---|
| 494 |
|
---|
| 495 | cout << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
|
---|
| 496 | cout << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
|
---|
| 497 | cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
|
---|
| 498 | cout << Verbose(0) << " c - calculate bond angle" << endl;
|
---|
[d52ea1b] | 499 | cout << Verbose(0) << " d - calculate principal axis of the system" << endl;
|
---|
| 500 | cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
|
---|
[698b04] | 501 | cout << Verbose(0) << " f - calculate temperature from current velocity" << endl;
|
---|
| 502 | cout << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
|
---|
[14de469] | 503 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 504 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 505 | cout << Verbose(0) << "INPUT: ";
|
---|
| 506 | cin >> choice;
|
---|
| 507 |
|
---|
| 508 | switch(choice) {
|
---|
| 509 | default:
|
---|
| 510 | cout << Verbose(1) << "Not a valid choice." << endl;
|
---|
| 511 | break;
|
---|
| 512 | case 'a':
|
---|
| 513 | first = mol->AskAtom("Enter first atom: ");
|
---|
[7f3b9d] | 514 | for (int i=MAX_ELEMENTS;i--;)
|
---|
[14de469] | 515 | min[i] = 0.;
|
---|
| 516 |
|
---|
| 517 | second = mol->start;
|
---|
| 518 | while ((second->next != mol->end)) {
|
---|
| 519 | second = second->next; // advance
|
---|
| 520 | Z = second->type->Z;
|
---|
| 521 | tmp1 = 0.;
|
---|
| 522 | if (first != second) {
|
---|
[e9b8bb] | 523 | x.CopyVector((const Vector *)&first->x);
|
---|
| 524 | x.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 525 | tmp1 = x.Norm();
|
---|
| 526 | }
|
---|
| 527 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
|
---|
| 528 | //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
|
---|
| 529 | }
|
---|
[7f3b9d] | 530 | for (int i=MAX_ELEMENTS;i--;)
|
---|
[14de469] | 531 | 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;
|
---|
| 532 | break;
|
---|
| 533 |
|
---|
| 534 | case 'b':
|
---|
| 535 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 536 | second = mol->AskAtom("Enter second atom: ");
|
---|
[7f3b9d] | 537 | for (int i=NDIM;i--;)
|
---|
[14de469] | 538 | min[i] = 0.;
|
---|
[e9b8bb] | 539 | x.CopyVector((const Vector *)&first->x);
|
---|
| 540 | x.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 541 | tmp1 = x.Norm();
|
---|
| 542 | cout << Verbose(1) << "Distance vector is ";
|
---|
| 543 | x.Output((ofstream *)&cout);
|
---|
| 544 | cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
|
---|
| 545 | break;
|
---|
| 546 |
|
---|
| 547 | case 'c':
|
---|
| 548 | cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
|
---|
| 549 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 550 | second = mol->AskAtom("Enter central atom: ");
|
---|
| 551 | third = mol->AskAtom("Enter last atom: ");
|
---|
| 552 | tmp1 = tmp2 = tmp3 = 0.;
|
---|
[e9b8bb] | 553 | x.CopyVector((const Vector *)&first->x);
|
---|
| 554 | x.SubtractVector((const Vector *)&second->x);
|
---|
| 555 | y.CopyVector((const Vector *)&third->x);
|
---|
| 556 | y.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 557 | cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
---|
[e9b8bb] | 558 | cout << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
|
---|
[14de469] | 559 | break;
|
---|
[d52ea1b] | 560 | case 'd':
|
---|
| 561 | cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
---|
| 562 | cout << Verbose(0) << "Shall we rotate? [0/1]: ";
|
---|
| 563 | cin >> Z;
|
---|
| 564 | if ((Z >=0) && (Z <=1))
|
---|
| 565 | mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
|
---|
| 566 | else
|
---|
| 567 | mol->PrincipalAxisSystem((ofstream *)&cout, false);
|
---|
| 568 | break;
|
---|
| 569 | case 'e':
|
---|
| 570 | cout << Verbose(0) << "Evaluating volume of the convex envelope.";
|
---|
[6c5812] | 571 | VolumeOfConvexEnvelope((ofstream *)&cout, configuration, NULL, mol);
|
---|
[d52ea1b] | 572 | break;
|
---|
[698b04] | 573 | case 'f':
|
---|
| 574 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps, (ofstream *)&cout);
|
---|
| 575 | break;
|
---|
| 576 | case 'g':
|
---|
| 577 | {
|
---|
| 578 | char filename[255];
|
---|
| 579 | cout << "Please enter filename: " << endl;
|
---|
| 580 | cin >> filename;
|
---|
| 581 | cout << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
|
---|
| 582 | ofstream *output = new ofstream(filename, ios::trunc);
|
---|
| 583 | if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
|
---|
| 584 | cout << Verbose(2) << "File could not be written." << endl;
|
---|
| 585 | else
|
---|
| 586 | cout << Verbose(2) << "File stored." << endl;
|
---|
| 587 | output->close();
|
---|
| 588 | delete(output);
|
---|
| 589 | }
|
---|
| 590 | break;
|
---|
[14de469] | 591 | }
|
---|
| 592 | };
|
---|
| 593 |
|
---|
| 594 | /** Submenu for measuring out the atoms in the molecule.
|
---|
| 595 | * \param *mol the molecule with all the atoms
|
---|
| 596 | * \param *configuration configuration structure for the to be written config files of all fragments
|
---|
| 597 | */
|
---|
[7f3b9d] | 598 | static void FragmentAtoms(molecule *mol, config *configuration)
|
---|
[14de469] | 599 | {
|
---|
[db942e] | 600 | int Order1;
|
---|
[14de469] | 601 | clock_t start, end;
|
---|
| 602 |
|
---|
| 603 | cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
---|
| 604 | cout << Verbose(0) << "What's the desired bond order: ";
|
---|
| 605 | cin >> Order1;
|
---|
| 606 | if (mol->first->next != mol->last) { // there are bonds
|
---|
| 607 | start = clock();
|
---|
[db942e] | 608 | mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
|
---|
[14de469] | 609 | end = clock();
|
---|
| 610 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
| 611 | } else
|
---|
| 612 | cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
|
---|
| 613 | };
|
---|
| 614 |
|
---|
| 615 | /********************************************** Test routine **************************************/
|
---|
| 616 |
|
---|
| 617 | /** Is called always as option 'T' in the menu.
|
---|
| 618 | */
|
---|
[7f3b9d] | 619 | static void testroutine(molecule *mol)
|
---|
[14de469] | 620 | {
|
---|
| 621 | // the current test routine checks the functionality of the KeySet&Graph concept:
|
---|
| 622 | // We want to have a multiindex (the KeySet) describing a unique subgraph
|
---|
| 623 | atom *Walker = mol->start;
|
---|
| 624 | int i, comp, counter=0;
|
---|
| 625 |
|
---|
| 626 | // generate some KeySets
|
---|
| 627 | cout << "Generating KeySets." << endl;
|
---|
| 628 | KeySet TestSets[mol->AtomCount+1];
|
---|
| 629 | i=1;
|
---|
| 630 | while (Walker->next != mol->end) {
|
---|
| 631 | Walker = Walker->next;
|
---|
| 632 | for (int j=0;j<i;j++) {
|
---|
| 633 | TestSets[j].insert(Walker->nr);
|
---|
| 634 | }
|
---|
| 635 | i++;
|
---|
| 636 | }
|
---|
| 637 | cout << "Testing insertion of already present item in KeySets." << endl;
|
---|
| 638 | KeySetTestPair test;
|
---|
| 639 | test = TestSets[mol->AtomCount-1].insert(Walker->nr);
|
---|
| 640 | if (test.second) {
|
---|
| 641 | cout << Verbose(1) << "Insertion worked?!" << endl;
|
---|
| 642 | } else {
|
---|
| 643 | cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
|
---|
| 644 | }
|
---|
| 645 | TestSets[mol->AtomCount].insert(mol->end->previous->nr);
|
---|
| 646 | TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
|
---|
| 647 |
|
---|
| 648 | // constructing Graph structure
|
---|
| 649 | cout << "Generating Subgraph class." << endl;
|
---|
| 650 | Graph Subgraphs;
|
---|
| 651 |
|
---|
| 652 | // insert KeySets into Subgraphs
|
---|
| 653 | cout << "Inserting KeySets into Subgraph class." << endl;
|
---|
| 654 | for (int j=0;j<mol->AtomCount;j++) {
|
---|
| 655 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
|
---|
| 656 | }
|
---|
| 657 | cout << "Testing insertion of already present item in Subgraph." << endl;
|
---|
| 658 | GraphTestPair test2;
|
---|
| 659 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
|
---|
| 660 | if (test2.second) {
|
---|
| 661 | cout << Verbose(1) << "Insertion worked?!" << endl;
|
---|
| 662 | } else {
|
---|
| 663 | cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | // show graphs
|
---|
| 667 | cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
|
---|
| 668 | Graph::iterator A = Subgraphs.begin();
|
---|
| 669 | while (A != Subgraphs.end()) {
|
---|
| 670 | cout << (*A).second.first << ": ";
|
---|
| 671 | KeySet::iterator key = (*A).first.begin();
|
---|
| 672 | comp = -1;
|
---|
| 673 | while (key != (*A).first.end()) {
|
---|
| 674 | if ((*key) > comp)
|
---|
| 675 | cout << (*key) << " ";
|
---|
| 676 | else
|
---|
| 677 | cout << (*key) << "! ";
|
---|
| 678 | comp = (*key);
|
---|
| 679 | key++;
|
---|
| 680 | }
|
---|
| 681 | cout << endl;
|
---|
| 682 | A++;
|
---|
| 683 | }
|
---|
| 684 | };
|
---|
| 685 |
|
---|
[dbe929] | 686 | /** Tries given filename or standard on saving the config file.
|
---|
| 687 | * \param *ConfigFileName name of file
|
---|
| 688 | * \param *configuration pointer to configuration structure with all the values
|
---|
| 689 | * \param *periode pointer to periodentafel structure with all the elements
|
---|
| 690 | * \param *mol pointer to molecule structure with all the atoms and coordinates
|
---|
| 691 | */
|
---|
[7f3b9d] | 692 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
|
---|
[dbe929] | 693 | {
|
---|
[c750cc] | 694 | char filename[MAXSTRINGSIZE];
|
---|
[dbe929] | 695 | ofstream output;
|
---|
| 696 |
|
---|
[73f80e] | 697 | cout << Verbose(0) << "Storing configuration ... " << endl;
|
---|
[dbe929] | 698 | // get correct valence orbitals
|
---|
| 699 | mol->CalculateOrbitals(*configuration);
|
---|
| 700 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
|
---|
[6590bee] | 701 | if (ConfigFileName != NULL) {
|
---|
[dbe929] | 702 | output.open(ConfigFileName, ios::trunc);
|
---|
[4885953] | 703 | } else if (strlen(configuration->configname) != 0) {
|
---|
[6590bee] | 704 | output.open(configuration->configname, ios::trunc);
|
---|
[4885953] | 705 | } else {
|
---|
| 706 | output.open(DEFAULTCONFIG, ios::trunc);
|
---|
| 707 | }
|
---|
[a8aadf6] | 708 | cout << Verbose(0) << "Saving of config file ";
|
---|
[dbe929] | 709 | if (configuration->Save(&output, periode, mol))
|
---|
[a8aadf6] | 710 | cout << "successful." << endl;
|
---|
[dbe929] | 711 | else
|
---|
[a8aadf6] | 712 | cout << "failed." << endl;
|
---|
[dbe929] | 713 | output.close();
|
---|
| 714 | output.clear();
|
---|
[a8aadf6] | 715 |
|
---|
[dbe929] | 716 | // and save to xyz file
|
---|
| 717 | if (ConfigFileName != NULL) {
|
---|
| 718 | strcpy(filename, ConfigFileName);
|
---|
| 719 | strcat(filename, ".xyz");
|
---|
| 720 | output.open(filename, ios::trunc);
|
---|
| 721 | }
|
---|
| 722 | if (output == NULL) {
|
---|
| 723 | strcpy(filename,"main_pcp_linux");
|
---|
| 724 | strcat(filename, ".xyz");
|
---|
| 725 | output.open(filename, ios::trunc);
|
---|
| 726 | }
|
---|
[a8aadf6] | 727 | cout << Verbose(0) << "Saving of XYZ file ";
|
---|
[362b0e] | 728 | if (mol->MDSteps <= 1) {
|
---|
| 729 | if (mol->OutputXYZ(&output))
|
---|
[a8aadf6] | 730 | cout << "successful." << endl;
|
---|
[362b0e] | 731 | else
|
---|
[a8aadf6] | 732 | cout << "failed." << endl;
|
---|
[362b0e] | 733 | } else {
|
---|
| 734 | if (mol->OutputTrajectoriesXYZ(&output))
|
---|
[a8aadf6] | 735 | cout << "successful." << endl;
|
---|
[362b0e] | 736 | else
|
---|
[a8aadf6] | 737 | cout << "failed." << endl;
|
---|
[362b0e] | 738 | }
|
---|
[dbe929] | 739 | output.close();
|
---|
| 740 | output.clear();
|
---|
[a8aadf6] | 741 |
|
---|
| 742 | // and save as MPQC configuration
|
---|
| 743 | if (ConfigFileName != NULL) {
|
---|
| 744 | strcpy(filename, ConfigFileName);
|
---|
| 745 | strcat(filename, ".in");
|
---|
| 746 | output.open(filename, ios::trunc);
|
---|
| 747 | }
|
---|
| 748 | if (output == NULL) {
|
---|
| 749 | strcpy(filename,"main_pcp_linux");
|
---|
| 750 | strcat(filename, ".in");
|
---|
| 751 | output.open(filename, ios::trunc);
|
---|
| 752 | }
|
---|
| 753 | cout << Verbose(0) << "Saving as mpqc input ";
|
---|
| 754 | if (configuration->SaveMPQC(&output, mol))
|
---|
| 755 | cout << "done." << endl;
|
---|
| 756 | else
|
---|
| 757 | cout << "failed." << endl;
|
---|
| 758 | output.close();
|
---|
| 759 | output.clear();
|
---|
[6590bee] | 760 |
|
---|
[2910e0] | 761 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
|
---|
| 762 | cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
|
---|
| 763 | }
|
---|
[dbe929] | 764 | };
|
---|
| 765 |
|
---|
[ca2b83] | 766 | /** Parses the command line options.
|
---|
| 767 | * \param argc argument count
|
---|
| 768 | * \param **argv arguments array
|
---|
| 769 | * \param *mol molecule structure
|
---|
| 770 | * \param *periode elements structure
|
---|
| 771 | * \param configuration config file structure
|
---|
| 772 | * \param *ConfigFileName pointer to config file name in **argv
|
---|
[d7d29c] | 773 | * \param *PathToDatabases pointer to db's path in **argv
|
---|
[ca2b83] | 774 | * \return exit code (0 - successful, all else - something's wrong)
|
---|
| 775 | */
|
---|
[d7d29c] | 776 | static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&PathToDatabases)
|
---|
[14de469] | 777 | {
|
---|
[e9b8bb] | 778 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
[ca2b83] | 779 | double *factor; // unit factor if desired
|
---|
[14de469] | 780 | ifstream test;
|
---|
| 781 | ofstream output;
|
---|
| 782 | string line;
|
---|
[ca2b83] | 783 | atom *first;
|
---|
[362b0e] | 784 | bool SaveFlag = false;
|
---|
[dd8cf8] | 785 | int ExitFlag = 0;
|
---|
[ca2b83] | 786 | int j;
|
---|
[edb650] | 787 | double volume = 0.;
|
---|
[dbe929] | 788 | enum ConfigStatus config_present = absent;
|
---|
[14de469] | 789 | clock_t start,end;
|
---|
[73f80e] | 790 | int argptr;
|
---|
[d7d29c] | 791 | PathToDatabases = LocalPath;
|
---|
[ca2b83] | 792 |
|
---|
[6590bee] | 793 | if (argc > 1) { // config file specified as option
|
---|
[73f80e] | 794 | // 1. : Parse options that just set variables or print help
|
---|
[ca2b83] | 795 | argptr = 1;
|
---|
| 796 | do {
|
---|
| 797 | if (argv[argptr][0] == '-') {
|
---|
[73f80e] | 798 | cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
|
---|
| 799 | argptr++;
|
---|
| 800 | switch(argv[argptr-1][1]) {
|
---|
| 801 | case 'h':
|
---|
| 802 | case 'H':
|
---|
| 803 | case '?':
|
---|
| 804 | cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
|
---|
[db942e] | 805 | cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
|
---|
[73f80e] | 806 | cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
|
---|
| 807 | cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
|
---|
[ca2b83] | 808 | cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
|
---|
[73f80e] | 809 | cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
|
---|
[362b0e] | 810 | cout << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
|
---|
[1f066fe] | 811 | cout << "\t-O\tCenter atoms in origin." << endl;
|
---|
[318bfd] | 812 | cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
|
---|
[d7d29c] | 813 | cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
|
---|
[4f2335] | 814 | cout << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
|
---|
[362b0e] | 815 | 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;
|
---|
[73f80e] | 816 | cout << "\t-h/-H/-?\tGive this help screen." << endl;
|
---|
[68cb0f] | 817 | cout << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
|
---|
[233e33] | 818 | cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
|
---|
[110ceb] | 819 | cout << "\t-o\tGet volume of the convex envelope (and store to tecplot file)." << endl;
|
---|
[73f80e] | 820 | cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
|
---|
[362b0e] | 821 | cout << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
|
---|
[73f80e] | 822 | cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
|
---|
| 823 | cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
|
---|
[698b04] | 824 | cout << "\t-T <file> Store temperatures from the config file in <file>." << endl;
|
---|
[73f80e] | 825 | cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
|
---|
[318bfd] | 826 | cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
|
---|
[73f80e] | 827 | cout << "\t-v/-V\t\tGives version information." << endl;
|
---|
[5b15ab] | 828 | cout << "Note: config files must not begin with '-' !" << endl;
|
---|
[2910e0] | 829 | delete(mol);
|
---|
| 830 | delete(periode);
|
---|
[ca2b83] | 831 | return (1);
|
---|
[73f80e] | 832 | break;
|
---|
| 833 | case 'v':
|
---|
| 834 | case 'V':
|
---|
| 835 | cout << argv[0] << " " << VERSIONSTRING << endl;
|
---|
| 836 | cout << "Build your own molecule position set." << endl;
|
---|
[2910e0] | 837 | delete(mol);
|
---|
| 838 | delete(periode);
|
---|
[ca2b83] | 839 | return (1);
|
---|
[73f80e] | 840 | break;
|
---|
| 841 | case 'e':
|
---|
| 842 | cout << "Using " << argv[argptr] << " as elements database." << endl;
|
---|
[d7d29c] | 843 | PathToDatabases = argv[argptr];
|
---|
[73f80e] | 844 | argptr+=1;
|
---|
| 845 | break;
|
---|
[233e33] | 846 | case 'n':
|
---|
| 847 | cout << "I won't parse trajectories." << endl;
|
---|
| 848 | configuration.FastParsing = true;
|
---|
[256520] | 849 | break;
|
---|
[73f80e] | 850 | default: // no match? Step on
|
---|
| 851 | argptr++;
|
---|
| 852 | break;
|
---|
| 853 | }
|
---|
[ca2b83] | 854 | } else
|
---|
| 855 | argptr++;
|
---|
[4885953] | 856 | } while (argptr < argc);
|
---|
[ca2b83] | 857 |
|
---|
| 858 | // 2. Parse the element database
|
---|
[d7d29c] | 859 | if (periode->LoadPeriodentafel(PathToDatabases)) {
|
---|
[73f80e] | 860 | cout << Verbose(0) << "Element list loaded successfully." << endl;
|
---|
[b61043] | 861 | //periode->Output((ofstream *)&cout);
|
---|
[14d4d4] | 862 | } else {
|
---|
[73f80e] | 863 | cout << Verbose(0) << "Element list loading failed." << endl;
|
---|
[14d4d4] | 864 | return 1;
|
---|
| 865 | }
|
---|
[4885953] | 866 |
|
---|
[ca2b83] | 867 | // 3. Find config file name and parse if possible
|
---|
[4885953] | 868 | if (argv[1][0] != '-') {
|
---|
[dbe929] | 869 | cout << Verbose(0) << "Config file given." << endl;
|
---|
[4885953] | 870 | test.open(argv[1], ios::in);
|
---|
[dbe929] | 871 | if (test == NULL) {
|
---|
| 872 | //return (1);
|
---|
[4885953] | 873 | output.open(argv[1], ios::out);
|
---|
[dbe929] | 874 | if (output == NULL) {
|
---|
[4885953] | 875 | cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
|
---|
[dbe929] | 876 | config_present = absent;
|
---|
| 877 | } else {
|
---|
| 878 | cout << "Empty configuration file." << endl;
|
---|
[4885953] | 879 | ConfigFileName = argv[1];
|
---|
[dbe929] | 880 | config_present = empty;
|
---|
| 881 | output.close();
|
---|
| 882 | }
|
---|
| 883 | } else {
|
---|
[5b15ab] | 884 | test.close();
|
---|
[4885953] | 885 | ConfigFileName = argv[1];
|
---|
[fedd5f] | 886 | cout << Verbose(1) << "Specified config file found, parsing ... ";
|
---|
[5b15ab] | 887 | switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
|
---|
[dbe929] | 888 | case 1:
|
---|
| 889 | cout << "new syntax." << endl;
|
---|
[5b15ab] | 890 | configuration.Load(ConfigFileName, periode, mol);
|
---|
[dbe929] | 891 | config_present = present;
|
---|
| 892 | break;
|
---|
| 893 | case 0:
|
---|
| 894 | cout << "old syntax." << endl;
|
---|
[5b15ab] | 895 | configuration.LoadOld(ConfigFileName, periode, mol);
|
---|
[dbe929] | 896 | config_present = present;
|
---|
| 897 | break;
|
---|
| 898 | default:
|
---|
| 899 | cout << "Unknown syntax or empty, yet present file." << endl;
|
---|
| 900 | config_present = empty;
|
---|
| 901 | }
|
---|
[14de469] | 902 | }
|
---|
[73f80e] | 903 | } else
|
---|
| 904 | config_present = absent;
|
---|
[4885953] | 905 |
|
---|
[73f80e] | 906 | // 4. parse again through options, now for those depending on elements db and config presence
|
---|
| 907 | argptr = 1;
|
---|
| 908 | do {
|
---|
[ca2b83] | 909 | cout << "Current Command line argument: " << argv[argptr] << "." << endl;
|
---|
[73f80e] | 910 | if (argv[argptr][0] == '-') {
|
---|
[dbe929] | 911 | argptr++;
|
---|
| 912 | if ((config_present == present) || (config_present == empty)) {
|
---|
| 913 | switch(argv[argptr-1][1]) {
|
---|
| 914 | case 'p':
|
---|
[dd8cf8] | 915 | ExitFlag = 1;
|
---|
[362b0e] | 916 | SaveFlag = true;
|
---|
[dbe929] | 917 | cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
|
---|
[ca2b83] | 918 | if (!mol->AddXYZFile(argv[argptr]))
|
---|
[dbe929] | 919 | cout << Verbose(2) << "File not found." << endl;
|
---|
[d7e30c] | 920 | else {
|
---|
[dbe929] | 921 | cout << Verbose(2) << "File found and parsed." << endl;
|
---|
[73f80e] | 922 | config_present = present;
|
---|
[d7e30c] | 923 | }
|
---|
[14de469] | 924 | break;
|
---|
[d1fc7f] | 925 | case 'a':
|
---|
| 926 | ExitFlag = 1;
|
---|
| 927 | SaveFlag = true;
|
---|
| 928 | cout << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
|
---|
| 929 | first = new atom;
|
---|
| 930 | first->type = periode->FindElement(atoi(argv[argptr]));
|
---|
| 931 | if (first->type != NULL)
|
---|
| 932 | cout << Verbose(2) << "found element " << first->type->name << endl;
|
---|
| 933 | for (int i=NDIM;i--;)
|
---|
| 934 | first->x.x[i] = atof(argv[argptr+1+i]);
|
---|
| 935 | if (first->type != NULL) {
|
---|
| 936 | mol->AddAtom(first); // add to molecule
|
---|
| 937 | if ((config_present == empty) && (mol->AtomCount != 0))
|
---|
| 938 | config_present = present;
|
---|
| 939 | } else
|
---|
| 940 | cerr << Verbose(1) << "Could not find the specified element." << endl;
|
---|
| 941 | argptr+=4;
|
---|
| 942 | break;
|
---|
[73f80e] | 943 | default: // no match? Don't step on (this is done in next switch's default)
|
---|
[14de469] | 944 | break;
|
---|
[dbe929] | 945 | }
|
---|
| 946 | }
|
---|
[ca2b83] | 947 | if (config_present == present) {
|
---|
| 948 | switch(argv[argptr-1][1]) {
|
---|
[362b0e] | 949 | case 'D':
|
---|
[dd8cf8] | 950 | ExitFlag = 1;
|
---|
[362b0e] | 951 | {
|
---|
| 952 | cout << Verbose(1) << "Depth-First-Search Analysis." << endl;
|
---|
| 953 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
---|
| 954 | int *MinimumRingSize = NULL;
|
---|
[698b04] | 955 | mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr]), configuration.GetIsAngstroem());
|
---|
[362b0e] | 956 | mol->CreateListOfBondsPerAtom((ofstream *)&cout);
|
---|
| 957 | Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
|
---|
| 958 | delete[](MinimumRingSize);
|
---|
| 959 | if (Subgraphs != NULL) {
|
---|
| 960 | while (Subgraphs->next != NULL) {
|
---|
| 961 | Subgraphs = Subgraphs->next;
|
---|
| 962 | delete(Subgraphs->previous);
|
---|
| 963 | }
|
---|
| 964 | delete(Subgraphs);
|
---|
| 965 | }
|
---|
| 966 | }
|
---|
| 967 | argptr+=1;
|
---|
[698b04] | 968 | break;
|
---|
[4f2335] | 969 | case 'E':
|
---|
| 970 | ExitFlag = 1;
|
---|
| 971 | SaveFlag = true;
|
---|
| 972 | cout << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl;
|
---|
| 973 | first = mol->FindAtom(atoi(argv[argptr]));
|
---|
| 974 | first->type = periode->FindElement(atoi(argv[argptr+1]));
|
---|
| 975 | argptr+=2;
|
---|
| 976 | break;
|
---|
| 977 | case 'T':
|
---|
[698b04] | 978 | ExitFlag = 1;
|
---|
| 979 | {
|
---|
| 980 | cout << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
|
---|
| 981 | ofstream *output = new ofstream(argv[argptr], ios::trunc);
|
---|
| 982 | if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
|
---|
| 983 | cout << Verbose(2) << "File could not be written." << endl;
|
---|
| 984 | else
|
---|
| 985 | cout << Verbose(2) << "File stored." << endl;
|
---|
| 986 | output->close();
|
---|
| 987 | delete(output);
|
---|
| 988 | }
|
---|
| 989 | argptr+=1;
|
---|
[362b0e] | 990 | break;
|
---|
[d7e30c] | 991 | case 'P':
|
---|
[dd8cf8] | 992 | ExitFlag = 1;
|
---|
[362b0e] | 993 | SaveFlag = true;
|
---|
[d7e30c] | 994 | cout << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
|
---|
[362b0e] | 995 | if (!mol->VerletForceIntegration(argv[argptr], configuration.Deltat, configuration.GetIsAngstroem()))
|
---|
[d7e30c] | 996 | cout << Verbose(2) << "File not found." << endl;
|
---|
| 997 | else
|
---|
| 998 | cout << Verbose(2) << "File found and parsed." << endl;
|
---|
[362b0e] | 999 | argptr+=1;
|
---|
[d7e30c] | 1000 | break;
|
---|
[ca2b83] | 1001 | case 't':
|
---|
[dd8cf8] | 1002 | ExitFlag = 1;
|
---|
[362b0e] | 1003 | SaveFlag = true;
|
---|
[ca2b83] | 1004 | cout << Verbose(1) << "Translating all ions to new origin." << endl;
|
---|
[7f3b9d] | 1005 | for (int i=NDIM;i--;)
|
---|
[ca2b83] | 1006 | x.x[i] = atof(argv[argptr+i]);
|
---|
[e9b8bb] | 1007 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 1008 | argptr+=3;
|
---|
| 1009 | break;
|
---|
| 1010 | case 's':
|
---|
[dd8cf8] | 1011 | ExitFlag = 1;
|
---|
[362b0e] | 1012 | SaveFlag = true;
|
---|
[ca2b83] | 1013 | j = -1;
|
---|
| 1014 | cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
|
---|
[7f3b9d] | 1015 | factor = new double[NDIM];
|
---|
[ca2b83] | 1016 | factor[0] = atof(argv[argptr]);
|
---|
| 1017 | if (argc > argptr+1)
|
---|
| 1018 | argptr++;
|
---|
| 1019 | factor[1] = atof(argv[argptr]);
|
---|
| 1020 | if (argc > argptr+1)
|
---|
| 1021 | argptr++;
|
---|
| 1022 | factor[2] = atof(argv[argptr]);
|
---|
| 1023 | mol->Scale(&factor);
|
---|
[7f3b9d] | 1024 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 1025 | j += i+1;
|
---|
[7f3b9d] | 1026 | x.x[i] = atof(argv[NDIM+i]);
|
---|
[ca2b83] | 1027 | mol->cell_size[j]*=factor[i];
|
---|
| 1028 | }
|
---|
[7f3b9d] | 1029 | delete[](factor);
|
---|
[ca2b83] | 1030 | argptr+=1;
|
---|
| 1031 | break;
|
---|
| 1032 | case 'b':
|
---|
[dd8cf8] | 1033 | ExitFlag = 1;
|
---|
[362b0e] | 1034 | SaveFlag = true;
|
---|
[ca2b83] | 1035 | j = -1;
|
---|
| 1036 | cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
---|
| 1037 | j=-1;
|
---|
[7f3b9d] | 1038 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 1039 | j += i+1;
|
---|
| 1040 | x.x[i] = atof(argv[argptr++]);
|
---|
| 1041 | mol->cell_size[j] += x.x[i]*2.;
|
---|
| 1042 | }
|
---|
| 1043 | // center
|
---|
| 1044 | mol->CenterInBox((ofstream *)&cout, &x);
|
---|
| 1045 | // update Box of atoms by boundary
|
---|
| 1046 | mol->SetBoxDimension(&x);
|
---|
| 1047 | break;
|
---|
| 1048 | case 'c':
|
---|
[dd8cf8] | 1049 | ExitFlag = 1;
|
---|
[362b0e] | 1050 | SaveFlag = true;
|
---|
[ca2b83] | 1051 | j = -1;
|
---|
| 1052 | cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
|
---|
| 1053 | // make every coordinate positive
|
---|
| 1054 | mol->CenterEdge((ofstream *)&cout, &x);
|
---|
| 1055 | // update Box of atoms by boundary
|
---|
| 1056 | mol->SetBoxDimension(&x);
|
---|
| 1057 | // translate each coordinate by boundary
|
---|
| 1058 | j=-1;
|
---|
[7f3b9d] | 1059 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 1060 | j += i+1;
|
---|
| 1061 | x.x[i] = atof(argv[argptr++]);
|
---|
| 1062 | mol->cell_size[j] += x.x[i]*2.;
|
---|
| 1063 | }
|
---|
[e9b8bb] | 1064 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 1065 | break;
|
---|
[1f066fe] | 1066 | case 'O':
|
---|
[dd8cf8] | 1067 | ExitFlag = 1;
|
---|
[362b0e] | 1068 | SaveFlag = true;
|
---|
[1f066fe] | 1069 | cout << Verbose(1) << "Centering atoms in origin." << endl;
|
---|
| 1070 | mol->CenterOrigin((ofstream *)&cout, &x);
|
---|
| 1071 | mol->SetBoxDimension(&x);
|
---|
| 1072 | break;
|
---|
[ca2b83] | 1073 | case 'r':
|
---|
[dd8cf8] | 1074 | ExitFlag = 1;
|
---|
[362b0e] | 1075 | SaveFlag = true;
|
---|
[ca2b83] | 1076 | cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
|
---|
| 1077 | break;
|
---|
[d7e30c] | 1078 | case 'F':
|
---|
[ca2b83] | 1079 | case 'f':
|
---|
[dd8cf8] | 1080 | ExitFlag = 1;
|
---|
[ca2b83] | 1081 | cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
|
---|
| 1082 | if (argc >= argptr+2) {
|
---|
| 1083 | cout << Verbose(0) << "Creating connection matrix..." << endl;
|
---|
| 1084 | start = clock();
|
---|
[a251a3] | 1085 | mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
|
---|
[ca2b83] | 1086 | cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
---|
| 1087 | if (mol->first->next != mol->last) {
|
---|
[362b0e] | 1088 | ExitFlag = mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
|
---|
[dbe929] | 1089 | }
|
---|
[ca2b83] | 1090 | end = clock();
|
---|
| 1091 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
[dbe929] | 1092 | argptr+=1;
|
---|
[ca2b83] | 1093 | } else {
|
---|
| 1094 | cerr << "Not enough arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
|
---|
| 1095 | }
|
---|
| 1096 | break;
|
---|
[d52ea1b] | 1097 | case 'm':
|
---|
[dd8cf8] | 1098 | ExitFlag = 1;
|
---|
[110ceb] | 1099 | j = atoi(argv[argptr++]);
|
---|
| 1100 | if ((j<0) || (j>1)) {
|
---|
| 1101 | cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
|
---|
| 1102 | j = 0;
|
---|
| 1103 | }
|
---|
[362b0e] | 1104 | if (j) {
|
---|
| 1105 | SaveFlag = true;
|
---|
[110ceb] | 1106 | cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
|
---|
[362b0e] | 1107 | } else
|
---|
[110ceb] | 1108 | cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
---|
| 1109 | mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
|
---|
| 1110 | break;
|
---|
| 1111 | case 'o':
|
---|
[dd8cf8] | 1112 | ExitFlag = 1;
|
---|
[362b0e] | 1113 | SaveFlag = true;
|
---|
[110ceb] | 1114 | cout << Verbose(0) << "Evaluating volume of the convex envelope.";
|
---|
[6c5812] | 1115 | VolumeOfConvexEnvelope((ofstream *)&cout, &configuration, NULL, mol);
|
---|
[d52ea1b] | 1116 | break;
|
---|
[edb650] | 1117 | case 'U':
|
---|
[dd8cf8] | 1118 | ExitFlag = 1;
|
---|
[edb650] | 1119 | volume = atof(argv[argptr++]);
|
---|
| 1120 | cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
|
---|
[318bfd] | 1121 | case 'u':
|
---|
[dd8cf8] | 1122 | ExitFlag = 1;
|
---|
[318bfd] | 1123 | {
|
---|
[edb650] | 1124 | double density;
|
---|
[362b0e] | 1125 | SaveFlag = true;
|
---|
[318bfd] | 1126 | cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
|
---|
[edb650] | 1127 | density = atof(argv[argptr++]);
|
---|
| 1128 | if (density < 1.0) {
|
---|
[318bfd] | 1129 | cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
|
---|
[edb650] | 1130 | density = 1.3;
|
---|
[318bfd] | 1131 | }
|
---|
| 1132 | // for(int i=0;i<NDIM;i++) {
|
---|
| 1133 | // repetition[i] = atoi(argv[argptr++]);
|
---|
| 1134 | // if (repetition[i] < 1)
|
---|
| 1135 | // cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
|
---|
| 1136 | // repetition[i] = 1;
|
---|
| 1137 | // }
|
---|
[edb650] | 1138 | PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density);
|
---|
[318bfd] | 1139 | }
|
---|
| 1140 | break;
|
---|
| 1141 | case 'd':
|
---|
[dd8cf8] | 1142 | ExitFlag = 1;
|
---|
[362b0e] | 1143 | SaveFlag = true;
|
---|
[318bfd] | 1144 | for (int axis = 1; axis <= NDIM; axis++) {
|
---|
| 1145 | int faktor = atoi(argv[argptr++]);
|
---|
| 1146 | int count;
|
---|
| 1147 | element ** Elements;
|
---|
[e9b8bb] | 1148 | Vector ** vectors;
|
---|
[318bfd] | 1149 | if (faktor < 1) {
|
---|
| 1150 | cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
|
---|
| 1151 | faktor = 1;
|
---|
| 1152 | }
|
---|
| 1153 | mol->CountAtoms((ofstream *)&cout); // recount atoms
|
---|
| 1154 | if (mol->AtomCount != 0) { // if there is more than none
|
---|
| 1155 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
---|
| 1156 | Elements = new element *[count];
|
---|
[e9b8bb] | 1157 | vectors = new Vector *[count];
|
---|
[318bfd] | 1158 | j = 0;
|
---|
| 1159 | first = mol->start;
|
---|
| 1160 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
---|
| 1161 | first = first->next;
|
---|
| 1162 | Elements[j] = first->type;
|
---|
[d7e30c] | 1163 | vectors[j] = &first->x;
|
---|
[318bfd] | 1164 | j++;
|
---|
| 1165 | }
|
---|
| 1166 | if (count != j)
|
---|
| 1167 | cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
---|
| 1168 | x.Zero();
|
---|
| 1169 | y.Zero();
|
---|
| 1170 | 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
|
---|
| 1171 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
| 1172 | x.AddVector(&y); // per factor one cell width further
|
---|
| 1173 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
| 1174 | first = new atom(); // create a new body
|
---|
[d7e30c] | 1175 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
---|
[318bfd] | 1176 | first->x.AddVector(&x); // translate the coordinates
|
---|
| 1177 | first->type = Elements[k]; // insert original element
|
---|
| 1178 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
| 1179 | }
|
---|
| 1180 | }
|
---|
| 1181 | // free memory
|
---|
| 1182 | delete[](Elements);
|
---|
[d7e30c] | 1183 | delete[](vectors);
|
---|
[318bfd] | 1184 | // correct cell size
|
---|
| 1185 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
| 1186 | x.Zero();
|
---|
| 1187 | x.AddVector(&y);
|
---|
| 1188 | x.Scale(-(faktor-1));
|
---|
| 1189 | mol->Translate(&x);
|
---|
| 1190 | }
|
---|
| 1191 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
| 1192 | }
|
---|
| 1193 | }
|
---|
| 1194 | break;
|
---|
[ca2b83] | 1195 | default: // no match? Step on
|
---|
[4f2335] | 1196 | if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
|
---|
[110ceb] | 1197 | argptr++;
|
---|
[ca2b83] | 1198 | break;
|
---|
[14de469] | 1199 | }
|
---|
| 1200 | }
|
---|
[ca2b83] | 1201 | } else argptr++;
|
---|
| 1202 | } while (argptr < argc);
|
---|
[362b0e] | 1203 | if (SaveFlag)
|
---|
[dbe929] | 1204 | SaveConfig(ConfigFileName, &configuration, periode, mol);
|
---|
[362b0e] | 1205 | if ((ExitFlag >= 1)) {
|
---|
[5b15ab] | 1206 | delete(mol);
|
---|
| 1207 | delete(periode);
|
---|
[362b0e] | 1208 | return (ExitFlag);
|
---|
[5b15ab] | 1209 | }
|
---|
[6590bee] | 1210 | } else { // no arguments, hence scan the elements db
|
---|
[d7d29c] | 1211 | if (periode->LoadPeriodentafel(PathToDatabases))
|
---|
[6590bee] | 1212 | cout << Verbose(0) << "Element list loaded successfully." << endl;
|
---|
| 1213 | else
|
---|
| 1214 | cout << Verbose(0) << "Element list loading failed." << endl;
|
---|
| 1215 | configuration.RetrieveConfigPathAndName("main_pcp_linux");
|
---|
[14de469] | 1216 | }
|
---|
[ca2b83] | 1217 | return(0);
|
---|
| 1218 | };
|
---|
| 1219 |
|
---|
| 1220 | /********************************************** Main routine **************************************/
|
---|
[14de469] | 1221 |
|
---|
[ca2b83] | 1222 | int main(int argc, char **argv)
|
---|
| 1223 | {
|
---|
| 1224 | periodentafel *periode = new periodentafel; // and a period table of all elements
|
---|
| 1225 | molecule *mol = new molecule(periode); // first we need an empty molecule
|
---|
| 1226 | config configuration;
|
---|
| 1227 | double tmp1;
|
---|
| 1228 | double bond, min_bond;
|
---|
| 1229 | atom *first, *second;
|
---|
| 1230 | char choice; // menu choice char
|
---|
[e9b8bb] | 1231 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
[ca2b83] | 1232 | double *factor; // unit factor if desired
|
---|
| 1233 | bool valid; // flag if input was valid or not
|
---|
| 1234 | ifstream test;
|
---|
| 1235 | ofstream output;
|
---|
| 1236 | string line;
|
---|
| 1237 | char filename[MAXSTRINGSIZE];
|
---|
| 1238 | char *ConfigFileName = NULL;
|
---|
| 1239 | char *ElementsFileName = NULL;
|
---|
| 1240 | int Z;
|
---|
| 1241 | int j, axis, count, faktor;
|
---|
| 1242 | int *MinimumRingSize = NULL;
|
---|
| 1243 | MoleculeLeafClass *Subgraphs = NULL;
|
---|
| 1244 | clock_t start,end;
|
---|
| 1245 | element **Elements;
|
---|
[e9b8bb] | 1246 | Vector **vectors;
|
---|
[ca2b83] | 1247 |
|
---|
| 1248 | // =========================== PARSE COMMAND LINE OPTIONS ====================================
|
---|
| 1249 | j = ParseCommandLineOptions(argc, argv, mol, periode, configuration, ConfigFileName, ElementsFileName);
|
---|
[d7d29c] | 1250 | if (j == 1) return 0; // just for -v and -h options
|
---|
[ca2b83] | 1251 | if (j) return j; // something went wrong
|
---|
[14de469] | 1252 |
|
---|
| 1253 | // General stuff
|
---|
| 1254 | if (mol->cell_size[0] == 0.) {
|
---|
| 1255 | cout << Verbose(0) << "enter lower triadiagonal form of basis matrix" << endl << endl;
|
---|
| 1256 | for (int i=0;i<6;i++) {
|
---|
| 1257 | cout << Verbose(1) << "Cell size" << i << ": ";
|
---|
| 1258 | cin >> mol->cell_size[i];
|
---|
| 1259 | }
|
---|
| 1260 | }
|
---|
| 1261 |
|
---|
[73f80e] | 1262 | // =========================== START INTERACTIVE SESSION ====================================
|
---|
| 1263 |
|
---|
[14de469] | 1264 | // now the main construction loop
|
---|
| 1265 | cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
|
---|
| 1266 | do {
|
---|
| 1267 | cout << Verbose(0) << endl << endl;
|
---|
| 1268 | cout << Verbose(0) << "============Element list=======================" << endl;
|
---|
| 1269 | mol->Checkout((ofstream *)&cout);
|
---|
| 1270 | cout << Verbose(0) << "============Atom list==========================" << endl;
|
---|
| 1271 | mol->Output((ofstream *)&cout);
|
---|
| 1272 | cout << Verbose(0) << "============Menu===============================" << endl;
|
---|
| 1273 | cout << Verbose(0) << "a - add an atom" << endl;
|
---|
| 1274 | cout << Verbose(0) << "r - remove an atom" << endl;
|
---|
| 1275 | cout << Verbose(0) << "b - scale a bond between atoms" << endl;
|
---|
| 1276 | cout << Verbose(0) << "u - change an atoms element" << endl;
|
---|
| 1277 | cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
|
---|
| 1278 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1279 | cout << Verbose(0) << "p - Parse xyz file" << endl;
|
---|
| 1280 | cout << Verbose(0) << "e - edit the current configuration" << endl;
|
---|
| 1281 | cout << Verbose(0) << "o - create connection matrix" << endl;
|
---|
| 1282 | cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
|
---|
| 1283 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1284 | cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
|
---|
| 1285 | cout << Verbose(0) << "i - realign molecule" << endl;
|
---|
| 1286 | cout << Verbose(0) << "m - mirror all molecules" << endl;
|
---|
| 1287 | cout << Verbose(0) << "t - translate molecule by vector" << endl;
|
---|
| 1288 | cout << Verbose(0) << "c - scale by unit transformation" << endl;
|
---|
| 1289 | cout << Verbose(0) << "g - center atoms in box" << endl;
|
---|
| 1290 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1291 | cout << Verbose(0) << "s - save current setup to config file" << endl;
|
---|
| 1292 | cout << Verbose(0) << "T - call the current test routine" << endl;
|
---|
| 1293 | cout << Verbose(0) << "q - quit" << endl;
|
---|
| 1294 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 1295 | cout << Verbose(0) << "Input: ";
|
---|
| 1296 | cin >> choice;
|
---|
| 1297 |
|
---|
| 1298 | switch (choice) {
|
---|
| 1299 | default:
|
---|
| 1300 | case 'a': // add atom
|
---|
| 1301 | AddAtoms(periode, mol);
|
---|
| 1302 | choice = 'a';
|
---|
| 1303 | break;
|
---|
| 1304 |
|
---|
[ca2b83] | 1305 | case 'b': // scale a bond
|
---|
| 1306 | cout << Verbose(0) << "Scaling bond length between two atoms." << endl;
|
---|
| 1307 | first = mol->AskAtom("Enter first (fixed) atom: ");
|
---|
| 1308 | second = mol->AskAtom("Enter second (shifting) atom: ");
|
---|
| 1309 | min_bond = 0.;
|
---|
[7f3b9d] | 1310 | for (int i=NDIM;i--;)
|
---|
[ca2b83] | 1311 | min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
|
---|
| 1312 | min_bond = sqrt(min_bond);
|
---|
| 1313 | 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;
|
---|
| 1314 | cout << Verbose(0) << "Enter new bond length [a.u.]: ";
|
---|
| 1315 | cin >> bond;
|
---|
[7f3b9d] | 1316 | for (int i=NDIM;i--;) {
|
---|
[ca2b83] | 1317 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
|
---|
| 1318 | }
|
---|
| 1319 | //cout << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
|
---|
| 1320 | //second->Output(second->type->No, 1, (ofstream *)&cout);
|
---|
| 1321 | break;
|
---|
| 1322 |
|
---|
| 1323 | case 'c': // unit scaling of the metric
|
---|
| 1324 | cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
|
---|
| 1325 | cout << Verbose(0) << "Enter three factors: ";
|
---|
| 1326 | factor = new double[NDIM];
|
---|
| 1327 | cin >> factor[0];
|
---|
| 1328 | cin >> factor[1];
|
---|
| 1329 | cin >> factor[2];
|
---|
| 1330 | valid = true;
|
---|
| 1331 | mol->Scale(&factor);
|
---|
| 1332 | delete[](factor);
|
---|
| 1333 | break;
|
---|
| 1334 |
|
---|
[14de469] | 1335 | case 'd': // duplicate the periodic cell along a given axis, given times
|
---|
| 1336 | cout << Verbose(0) << "State the axis [(+-)123]: ";
|
---|
| 1337 | cin >> axis;
|
---|
| 1338 | cout << Verbose(0) << "State the factor: ";
|
---|
| 1339 | cin >> faktor;
|
---|
| 1340 |
|
---|
| 1341 | mol->CountAtoms((ofstream *)&cout); // recount atoms
|
---|
| 1342 | if (mol->AtomCount != 0) { // if there is more than none
|
---|
| 1343 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
---|
[ca2b83] | 1344 | Elements = new element *[count];
|
---|
[e9b8bb] | 1345 | vectors = new Vector *[count];
|
---|
[14de469] | 1346 | j = 0;
|
---|
| 1347 | first = mol->start;
|
---|
| 1348 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
---|
| 1349 | first = first->next;
|
---|
| 1350 | Elements[j] = first->type;
|
---|
[d7e30c] | 1351 | vectors[j] = &first->x;
|
---|
[14de469] | 1352 | j++;
|
---|
| 1353 | }
|
---|
| 1354 | if (count != j)
|
---|
| 1355 | cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
---|
| 1356 | x.Zero();
|
---|
| 1357 | y.Zero();
|
---|
| 1358 | 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
|
---|
| 1359 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
| 1360 | x.AddVector(&y); // per factor one cell width further
|
---|
[7f3b9d] | 1361 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
[14de469] | 1362 | first = new atom(); // create a new body
|
---|
[d7e30c] | 1363 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
---|
[14de469] | 1364 | first->x.AddVector(&x); // translate the coordinates
|
---|
| 1365 | first->type = Elements[k]; // insert original element
|
---|
| 1366 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
| 1367 | }
|
---|
| 1368 | }
|
---|
| 1369 | if (mol->first->next != mol->last) // if connect matrix is present already, redo it
|
---|
[a251a3] | 1370 | mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration.GetIsAngstroem());
|
---|
[14de469] | 1371 | // free memory
|
---|
[ca2b83] | 1372 | delete[](Elements);
|
---|
[d7e30c] | 1373 | delete[](vectors);
|
---|
[14de469] | 1374 | // correct cell size
|
---|
| 1375 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
| 1376 | x.Zero();
|
---|
| 1377 | x.AddVector(&y);
|
---|
| 1378 | x.Scale(-(faktor-1));
|
---|
| 1379 | mol->Translate(&x);
|
---|
| 1380 | }
|
---|
| 1381 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
| 1382 | }
|
---|
| 1383 | break;
|
---|
| 1384 |
|
---|
[ca2b83] | 1385 | case 'e': // edit each field of the configuration
|
---|
| 1386 | configuration.Edit(mol);
|
---|
| 1387 | break;
|
---|
| 1388 |
|
---|
| 1389 | case 'f':
|
---|
| 1390 | FragmentAtoms(mol, &configuration);
|
---|
| 1391 | break;
|
---|
| 1392 |
|
---|
[14de469] | 1393 | case 'g': // center the atoms
|
---|
| 1394 | CenterAtoms(mol);
|
---|
| 1395 | break;
|
---|
| 1396 |
|
---|
| 1397 | case 'i': // align all atoms
|
---|
| 1398 | AlignAtoms(periode, mol);
|
---|
| 1399 | break;
|
---|
| 1400 |
|
---|
| 1401 | case 'l': // measure distances or angles
|
---|
[d52ea1b] | 1402 | MeasureAtoms(periode, mol, &configuration);
|
---|
[14de469] | 1403 | break;
|
---|
| 1404 |
|
---|
[ca2b83] | 1405 | case 'm': // mirror atoms along a given axis
|
---|
| 1406 | MirrorAtoms(mol);
|
---|
[14de469] | 1407 | break;
|
---|
[ca2b83] | 1408 |
|
---|
[14de469] | 1409 | case 'o': // create the connection matrix
|
---|
| 1410 | cout << Verbose(0) << "What's the maximum bond distance: ";
|
---|
| 1411 | cin >> tmp1;
|
---|
| 1412 | start = clock();
|
---|
[a251a3] | 1413 | mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
|
---|
[14de469] | 1414 | //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
|
---|
[d52ea1b] | 1415 | Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
|
---|
[14de469] | 1416 | while (Subgraphs->next != NULL) {
|
---|
| 1417 | Subgraphs = Subgraphs->next;
|
---|
| 1418 | delete(Subgraphs->previous);
|
---|
| 1419 | }
|
---|
| 1420 | delete(Subgraphs); // we don't need the list here, so free everything
|
---|
[fc850d] | 1421 | delete[](MinimumRingSize);
|
---|
[14de469] | 1422 | Subgraphs = NULL;
|
---|
| 1423 | end = clock();
|
---|
| 1424 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
| 1425 | break;
|
---|
| 1426 |
|
---|
[ca2b83] | 1427 | case 'p': // parse and XYZ file
|
---|
| 1428 | cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
|
---|
| 1429 | do {
|
---|
| 1430 | cout << Verbose(0) << "Enter file name: ";
|
---|
| 1431 | cin >> filename;
|
---|
| 1432 | } while (!mol->AddXYZFile(filename));
|
---|
| 1433 | break;
|
---|
| 1434 |
|
---|
| 1435 | case 'q': // quit
|
---|
| 1436 | break;
|
---|
[14de469] | 1437 |
|
---|
[ca2b83] | 1438 | case 'r': // remove atom
|
---|
| 1439 | RemoveAtoms(mol);
|
---|
| 1440 | break;
|
---|
| 1441 |
|
---|
| 1442 | case 's': // save to config file
|
---|
| 1443 | SaveConfig(ConfigFileName, &configuration, periode, mol);
|
---|
| 1444 | break;
|
---|
| 1445 |
|
---|
| 1446 | case 't': // translate all atoms
|
---|
| 1447 | cout << Verbose(0) << "Enter translation vector." << endl;
|
---|
| 1448 | x.AskPosition(mol->cell_size,0);
|
---|
[e9b8bb] | 1449 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 1450 | break;
|
---|
| 1451 |
|
---|
| 1452 | case 'T':
|
---|
| 1453 | testroutine(mol);
|
---|
| 1454 | break;
|
---|
| 1455 |
|
---|
[14de469] | 1456 | case 'u': // change an atom's element
|
---|
| 1457 | first = NULL;
|
---|
| 1458 | do {
|
---|
| 1459 | cout << Verbose(0) << "Change the element of which atom: ";
|
---|
| 1460 | cin >> Z;
|
---|
| 1461 | } while ((first = mol->FindAtom(Z)) == NULL);
|
---|
| 1462 | cout << Verbose(0) << "New element by atomic number Z: ";
|
---|
| 1463 | cin >> Z;
|
---|
| 1464 | first->type = periode->FindElement(Z);
|
---|
| 1465 | cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
|
---|
| 1466 | break;
|
---|
| 1467 | };
|
---|
| 1468 | } while (choice != 'q');
|
---|
| 1469 |
|
---|
| 1470 | // save element data base
|
---|
[110ceb] | 1471 | if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
|
---|
[14de469] | 1472 | cout << Verbose(0) << "Saving of elements.db successful." << endl;
|
---|
| 1473 | else
|
---|
| 1474 | cout << Verbose(0) << "Saving of elements.db failed." << endl;
|
---|
| 1475 |
|
---|
| 1476 | // Free all
|
---|
| 1477 | if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
|
---|
| 1478 | while (Subgraphs->next != NULL) {
|
---|
| 1479 | Subgraphs = Subgraphs->next;
|
---|
| 1480 | delete(Subgraphs->previous);
|
---|
| 1481 | }
|
---|
| 1482 | delete(Subgraphs);
|
---|
| 1483 | }
|
---|
| 1484 | delete(mol);
|
---|
| 1485 | delete(periode);
|
---|
| 1486 | return (0);
|
---|
| 1487 | }
|
---|
| 1488 |
|
---|
| 1489 | /********************************************** E N D **************************************************/
|
---|