source: src/Actions/FillAction/FillRegularGridAction.cpp@ 345eda

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

Enhanced FillRegularGridAction to avoid tesselated surfaces.

  • selected molecules (if any) are now tesselated ans IsInsideSurface is used to only fill outside.
  • Property mode set to 100644
File size: 8.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-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 * FillRegularGridAction.cpp
10 *
11 * Created on: Jan 12, 2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "Atom/atom.hpp"
23#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
24#include "CodePatterns/Log.hpp"
25#include "Descriptors/MoleculeOrderDescriptor.hpp"
26#include "Filling/Cluster.hpp"
27#include "Filling/Filler.hpp"
28#include "Filling/Mesh/CubeMesh.hpp"
29#include "Filling/Predicates/IsInsideSurface_FillPredicate.hpp"
30#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
31#include "Filling/Predicates/Ops_FillPredicate.hpp"
32#include "LinkedCell/linkedcell.hpp"
33#include "LinkedCell/PointCloudAdaptor.hpp"
34#include "molecule.hpp"
35#include "MoleculeListClass.hpp"
36#include "Parser/FormatParserInterface.hpp"
37#include "Parser/FormatParserStorage.hpp"
38#include "Shapes/BaseShapes.hpp"
39#include "Tesselation/tesselation.hpp"
40#include "Tesselation/BoundaryLineSet.hpp"
41#include "Tesselation/BoundaryTriangleSet.hpp"
42#include "Tesselation/CandidateForTesselation.hpp"
43#include "World.hpp"
44
45
46#include <algorithm>
47#include <iostream>
48#include <string>
49#include <vector>
50
51#include "Actions/FillAction/FillRegularGridAction.hpp"
52
53using namespace MoleCuilder;
54
55// and construct the stuff
56#include "FillRegularGridAction.def"
57#include "Action_impl_pre.hpp"
58/** =========== define the function ====================== */
59Action::state_ptr FillRegularGridAction::performCall() {
60 typedef std::vector<atom*> AtomVector;
61
62 // obtain information
63 getParametersfromValueStorage();
64
65 // get all present atoms for UndoState
66 AtomVector presentatoms = World::getInstance().getAllAtoms();
67
68 // get selected atoms and find containing sphere
69 World::AtomComposite atoms = World::getInstance().getSelectedAtoms();
70 if (atoms.size() == 0) {
71 ELOG(2, "No atoms selected, aborting,");
72 return Action::failure;
73 }
74
75 Vector center;
76 double radius = 0.;
77 {
78 center.Zero();
79 for(World::AtomComposite::const_iterator iter = atoms.begin();
80 iter != atoms.end(); ++iter)
81 center += (*iter)->getPosition();
82 center *= 1./(double)atoms.size();
83 for(World::AtomComposite::const_iterator iter = atoms.begin();
84 iter != atoms.end(); ++iter) {
85 const Vector &position = (*iter)->getPosition();
86 for (size_t i=0;i<NDIM;++i) {
87 const double temp_distance = fabs(position[i] - center[i]);
88 if (temp_distance > radius)
89 radius = temp_distance;
90 }
91 }
92 }
93 // always move cluster to be centered at origin
94 for(World::AtomComposite::iterator iter = atoms.begin();
95 iter != atoms.end(); ++iter)
96 (*iter)->setPosition((*iter)->getPosition() - center);
97 if (radius == 0.) { // never have zero radius: set to one or less
98 ASSERT( (params.counts[0] != 0.) && (params.counts[1] != 0.) && (params.counts[2] != 0.),
99 "FillRegularGridAction::performCall() - counts must not be zero.");
100 const Vector diag(1./(double)(params.counts[0]+1), 1./(double)(params.counts[1]+1), 1./(double)(params.counts[2]+1));
101 radius = std::min(1.,World::getInstance().getDomain().translateIn(diag).Norm()/2.);
102 }
103 // add some small boundary
104 radius += 1e+6*std::numeric_limits<double>::epsilon();
105 radius = std::max(params.mindistance, radius);
106 LOG(2, "INFO: The " << atoms.size() << " are contained in a sphere at "
107 << center << " with radius " << radius << ".");
108 Shape *s = new Shape(Sphere(zeroVec, radius));
109 LOG(2, "INFO: Created sphere at " << s->getCenter() << " and radius " << s->getRadius() << ".");
110
111 // create set of atomic ids
112 std::vector<atomId_t> atomIds(atoms.size(), (size_t)-1);
113 std::transform(atoms.begin(), atoms.end(), atomIds.begin(),
114 boost::bind(&atom::getId, _1) );
115 Cluster::atomIdSet atomset(atomIds.begin(), atomIds.end());
116 LOG(2, "INFO: Created atomset of size " << atomset.size() << ".");
117
118 // create cluster
119 ClusterInterface::Cluster_impl cluster(new Cluster(atomset, *s));
120 LOG(2, "INFO: Created cluster of size " << atomset.size() << ".");
121
122 // check for selected molecules and create surfaces from them
123 const std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
124 typedef std::list<FillPredicate *> predicate_list_t;
125 typedef std::list<LinkedCell_deprecated *> LC_list_t;
126 typedef std::list<Tesselation *> Tesselation_list_t;
127 predicate_list_t surface_predicate_list;
128 LC_list_t LinkedCell_deprecated_list;
129 Tesselation_list_t Tesselation_list;
130 if (params.SphereRadius != 0.) {
131 if ( molecules.size() == 0) {
132 ELOG(1, "You have given a sphere radius " << params.SphereRadius
133 << " != 0, but have not select any molecules.");
134 }
135 for (std::vector<molecule *>::const_iterator iter = molecules.begin();
136 iter != molecules.end(); ++iter) {
137 // create adaptor for the current molecule
138 PointCloudAdaptor< molecule > cloud(*iter, (*iter)->name);
139 LinkedCell_deprecated_list.push_back(
140 new LinkedCell_deprecated(cloud, 2.*params.SphereRadius)
141 );
142
143 // create tesselation
144 Tesselation_list.push_back(
145 new Tesselation
146 );
147 (*Tesselation_list.back())(cloud, params.SphereRadius);
148
149 // and create predicate
150 surface_predicate_list.push_back(
151 new FillPredicate( IsInsideSurface_FillPredicate(
152 *Tesselation_list.back(),
153 *LinkedCell_deprecated_list.back()) )
154 );
155 }
156 }
157
158 // create predicate, mesh, and filler
159 {
160 FillPredicate *voidnode_predicate = new FillPredicate( IsVoidNode_FillPredicate(*s) );
161 FillPredicate Andpredicate = (*voidnode_predicate);
162 for (predicate_list_t::iterator iter = surface_predicate_list.begin();
163 iter != surface_predicate_list.end(); ++iter)
164 Andpredicate = (Andpredicate) && !(**iter);
165 Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
166 Filler *fillerFunction = new Filler(*mesh, Andpredicate);
167
168 // fill
169 CopyAtoms_withBonds copyMethod;
170 (*fillerFunction)(copyMethod, cluster);
171
172 // remove
173 delete fillerFunction;
174 delete mesh;
175 delete voidnode_predicate;
176 for (LC_list_t::iterator iter = LinkedCell_deprecated_list.begin();
177 iter != LinkedCell_deprecated_list.end(); ++iter)
178 delete (*iter);
179 LinkedCell_deprecated_list.clear();
180 for (Tesselation_list_t::iterator iter = Tesselation_list.begin();
181 iter != Tesselation_list.end(); ++iter)
182 delete (*iter);
183 Tesselation_list.clear();
184 delete s;
185 }
186
187 // generate list of newly created atoms
188 // (we can in general remove more quickly from a list than a vector)
189 AtomVector filleratoms = World::getInstance().getAllAtoms();
190// LOG(0, filleratoms.size() << " atoms are present.");
191 std::list<atom *> filleratoms_list;
192 std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list ));
193// LOG(0, filleratoms_list.size() << " atoms have been copied.");
194 for (AtomVector::const_iterator iter = presentatoms.begin();
195 iter != presentatoms.end();
196 ++iter) {
197 filleratoms_list.remove(*iter);
198 }
199// LOG(0, filleratoms_list.size() << " atoms left after removal.");
200 filleratoms.clear();
201 std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
202
203// LOG(0, filleratoms.size() << " atoms have been inserted.");
204
205 return Action::state_ptr(new FillRegularGridState(filleratoms,params));
206}
207
208Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
209// FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
210//
211// BOOST_FOREACH(atom *_atom, state->filleratoms) {
212// World::getInstance().destroyAtom(Walker);
213// }
214//
215// // as atoms and atoms from state are removed, we have to create a new one
216// std::vector<atom*> filleratoms;
217// return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
218 return Action::failure;
219}
220
221Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
222 //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
223
224 return Action::failure;
225 //return Action::state_ptr(_state);
226}
227
228bool FillRegularGridAction::canUndo() {
229 return false;
230}
231
232bool FillRegularGridAction::shouldUndo() {
233 return false;
234}
235/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.