source: src/builder.cpp@ 5b0b98

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 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 5b0b98 was 229e3c, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added custom Assert makro that allows ignoring asserts

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