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