source: molecuilder/src/builder.cpp@ 356180

Last change on this file since 356180 was 356180, checked in by Frederik Heber <heber@…>, 16 years ago

FIX: Flag returned by ParseCommandLineOptions() needs to be heeded, e.g. for FragmentMolecule().

  • now, there is again an ExitFlag and if {0,1} we return 0 and else the ExitFlag on exit.

Signed-off-by: Frederik Heber <heber@…>

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