source: src/Actions/FillAction/FillRegularGridAction.cpp@ 5a4cbc

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

VERBOSITY: Increased verbosity threshold of some outputs connected to FillRegularGridAction.

  • Property mode set to 100644
File size: 6.1 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/IsVoidNode_FillPredicate.hpp"
30#include "MoleculeListClass.hpp"
31#include "Parser/FormatParserInterface.hpp"
32#include "Parser/FormatParserStorage.hpp"
33#include "Shapes/BaseShapes.hpp"
34#include "World.hpp"
35
36
37#include <algorithm>
38#include <iostream>
39#include <string>
40#include <vector>
41
42#include "Actions/FillAction/FillRegularGridAction.hpp"
43
44using namespace MoleCuilder;
45
46// and construct the stuff
47#include "FillRegularGridAction.def"
48#include "Action_impl_pre.hpp"
49/** =========== define the function ====================== */
50Action::state_ptr FillRegularGridAction::performCall() {
51 typedef std::vector<atom*> AtomVector;
52
53 // obtain information
54 getParametersfromValueStorage();
55
56 // get all present atoms for UndoState
57 AtomVector presentatoms = World::getInstance().getAllAtoms();
58
59 // get selected atoms and find containing sphere
60 World::AtomComposite atoms = World::getInstance().getSelectedAtoms();
61 if (atoms.size() == 0) {
62 ELOG(2, "No atoms selected, aborting,");
63 return Action::failure;
64 }
65
66 Vector center;
67 double radius = 0.;
68 {
69 center.Zero();
70 for(World::AtomComposite::const_iterator iter = atoms.begin();
71 iter != atoms.end(); ++iter)
72 center += (*iter)->getPosition();
73 center *= 1./(double)atoms.size();
74 for(World::AtomComposite::const_iterator iter = atoms.begin();
75 iter != atoms.end(); ++iter) {
76 const Vector &position = (*iter)->getPosition();
77 for (size_t i=0;i<NDIM;++i) {
78 const double temp_distance = fabs(position[i] - center[i]);
79 if (temp_distance > radius)
80 radius = temp_distance;
81 }
82 }
83 }
84 // always move cluster to be centered at origin
85 for(World::AtomComposite::iterator iter = atoms.begin();
86 iter != atoms.end(); ++iter)
87 (*iter)->setPosition((*iter)->getPosition() - center);
88 if (radius == 0.) { // never have zero radius: set to one or less
89 ASSERT( (params.counts[0] != 0.) && (params.counts[1] != 0.) && (params.counts[2] != 0.),
90 "FillRegularGridAction::performCall() - counts must not be zero.");
91 const Vector diag(1./(double)(params.counts[0]+1), 1./(double)(params.counts[1]+1), 1./(double)(params.counts[2]+1));
92 radius = std::min(1.,World::getInstance().getDomain().translateIn(diag).Norm()/2.);
93 }
94 // add some small boundary
95 radius += 1e+6*std::numeric_limits<double>::epsilon();
96 radius = std::max(params.mindistance, radius);
97 LOG(2, "INFO: The " << atoms.size() << " are contained in a sphere at "
98 << center << " with radius " << radius << ".");
99 Shape *s = new Shape(Sphere(zeroVec, radius));
100 LOG(2, "INFO: Created sphere at " << s->getCenter() << " and radius " << s->getRadius() << ".");
101
102 // create set of atomic ids
103 std::vector<atomId_t> atomIds(atoms.size(), (size_t)-1);
104 std::transform(atoms.begin(), atoms.end(), atomIds.begin(),
105 boost::bind(&atom::getId, _1) );
106 Cluster::atomIdSet atomset(atomIds.begin(), atomIds.end());
107 LOG(2, "INFO: Created atomset of size " << atomset.size() << ".");
108
109 // create cluster
110 ClusterInterface::Cluster_impl cluster(new Cluster(atomset, *s));
111 LOG(2, "INFO: Created cluster of size " << atomset.size() << ".");
112
113 // create predicate, mesh, and filler
114 {
115 FillPredicate *predicate = new FillPredicate( IsVoidNode_FillPredicate(*s) );
116 Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
117 Filler *fillerFunction = new Filler(*mesh, *predicate);
118
119 // fill
120 CopyAtoms_withBonds copyMethod;
121 (*fillerFunction)(copyMethod, cluster);
122
123 // remove
124 delete fillerFunction;
125 delete mesh;
126 delete predicate;
127 delete s;
128 }
129
130 // generate list of newly created atoms
131 // (we can in general remove more quickly from a list than a vector)
132 AtomVector filleratoms = World::getInstance().getAllAtoms();
133// LOG(0, filleratoms.size() << " atoms are present.");
134 std::list<atom *> filleratoms_list;
135 std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list ));
136// LOG(0, filleratoms_list.size() << " atoms have been copied.");
137 for (AtomVector::const_iterator iter = presentatoms.begin();
138 iter != presentatoms.end();
139 ++iter) {
140 filleratoms_list.remove(*iter);
141 }
142// LOG(0, filleratoms_list.size() << " atoms left after removal.");
143 filleratoms.clear();
144 std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
145
146// LOG(0, filleratoms.size() << " atoms have been inserted.");
147
148 return Action::state_ptr(new FillRegularGridState(filleratoms,params));
149}
150
151Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
152// FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
153//
154// BOOST_FOREACH(atom *_atom, state->filleratoms) {
155// World::getInstance().destroyAtom(Walker);
156// }
157//
158// // as atoms and atoms from state are removed, we have to create a new one
159// std::vector<atom*> filleratoms;
160// return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
161 return Action::failure;
162}
163
164Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
165 //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
166
167 return Action::failure;
168 //return Action::state_ptr(_state);
169}
170
171bool FillRegularGridAction::canUndo() {
172 return false;
173}
174
175bool FillRegularGridAction::shouldUndo() {
176 return false;
177}
178/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.