source: src/Filling/Generators/NodeGenerator.cpp@ 595cfd

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 595cfd was 595cfd, checked in by Frederik Heber <heber@…>, 13 years ago

Added NodeGenerator.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * NodeGenerator.cpp
10 *
11 *
12 * Created on: Jan 16, 2012
13 * Author: heber
14 */
15
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include "CodePatterns/MemDebug.hpp"
23
24#include "NodeGenerator.hpp"
25
26#include <cmath>
27#include <vector>
28
29#include "Shapes/Shape.hpp"
30#include "Shapes/ShapeOps.hpp"
31
32/** Constructor for NodeGenerator.
33 *
34 * @param _shape Shape which is to be filled with nodes
35 */
36NodeGenerator::NodeGenerator(const Shape &_shape) :
37 shape(_shape)
38{}
39
40/** Destructor for NodeGenerator.
41 *
42 */
43NodeGenerator::~NodeGenerator()
44{}
45
46/** Returns a set of points contained in the \a NodeGenerator::_shape
47 * with a homogeneous density.
48 *
49 * The central idea of the algorithm is to make use of the present function
50 * for obtaining homogeneously distributed points on all surfaces of
51 * presently implemented Shape's.
52 *
53 * The given \a _shape is shrinked such that eventually the volume is filled
54 * with points. Points filled in that actually reside outside the given
55 * Shape are eventually extracted as all are checked for inclusion.
56 *
57 * \note Although a certain density of points given as it has to be converted
58 * to an discrete regime this density can in general be matched only
59 * approximately.
60 *
61 * @param density desired density of points, the unit is the inverse of the
62 * required volume per point
63 * @return set of nodes
64 */
65NodeSet NodeGenerator::operator()(const double density)
66{
67 // calculate volume and surface of the given Shape
68 const double volume = shape.getVolume();
69 const double surface = shape.getSurfaceArea();
70
71 // calculate the number of shrinking operations
72 const double radius = shape.getRadius();
73 const double fraction = surface/volume;
74 const int factor = floor(radius * fraction);
75
76 // calculate correction for surface density due to discrete number of layers
77 const double surfaceDensity = volume/(double)factor;
78
79 // fill the shrinking vector
80 std::vector<double> shrinking_factors;
81 for(int f=0; f < factor; ++f)
82 shrinking_factors.push_back(radius*((double)f/(double)factor));
83
84 // go through the shrinking operations
85 NodeSet nodes;
86 for (std::vector<double>::const_iterator iter = shrinking_factors.begin();
87 iter != shrinking_factors.end(); ++iter) {
88 const Shape currentShape = resize(shape, *iter);
89 std::vector<Vector> pointsOnSurface =
90 currentShape.getHomogeneousPointsOnSurface(surfaceDensity);
91 nodes.insert(nodes.end(), pointsOnSurface.begin(), pointsOnSurface.end());
92 }
93
94 // check each point whether its inside the surface
95 return filterOutsidePoints(nodes);
96}
97
98/** Filters out all points that are not contained inside NodeGenerator::shape.
99 *
100 * @param nodes nodes to check
101 * @return subset of nodes that fulfill Shape::isInisde().
102 */
103NodeSet NodeGenerator::filterOutsidePoints(const NodeSet &nodes) const
104{
105 NodeSet return_nodes;
106 return_nodes.reserve(nodes.size());
107 for (NodeSet::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
108 if (shape.isInside(*iter))
109 return_nodes.push_back(*iter);
110 }
111
112 return return_nodes;
113}
Note: See TracBrowser for help on using the repository browser.