source: src/builder.cpp@ 1cbf47

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 1cbf47 was 1cbf47, checked in by Frederik Heber <heber@…>, 16 years ago

Introduced CountHydrogenBridgeBonds() function.

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

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