[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;
|
---|
[14de469] | 501 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
| 502 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 503 | cout << Verbose(0) << "INPUT: ";
|
---|
| 504 | cin >> choice;
|
---|
| 505 |
|
---|
| 506 | switch(choice) {
|
---|
| 507 | default:
|
---|
| 508 | cout << Verbose(1) << "Not a valid choice." << endl;
|
---|
| 509 | break;
|
---|
| 510 | case 'a':
|
---|
| 511 | first = mol->AskAtom("Enter first atom: ");
|
---|
[7f3b9d] | 512 | for (int i=MAX_ELEMENTS;i--;)
|
---|
[14de469] | 513 | min[i] = 0.;
|
---|
| 514 |
|
---|
| 515 | second = mol->start;
|
---|
| 516 | while ((second->next != mol->end)) {
|
---|
| 517 | second = second->next; // advance
|
---|
| 518 | Z = second->type->Z;
|
---|
| 519 | tmp1 = 0.;
|
---|
| 520 | if (first != second) {
|
---|
[e9b8bb] | 521 | x.CopyVector((const Vector *)&first->x);
|
---|
| 522 | x.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 523 | tmp1 = x.Norm();
|
---|
| 524 | }
|
---|
| 525 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
|
---|
| 526 | //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
|
---|
| 527 | }
|
---|
[7f3b9d] | 528 | for (int i=MAX_ELEMENTS;i--;)
|
---|
[14de469] | 529 | 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;
|
---|
| 530 | break;
|
---|
| 531 |
|
---|
| 532 | case 'b':
|
---|
| 533 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 534 | second = mol->AskAtom("Enter second atom: ");
|
---|
[7f3b9d] | 535 | for (int i=NDIM;i--;)
|
---|
[14de469] | 536 | min[i] = 0.;
|
---|
[e9b8bb] | 537 | x.CopyVector((const Vector *)&first->x);
|
---|
| 538 | x.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 539 | tmp1 = x.Norm();
|
---|
| 540 | cout << Verbose(1) << "Distance vector is ";
|
---|
| 541 | x.Output((ofstream *)&cout);
|
---|
| 542 | cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
|
---|
| 543 | break;
|
---|
| 544 |
|
---|
| 545 | case 'c':
|
---|
| 546 | cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
|
---|
| 547 | first = mol->AskAtom("Enter first atom: ");
|
---|
| 548 | second = mol->AskAtom("Enter central atom: ");
|
---|
| 549 | third = mol->AskAtom("Enter last atom: ");
|
---|
| 550 | tmp1 = tmp2 = tmp3 = 0.;
|
---|
[e9b8bb] | 551 | x.CopyVector((const Vector *)&first->x);
|
---|
| 552 | x.SubtractVector((const Vector *)&second->x);
|
---|
| 553 | y.CopyVector((const Vector *)&third->x);
|
---|
| 554 | y.SubtractVector((const Vector *)&second->x);
|
---|
[14de469] | 555 | cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
---|
[e9b8bb] | 556 | cout << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
|
---|
[14de469] | 557 | break;
|
---|
[d52ea1b] | 558 | case 'd':
|
---|
| 559 | cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
---|
| 560 | cout << Verbose(0) << "Shall we rotate? [0/1]: ";
|
---|
| 561 | cin >> Z;
|
---|
| 562 | if ((Z >=0) && (Z <=1))
|
---|
| 563 | mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
|
---|
| 564 | else
|
---|
| 565 | mol->PrincipalAxisSystem((ofstream *)&cout, false);
|
---|
| 566 | break;
|
---|
| 567 | case 'e':
|
---|
| 568 | cout << Verbose(0) << "Evaluating volume of the convex envelope.";
|
---|
[6c5812] | 569 | VolumeOfConvexEnvelope((ofstream *)&cout, configuration, NULL, mol);
|
---|
[d52ea1b] | 570 | break;
|
---|
[14de469] | 571 | }
|
---|
| 572 | };
|
---|
| 573 |
|
---|
| 574 | /** Submenu for measuring out the atoms in the molecule.
|
---|
| 575 | * \param *mol the molecule with all the atoms
|
---|
| 576 | * \param *configuration configuration structure for the to be written config files of all fragments
|
---|
| 577 | */
|
---|
[7f3b9d] | 578 | static void FragmentAtoms(molecule *mol, config *configuration)
|
---|
[14de469] | 579 | {
|
---|
[db942e] | 580 | int Order1;
|
---|
[14de469] | 581 | clock_t start, end;
|
---|
| 582 |
|
---|
| 583 | cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
---|
| 584 | cout << Verbose(0) << "What's the desired bond order: ";
|
---|
| 585 | cin >> Order1;
|
---|
| 586 | if (mol->first->next != mol->last) { // there are bonds
|
---|
| 587 | start = clock();
|
---|
[db942e] | 588 | mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
|
---|
[14de469] | 589 | end = clock();
|
---|
| 590 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
| 591 | } else
|
---|
| 592 | cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
|
---|
| 593 | };
|
---|
| 594 |
|
---|
| 595 | /********************************************** Test routine **************************************/
|
---|
| 596 |
|
---|
| 597 | /** Is called always as option 'T' in the menu.
|
---|
| 598 | */
|
---|
[7f3b9d] | 599 | static void testroutine(molecule *mol)
|
---|
[14de469] | 600 | {
|
---|
| 601 | // the current test routine checks the functionality of the KeySet&Graph concept:
|
---|
| 602 | // We want to have a multiindex (the KeySet) describing a unique subgraph
|
---|
| 603 | atom *Walker = mol->start;
|
---|
| 604 | int i, comp, counter=0;
|
---|
| 605 |
|
---|
| 606 | // generate some KeySets
|
---|
| 607 | cout << "Generating KeySets." << endl;
|
---|
| 608 | KeySet TestSets[mol->AtomCount+1];
|
---|
| 609 | i=1;
|
---|
| 610 | while (Walker->next != mol->end) {
|
---|
| 611 | Walker = Walker->next;
|
---|
| 612 | for (int j=0;j<i;j++) {
|
---|
| 613 | TestSets[j].insert(Walker->nr);
|
---|
| 614 | }
|
---|
| 615 | i++;
|
---|
| 616 | }
|
---|
| 617 | cout << "Testing insertion of already present item in KeySets." << endl;
|
---|
| 618 | KeySetTestPair test;
|
---|
| 619 | test = TestSets[mol->AtomCount-1].insert(Walker->nr);
|
---|
| 620 | if (test.second) {
|
---|
| 621 | cout << Verbose(1) << "Insertion worked?!" << endl;
|
---|
| 622 | } else {
|
---|
| 623 | cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
|
---|
| 624 | }
|
---|
| 625 | TestSets[mol->AtomCount].insert(mol->end->previous->nr);
|
---|
| 626 | TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
|
---|
| 627 |
|
---|
| 628 | // constructing Graph structure
|
---|
| 629 | cout << "Generating Subgraph class." << endl;
|
---|
| 630 | Graph Subgraphs;
|
---|
| 631 |
|
---|
| 632 | // insert KeySets into Subgraphs
|
---|
| 633 | cout << "Inserting KeySets into Subgraph class." << endl;
|
---|
| 634 | for (int j=0;j<mol->AtomCount;j++) {
|
---|
| 635 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
|
---|
| 636 | }
|
---|
| 637 | cout << "Testing insertion of already present item in Subgraph." << endl;
|
---|
| 638 | GraphTestPair test2;
|
---|
| 639 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
|
---|
| 640 | if (test2.second) {
|
---|
| 641 | cout << Verbose(1) << "Insertion worked?!" << endl;
|
---|
| 642 | } else {
|
---|
| 643 | cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | // show graphs
|
---|
| 647 | cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
|
---|
| 648 | Graph::iterator A = Subgraphs.begin();
|
---|
| 649 | while (A != Subgraphs.end()) {
|
---|
| 650 | cout << (*A).second.first << ": ";
|
---|
| 651 | KeySet::iterator key = (*A).first.begin();
|
---|
| 652 | comp = -1;
|
---|
| 653 | while (key != (*A).first.end()) {
|
---|
| 654 | if ((*key) > comp)
|
---|
| 655 | cout << (*key) << " ";
|
---|
| 656 | else
|
---|
| 657 | cout << (*key) << "! ";
|
---|
| 658 | comp = (*key);
|
---|
| 659 | key++;
|
---|
| 660 | }
|
---|
| 661 | cout << endl;
|
---|
| 662 | A++;
|
---|
| 663 | }
|
---|
| 664 | };
|
---|
| 665 |
|
---|
[dbe929] | 666 | /** Tries given filename or standard on saving the config file.
|
---|
| 667 | * \param *ConfigFileName name of file
|
---|
| 668 | * \param *configuration pointer to configuration structure with all the values
|
---|
| 669 | * \param *periode pointer to periodentafel structure with all the elements
|
---|
| 670 | * \param *mol pointer to molecule structure with all the atoms and coordinates
|
---|
| 671 | */
|
---|
[7f3b9d] | 672 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
|
---|
[dbe929] | 673 | {
|
---|
[c750cc] | 674 | char filename[MAXSTRINGSIZE];
|
---|
[dbe929] | 675 | ofstream output;
|
---|
| 676 |
|
---|
[73f80e] | 677 | cout << Verbose(0) << "Storing configuration ... " << endl;
|
---|
[dbe929] | 678 | // get correct valence orbitals
|
---|
| 679 | mol->CalculateOrbitals(*configuration);
|
---|
| 680 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
|
---|
[6590bee] | 681 | if (ConfigFileName != NULL) {
|
---|
[dbe929] | 682 | output.open(ConfigFileName, ios::trunc);
|
---|
[4885953] | 683 | } else if (strlen(configuration->configname) != 0) {
|
---|
[6590bee] | 684 | output.open(configuration->configname, ios::trunc);
|
---|
[4885953] | 685 | } else {
|
---|
| 686 | output.open(DEFAULTCONFIG, ios::trunc);
|
---|
| 687 | }
|
---|
[a8aadf6] | 688 | cout << Verbose(0) << "Saving of config file ";
|
---|
[dbe929] | 689 | if (configuration->Save(&output, periode, mol))
|
---|
[a8aadf6] | 690 | cout << "successful." << endl;
|
---|
[dbe929] | 691 | else
|
---|
[a8aadf6] | 692 | cout << "failed." << endl;
|
---|
[dbe929] | 693 | output.close();
|
---|
| 694 | output.clear();
|
---|
[a8aadf6] | 695 |
|
---|
[dbe929] | 696 | // and save to xyz file
|
---|
| 697 | if (ConfigFileName != NULL) {
|
---|
| 698 | strcpy(filename, ConfigFileName);
|
---|
| 699 | strcat(filename, ".xyz");
|
---|
| 700 | output.open(filename, ios::trunc);
|
---|
| 701 | }
|
---|
| 702 | if (output == NULL) {
|
---|
| 703 | strcpy(filename,"main_pcp_linux");
|
---|
| 704 | strcat(filename, ".xyz");
|
---|
| 705 | output.open(filename, ios::trunc);
|
---|
| 706 | }
|
---|
[a8aadf6] | 707 | cout << Verbose(0) << "Saving of XYZ file ";
|
---|
[362b0e] | 708 | if (mol->MDSteps <= 1) {
|
---|
| 709 | if (mol->OutputXYZ(&output))
|
---|
[a8aadf6] | 710 | cout << "successful." << endl;
|
---|
[362b0e] | 711 | else
|
---|
[a8aadf6] | 712 | cout << "failed." << endl;
|
---|
[362b0e] | 713 | } else {
|
---|
| 714 | if (mol->OutputTrajectoriesXYZ(&output))
|
---|
[a8aadf6] | 715 | cout << "successful." << endl;
|
---|
[362b0e] | 716 | else
|
---|
[a8aadf6] | 717 | cout << "failed." << endl;
|
---|
[362b0e] | 718 | }
|
---|
[dbe929] | 719 | output.close();
|
---|
| 720 | output.clear();
|
---|
[a8aadf6] | 721 |
|
---|
| 722 | // and save as MPQC configuration
|
---|
| 723 | if (ConfigFileName != NULL) {
|
---|
| 724 | strcpy(filename, ConfigFileName);
|
---|
| 725 | strcat(filename, ".in");
|
---|
| 726 | output.open(filename, ios::trunc);
|
---|
| 727 | }
|
---|
| 728 | if (output == NULL) {
|
---|
| 729 | strcpy(filename,"main_pcp_linux");
|
---|
| 730 | strcat(filename, ".in");
|
---|
| 731 | output.open(filename, ios::trunc);
|
---|
| 732 | }
|
---|
| 733 | cout << Verbose(0) << "Saving as mpqc input ";
|
---|
| 734 | if (configuration->SaveMPQC(&output, mol))
|
---|
| 735 | cout << "done." << endl;
|
---|
| 736 | else
|
---|
| 737 | cout << "failed." << endl;
|
---|
| 738 | output.close();
|
---|
| 739 | output.clear();
|
---|
[6590bee] | 740 |
|
---|
[2910e0] | 741 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
|
---|
| 742 | cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
|
---|
| 743 | }
|
---|
[dbe929] | 744 | };
|
---|
| 745 |
|
---|
[ca2b83] | 746 | /** Parses the command line options.
|
---|
| 747 | * \param argc argument count
|
---|
| 748 | * \param **argv arguments array
|
---|
| 749 | * \param *mol molecule structure
|
---|
| 750 | * \param *periode elements structure
|
---|
| 751 | * \param configuration config file structure
|
---|
| 752 | * \param *ConfigFileName pointer to config file name in **argv
|
---|
[d7d29c] | 753 | * \param *PathToDatabases pointer to db's path in **argv
|
---|
[ca2b83] | 754 | * \return exit code (0 - successful, all else - something's wrong)
|
---|
| 755 | */
|
---|
[d7d29c] | 756 | static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&PathToDatabases)
|
---|
[14de469] | 757 | {
|
---|
[e9b8bb] | 758 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
[ca2b83] | 759 | double *factor; // unit factor if desired
|
---|
[14de469] | 760 | ifstream test;
|
---|
| 761 | ofstream output;
|
---|
| 762 | string line;
|
---|
[ca2b83] | 763 | atom *first;
|
---|
[362b0e] | 764 | bool SaveFlag = false;
|
---|
[dd8cf8] | 765 | int ExitFlag = 0;
|
---|
[ca2b83] | 766 | int j;
|
---|
[edb650] | 767 | double volume = 0.;
|
---|
[dbe929] | 768 | enum ConfigStatus config_present = absent;
|
---|
[14de469] | 769 | clock_t start,end;
|
---|
[73f80e] | 770 | int argptr;
|
---|
[d7d29c] | 771 | PathToDatabases = LocalPath;
|
---|
[ca2b83] | 772 |
|
---|
[6590bee] | 773 | if (argc > 1) { // config file specified as option
|
---|
[73f80e] | 774 | // 1. : Parse options that just set variables or print help
|
---|
[ca2b83] | 775 | argptr = 1;
|
---|
| 776 | do {
|
---|
| 777 | if (argv[argptr][0] == '-') {
|
---|
[73f80e] | 778 | cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
|
---|
| 779 | argptr++;
|
---|
| 780 | switch(argv[argptr-1][1]) {
|
---|
| 781 | case 'h':
|
---|
| 782 | case 'H':
|
---|
| 783 | case '?':
|
---|
| 784 | cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
|
---|
[db942e] | 785 | cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
|
---|
[73f80e] | 786 | cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
|
---|
| 787 | cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
|
---|
[ca2b83] | 788 | cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
|
---|
[73f80e] | 789 | cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
|
---|
[362b0e] | 790 | cout << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
|
---|
[1f066fe] | 791 | cout << "\t-O\tCenter atoms in origin." << endl;
|
---|
[318bfd] | 792 | cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
|
---|
[d7d29c] | 793 | cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
|
---|
[362b0e] | 794 | 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] | 795 | cout << "\t-h/-H/-?\tGive this help screen." << endl;
|
---|
[68cb0f] | 796 | cout << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
|
---|
[233e33] | 797 | cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
|
---|
[110ceb] | 798 | cout << "\t-o\tGet volume of the convex envelope (and store to tecplot file)." << endl;
|
---|
[73f80e] | 799 | cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
|
---|
[362b0e] | 800 | cout << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
|
---|
[73f80e] | 801 | cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
|
---|
| 802 | cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
|
---|
| 803 | cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
|
---|
[318bfd] | 804 | cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
|
---|
[73f80e] | 805 | cout << "\t-v/-V\t\tGives version information." << endl;
|
---|
[5b15ab] | 806 | cout << "Note: config files must not begin with '-' !" << endl;
|
---|
[2910e0] | 807 | delete(mol);
|
---|
| 808 | delete(periode);
|
---|
[ca2b83] | 809 | return (1);
|
---|
[73f80e] | 810 | break;
|
---|
| 811 | case 'v':
|
---|
| 812 | case 'V':
|
---|
| 813 | cout << argv[0] << " " << VERSIONSTRING << endl;
|
---|
| 814 | cout << "Build your own molecule position set." << endl;
|
---|
[2910e0] | 815 | delete(mol);
|
---|
| 816 | delete(periode);
|
---|
[ca2b83] | 817 | return (1);
|
---|
[73f80e] | 818 | break;
|
---|
| 819 | case 'e':
|
---|
| 820 | cout << "Using " << argv[argptr] << " as elements database." << endl;
|
---|
[d7d29c] | 821 | PathToDatabases = argv[argptr];
|
---|
[73f80e] | 822 | argptr+=1;
|
---|
| 823 | break;
|
---|
[233e33] | 824 | case 'n':
|
---|
| 825 | cout << "I won't parse trajectories." << endl;
|
---|
| 826 | configuration.FastParsing = true;
|
---|
[256520] | 827 | break;
|
---|
[73f80e] | 828 | default: // no match? Step on
|
---|
| 829 | argptr++;
|
---|
| 830 | break;
|
---|
| 831 | }
|
---|
[ca2b83] | 832 | } else
|
---|
| 833 | argptr++;
|
---|
[4885953] | 834 | } while (argptr < argc);
|
---|
[ca2b83] | 835 |
|
---|
| 836 | // 2. Parse the element database
|
---|
[d7d29c] | 837 | if (periode->LoadPeriodentafel(PathToDatabases)) {
|
---|
[73f80e] | 838 | cout << Verbose(0) << "Element list loaded successfully." << endl;
|
---|
[b61043] | 839 | //periode->Output((ofstream *)&cout);
|
---|
[14d4d4] | 840 | } else {
|
---|
[73f80e] | 841 | cout << Verbose(0) << "Element list loading failed." << endl;
|
---|
[14d4d4] | 842 | return 1;
|
---|
| 843 | }
|
---|
[4885953] | 844 |
|
---|
[ca2b83] | 845 | // 3. Find config file name and parse if possible
|
---|
[4885953] | 846 | if (argv[1][0] != '-') {
|
---|
[dbe929] | 847 | cout << Verbose(0) << "Config file given." << endl;
|
---|
[4885953] | 848 | test.open(argv[1], ios::in);
|
---|
[dbe929] | 849 | if (test == NULL) {
|
---|
| 850 | //return (1);
|
---|
[4885953] | 851 | output.open(argv[1], ios::out);
|
---|
[dbe929] | 852 | if (output == NULL) {
|
---|
[4885953] | 853 | cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
|
---|
[dbe929] | 854 | config_present = absent;
|
---|
| 855 | } else {
|
---|
| 856 | cout << "Empty configuration file." << endl;
|
---|
[4885953] | 857 | ConfigFileName = argv[1];
|
---|
[dbe929] | 858 | config_present = empty;
|
---|
| 859 | output.close();
|
---|
| 860 | }
|
---|
| 861 | } else {
|
---|
[5b15ab] | 862 | test.close();
|
---|
[4885953] | 863 | ConfigFileName = argv[1];
|
---|
[fedd5f] | 864 | cout << Verbose(1) << "Specified config file found, parsing ... ";
|
---|
[5b15ab] | 865 | switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
|
---|
[dbe929] | 866 | case 1:
|
---|
| 867 | cout << "new syntax." << endl;
|
---|
[5b15ab] | 868 | configuration.Load(ConfigFileName, periode, mol);
|
---|
[dbe929] | 869 | config_present = present;
|
---|
| 870 | break;
|
---|
| 871 | case 0:
|
---|
| 872 | cout << "old syntax." << endl;
|
---|
[5b15ab] | 873 | configuration.LoadOld(ConfigFileName, periode, mol);
|
---|
[dbe929] | 874 | config_present = present;
|
---|
| 875 | break;
|
---|
| 876 | default:
|
---|
| 877 | cout << "Unknown syntax or empty, yet present file." << endl;
|
---|
| 878 | config_present = empty;
|
---|
| 879 | }
|
---|
[14de469] | 880 | }
|
---|
[73f80e] | 881 | } else
|
---|
| 882 | config_present = absent;
|
---|
[4885953] | 883 |
|
---|
[73f80e] | 884 | // 4. parse again through options, now for those depending on elements db and config presence
|
---|
| 885 | argptr = 1;
|
---|
| 886 | do {
|
---|
[ca2b83] | 887 | cout << "Current Command line argument: " << argv[argptr] << "." << endl;
|
---|
[73f80e] | 888 | if (argv[argptr][0] == '-') {
|
---|
[dbe929] | 889 | argptr++;
|
---|
| 890 | if ((config_present == present) || (config_present == empty)) {
|
---|
| 891 | switch(argv[argptr-1][1]) {
|
---|
| 892 | case 'p':
|
---|
[dd8cf8] | 893 | ExitFlag = 1;
|
---|
[362b0e] | 894 | SaveFlag = true;
|
---|
[dbe929] | 895 | cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
|
---|
[ca2b83] | 896 | if (!mol->AddXYZFile(argv[argptr]))
|
---|
[dbe929] | 897 | cout << Verbose(2) << "File not found." << endl;
|
---|
[d7e30c] | 898 | else {
|
---|
[dbe929] | 899 | cout << Verbose(2) << "File found and parsed." << endl;
|
---|
[73f80e] | 900 | config_present = present;
|
---|
[d7e30c] | 901 | }
|
---|
[14de469] | 902 | break;
|
---|
[d1fc7f] | 903 | case 'a':
|
---|
| 904 | ExitFlag = 1;
|
---|
| 905 | SaveFlag = true;
|
---|
| 906 | cout << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
|
---|
| 907 | first = new atom;
|
---|
| 908 | first->type = periode->FindElement(atoi(argv[argptr]));
|
---|
| 909 | if (first->type != NULL)
|
---|
| 910 | cout << Verbose(2) << "found element " << first->type->name << endl;
|
---|
| 911 | for (int i=NDIM;i--;)
|
---|
| 912 | first->x.x[i] = atof(argv[argptr+1+i]);
|
---|
| 913 | if (first->type != NULL) {
|
---|
| 914 | mol->AddAtom(first); // add to molecule
|
---|
| 915 | if ((config_present == empty) && (mol->AtomCount != 0))
|
---|
| 916 | config_present = present;
|
---|
| 917 | } else
|
---|
| 918 | cerr << Verbose(1) << "Could not find the specified element." << endl;
|
---|
| 919 | argptr+=4;
|
---|
| 920 | break;
|
---|
[73f80e] | 921 | default: // no match? Don't step on (this is done in next switch's default)
|
---|
[14de469] | 922 | break;
|
---|
[dbe929] | 923 | }
|
---|
| 924 | }
|
---|
[ca2b83] | 925 | if (config_present == present) {
|
---|
| 926 | switch(argv[argptr-1][1]) {
|
---|
[362b0e] | 927 | case 'D':
|
---|
[dd8cf8] | 928 | ExitFlag = 1;
|
---|
[362b0e] | 929 | {
|
---|
| 930 | cout << Verbose(1) << "Depth-First-Search Analysis." << endl;
|
---|
| 931 | MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
|
---|
| 932 | int *MinimumRingSize = NULL;
|
---|
| 933 | mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
|
---|
| 934 | mol->CreateListOfBondsPerAtom((ofstream *)&cout);
|
---|
| 935 | Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
|
---|
| 936 | delete[](MinimumRingSize);
|
---|
| 937 | if (Subgraphs != NULL) {
|
---|
| 938 | while (Subgraphs->next != NULL) {
|
---|
| 939 | Subgraphs = Subgraphs->next;
|
---|
| 940 | delete(Subgraphs->previous);
|
---|
| 941 | }
|
---|
| 942 | delete(Subgraphs);
|
---|
| 943 | }
|
---|
| 944 | }
|
---|
| 945 | argptr+=1;
|
---|
| 946 | break;
|
---|
[d7e30c] | 947 | case 'P':
|
---|
[dd8cf8] | 948 | ExitFlag = 1;
|
---|
[362b0e] | 949 | SaveFlag = true;
|
---|
[d7e30c] | 950 | cout << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
|
---|
[362b0e] | 951 | if (!mol->VerletForceIntegration(argv[argptr], configuration.Deltat, configuration.GetIsAngstroem()))
|
---|
[d7e30c] | 952 | cout << Verbose(2) << "File not found." << endl;
|
---|
| 953 | else
|
---|
| 954 | cout << Verbose(2) << "File found and parsed." << endl;
|
---|
[362b0e] | 955 | argptr+=1;
|
---|
[d7e30c] | 956 | break;
|
---|
[ca2b83] | 957 | case 't':
|
---|
[dd8cf8] | 958 | ExitFlag = 1;
|
---|
[362b0e] | 959 | SaveFlag = true;
|
---|
[ca2b83] | 960 | cout << Verbose(1) << "Translating all ions to new origin." << endl;
|
---|
[7f3b9d] | 961 | for (int i=NDIM;i--;)
|
---|
[ca2b83] | 962 | x.x[i] = atof(argv[argptr+i]);
|
---|
[e9b8bb] | 963 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 964 | argptr+=3;
|
---|
| 965 | break;
|
---|
| 966 | case 's':
|
---|
[dd8cf8] | 967 | ExitFlag = 1;
|
---|
[362b0e] | 968 | SaveFlag = true;
|
---|
[ca2b83] | 969 | j = -1;
|
---|
| 970 | cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
|
---|
[7f3b9d] | 971 | factor = new double[NDIM];
|
---|
[ca2b83] | 972 | factor[0] = atof(argv[argptr]);
|
---|
| 973 | if (argc > argptr+1)
|
---|
| 974 | argptr++;
|
---|
| 975 | factor[1] = atof(argv[argptr]);
|
---|
| 976 | if (argc > argptr+1)
|
---|
| 977 | argptr++;
|
---|
| 978 | factor[2] = atof(argv[argptr]);
|
---|
| 979 | mol->Scale(&factor);
|
---|
[7f3b9d] | 980 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 981 | j += i+1;
|
---|
[7f3b9d] | 982 | x.x[i] = atof(argv[NDIM+i]);
|
---|
[ca2b83] | 983 | mol->cell_size[j]*=factor[i];
|
---|
| 984 | }
|
---|
[7f3b9d] | 985 | delete[](factor);
|
---|
[ca2b83] | 986 | argptr+=1;
|
---|
| 987 | break;
|
---|
| 988 | case 'b':
|
---|
[dd8cf8] | 989 | ExitFlag = 1;
|
---|
[362b0e] | 990 | SaveFlag = true;
|
---|
[ca2b83] | 991 | j = -1;
|
---|
| 992 | cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
---|
| 993 | j=-1;
|
---|
[7f3b9d] | 994 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 995 | j += i+1;
|
---|
| 996 | x.x[i] = atof(argv[argptr++]);
|
---|
| 997 | mol->cell_size[j] += x.x[i]*2.;
|
---|
| 998 | }
|
---|
| 999 | // center
|
---|
| 1000 | mol->CenterInBox((ofstream *)&cout, &x);
|
---|
| 1001 | // update Box of atoms by boundary
|
---|
| 1002 | mol->SetBoxDimension(&x);
|
---|
| 1003 | break;
|
---|
| 1004 | case 'c':
|
---|
[dd8cf8] | 1005 | ExitFlag = 1;
|
---|
[362b0e] | 1006 | SaveFlag = true;
|
---|
[ca2b83] | 1007 | j = -1;
|
---|
| 1008 | cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
|
---|
| 1009 | // make every coordinate positive
|
---|
| 1010 | mol->CenterEdge((ofstream *)&cout, &x);
|
---|
| 1011 | // update Box of atoms by boundary
|
---|
| 1012 | mol->SetBoxDimension(&x);
|
---|
| 1013 | // translate each coordinate by boundary
|
---|
| 1014 | j=-1;
|
---|
[7f3b9d] | 1015 | for (int i=0;i<NDIM;i++) {
|
---|
[ca2b83] | 1016 | j += i+1;
|
---|
| 1017 | x.x[i] = atof(argv[argptr++]);
|
---|
| 1018 | mol->cell_size[j] += x.x[i]*2.;
|
---|
| 1019 | }
|
---|
[e9b8bb] | 1020 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 1021 | break;
|
---|
[1f066fe] | 1022 | case 'O':
|
---|
[dd8cf8] | 1023 | ExitFlag = 1;
|
---|
[362b0e] | 1024 | SaveFlag = true;
|
---|
[1f066fe] | 1025 | cout << Verbose(1) << "Centering atoms in origin." << endl;
|
---|
| 1026 | mol->CenterOrigin((ofstream *)&cout, &x);
|
---|
| 1027 | mol->SetBoxDimension(&x);
|
---|
| 1028 | break;
|
---|
[ca2b83] | 1029 | case 'r':
|
---|
[dd8cf8] | 1030 | ExitFlag = 1;
|
---|
[362b0e] | 1031 | SaveFlag = true;
|
---|
[ca2b83] | 1032 | cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
|
---|
| 1033 | break;
|
---|
[d7e30c] | 1034 | case 'F':
|
---|
[ca2b83] | 1035 | case 'f':
|
---|
[dd8cf8] | 1036 | ExitFlag = 1;
|
---|
[ca2b83] | 1037 | cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
|
---|
| 1038 | if (argc >= argptr+2) {
|
---|
| 1039 | cout << Verbose(0) << "Creating connection matrix..." << endl;
|
---|
| 1040 | start = clock();
|
---|
[a251a3] | 1041 | mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
|
---|
[ca2b83] | 1042 | cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
---|
| 1043 | if (mol->first->next != mol->last) {
|
---|
[362b0e] | 1044 | ExitFlag = mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
|
---|
[dbe929] | 1045 | }
|
---|
[ca2b83] | 1046 | end = clock();
|
---|
| 1047 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
[dbe929] | 1048 | argptr+=1;
|
---|
[ca2b83] | 1049 | } else {
|
---|
| 1050 | cerr << "Not enough arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
|
---|
| 1051 | }
|
---|
| 1052 | break;
|
---|
[d52ea1b] | 1053 | case 'm':
|
---|
[dd8cf8] | 1054 | ExitFlag = 1;
|
---|
[110ceb] | 1055 | j = atoi(argv[argptr++]);
|
---|
| 1056 | if ((j<0) || (j>1)) {
|
---|
| 1057 | cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
|
---|
| 1058 | j = 0;
|
---|
| 1059 | }
|
---|
[362b0e] | 1060 | if (j) {
|
---|
| 1061 | SaveFlag = true;
|
---|
[110ceb] | 1062 | cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
|
---|
[362b0e] | 1063 | } else
|
---|
[110ceb] | 1064 | cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
---|
| 1065 | mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
|
---|
| 1066 | break;
|
---|
| 1067 | case 'o':
|
---|
[dd8cf8] | 1068 | ExitFlag = 1;
|
---|
[362b0e] | 1069 | SaveFlag = true;
|
---|
[110ceb] | 1070 | cout << Verbose(0) << "Evaluating volume of the convex envelope.";
|
---|
[6c5812] | 1071 | VolumeOfConvexEnvelope((ofstream *)&cout, &configuration, NULL, mol);
|
---|
[d52ea1b] | 1072 | break;
|
---|
[edb650] | 1073 | case 'U':
|
---|
[dd8cf8] | 1074 | ExitFlag = 1;
|
---|
[edb650] | 1075 | volume = atof(argv[argptr++]);
|
---|
| 1076 | cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
|
---|
[318bfd] | 1077 | case 'u':
|
---|
[dd8cf8] | 1078 | ExitFlag = 1;
|
---|
[318bfd] | 1079 | {
|
---|
[edb650] | 1080 | double density;
|
---|
[362b0e] | 1081 | SaveFlag = true;
|
---|
[318bfd] | 1082 | cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
|
---|
[edb650] | 1083 | density = atof(argv[argptr++]);
|
---|
| 1084 | if (density < 1.0) {
|
---|
[318bfd] | 1085 | cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
|
---|
[edb650] | 1086 | density = 1.3;
|
---|
[318bfd] | 1087 | }
|
---|
| 1088 | // for(int i=0;i<NDIM;i++) {
|
---|
| 1089 | // repetition[i] = atoi(argv[argptr++]);
|
---|
| 1090 | // if (repetition[i] < 1)
|
---|
| 1091 | // cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
|
---|
| 1092 | // repetition[i] = 1;
|
---|
| 1093 | // }
|
---|
[edb650] | 1094 | PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density);
|
---|
[318bfd] | 1095 | }
|
---|
| 1096 | break;
|
---|
| 1097 | case 'd':
|
---|
[dd8cf8] | 1098 | ExitFlag = 1;
|
---|
[362b0e] | 1099 | SaveFlag = true;
|
---|
[318bfd] | 1100 | for (int axis = 1; axis <= NDIM; axis++) {
|
---|
| 1101 | int faktor = atoi(argv[argptr++]);
|
---|
| 1102 | int count;
|
---|
| 1103 | element ** Elements;
|
---|
[e9b8bb] | 1104 | Vector ** vectors;
|
---|
[318bfd] | 1105 | if (faktor < 1) {
|
---|
| 1106 | cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
|
---|
| 1107 | faktor = 1;
|
---|
| 1108 | }
|
---|
| 1109 | mol->CountAtoms((ofstream *)&cout); // recount atoms
|
---|
| 1110 | if (mol->AtomCount != 0) { // if there is more than none
|
---|
| 1111 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
---|
| 1112 | Elements = new element *[count];
|
---|
[e9b8bb] | 1113 | vectors = new Vector *[count];
|
---|
[318bfd] | 1114 | j = 0;
|
---|
| 1115 | first = mol->start;
|
---|
| 1116 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
---|
| 1117 | first = first->next;
|
---|
| 1118 | Elements[j] = first->type;
|
---|
[d7e30c] | 1119 | vectors[j] = &first->x;
|
---|
[318bfd] | 1120 | j++;
|
---|
| 1121 | }
|
---|
| 1122 | if (count != j)
|
---|
| 1123 | cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
---|
| 1124 | x.Zero();
|
---|
| 1125 | y.Zero();
|
---|
| 1126 | 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
|
---|
| 1127 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
| 1128 | x.AddVector(&y); // per factor one cell width further
|
---|
| 1129 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
| 1130 | first = new atom(); // create a new body
|
---|
[d7e30c] | 1131 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
---|
[318bfd] | 1132 | first->x.AddVector(&x); // translate the coordinates
|
---|
| 1133 | first->type = Elements[k]; // insert original element
|
---|
| 1134 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
| 1135 | }
|
---|
| 1136 | }
|
---|
| 1137 | // free memory
|
---|
| 1138 | delete[](Elements);
|
---|
[d7e30c] | 1139 | delete[](vectors);
|
---|
[318bfd] | 1140 | // correct cell size
|
---|
| 1141 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
| 1142 | x.Zero();
|
---|
| 1143 | x.AddVector(&y);
|
---|
| 1144 | x.Scale(-(faktor-1));
|
---|
| 1145 | mol->Translate(&x);
|
---|
| 1146 | }
|
---|
| 1147 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
| 1148 | }
|
---|
| 1149 | }
|
---|
| 1150 | break;
|
---|
[ca2b83] | 1151 | default: // no match? Step on
|
---|
[110ceb] | 1152 | if (argv[argptr][0] != '-') // if it started with a '-' we've already made a step!
|
---|
| 1153 | argptr++;
|
---|
[ca2b83] | 1154 | break;
|
---|
[14de469] | 1155 | }
|
---|
| 1156 | }
|
---|
[ca2b83] | 1157 | } else argptr++;
|
---|
| 1158 | } while (argptr < argc);
|
---|
[362b0e] | 1159 | if (SaveFlag)
|
---|
[dbe929] | 1160 | SaveConfig(ConfigFileName, &configuration, periode, mol);
|
---|
[362b0e] | 1161 | if ((ExitFlag >= 1)) {
|
---|
[5b15ab] | 1162 | delete(mol);
|
---|
| 1163 | delete(periode);
|
---|
[362b0e] | 1164 | return (ExitFlag);
|
---|
[5b15ab] | 1165 | }
|
---|
[6590bee] | 1166 | } else { // no arguments, hence scan the elements db
|
---|
[d7d29c] | 1167 | if (periode->LoadPeriodentafel(PathToDatabases))
|
---|
[6590bee] | 1168 | cout << Verbose(0) << "Element list loaded successfully." << endl;
|
---|
| 1169 | else
|
---|
| 1170 | cout << Verbose(0) << "Element list loading failed." << endl;
|
---|
| 1171 | configuration.RetrieveConfigPathAndName("main_pcp_linux");
|
---|
[14de469] | 1172 | }
|
---|
[ca2b83] | 1173 | return(0);
|
---|
| 1174 | };
|
---|
| 1175 |
|
---|
| 1176 | /********************************************** Main routine **************************************/
|
---|
[14de469] | 1177 |
|
---|
[ca2b83] | 1178 | int main(int argc, char **argv)
|
---|
| 1179 | {
|
---|
| 1180 | periodentafel *periode = new periodentafel; // and a period table of all elements
|
---|
| 1181 | molecule *mol = new molecule(periode); // first we need an empty molecule
|
---|
| 1182 | config configuration;
|
---|
| 1183 | double tmp1;
|
---|
| 1184 | double bond, min_bond;
|
---|
| 1185 | atom *first, *second;
|
---|
| 1186 | char choice; // menu choice char
|
---|
[e9b8bb] | 1187 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
[ca2b83] | 1188 | double *factor; // unit factor if desired
|
---|
| 1189 | bool valid; // flag if input was valid or not
|
---|
| 1190 | ifstream test;
|
---|
| 1191 | ofstream output;
|
---|
| 1192 | string line;
|
---|
| 1193 | char filename[MAXSTRINGSIZE];
|
---|
| 1194 | char *ConfigFileName = NULL;
|
---|
| 1195 | char *ElementsFileName = NULL;
|
---|
| 1196 | int Z;
|
---|
| 1197 | int j, axis, count, faktor;
|
---|
| 1198 | int *MinimumRingSize = NULL;
|
---|
| 1199 | MoleculeLeafClass *Subgraphs = NULL;
|
---|
| 1200 | clock_t start,end;
|
---|
| 1201 | element **Elements;
|
---|
[e9b8bb] | 1202 | Vector **vectors;
|
---|
[ca2b83] | 1203 |
|
---|
| 1204 | // =========================== PARSE COMMAND LINE OPTIONS ====================================
|
---|
| 1205 | j = ParseCommandLineOptions(argc, argv, mol, periode, configuration, ConfigFileName, ElementsFileName);
|
---|
[d7d29c] | 1206 | if (j == 1) return 0; // just for -v and -h options
|
---|
[ca2b83] | 1207 | if (j) return j; // something went wrong
|
---|
[14de469] | 1208 |
|
---|
| 1209 | // General stuff
|
---|
| 1210 | if (mol->cell_size[0] == 0.) {
|
---|
| 1211 | cout << Verbose(0) << "enter lower triadiagonal form of basis matrix" << endl << endl;
|
---|
| 1212 | for (int i=0;i<6;i++) {
|
---|
| 1213 | cout << Verbose(1) << "Cell size" << i << ": ";
|
---|
| 1214 | cin >> mol->cell_size[i];
|
---|
| 1215 | }
|
---|
| 1216 | }
|
---|
| 1217 |
|
---|
[73f80e] | 1218 | // =========================== START INTERACTIVE SESSION ====================================
|
---|
| 1219 |
|
---|
[14de469] | 1220 | // now the main construction loop
|
---|
| 1221 | cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
|
---|
| 1222 | do {
|
---|
| 1223 | cout << Verbose(0) << endl << endl;
|
---|
| 1224 | cout << Verbose(0) << "============Element list=======================" << endl;
|
---|
| 1225 | mol->Checkout((ofstream *)&cout);
|
---|
| 1226 | cout << Verbose(0) << "============Atom list==========================" << endl;
|
---|
| 1227 | mol->Output((ofstream *)&cout);
|
---|
| 1228 | cout << Verbose(0) << "============Menu===============================" << endl;
|
---|
| 1229 | cout << Verbose(0) << "a - add an atom" << endl;
|
---|
| 1230 | cout << Verbose(0) << "r - remove an atom" << endl;
|
---|
| 1231 | cout << Verbose(0) << "b - scale a bond between atoms" << endl;
|
---|
| 1232 | cout << Verbose(0) << "u - change an atoms element" << endl;
|
---|
| 1233 | cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
|
---|
| 1234 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1235 | cout << Verbose(0) << "p - Parse xyz file" << endl;
|
---|
| 1236 | cout << Verbose(0) << "e - edit the current configuration" << endl;
|
---|
| 1237 | cout << Verbose(0) << "o - create connection matrix" << endl;
|
---|
| 1238 | cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
|
---|
| 1239 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1240 | cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
|
---|
| 1241 | cout << Verbose(0) << "i - realign molecule" << endl;
|
---|
| 1242 | cout << Verbose(0) << "m - mirror all molecules" << endl;
|
---|
| 1243 | cout << Verbose(0) << "t - translate molecule by vector" << endl;
|
---|
| 1244 | cout << Verbose(0) << "c - scale by unit transformation" << endl;
|
---|
| 1245 | cout << Verbose(0) << "g - center atoms in box" << endl;
|
---|
| 1246 | cout << Verbose(0) << "-----------------------------------------------" << endl;
|
---|
| 1247 | cout << Verbose(0) << "s - save current setup to config file" << endl;
|
---|
| 1248 | cout << Verbose(0) << "T - call the current test routine" << endl;
|
---|
| 1249 | cout << Verbose(0) << "q - quit" << endl;
|
---|
| 1250 | cout << Verbose(0) << "===============================================" << endl;
|
---|
| 1251 | cout << Verbose(0) << "Input: ";
|
---|
| 1252 | cin >> choice;
|
---|
| 1253 |
|
---|
| 1254 | switch (choice) {
|
---|
| 1255 | default:
|
---|
| 1256 | case 'a': // add atom
|
---|
| 1257 | AddAtoms(periode, mol);
|
---|
| 1258 | choice = 'a';
|
---|
| 1259 | break;
|
---|
| 1260 |
|
---|
[ca2b83] | 1261 | case 'b': // scale a bond
|
---|
| 1262 | cout << Verbose(0) << "Scaling bond length between two atoms." << endl;
|
---|
| 1263 | first = mol->AskAtom("Enter first (fixed) atom: ");
|
---|
| 1264 | second = mol->AskAtom("Enter second (shifting) atom: ");
|
---|
| 1265 | min_bond = 0.;
|
---|
[7f3b9d] | 1266 | for (int i=NDIM;i--;)
|
---|
[ca2b83] | 1267 | min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
|
---|
| 1268 | min_bond = sqrt(min_bond);
|
---|
| 1269 | 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;
|
---|
| 1270 | cout << Verbose(0) << "Enter new bond length [a.u.]: ";
|
---|
| 1271 | cin >> bond;
|
---|
[7f3b9d] | 1272 | for (int i=NDIM;i--;) {
|
---|
[ca2b83] | 1273 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
|
---|
| 1274 | }
|
---|
| 1275 | //cout << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
|
---|
| 1276 | //second->Output(second->type->No, 1, (ofstream *)&cout);
|
---|
| 1277 | break;
|
---|
| 1278 |
|
---|
| 1279 | case 'c': // unit scaling of the metric
|
---|
| 1280 | cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
|
---|
| 1281 | cout << Verbose(0) << "Enter three factors: ";
|
---|
| 1282 | factor = new double[NDIM];
|
---|
| 1283 | cin >> factor[0];
|
---|
| 1284 | cin >> factor[1];
|
---|
| 1285 | cin >> factor[2];
|
---|
| 1286 | valid = true;
|
---|
| 1287 | mol->Scale(&factor);
|
---|
| 1288 | delete[](factor);
|
---|
| 1289 | break;
|
---|
| 1290 |
|
---|
[14de469] | 1291 | case 'd': // duplicate the periodic cell along a given axis, given times
|
---|
| 1292 | cout << Verbose(0) << "State the axis [(+-)123]: ";
|
---|
| 1293 | cin >> axis;
|
---|
| 1294 | cout << Verbose(0) << "State the factor: ";
|
---|
| 1295 | cin >> faktor;
|
---|
| 1296 |
|
---|
| 1297 | mol->CountAtoms((ofstream *)&cout); // recount atoms
|
---|
| 1298 | if (mol->AtomCount != 0) { // if there is more than none
|
---|
| 1299 | count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
|
---|
[ca2b83] | 1300 | Elements = new element *[count];
|
---|
[e9b8bb] | 1301 | vectors = new Vector *[count];
|
---|
[14de469] | 1302 | j = 0;
|
---|
| 1303 | first = mol->start;
|
---|
| 1304 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
---|
| 1305 | first = first->next;
|
---|
| 1306 | Elements[j] = first->type;
|
---|
[d7e30c] | 1307 | vectors[j] = &first->x;
|
---|
[14de469] | 1308 | j++;
|
---|
| 1309 | }
|
---|
| 1310 | if (count != j)
|
---|
| 1311 | cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
---|
| 1312 | x.Zero();
|
---|
| 1313 | y.Zero();
|
---|
| 1314 | 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
|
---|
| 1315 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
| 1316 | x.AddVector(&y); // per factor one cell width further
|
---|
[7f3b9d] | 1317 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
[14de469] | 1318 | first = new atom(); // create a new body
|
---|
[d7e30c] | 1319 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
---|
[14de469] | 1320 | first->x.AddVector(&x); // translate the coordinates
|
---|
| 1321 | first->type = Elements[k]; // insert original element
|
---|
| 1322 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
| 1323 | }
|
---|
| 1324 | }
|
---|
| 1325 | if (mol->first->next != mol->last) // if connect matrix is present already, redo it
|
---|
[a251a3] | 1326 | mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration.GetIsAngstroem());
|
---|
[14de469] | 1327 | // free memory
|
---|
[ca2b83] | 1328 | delete[](Elements);
|
---|
[d7e30c] | 1329 | delete[](vectors);
|
---|
[14de469] | 1330 | // correct cell size
|
---|
| 1331 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
| 1332 | x.Zero();
|
---|
| 1333 | x.AddVector(&y);
|
---|
| 1334 | x.Scale(-(faktor-1));
|
---|
| 1335 | mol->Translate(&x);
|
---|
| 1336 | }
|
---|
| 1337 | mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
| 1338 | }
|
---|
| 1339 | break;
|
---|
| 1340 |
|
---|
[ca2b83] | 1341 | case 'e': // edit each field of the configuration
|
---|
| 1342 | configuration.Edit(mol);
|
---|
| 1343 | break;
|
---|
| 1344 |
|
---|
| 1345 | case 'f':
|
---|
| 1346 | FragmentAtoms(mol, &configuration);
|
---|
| 1347 | break;
|
---|
| 1348 |
|
---|
[14de469] | 1349 | case 'g': // center the atoms
|
---|
| 1350 | CenterAtoms(mol);
|
---|
| 1351 | break;
|
---|
| 1352 |
|
---|
| 1353 | case 'i': // align all atoms
|
---|
| 1354 | AlignAtoms(periode, mol);
|
---|
| 1355 | break;
|
---|
| 1356 |
|
---|
| 1357 | case 'l': // measure distances or angles
|
---|
[d52ea1b] | 1358 | MeasureAtoms(periode, mol, &configuration);
|
---|
[14de469] | 1359 | break;
|
---|
| 1360 |
|
---|
[ca2b83] | 1361 | case 'm': // mirror atoms along a given axis
|
---|
| 1362 | MirrorAtoms(mol);
|
---|
[14de469] | 1363 | break;
|
---|
[ca2b83] | 1364 |
|
---|
[14de469] | 1365 | case 'o': // create the connection matrix
|
---|
| 1366 | cout << Verbose(0) << "What's the maximum bond distance: ";
|
---|
| 1367 | cin >> tmp1;
|
---|
| 1368 | start = clock();
|
---|
[a251a3] | 1369 | mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
|
---|
[14de469] | 1370 | //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
|
---|
[d52ea1b] | 1371 | Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
|
---|
[14de469] | 1372 | while (Subgraphs->next != NULL) {
|
---|
| 1373 | Subgraphs = Subgraphs->next;
|
---|
| 1374 | delete(Subgraphs->previous);
|
---|
| 1375 | }
|
---|
| 1376 | delete(Subgraphs); // we don't need the list here, so free everything
|
---|
[fc850d] | 1377 | delete[](MinimumRingSize);
|
---|
[14de469] | 1378 | Subgraphs = NULL;
|
---|
| 1379 | end = clock();
|
---|
| 1380 | cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
| 1381 | break;
|
---|
| 1382 |
|
---|
[ca2b83] | 1383 | case 'p': // parse and XYZ file
|
---|
| 1384 | cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
|
---|
| 1385 | do {
|
---|
| 1386 | cout << Verbose(0) << "Enter file name: ";
|
---|
| 1387 | cin >> filename;
|
---|
| 1388 | } while (!mol->AddXYZFile(filename));
|
---|
| 1389 | break;
|
---|
| 1390 |
|
---|
| 1391 | case 'q': // quit
|
---|
| 1392 | break;
|
---|
[14de469] | 1393 |
|
---|
[ca2b83] | 1394 | case 'r': // remove atom
|
---|
| 1395 | RemoveAtoms(mol);
|
---|
| 1396 | break;
|
---|
| 1397 |
|
---|
| 1398 | case 's': // save to config file
|
---|
| 1399 | SaveConfig(ConfigFileName, &configuration, periode, mol);
|
---|
| 1400 | break;
|
---|
| 1401 |
|
---|
| 1402 | case 't': // translate all atoms
|
---|
| 1403 | cout << Verbose(0) << "Enter translation vector." << endl;
|
---|
| 1404 | x.AskPosition(mol->cell_size,0);
|
---|
[e9b8bb] | 1405 | mol->Translate((const Vector *)&x);
|
---|
[ca2b83] | 1406 | break;
|
---|
| 1407 |
|
---|
| 1408 | case 'T':
|
---|
| 1409 | testroutine(mol);
|
---|
| 1410 | break;
|
---|
| 1411 |
|
---|
[14de469] | 1412 | case 'u': // change an atom's element
|
---|
| 1413 | first = NULL;
|
---|
| 1414 | do {
|
---|
| 1415 | cout << Verbose(0) << "Change the element of which atom: ";
|
---|
| 1416 | cin >> Z;
|
---|
| 1417 | } while ((first = mol->FindAtom(Z)) == NULL);
|
---|
| 1418 | cout << Verbose(0) << "New element by atomic number Z: ";
|
---|
| 1419 | cin >> Z;
|
---|
| 1420 | first->type = periode->FindElement(Z);
|
---|
| 1421 | cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
|
---|
| 1422 | break;
|
---|
| 1423 | };
|
---|
| 1424 | } while (choice != 'q');
|
---|
| 1425 |
|
---|
| 1426 | // save element data base
|
---|
[110ceb] | 1427 | if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
|
---|
[14de469] | 1428 | cout << Verbose(0) << "Saving of elements.db successful." << endl;
|
---|
| 1429 | else
|
---|
| 1430 | cout << Verbose(0) << "Saving of elements.db failed." << endl;
|
---|
| 1431 |
|
---|
| 1432 | // Free all
|
---|
| 1433 | if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
|
---|
| 1434 | while (Subgraphs->next != NULL) {
|
---|
| 1435 | Subgraphs = Subgraphs->next;
|
---|
| 1436 | delete(Subgraphs->previous);
|
---|
| 1437 | }
|
---|
| 1438 | delete(Subgraphs);
|
---|
| 1439 | }
|
---|
| 1440 | delete(mol);
|
---|
| 1441 | delete(periode);
|
---|
| 1442 | return (0);
|
---|
| 1443 | }
|
---|
| 1444 |
|
---|
| 1445 | /********************************************** E N D **************************************************/
|
---|