source: src/Filling/Filler.cpp@ e32fa6

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

Modified Filler:operator() such that Inserters only modify position, not clone.

  • Property mode set to 100644
File size: 3.8 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 * Filler.cpp
10 *
11 * Created on: Jan 16, 2012
12 * Author: heber
13 */
14
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "CodePatterns/MemDebug.hpp"
22
23#include <algorithm>
24#include <boost/bind.hpp>
25#include <boost/lambda/lambda.hpp>
26#include <sstream>
27#include <vector>
28
29#include "Filler.hpp"
30
31#include "CodePatterns/Assert.hpp"
32#include "CodePatterns/Log.hpp"
33
34#include "Atom/atom.hpp"
35#include "ClusterInterface.hpp"
36#include "Descriptors/AtomIdDescriptor.hpp"
37#include "Inserter/Inserter.hpp"
38#include "LinearAlgebra/Vector.hpp"
39#include "NodeTypes.hpp"
40#include "Predicates/FillPredicate.hpp"
41#include "Predicates/Ops_FillPredicate.hpp"
42#include "World.hpp"
43
44
45/** Constructor for class Filler.
46 *
47 * \note We store inverted \a _predicate because we need it only for
48 * remove_copy_if which works in this inverted way as desired.
49 *
50 * @param _mesh Mesh with a NodeSet that fills its Shape
51 * @param _predicate predicate construct to check at each Node
52 * @param _inserter inserter which places the cloned cluster
53 */
54Filler::Filler(const Mesh &_mesh, const FillPredicate &_predicate, const Inserter &_inserter) :
55 mesh(_mesh),
56 predicate(!_predicate),
57 inserter(_inserter)
58{}
59
60/** Destructor for class Filler.
61 *
62 */
63Filler::~Filler()
64{}
65
66/** Fill in the desired Cluster at each remaining node.
67 *
68 * \note The cluster is non-const because it is moved to the first vacant node.
69 *
70 * @param copyMethod functor that knows how to copy atoms.
71 * @param cluster set of atomic ids contained in a specific Shape to fill each Node with
72 * @return true - at least one node has been filled, false - no node filled
73 */
74bool Filler::operator()(
75 CopyAtomsInterface &copyMethod,
76 ClusterInterface::Cluster_impl cluster) const
77{
78 const NodeSet &nodes = mesh.getNodes();
79 std::stringstream output;
80 std::for_each( nodes.begin(), nodes.end(), output << boost::lambda::_1 << " ");
81 LOG(3, "DEBUG: Listing nodes to check: " << output.str());
82 if (nodes.size() == 0)
83 return false;
84 NodeSet FillNodes(nodes.size(), zeroVec);
85
86 // evaluate predicate and gather into new set
87 NodeSet::iterator transform_end =
88 std::remove_copy_if(nodes.begin(), nodes.end(), FillNodes.begin(), predicate );
89 FillNodes.erase(transform_end, FillNodes.end());
90
91 if (FillNodes.size() == 0) {
92 ELOG(2, "For none of the nodes did the predicate return true.");
93 return false;
94 } else {
95 LOG(1, "INFO: " << FillNodes.size() << " out of " << nodes.size() << " returned true from predicate.");
96 }
97
98 // clone clusters
99 std::vector<ClusterInterface::Cluster_impl> clusters(FillNodes.size());
100 std::vector<ClusterInterface::Cluster_impl>::iterator clusteriter = clusters.begin();
101 *clusteriter = cluster;
102 clusteriter++;
103 std::generate_n(clusteriter, FillNodes.size()-1,
104 boost::bind(&ClusterInterface::clone, boost::cref(cluster), boost::ref(copyMethod), zeroVec) );
105
106 // insert each cluster by abusing std::search a bit:
107 // we look for the subsequence of FillNodes inside clusters. If Inserter always
108 // returns true, we'll have the iterator pointing at first cluster
109 std::vector<ClusterInterface::Cluster_impl>::const_iterator inserteriter =
110 std::search(clusters.begin(), clusters.end(), FillNodes.begin(), FillNodes.end(),
111 boost::bind(&Inserter::operator(), boost::cref(inserter), _1, _2));
112 if( inserteriter != clusters.begin()) {
113 ELOG(1, "Not all cloned clusters could be successfully inserted.");
114 return false;
115 }
116
117 // give final statment on whether at least \a single cluster has been placed
118 if ( FillNodes.size() != 0)
119 return true;
120 else
121 return false;
122}
123
Note: See TracBrowser for help on using the repository browser.