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