source: src/Actions/FillAction/FillRegularGridAction.cpp@ a88452

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

Added new Action subfolder, menu, and CommandLine options map, and FillRegularGrid Action in it.

  • counts, offset and min-distance as parameters that determine the filling.
  • we find bounding sphere for the selected set of atoms.
  • CopyAtoms_withBonds is used in cloning the cluster.
  • libMolecuilderFilling added to libMolecuilderUI.
  • Property mode set to 100644
File size: 5.9 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 Vector center;
62 double radius = 0.;
63 {
64 center.Zero();
65 for(World::AtomComposite::const_iterator iter = atoms.begin();
66 iter != atoms.end(); ++iter)
67 center += (*iter)->getPosition();
68 center *= 1./(double)atoms.size();
69 for(World::AtomComposite::const_iterator iter = atoms.begin();
70 iter != atoms.end(); ++iter) {
71 const Vector &position = (*iter)->getPosition();
72 for (size_t i=0;i<NDIM;++i) {
73 const double temp_distance = fabs(position[i] - center[i]);
74 if (temp_distance > radius)
75 radius = temp_distance;
76 }
77 }
78 }
79 // always move cluster to be centered at origin
80 for(World::AtomComposite::iterator iter = atoms.begin();
81 iter != atoms.end(); ++iter)
82 (*iter)->setPosition((*iter)->getPosition() - center);
83 if (radius == 0.) { // never have zero radius: set to one or less
84 ASSERT( (params.counts[0] != 0.) && (params.counts[1] != 0.) && (params.counts[2] != 0.),
85 "FillRegularGridAction::performCall() - counts must not be zero.");
86 const Vector diag(1./(double)(params.counts[0]+1), 1./(double)(params.counts[1]+1), 1./(double)(params.counts[2]+1));
87 radius = std::min(1.,World::getInstance().getDomain().translateIn(diag).Norm()/2.);
88 }
89 // add some small boundary
90 radius += 1e+6*std::numeric_limits<double>::epsilon();
91 radius = std::max(params.mindistance, radius);
92 LOG(1, "INFO: The " << atoms.size() << " are contained in a sphere at "
93 << center << " with radius " << radius << ".");
94 Shape *s = new Shape(Sphere(zeroVec, radius));
95 LOG(1, "INFO: Created sphere at " << s->getCenter() << " and radius " << s->getRadius() << ".");
96
97 // create set of atomic ids
98 std::vector<atomId_t> atomIds(atoms.size(), (size_t)-1);
99 std::transform(atoms.begin(), atoms.end(), atomIds.begin(),
100 boost::bind(&atom::getId, _1) );
101 Cluster::atomIdSet atomset(atomIds.begin(), atomIds.end());
102 LOG(1, "INFO: Created atomset of size " << atomset.size() << ".");
103
104 // create cluster
105 ClusterInterface::Cluster_impl cluster(new Cluster(atomset, *s));
106 LOG(1, "INFO: Created cluster of size " << atomset.size() << ".");
107
108 // create predicate, mesh, and filler
109 {
110 FillPredicate *predicate = new FillPredicate( IsVoidNode_FillPredicate(*s) );
111 Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
112 Filler *fillerFunction = new Filler(*mesh, *predicate);
113
114 // fill
115 CopyAtoms_withBonds copyMethod;
116 (*fillerFunction)(copyMethod, cluster);
117
118 // remove
119 delete fillerFunction;
120 delete mesh;
121 delete predicate;
122 delete s;
123 }
124
125 // generate list of newly created atoms
126 // (we can in general remove more quickly from a list than a vector)
127 AtomVector filleratoms = World::getInstance().getAllAtoms();
128// LOG(0, filleratoms.size() << " atoms are present.");
129 std::list<atom *> filleratoms_list;
130 std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list ));
131// LOG(0, filleratoms_list.size() << " atoms have been copied.");
132 for (AtomVector::const_iterator iter = presentatoms.begin();
133 iter != presentatoms.end();
134 ++iter) {
135 filleratoms_list.remove(*iter);
136 }
137// LOG(0, filleratoms_list.size() << " atoms left after removal.");
138 filleratoms.clear();
139 std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
140
141// LOG(0, filleratoms.size() << " atoms have been inserted.");
142
143 return Action::state_ptr(new FillRegularGridState(filleratoms,params));
144}
145
146Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
147// FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
148//
149// BOOST_FOREACH(atom *_atom, state->filleratoms) {
150// World::getInstance().destroyAtom(Walker);
151// }
152//
153// // as atoms and atoms from state are removed, we have to create a new one
154// std::vector<atom*> filleratoms;
155// return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
156 return Action::failure;
157}
158
159Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
160 //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
161
162 return Action::failure;
163 //return Action::state_ptr(_state);
164}
165
166bool FillRegularGridAction::canUndo() {
167 return false;
168}
169
170bool FillRegularGridAction::shouldUndo() {
171 return false;
172}
173/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.