source: src/builder.cpp@ 6670a97

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 6670a97 was eff648, checked in by Frederik Heber <heber@…>, 15 years ago

BUGFIX: In ParseCommandLineOptions() -v and -V were mixed.

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