source: src/builder.cpp@ a80241

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 a80241 was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

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