source: src/builder.cpp@ 2561df

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

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/unittests/Makefile.am
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

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