source: src/builder.cpp@ c5805a

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

ManipulateAtoms() can turn atoms around bonds again, in ParseCommandLineOptions() case 'C' Binwidth can be specified.

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