source: src/Tesselation/boundary.cpp@ 50e4e5

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 50e4e5 was 42127c, checked in by Frederik Heber <heber@…>, 13 years ago

Extracted definition of MoleculeListClass and put into own header module.

  • Property mode set to 100644
File size: 63.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file boundary.cpp
9 *
10 * Implementations and super-function for envelopes
11 */
12
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "CodePatterns/MemDebug.hpp"
19
20#include "atom.hpp"
21#include "Bond/bond.hpp"
22#include "boundary.hpp"
23#include "BoundaryLineSet.hpp"
24#include "BoundaryPointSet.hpp"
25#include "BoundaryTriangleSet.hpp"
26#include "Box.hpp"
27#include "CandidateForTesselation.hpp"
28#include "CodePatterns/Info.hpp"
29#include "CodePatterns/Log.hpp"
30#include "CodePatterns/Verbose.hpp"
31#include "config.hpp"
32#include "Element/element.hpp"
33#include "LinearAlgebra/Plane.hpp"
34#include "LinearAlgebra/RealSpaceMatrix.hpp"
35#include "linkedcell.hpp"
36#include "molecule.hpp"
37#include "MoleculeListClass.hpp"
38#include "PointCloudAdaptor.hpp"
39#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
40#include "RandomNumbers/RandomNumberGenerator.hpp"
41#include "tesselation.hpp"
42#include "tesselationhelpers.hpp"
43#include "World.hpp"
44
45#include <iostream>
46#include <iomanip>
47
48#include<gsl/gsl_poly.h>
49#include<time.h>
50
51// ========================================== F U N C T I O N S =================================
52
53
54/** Determines greatest diameters of a cluster defined by its convex envelope.
55 * Looks at lines parallel to one axis and where they intersect on the projected planes
56 * \param *out output stream for debugging
57 * \param *BoundaryPoints NDIM set of boundary points defining the convex envelope on each projected plane
58 * \param *mol molecule structure representing the cluster
59 * \param *&TesselStruct Tesselation structure with triangles
60 * \param IsAngstroem whether we have angstroem or atomic units
61 * \return NDIM array of the diameters
62 */
63double *GetDiametersOfCluster(const Boundaries *BoundaryPtr, const molecule *mol, Tesselation *&TesselStruct, const bool IsAngstroem)
64{
65 Info FunctionInfo(__func__);
66 // get points on boundary of NULL was given as parameter
67 bool BoundaryFreeFlag = false;
68 double OldComponent = 0.;
69 double tmp = 0.;
70 double w1 = 0.;
71 double w2 = 0.;
72 Vector DistanceVector;
73 Vector OtherVector;
74 int component = 0;
75 int Othercomponent = 0;
76 Boundaries::const_iterator Neighbour;
77 Boundaries::const_iterator OtherNeighbour;
78 double *GreatestDiameter = new double[NDIM];
79
80 const Boundaries *BoundaryPoints;
81 if (BoundaryPtr == NULL) {
82 BoundaryFreeFlag = true;
83 BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
84 } else {
85 BoundaryPoints = BoundaryPtr;
86 DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
87 }
88 // determine biggest "diameter" of cluster for each axis
89 for (int i = 0; i < NDIM; i++)
90 GreatestDiameter[i] = 0.;
91 for (int axis = 0; axis < NDIM; axis++)
92 { // regard each projected plane
93 //Log() << Verbose(1) << "Current axis is " << axis << "." << endl;
94 for (int j = 0; j < 2; j++)
95 { // and for both axis on the current plane
96 component = (axis + j + 1) % NDIM;
97 Othercomponent = (axis + 1 + ((j + 1) & 1)) % NDIM;
98 //Log() << Verbose(1) << "Current component is " << component << ", Othercomponent is " << Othercomponent << "." << endl;
99 for (Boundaries::const_iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
100 //Log() << Verbose(1) << "Current runner is " << *(runner->second.second) << "." << endl;
101 // seek for the neighbours pair where the Othercomponent sign flips
102 Neighbour = runner;
103 Neighbour++;
104 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
105 Neighbour = BoundaryPoints[axis].begin();
106 DistanceVector = (runner->second.second->getPosition()) - (Neighbour->second.second->getPosition());
107 do { // seek for neighbour pair where it flips
108 OldComponent = DistanceVector[Othercomponent];
109 Neighbour++;
110 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
111 Neighbour = BoundaryPoints[axis].begin();
112 DistanceVector = (runner->second.second->getPosition()) - (Neighbour->second.second->getPosition());
113 //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
114 } while ((runner != Neighbour) && (fabs(OldComponent / fabs(
115 OldComponent) - DistanceVector[Othercomponent] / fabs(
116 DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip
117 if (runner != Neighbour) {
118 OtherNeighbour = Neighbour;
119 if (OtherNeighbour == BoundaryPoints[axis].begin()) // make it wrap around
120 OtherNeighbour = BoundaryPoints[axis].end();
121 OtherNeighbour--;
122 //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
123 // now we have found the pair: Neighbour and OtherNeighbour
124 OtherVector = (runner->second.second->getPosition()) - (OtherNeighbour->second.second->getPosition());
125 //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
126 //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
127 // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour
128 w1 = fabs(OtherVector[Othercomponent]);
129 w2 = fabs(DistanceVector[Othercomponent]);
130 tmp = fabs((w1 * DistanceVector[component] + w2
131 * OtherVector[component]) / (w1 + w2));
132 // mark if it has greater diameter
133 //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
134 GreatestDiameter[component] = (GreatestDiameter[component]
135 > tmp) ? GreatestDiameter[component] : tmp;
136 } //else
137 //Log() << Verbose(1) << "Saw no sign flip, probably top or bottom node." << endl;
138 }
139 }
140 }
141 Log() << Verbose(0) << "RESULT: The biggest diameters are "
142 << GreatestDiameter[0] << " and " << GreatestDiameter[1] << " and "
143 << GreatestDiameter[2] << " " << (IsAngstroem ? "angstrom"
144 : "atomiclength") << "." << endl;
145
146 // free reference lists
147 if (BoundaryFreeFlag)
148 delete[] (BoundaryPoints);
149
150 return GreatestDiameter;
151}
152;
153
154
155/** Determines the boundary points of a cluster.
156 * Does a projection per axis onto the orthogonal plane, transforms into spherical coordinates, sorts them by the angle
157 * and looks at triples: if the middle has less a distance than the allowed maximum height of the triangle formed by the plane's
158 * center and first and last point in the triple, it is thrown out.
159 * \param *out output stream for debugging
160 * \param *mol molecule structure representing the cluster
161 * \param *&TesselStruct pointer to Tesselation structure
162 */
163Boundaries *GetBoundaryPoints(const molecule *mol, Tesselation *&TesselStruct)
164{
165 Info FunctionInfo(__func__);
166 PointMap PointsOnBoundary;
167 LineMap LinesOnBoundary;
168 TriangleMap TrianglesOnBoundary;
169 Vector *MolCenter = mol->DetermineCenterOfAll();
170 Vector helper;
171 BoundariesTestPair BoundaryTestPair;
172 Vector AxisVector;
173 Vector AngleReferenceVector;
174 Vector AngleReferenceNormalVector;
175 Vector ProjectedVector;
176 Boundaries *BoundaryPoints = new Boundaries[NDIM]; // first is alpha, second is (r, Nr)
177 double angle = 0.;
178
179 // 3a. Go through every axis
180 for (int axis = 0; axis < NDIM; axis++) {
181 AxisVector.Zero();
182 AngleReferenceVector.Zero();
183 AngleReferenceNormalVector.Zero();
184 AxisVector[axis] = 1.;
185 AngleReferenceVector[(axis + 1) % NDIM] = 1.;
186 AngleReferenceNormalVector[(axis + 2) % NDIM] = 1.;
187
188 DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl);
189
190 // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
191 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
192 ProjectedVector = (*iter)->getPosition() - (*MolCenter);
193 ProjectedVector.ProjectOntoPlane(AxisVector);
194
195 // correct for negative side
196 const double radius = ProjectedVector.NormSquared();
197 if (fabs(radius) > MYEPSILON)
198 angle = ProjectedVector.Angle(AngleReferenceVector);
199 else
200 angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
201
202 //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
203 if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) {
204 angle = 2. * M_PI - angle;
205 }
206 DoLog(1) && (Log() << Verbose(1) << "Inserting " << **iter << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
207 BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, TesselPointDistancePair (radius, (*iter))));
208 if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
209 DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);
210 DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);
211 DoLog(2) && (Log() << Verbose(2) << "New vector: " << **iter << endl);
212 const double ProjectedVectorNorm = ProjectedVector.NormSquared();
213 if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) {
214 BoundaryTestPair.first->second.first = ProjectedVectorNorm;
215 BoundaryTestPair.first->second.second = (*iter);
216 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
217 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
218 helper = (*iter)->getPosition() - (*MolCenter);
219 const double oldhelperNorm = helper.NormSquared();
220 helper = BoundaryTestPair.first->second.second->getPosition() - (*MolCenter);
221 if (helper.NormSquared() < oldhelperNorm) {
222 BoundaryTestPair.first->second.second = (*iter);
223 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);
224 } else {
225 DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger distance to molecule center " << oldhelperNorm << "." << endl);
226 }
227 } else {
228 DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
229 }
230 }
231 }
232 // printing all inserted for debugging
233 // {
234 // Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
235 // int i=0;
236 // for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
237 // if (runner != BoundaryPoints[axis].begin())
238 // Log() << Verbose(0) << ", " << i << ": " << *runner->second.second;
239 // else
240 // Log() << Verbose(0) << i << ": " << *runner->second.second;
241 // i++;
242 // }
243 // Log() << Verbose(0) << endl;
244 // }
245 // 3c. throw out points whose distance is less than the mean of left and right neighbours
246 bool flag = false;
247 DoLog(1) && (Log() << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl);
248 do { // do as long as we still throw one out per round
249 flag = false;
250 Boundaries::iterator left = BoundaryPoints[axis].begin();
251 Boundaries::iterator right = BoundaryPoints[axis].begin();
252 Boundaries::iterator runner = BoundaryPoints[axis].begin();
253 bool LoopOnceDone = false;
254 while (!LoopOnceDone) {
255 runner = right;
256 right++;
257 // set neighbours correctly
258 if (runner == BoundaryPoints[axis].begin()) {
259 left = BoundaryPoints[axis].end();
260 } else {
261 left = runner;
262 }
263 left--;
264 if (right == BoundaryPoints[axis].end()) {
265 right = BoundaryPoints[axis].begin();
266 LoopOnceDone = true;
267 }
268 // check distance
269
270 // construct the vector of each side of the triangle on the projected plane (defined by normal vector AxisVector)
271 {
272 Vector SideA, SideB, SideC, SideH;
273 SideA = left->second.second->getPosition() - (*MolCenter);
274 SideA.ProjectOntoPlane(AxisVector);
275 // Log() << Verbose(1) << "SideA: " << SideA << endl;
276
277 SideB = right->second.second->getPosition() -(*MolCenter);
278 SideB.ProjectOntoPlane(AxisVector);
279 // Log() << Verbose(1) << "SideB: " << SideB << endl;
280
281 SideC = left->second.second->getPosition() - right->second.second->getPosition();
282 SideC.ProjectOntoPlane(AxisVector);
283 // Log() << Verbose(1) << "SideC: " << SideC << endl;
284
285 SideH = runner->second.second->getPosition() -(*MolCenter);
286 SideH.ProjectOntoPlane(AxisVector);
287 // Log() << Verbose(1) << "SideH: " << SideH << endl;
288
289 // calculate each length
290 const double a = SideA.Norm();
291 //const double b = SideB.Norm();
292 //const double c = SideC.Norm();
293 const double h = SideH.Norm();
294 // calculate the angles
295 const double alpha = SideA.Angle(SideH);
296 const double beta = SideA.Angle(SideC);
297 const double gamma = SideB.Angle(SideH);
298 const double delta = SideC.Angle(SideH);
299 const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.);
300 //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl;
301 DoLog(1) && (Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl);
302 if ((fabs(h / fabs(h) - MinDistance / fabs(MinDistance)) < MYEPSILON) && ((h - MinDistance)) < -MYEPSILON) {
303 // throw out point
304 DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl);
305 BoundaryPoints[axis].erase(runner);
306 runner = right;
307 flag = true;
308 }
309 }
310 }
311 } while (flag);
312 }
313 delete(MolCenter);
314 return BoundaryPoints;
315};
316
317/** Tesselates the convex boundary by finding all boundary points.
318 * \param *out output stream for debugging
319 * \param *mol molecule structure with Atom's and Bond's.
320 * \param *BoundaryPts set of boundary points to use or NULL
321 * \param *TesselStruct Tesselation filled with points, lines and triangles on boundary on return
322 * \param *LCList atoms in LinkedCell list
323 * \param *filename filename prefix for output of vertex data
324 * \return *TesselStruct is filled with convex boundary and tesselation is stored under \a *filename.
325 */
326void FindConvexBorder(const molecule* mol, Boundaries *BoundaryPts, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename)
327{
328 Info FunctionInfo(__func__);
329 bool BoundaryFreeFlag = false;
330 Boundaries *BoundaryPoints = NULL;
331
332 if (TesselStruct != NULL) // free if allocated
333 delete(TesselStruct);
334 TesselStruct = new class Tesselation;
335
336 // 1. Find all points on the boundary
337 if (BoundaryPts == NULL) {
338 BoundaryFreeFlag = true;
339 BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
340 } else {
341 BoundaryPoints = BoundaryPts;
342 DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
343 }
344
345// printing all inserted for debugging
346 for (int axis=0; axis < NDIM; axis++) {
347 DoLog(1) && (Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl);
348 int i=0;
349 for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
350 if (runner != BoundaryPoints[axis].begin())
351 DoLog(0) && (Log() << Verbose(0) << ", " << i << ": " << *runner->second.second);
352 else
353 DoLog(0) && (Log() << Verbose(0) << i << ": " << *runner->second.second);
354 i++;
355 }
356 DoLog(0) && (Log() << Verbose(0) << endl);
357 }
358
359 // 2. fill the boundary point list
360 for (int axis = 0; axis < NDIM; axis++)
361 for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++)
362 if (!TesselStruct->AddBoundaryPoint(runner->second.second, 0))
363 DoLog(2) && (Log()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present." << endl);
364
365 DoLog(0) && (Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl);
366 // now we have the whole set of edge points in the BoundaryList
367
368 // listing for debugging
369 // Log() << Verbose(1) << "Listing PointsOnBoundary:";
370 // for(PointMap::iterator runner = PointsOnBoundary.begin(); runner != PointsOnBoundary.end(); runner++) {
371 // Log() << Verbose(0) << " " << *runner->second;
372 // }
373 // Log() << Verbose(0) << endl;
374
375 // 3a. guess starting triangle
376 TesselStruct->GuessStartingTriangle();
377
378 // 3b. go through all lines, that are not yet part of two triangles (only of one so far)
379 PointCloudAdaptor< molecule > cloud(const_cast<molecule *>(mol), mol->name);
380 TesselStruct->TesselateOnBoundary(cloud);
381
382 // 3c. check whether all atoms lay inside the boundary, if not, add to boundary points, segment triangle into three with the new point
383 if (!TesselStruct->InsertStraddlingPoints(cloud, LCList))
384 DoeLog(1) && (eLog()<< Verbose(1) << "Insertion of straddling points failed!" << endl);
385
386 DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);
387
388 // 4. Store triangles in tecplot file
389 StoreTrianglesinFile(mol, TesselStruct, filename, "_intermed");
390
391 // 3d. check all baselines whether the peaks of the two adjacent triangles with respect to center of baseline are convex, if not, make the baseline between the two peaks and baseline endpoints become the new peaks
392 bool AllConvex = true;
393 class BoundaryLineSet *line = NULL;
394 do {
395 AllConvex = true;
396 for (LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
397 line = LineRunner->second;
398 DoLog(1) && (Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl);
399 if (!line->CheckConvexityCriterion()) {
400 DoLog(1) && (Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl);
401
402 // flip the line
403 if (TesselStruct->PickFarthestofTwoBaselines(line) == 0.)
404 DoeLog(1) && (eLog()<< Verbose(1) << "Correction of concave baselines failed!" << endl);
405 else {
406 TesselStruct->FlipBaseline(line);
407 DoLog(1) && (Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl);
408 LineRunner = TesselStruct->LinesOnBoundary.begin(); // LineRunner may have been erase if line was deleted from LinesOnBoundary
409 }
410 }
411 }
412 } while (!AllConvex);
413
414 // 3e. we need another correction here, for TesselPoints that are below the surface (i.e. have an odd number of concave triangles surrounding it)
415// if (!TesselStruct->CorrectConcaveTesselPoints(out))
416// Log() << Verbose(1) << "Correction of concave tesselpoints failed!" << endl;
417
418 DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);
419
420 // 4. Store triangles in tecplot file
421 StoreTrianglesinFile(mol, TesselStruct, filename, "");
422
423 // free reference lists
424 if (BoundaryFreeFlag)
425 delete[] (BoundaryPoints);
426};
427
428/** For testing removes one boundary point after another to check for leaks.
429 * \param *out output stream for debugging
430 * \param *TesselStruct Tesselation containing envelope with boundary points
431 * \param *mol molecule
432 * \param *filename name of file
433 * \return true - all removed, false - something went wrong
434 */
435bool RemoveAllBoundaryPoints(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
436{
437 Info FunctionInfo(__func__);
438 int i=0;
439 char number[MAXSTRINGSIZE];
440
441 if ((TesselStruct == NULL) || (TesselStruct->PointsOnBoundary.empty())) {
442 DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty." << endl);
443 return false;
444 }
445
446 PointMap::iterator PointRunner;
447 while (!TesselStruct->PointsOnBoundary.empty()) {
448 DoLog(1) && (Log() << Verbose(1) << "Remaining points are: ");
449 for (PointMap::iterator PointSprinter = TesselStruct->PointsOnBoundary.begin(); PointSprinter != TesselStruct->PointsOnBoundary.end(); PointSprinter++)
450 DoLog(0) && (Log() << Verbose(0) << *(PointSprinter->second) << "\t");
451 DoLog(0) && (Log() << Verbose(0) << endl);
452
453 PointRunner = TesselStruct->PointsOnBoundary.begin();
454 // remove point
455 TesselStruct->RemovePointFromTesselatedSurface(PointRunner->second);
456
457 // store envelope
458 sprintf(number, "-%04d", i++);
459 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, number);
460 }
461
462 return true;
463};
464
465/** Creates a convex envelope from a given non-convex one.
466 * -# First step, remove concave spots, i.e. singular "dents"
467 * -# We go through all PointsOnBoundary.
468 * -# We CheckConvexityCriterion() for all its lines.
469 * -# If all its lines are concave, it cannot be on the convex envelope.
470 * -# Hence, we remove it and re-create all its triangles from its getCircleOfConnectedPoints()
471 * -# We calculate the additional volume.
472 * -# We go over all lines until none yields a concavity anymore.
473 * -# Second step, remove concave lines, i.e. line-shape "dents"
474 * -# We go through all LinesOnBoundary
475 * -# We CheckConvexityCriterion()
476 * -# If it returns concave, we flip the line in this quadrupel of points (abusing the degeneracy of the tesselation)
477 * -# We CheckConvexityCriterion(),
478 * -# if it's concave, we continue
479 * -# if not, we mark an error and stop
480 * Note: This routine - for free - calculates the difference in volume between convex and
481 * non-convex envelope, as the former is easy to calculate - VolumeOfConvexEnvelope() - it
482 * can be used to compute volumes of arbitrary shapes.
483 * \param *out output stream for debugging
484 * \param *TesselStruct non-convex envelope, is changed in return!
485 * \param *mol molecule
486 * \param *filename name of file
487 * \return volume difference between the non- and the created convex envelope
488 */
489double ConvexizeNonconvexEnvelope(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
490{
491 Info FunctionInfo(__func__);
492 double volume = 0;
493 class BoundaryPointSet *point = NULL;
494 class BoundaryLineSet *line = NULL;
495 bool Concavity = false;
496 char dummy[MAXSTRINGSIZE];
497 PointMap::iterator PointRunner;
498 PointMap::iterator PointAdvance;
499 LineMap::iterator LineRunner;
500 LineMap::iterator LineAdvance;
501 TriangleMap::iterator TriangleRunner;
502 TriangleMap::iterator TriangleAdvance;
503 int run = 0;
504
505 // check whether there is something to work on
506 if (TesselStruct == NULL) {
507 DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty!" << endl);
508 return volume;
509 }
510
511 // First step: RemovePointFromTesselatedSurface
512 do {
513 Concavity = false;
514 sprintf(dummy, "-first-%d", run);
515 //CalculateConcavityPerBoundaryPoint(TesselStruct);
516 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, dummy);
517
518 PointRunner = TesselStruct->PointsOnBoundary.begin();
519 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed
520 while (PointRunner != TesselStruct->PointsOnBoundary.end()) {
521 PointAdvance++;
522 point = PointRunner->second;
523 DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);
524 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
525 line = LineRunner->second;
526 DoLog(1) && (Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl);
527 if (!line->CheckConvexityCriterion()) {
528 // remove the point if needed
529 DoLog(1) && (Log() << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl);
530 volume += TesselStruct->RemovePointFromTesselatedSurface(point);
531 sprintf(dummy, "-first-%d", ++run);
532 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, dummy);
533 Concavity = true;
534 break;
535 }
536 }
537 PointRunner = PointAdvance;
538 }
539
540 sprintf(dummy, "-second-%d", run);
541 //CalculateConcavityPerBoundaryPoint(TesselStruct);
542 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, dummy);
543
544 // second step: PickFarthestofTwoBaselines
545 LineRunner = TesselStruct->LinesOnBoundary.begin();
546 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed
547 while (LineRunner != TesselStruct->LinesOnBoundary.end()) {
548 LineAdvance++;
549 line = LineRunner->second;
550 DoLog(1) && (Log() << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl);
551 // take highest of both lines
552 if (TesselStruct->IsConvexRectangle(line) == NULL) {
553 const double tmp = TesselStruct->PickFarthestofTwoBaselines(line);
554 volume += tmp;
555 if (tmp != 0.) {
556 TesselStruct->FlipBaseline(line);
557 Concavity = true;
558 }
559 }
560 LineRunner = LineAdvance;
561 }
562 run++;
563 } while (Concavity);
564 //CalculateConcavityPerBoundaryPoint(TesselStruct);
565 //StoreTrianglesinFile(mol, filename, "-third");
566
567 // third step: IsConvexRectangle
568// LineRunner = TesselStruct->LinesOnBoundary.begin();
569// LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed
570// while (LineRunner != TesselStruct->LinesOnBoundary.end()) {
571// LineAdvance++;
572// line = LineRunner->second;
573// Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl;
574// //if (LineAdvance != TesselStruct->LinesOnBoundary.end())
575// //Log() << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;
576// if (!line->CheckConvexityCriterion(out)) {
577// Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;
578//
579// // take highest of both lines
580// point = TesselStruct->IsConvexRectangle(line);
581// if (point != NULL)
582// volume += TesselStruct->RemovePointFromTesselatedSurface(point);
583// }
584// LineRunner = LineAdvance;
585// }
586
587 CalculateConcavityPerBoundaryPoint(TesselStruct);
588 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
589
590 // end
591 DoLog(0) && (Log() << Verbose(0) << "Volume is " << volume << "." << endl);
592 return volume;
593};
594
595
596/** Determines the volume of a cluster.
597 * Determines first the convex envelope, then tesselates it and calculates its volume.
598 * \param *out output stream for debugging
599 * \param *TesselStruct Tesselation filled with points, lines and triangles on boundary on return
600 * \param *configuration needed for path to store convex envelope file
601 * \return determined volume of the cluster in cubed config:GetIsAngstroem()
602 */
603double VolumeOfConvexEnvelope(class Tesselation *TesselStruct, class config *configuration)
604{
605 Info FunctionInfo(__func__);
606 bool IsAngstroem = configuration->GetIsAngstroem();
607 double volume = 0.;
608 Vector x;
609 Vector y;
610
611 // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
612 for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++)
613 { // go through every triangle, calculate volume of its pyramid with CoG as peak
614 x = runner->second->getEndpoint(0) - runner->second->getEndpoint(1);
615 y = runner->second->getEndpoint(0) - runner->second->getEndpoint(2);
616 const double a = x.Norm();
617 const double b = y.Norm();
618 const double c = runner->second->getEndpoint(2).distance(runner->second->getEndpoint(1));
619 const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle
620 x = runner->second->getPlane().getNormal();
621 x.Scale(runner->second->getEndpoint(1).ScalarProduct(x));
622 const double h = x.Norm(); // distance of CoG to triangle
623 const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
624 Log() << Verbose(1) << "Area of triangle is " << setprecision(10) << G << " "
625 << (IsAngstroem ? "angstrom" : "atomiclength") << "^2, height is "
626 << h << " and the volume is " << PyramidVolume << " "
627 << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
628 volume += PyramidVolume;
629 }
630 Log() << Verbose(0) << "RESULT: The summed volume is " << setprecision(6)
631 << volume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3."
632 << endl;
633
634 return volume;
635};
636
637/** Stores triangles to file.
638 * \param *out output stream for debugging
639 * \param *mol molecule with atoms and bonds
640 * \param *TesselStruct Tesselation with boundary triangles
641 * \param *filename prefix of filename
642 * \param *extraSuffix intermediate suffix
643 */
644void StoreTrianglesinFile(const molecule * const mol, const Tesselation * const TesselStruct, const char *filename, const char *extraSuffix)
645{
646 Info FunctionInfo(__func__);
647 PointCloudAdaptor< molecule > cloud(const_cast<molecule *>(mol), mol->name);
648 // 4. Store triangles in tecplot file
649 if (filename != NULL) {
650 if (DoTecplotOutput) {
651 string OutputName(filename);
652 OutputName.append(extraSuffix);
653 OutputName.append(TecplotSuffix);
654 ofstream *tecplot = new ofstream(OutputName.c_str());
655 WriteTecplotFile(tecplot, TesselStruct, cloud, -1);
656 tecplot->close();
657 delete(tecplot);
658 }
659 if (DoRaster3DOutput) {
660 string OutputName(filename);
661 OutputName.append(extraSuffix);
662 OutputName.append(Raster3DSuffix);
663 ofstream *rasterplot = new ofstream(OutputName.c_str());
664 WriteRaster3dFile(rasterplot, TesselStruct, cloud);
665 rasterplot->close();
666 delete(rasterplot);
667 }
668 }
669};
670
671/** Creates multiples of the by \a *mol given cluster and suspends them in water with a given final density.
672 * We get cluster volume by VolumeOfConvexEnvelope() and its diameters by GetDiametersOfCluster()
673 * TODO: Here, we need a VolumeOfGeneralEnvelope (i.e. non-convex one)
674 * \param *out output stream for debugging
675 * \param *configuration needed for path to store convex envelope file
676 * \param *mol molecule structure representing the cluster
677 * \param *&TesselStruct Tesselation structure with triangles on return
678 * \param ClusterVolume guesstimated cluster volume, if equal 0 we used VolumeOfConvexEnvelope() instead.
679 * \param celldensity desired average density in final cell
680 */
681void PrepareClustersinWater(config *configuration, molecule *mol, double ClusterVolume, double celldensity)
682{
683 Info FunctionInfo(__func__);
684 bool IsAngstroem = true;
685 double *GreatestDiameter = NULL;
686 Boundaries *BoundaryPoints = NULL;
687 class Tesselation *TesselStruct = NULL;
688 Vector BoxLengths;
689 int repetition[NDIM] = { 1, 1, 1 };
690 int TotalNoClusters = 1;
691 double totalmass = 0.;
692 double clustervolume = 0.;
693 double cellvolume = 0.;
694
695 // transform to PAS by Action
696 Vector MainAxis(0.,0.,1.);
697 mol->RotateToPrincipalAxisSystem(MainAxis);
698
699 IsAngstroem = configuration->GetIsAngstroem();
700 BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
701 GreatestDiameter = GetDiametersOfCluster(BoundaryPoints, mol, TesselStruct, IsAngstroem);
702 PointCloudAdaptor< molecule > cloud(mol, mol->name);
703 LinkedCell *LCList = new LinkedCell(cloud, 10.);
704 FindConvexBorder(mol, BoundaryPoints, TesselStruct, (const LinkedCell *&)LCList, NULL);
705 delete (LCList);
706 delete[] BoundaryPoints;
707
708
709 // some preparations beforehand
710 if (ClusterVolume == 0)
711 clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
712 else
713 clustervolume = ClusterVolume;
714
715 delete TesselStruct;
716
717 for (int i = 0; i < NDIM; i++)
718 TotalNoClusters *= repetition[i];
719
720 // sum up the atomic masses
721 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
722 totalmass += (*iter)->getType()->getMass();
723 }
724 DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);
725 DoLog(0) && (Log() << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass / clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
726
727 // solve cubic polynomial
728 DoLog(1) && (Log() << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl);
729 if (IsAngstroem)
730 cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_A - (totalmass / clustervolume)) / (celldensity - 1);
731 else
732 cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_a0 - (totalmass / clustervolume)) / (celldensity - 1);
733 DoLog(1) && (Log() << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
734
735 double minimumvolume = TotalNoClusters * (GreatestDiameter[0] * GreatestDiameter[1] * GreatestDiameter[2]);
736 DoLog(1) && (Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
737 if (minimumvolume > cellvolume) {
738 DoeLog(1) && (eLog()<< Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl);
739 DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl);
740 for (int i = 0; i < NDIM; i++)
741 BoxLengths[i] = GreatestDiameter[i];
742 mol->CenterEdge(&BoxLengths);
743 } else {
744 BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);
745 BoxLengths[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]);
746 BoxLengths[2] = minimumvolume - cellvolume;
747 double x0 = 0.;
748 double x1 = 0.;
749 double x2 = 0.;
750 if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return
751 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl);
752 else {
753 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl);
754 x0 = x2; // sorted in ascending order
755 }
756
757 cellvolume = 1.;
758 for (int i = 0; i < NDIM; i++) {
759 BoxLengths[i] = repetition[i] * (x0 + GreatestDiameter[i]);
760 cellvolume *= BoxLengths[i];
761 }
762
763 // set new box dimensions
764 DoLog(0) && (Log() << Verbose(0) << "Translating to box with these boundaries." << endl);
765 mol->SetBoxDimension(&BoxLengths);
766 mol->CenterInBox();
767 }
768 delete GreatestDiameter;
769 // update Box of atoms by boundary
770 mol->SetBoxDimension(&BoxLengths);
771 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths[0] << " and " << BoxLengths[1] << " and " << BoxLengths[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
772};
773
774
775/** Fills the empty space around other molecules' surface of the simulation box with a filler.
776 * \param *out output stream for debugging
777 * \param *List list of molecules already present in box
778 * \param *TesselStruct contains tesselated surface
779 * \param *filler molecule which the box is to be filled with
780 * \param configuration contains box dimensions
781 * \param MaxDistance fills in molecules only up to this distance (set to -1 if whole of the domain)
782 * \param distance[NDIM] distance between filling molecules in each direction
783 * \param boundary length of boundary zone between molecule and filling mollecules
784 * \param epsilon distance to surface which is not filled
785 * \param RandAtomDisplacement maximum distance for random displacement per atom
786 * \param RandMolDisplacement maximum distance for random displacement per filler molecule
787 * \param DoRandomRotation true - do random rotiations, false - don't
788 */
789void FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double MaxDistance, const double distance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation)
790{
791 Info FunctionInfo(__func__);
792 molecule *Filling = World::getInstance().createMolecule();
793 Vector CurrentPosition;
794 int N[NDIM];
795 int n[NDIM];
796 const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
797 RealSpaceMatrix Rotations;
798 const RealSpaceMatrix &MInverse = World::getInstance().getDomain().getMinv();
799 Vector AtomTranslations;
800 Vector FillerTranslations;
801 Vector FillerDistance;
802 Vector Inserter;
803 double FillIt = false;
804 bond *Binder = NULL;
805 double phi[NDIM];
806 map<molecule *, Tesselation *> TesselStruct;
807 map<molecule *, LinkedCell *> LCList;
808
809 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++)
810 if ((*ListRunner)->getAtomCount() > 0) {
811 DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
812 PointCloudAdaptor< molecule > cloud(*ListRunner, (*ListRunner)->name);
813 LCList[(*ListRunner)] = new LinkedCell(cloud, 10.); // get linked cell list
814 DoLog(1) && (Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl);
815 TesselStruct[(*ListRunner)] = NULL;
816 FindNonConvexBorder((*ListRunner), TesselStruct[(*ListRunner)], (const LinkedCell *&)LCList[(*ListRunner)], 5., NULL);
817 }
818
819 // Center filler at origin
820 filler->CenterEdge(&Inserter);
821 const int FillerCount = filler->getAtomCount();
822 DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl);
823 for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner) {
824 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
825 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
826 BondRunner != ListOfBonds.end();
827 ++BondRunner) {
828 if ((*BondRunner)->leftatom == *AtomRunner)
829 DoLog(2) && (Log() << Verbose(2) << " " << *(*BondRunner) << endl);
830 }
831 }
832
833 atom * CopyAtoms[FillerCount];
834
835 // calculate filler grid in [0,1]^3
836 FillerDistance = MInverse * Vector(distance[0], distance[1], distance[2]);
837 for(int i=0;i<NDIM;i++)
838 N[i] = (int) ceil(1./FillerDistance[i]);
839 DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);
840
841 // initialize seed of random number generator to current time
842 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
843 const double rng_min = random.min();
844 const double rng_max = random.max();
845 //srand ( time(NULL) );
846
847 // go over [0,1]^3 filler grid
848 for (n[0] = 0; n[0] < N[0]; n[0]++)
849 for (n[1] = 0; n[1] < N[1]; n[1]++)
850 for (n[2] = 0; n[2] < N[2]; n[2]++) {
851 // calculate position of current grid vector in untransformed box
852 CurrentPosition = M * Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
853 // create molecule random translation vector ...
854 for (int i=0;i<NDIM;i++)
855 FillerTranslations[i] = RandomMolDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
856 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
857
858 // go through all atoms
859 for (int i=0;i<FillerCount;i++)
860 CopyAtoms[i] = NULL;
861
862 // have same rotation angles for all molecule's atoms
863 if (DoRandomRotation)
864 for (int i=0;i<NDIM;i++)
865 phi[i] = (random()/(rng_max-rng_min))*(2.*M_PI);
866
867 for(molecule::const_iterator iter = filler->begin(); iter !=filler->end();++iter){
868
869 // create atomic random translation vector ...
870 for (int i=0;i<NDIM;i++)
871 AtomTranslations[i] = RandomAtomDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
872
873 // ... and rotation matrix
874 if (DoRandomRotation) {
875 Rotations.set(0,0, cos(phi[0]) *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2])));
876 Rotations.set(0,1, sin(phi[0]) *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2])));
877 Rotations.set(0,2, cos(phi[1])*sin(phi[2]) );
878 Rotations.set(1,0, -sin(phi[0])*cos(phi[1]) );
879 Rotations.set(1,1, cos(phi[0])*cos(phi[1]) );
880 Rotations.set(1,2, sin(phi[1]) );
881 Rotations.set(2,0, -cos(phi[0]) *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2])));
882 Rotations.set(2,1, -sin(phi[0]) *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2])));
883 Rotations.set(2,2, cos(phi[1])*cos(phi[2]) );
884 }
885
886 // ... and put at new position
887 Inserter = (*iter)->getPosition();
888 if (DoRandomRotation)
889 Inserter *= Rotations;
890 Inserter += AtomTranslations + FillerTranslations + CurrentPosition;
891
892 // check whether inserter is inside box
893 Inserter *= MInverse;
894 FillIt = true;
895 for (int i=0;i<NDIM;i++)
896 FillIt = FillIt && (Inserter[i] >= -MYEPSILON) && ((Inserter[i]-1.) <= MYEPSILON);
897 Inserter *= M;
898
899 // Check whether point is in- or outside
900 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
901 // get linked cell list
902 if (TesselStruct[(*ListRunner)] != NULL) {
903 const double distance = (TesselStruct[(*ListRunner)]->GetDistanceToSurface(Inserter, LCList[(*ListRunner)]));
904 FillIt = FillIt && (distance > boundary) && ((MaxDistance < 0) || (MaxDistance > distance));
905 }
906 }
907 // insert into Filling
908 if (FillIt) {
909 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl);
910 // copy atom ...
911 CopyAtoms[(*iter)->getNr()] = (*iter)->clone();
912 (*CopyAtoms[(*iter)->getNr()]).setPosition(Inserter);
913 Filling->AddAtom(CopyAtoms[(*iter)->getNr()]);
914 DoLog(1) && (Log() << Verbose(1) << "Filling atom " << **iter << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[(*iter)->getNr()]->getPosition()) << "." << endl);
915 } else {
916 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);
917 CopyAtoms[(*iter)->getNr()] = NULL;
918 continue;
919 }
920 }
921 // go through all bonds and add as well
922 for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner) {
923 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
924 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
925 BondRunner != ListOfBonds.end();
926 ++BondRunner)
927 if ((*BondRunner)->leftatom == *AtomRunner) {
928 Binder = (*BondRunner);
929 if ((CopyAtoms[Binder->leftatom->getNr()] != NULL) && (CopyAtoms[Binder->rightatom->getNr()] != NULL)) {
930 Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->getNr()] << " and " << *CopyAtoms[Binder->rightatom->getNr()]<< "." << endl;
931 Filling->AddBond(CopyAtoms[Binder->leftatom->getNr()], CopyAtoms[Binder->rightatom->getNr()], Binder->BondDegree);
932 }
933 }
934 }
935 }
936 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
937 delete LCList[*ListRunner];
938 delete TesselStruct[(*ListRunner)];
939 }
940};
941
942/** Rotates given molecule \a Filling and moves its atoms according to given
943 * \a RandomAtomDisplacement.
944 *
945 * Note that for rotation to be sensible, the molecule should be centered at
946 * the origin. This is not done here!
947 *
948 * \param &Filling molecule whose atoms to displace
949 * \param RandomAtomDisplacement magnitude of random displacement
950 * \param &Rotations 3D rotation matrix (or unity if no rotation desired)
951 */
952void RandomizeMoleculePositions(
953 molecule *&Filling,
954 double RandomAtomDisplacement,
955 RealSpaceMatrix &Rotations,
956 RandomNumberGenerator &random
957 )
958{
959 const double rng_min = random.min();
960 const double rng_max = random.max();
961
962 Vector AtomTranslations;
963 for(molecule::iterator miter = Filling->begin(); miter != Filling->end(); ++miter) {
964 Vector temp = (*miter)->getPosition();
965 temp *= Rotations;
966 (*miter)->setPosition(temp);
967 // create atomic random translation vector ...
968 for (int i=0;i<NDIM;i++)
969 AtomTranslations[i] = RandomAtomDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
970 (*miter)->setPosition((*miter)->getPosition() + AtomTranslations);
971 }
972}
973
974/** Removes all atoms of a molecule outside.
975 *
976 * If the molecule is empty, it is removed as well.
977 *
978 * @param Filling molecule whose atoms to check, removed if eventually left
979 * empty.
980 * @return true - atoms had to be removed, false - no atoms have been removed
981 */
982bool RemoveAtomsOutsideDomain(molecule *&Filling)
983{
984 bool status = false;
985 Box &Domain = World::getInstance().getDomain();
986 // check if all is still inside domain
987 for(molecule::iterator miter = Filling->begin(); miter != Filling->end(); ) {
988 // check whether each atom is inside box
989 if (!Domain.isInside((*miter)->getPosition())) {
990 status = true;
991 atom *Walker = *miter;
992 ++miter;
993 World::getInstance().destroyAtom(Walker);
994 } else {
995 ++miter;
996 }
997 }
998 if (Filling->empty()) {
999 DoLog(0) && (Log() << Verbose(0) << "Removing molecule " << Filling->getName() << ", all atoms have been removed." << std::endl);
1000 World::getInstance().destroyMolecule(Filling);
1001 Filling = NULL;
1002 }
1003 return status;
1004}
1005
1006/** Checks whether there are no atoms inside a sphere around \a CurrentPosition
1007 * except those atoms present in \a *filler.
1008 * If filler is NULL, then we just call LinkedCell::GetPointsInsideSphere() and
1009 * check whether the return list is empty.
1010 * @param *filler
1011 * @param boundary
1012 * @param CurrentPosition
1013 */
1014bool isSpaceAroundPointVoid(
1015 LinkedCell *LC,
1016 molecule *filler,
1017 const double boundary,
1018 Vector &CurrentPosition)
1019{
1020 size_t compareTo = 0;
1021 TesselPointSTLList* liste = LC->GetPointsInsideSphere(boundary == 0. ? MYEPSILON : boundary, &CurrentPosition);
1022 if (filler != NULL) {
1023 for (TesselPointSTLList::const_iterator iter = liste->begin();
1024 iter != liste->end();
1025 ++iter) {
1026 for (molecule::iterator miter = filler->begin();
1027 miter != filler->end();
1028 ++miter) {
1029 if (*iter == *miter)
1030 ++compareTo;
1031 }
1032 }
1033 }
1034 const bool result = (liste->size() == compareTo);
1035 if (!result) {
1036 DoLog(0) && (Log() << Verbose(0) << "Skipping because of the following atoms:" << std::endl);
1037 for (TesselPointSTLList::const_iterator iter = liste->begin();
1038 iter != liste->end();
1039 ++iter) {
1040 DoLog(0) && (Log() << Verbose(0) << **iter << std::endl);
1041 }
1042 }
1043 delete(liste);
1044 return result;
1045}
1046
1047/** Sets given 3x3 matrix to a random rotation matrix.
1048 *
1049 * @param a matrix to set
1050 */
1051inline void setRandomRotation(RealSpaceMatrix &a)
1052{
1053 double phi[NDIM];
1054 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
1055 const double rng_min = random.min();
1056 const double rng_max = random.max();
1057
1058 for (int i=0;i<NDIM;i++) {
1059 phi[i] = (random()/(rng_max-rng_min))*(2.*M_PI);
1060 std::cout << "Random angle is " << phi[i] << std::endl;
1061 }
1062
1063 a.setRotation(phi);
1064}
1065
1066/** Fills the empty space of the simulation box with water.
1067 * \param *filler molecule which the box is to be filled with
1068 * \param configuration contains box dimensions
1069 * \param distance[NDIM] distance between filling molecules in each direction
1070 * \param boundary length of boundary zone between molecule and filling molecules
1071 * \param RandAtomDisplacement maximum distance for random displacement per atom
1072 * \param RandMolDisplacement maximum distance for random displacement per filler molecule
1073 * \param MinDistance minimum distance to boundary of domain and present molecules
1074 * \param DoRandomRotation true - do random rotations, false - don't
1075 */
1076void FillVoidWithMolecule(
1077 molecule *&filler,
1078 config &configuration,
1079 const double distance[NDIM],
1080 const double boundary,
1081 const double RandomAtomDisplacement,
1082 const double RandomMolDisplacement,
1083 const double MinDistance,
1084 const bool DoRandomRotation
1085 )
1086{
1087 Info FunctionInfo(__func__);
1088 molecule *Filling = NULL;
1089 Vector CurrentPosition;
1090 int N[NDIM];
1091 int n[NDIM];
1092 const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
1093 RealSpaceMatrix Rotations;
1094 const RealSpaceMatrix &MInverse = World::getInstance().getDomain().getMinv();
1095 Vector FillerTranslations;
1096 Vector FillerDistance;
1097 Vector Inserter;
1098 double FillIt = false;
1099 Vector firstInserter;
1100 bool firstInsertion = true;
1101 const Box &Domain = World::getInstance().getDomain();
1102 map<molecule *, LinkedCell *> LCList;
1103 std::vector<molecule *> List = World::getInstance().getAllMolecules();
1104 MoleculeListClass *MolList = World::getInstance().getMolecules();
1105
1106 for (std::vector<molecule *>::iterator ListRunner = List.begin(); ListRunner != List.end(); ListRunner++)
1107 if ((*ListRunner)->getAtomCount() > 0) {
1108 DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
1109 PointCloudAdaptor< molecule > cloud(*ListRunner, (*ListRunner)->name);
1110 LCList[(*ListRunner)] = new LinkedCell(cloud, 10.); // get linked cell list
1111 }
1112
1113 // Center filler at its center of gravity
1114 Vector *gravity = filler->DetermineCenterOfGravity();
1115 filler->CenterAtVector(gravity);
1116 delete gravity;
1117 //const int FillerCount = filler->getAtomCount();
1118 DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl);
1119 for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner) {
1120 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
1121 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
1122 BondRunner != ListOfBonds.end();
1123 ++BondRunner)
1124 if ((*BondRunner)->leftatom == *AtomRunner)
1125 DoLog(2) && (Log() << Verbose(2) << " " << *(*BondRunner) << endl);
1126 }
1127
1128 // calculate filler grid in [0,1]^3
1129 FillerDistance = MInverse * Vector(distance[0], distance[1], distance[2]);
1130 for(int i=0;i<NDIM;i++)
1131 N[i] = (int) ceil(1./FillerDistance[i]);
1132 DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);
1133
1134 // initialize seed of random number generator to current time
1135 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
1136 const double rng_min = random.min();
1137 const double rng_max = random.max();
1138 //srand ( time(NULL) );
1139
1140 // go over [0,1]^3 filler grid
1141 for (n[0] = 0; n[0] < N[0]; n[0]++)
1142 for (n[1] = 0; n[1] < N[1]; n[1]++)
1143 for (n[2] = 0; n[2] < N[2]; n[2]++) {
1144 // calculate position of current grid vector in untransformed box
1145 CurrentPosition = M * Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
1146 // create molecule random translation vector ...
1147 for (int i=0;i<NDIM;i++) // have the random values [-1,1]*RandomMolDisplacement
1148 FillerTranslations[i] = RandomMolDisplacement*(random()/((rng_max-rng_min)/2.) - 1.);
1149 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
1150
1151 // ... and rotation matrix
1152 if (DoRandomRotation)
1153 setRandomRotation(Rotations);
1154 else
1155 Rotations.setIdentity();
1156
1157
1158 // Check whether there is anything too close by and whether atom is outside of domain
1159 FillIt = true;
1160 for (std::map<molecule *, LinkedCell *>::iterator ListRunner = LCList.begin(); ListRunner != LCList.end(); ++ListRunner) {
1161 FillIt = FillIt && isSpaceAroundPointVoid(
1162 ListRunner->second,
1163 (firstInsertion ? filler : NULL),
1164 boundary,
1165 CurrentPosition);
1166 FillIt = FillIt && (Domain.isInside(CurrentPosition))
1167 && ((Domain.DistanceToBoundary(CurrentPosition) - MinDistance) > -MYEPSILON);
1168 if (!FillIt)
1169 break;
1170 }
1171
1172 // insert into Filling
1173 if (FillIt) {
1174 Inserter = CurrentPosition + FillerTranslations;
1175 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is void point." << endl);
1176 // fill!
1177 Filling = filler->CopyMolecule();
1178 RandomizeMoleculePositions(Filling, RandomAtomDisplacement, Rotations, random);
1179 // translation
1180 Filling->Translate(&Inserter);
1181 // remove out-of-bounds atoms
1182 const bool status = RemoveAtomsOutsideDomain(Filling);
1183 if ((firstInsertion) && (!status)) { // no atom has been removed
1184 // remove copied atoms and molecule again
1185 Filling->removeAtomsinMolecule();
1186 World::getInstance().destroyMolecule(Filling);
1187 // and mark is final filler position
1188 Filling = filler;
1189 firstInsertion = false;
1190 firstInserter = Inserter;
1191 } else {
1192 // TODO: Remove when World has no MoleculeListClass anymore
1193 if (Filling)
1194 MolList->insert(Filling);
1195 }
1196 } else {
1197 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is non-void point, within boundary or outside of MaxDistance." << endl);
1198 continue;
1199 }
1200 }
1201
1202 // have we inserted any molecules?
1203 if (firstInsertion) {
1204 // If not remove filler
1205 for(molecule::iterator miter = filler->begin(); !filler->empty(); miter = filler->begin()) {
1206 atom *Walker = *miter;
1207 World::getInstance().destroyAtom(Walker);
1208 }
1209 World::getInstance().destroyMolecule(filler);
1210 } else {
1211 // otherwise translate and randomize to final position
1212 if (DoRandomRotation)
1213 setRandomRotation(Rotations);
1214 else
1215 Rotations.setIdentity();
1216 RandomizeMoleculePositions(filler, RandomAtomDisplacement, Rotations, random);
1217 // translation
1218 filler->Translate(&firstInserter);
1219 // remove out-of-bounds atoms
1220 RemoveAtomsOutsideDomain(filler);
1221 }
1222
1223 DoLog(0) && (Log() << Verbose(0) << MolList->ListOfMolecules.size() << " molecules have been inserted." << std::endl);
1224
1225 for (std::map<molecule *, LinkedCell *>::iterator ListRunner = LCList.begin(); !LCList.empty(); ListRunner = LCList.begin()) {
1226 delete ListRunner->second;
1227 LCList.erase(ListRunner);
1228 }
1229};
1230
1231/** Tesselates the non convex boundary by rolling a virtual sphere along the surface of the molecule.
1232 * \param *out output stream for debugging
1233 * \param *mol molecule structure with Atom's and Bond's
1234 * \param *&TesselStruct Tesselation filled with points, lines and triangles on boundary on return
1235 * \param *&LCList atoms in LinkedCell list
1236 * \param RADIUS radius of the virtual sphere
1237 * \param *filename filename prefix for output of vertex data
1238 * \return true - tesselation successful, false - tesselation failed
1239 */
1240bool FindNonConvexBorder(molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LCList, const double RADIUS, const char *filename = NULL)
1241{
1242 Info FunctionInfo(__func__);
1243 bool freeLC = false;
1244 bool status = false;
1245 CandidateForTesselation *baseline = NULL;
1246 bool OneLoopWithoutSuccessFlag = true; // marks whether we went once through all baselines without finding any without two triangles
1247 bool TesselationFailFlag = false;
1248
1249 mol->getAtomCount();
1250
1251 if (TesselStruct == NULL) {
1252 DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);
1253 TesselStruct= new Tesselation;
1254 } else {
1255 delete(TesselStruct);
1256 DoLog(1) && (Log() << Verbose(1) << "Re-Allocating Tesselation struct ..." << endl);
1257 TesselStruct = new Tesselation;
1258 }
1259
1260 // initialise Linked Cell
1261 PointCloudAdaptor< molecule > cloud(mol, mol->name);
1262 if (LCList == NULL) {
1263 LCList = new LinkedCell(cloud, 2.*RADIUS);
1264 freeLC = true;
1265 }
1266
1267 // 1. get starting triangle
1268 if (!TesselStruct->FindStartingTriangle(RADIUS, LCList)) {
1269 DoeLog(0) && (eLog() << Verbose(0) << "No valid starting triangle found." << endl);
1270 //performCriticalExit();
1271 }
1272 if (filename != NULL) {
1273 if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
1274 TesselStruct->Output(filename, cloud);
1275 }
1276 }
1277
1278 // 2. expand from there
1279 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
1280 (cerr << "There are " << TesselStruct->TrianglesOnBoundary.size() << " triangles and " << TesselStruct->OpenLines.size() << " open lines to scan for candidates." << endl);
1281 // 2a. print OpenLines without candidates
1282 DoLog(1) && (Log() << Verbose(1) << "There are the following open lines to scan for a candidates:" << endl);
1283 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
1284 if (Runner->second->pointlist.empty())
1285 DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl);
1286
1287 // 2b. find best candidate for each OpenLine
1288 TesselationFailFlag = TesselStruct->FindCandidatesforOpenLines(RADIUS, LCList);
1289
1290 // 2c. print OpenLines with candidates again
1291 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl);
1292 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
1293 DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl);
1294
1295 // 2d. search for smallest ShortestAngle among all candidates
1296 double ShortestAngle = 4.*M_PI;
1297 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
1298 if (Runner->second->ShortestAngle < ShortestAngle) {
1299 baseline = Runner->second;
1300 ShortestAngle = baseline->ShortestAngle;
1301 DoLog(1) && (Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl);
1302 }
1303 }
1304 // 2e. if we found one, add candidate
1305 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
1306 OneLoopWithoutSuccessFlag = false;
1307 else {
1308 TesselStruct->AddCandidatePolygon(*baseline, RADIUS, LCList);
1309 }
1310
1311 // 2f. write temporary envelope
1312 if (filename != NULL) {
1313 if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
1314 TesselStruct->Output(filename, cloud);
1315 }
1316 }
1317 }
1318// // check envelope for consistency
1319// status = CheckListOfBaselines(TesselStruct);
1320//
1321// // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
1322// //->InsertStraddlingPoints(mol, LCList);
1323// for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
1324// class TesselPoint *Runner = NULL;
1325// Runner = *iter;
1326// Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl;
1327// if (!->IsInnerPoint(Runner, LCList)) {
1328// Log() << Verbose(2) << Runner->Name << " is outside of envelope, adding via degenerated triangles." << endl;
1329// ->AddBoundaryPointByDegeneratedTriangle(Runner, LCList);
1330// } else {
1331// Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl;
1332// }
1333// }
1334
1335// // Purges surplus triangles.
1336// TesselStruct->RemoveDegeneratedTriangles();
1337//
1338// // check envelope for consistency
1339// status = CheckListOfBaselines(TesselStruct);
1340
1341 cout << "before correction" << endl;
1342
1343 // store before correction
1344 StoreTrianglesinFile(mol, TesselStruct, filename, "");
1345
1346// // correct degenerated polygons
1347// TesselStruct->CorrectAllDegeneratedPolygons();
1348//
1349 // check envelope for consistency
1350 status = CheckListOfBaselines(TesselStruct);
1351
1352 // write final envelope
1353 CalculateConcavityPerBoundaryPoint(TesselStruct);
1354 cout << "after correction" << endl;
1355 StoreTrianglesinFile(mol, TesselStruct, filename, "");
1356
1357 if (freeLC)
1358 delete(LCList);
1359
1360 return status;
1361};
1362
1363
1364/** Finds a hole of sufficient size in \a *mols to embed \a *srcmol into it.
1365 * \param *out output stream for debugging
1366 * \param *mols molecules in the domain to embed in between
1367 * \param *srcmol embedding molecule
1368 * \return *Vector new center of \a *srcmol for embedding relative to \a this
1369 */
1370Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol)
1371{
1372 Info FunctionInfo(__func__);
1373 Vector *Center = new Vector;
1374 Center->Zero();
1375 // calculate volume/shape of \a *srcmol
1376
1377 // find embedding holes
1378
1379 // if more than one, let user choose
1380
1381 // return embedding center
1382 return Center;
1383};
1384
Note: See TracBrowser for help on using the repository browser.