source: molecuilder/src/builder.cpp@ 4bb871a

Last change on this file since 4bb871a was 4bb871a, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge commit 'heber/Analysis_PairCorrelation' into MenuRefactoring

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