source: src/Actions/FillAction/FillSphericalSurfaceAction.cpp@ be6b3a

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 be6b3a was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.0 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 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * FillSphericalSurfaceAction.cpp
25 *
26 * Created on: Mar 29, 2012
27 * Author: heber, bollerhe
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "Actions/UndoRedoHelpers.hpp"
38#include "Atom/atom.hpp"
39#include "Atom/AtomicInfo.hpp"
40#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
41#include "CodePatterns/Log.hpp"
42#include "Filling/Cluster.hpp"
43#include "Filling/Filler.hpp"
44#include "Filling/Inserter/Inserter.hpp"
45#include "Filling/Inserter/SurfaceInserter.hpp"
46#include "Filling/Mesh/MeshAdaptor.hpp"
47#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
48#include "molecule.hpp"
49#include "Shapes/BaseShapes.hpp"
50#include "World.hpp"
51
52
53#include <algorithm>
54#include <boost/foreach.hpp>
55#include <boost/function.hpp>
56#include <iostream>
57#include <string>
58#include <vector>
59
60#include "Actions/FillAction/FillSphericalSurfaceAction.hpp"
61
62using namespace MoleCuilder;
63
64// and construct the stuff
65#include "FillSphericalSurfaceAction.def"
66#include "Action_impl_pre.hpp"
67/** =========== define the function ====================== */
68Action::state_ptr FillSphericalSurfaceAction::performCall() {
69 // get the filler molecule
70 const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules();
71 std::vector<AtomicInfo> movedatoms;
72 if (molecules.size() != 1) {
73 ELOG(1, "No exactly one molecule selected, aborting,");
74 return Action::failure;
75 }
76 molecule *filler = *(molecules.begin());
77 for(molecule::const_iterator iter = filler->begin(); iter != filler->end(); ++iter)
78 movedatoms.push_back( AtomicInfo(*(*iter)) );
79 LOG(1, "INFO: Chosen molecule has " << filler->size() << " atoms.");
80
81 // center filler's tip at origin
82 Vector max;
83 filler->CenterEdge(&max);
84
85 // determine center with respect to alignment axis
86 Vector sum = zeroVec;
87 for (molecule::iterator it2=filler->begin();it2 !=filler->end();++it2) {
88 const Vector helper = (**it2).getPosition().partition(params.AlignedAxis.get()).second;
89 sum += helper;
90 }
91 sum *= 1./filler->size();
92
93 // translate molecule's closest atom to origin (such that is resides on the filler spot)
94 LOG(1, "DEBUG: molecule is off Alignment axis by " << sum << ", shifting ...");
95 {
96 Vector translater = -1.*sum;
97 filler->Translate(&translater);
98 }
99
100 // create predicate, mesh, and filler
101 FillSphericalSurfaceState *UndoState = NULL;
102 bool successflag = false;
103 {
104 FillPredicate *voidnode_predicate = new FillPredicate(
105 IsVoidNode_FillPredicate(
106 Sphere(zeroVec, params.mindistance.get())
107 )
108 );
109 Shape s = Sphere(params.center.get(), params.radius.get());
110 boost::function<const NodeSet ()> func =
111 boost::bind(&Shape::getHomogeneousPointsOnSurface, boost::ref(s), params.N.get());
112 Mesh *mesh = new MeshAdaptor(func);
113 Inserter *inserter = new Inserter(
114 Inserter::impl_ptr(new SurfaceInserter(s, params.AlignedAxis.get())));
115
116 // fill
117 {
118 Filler *fillerFunction = new Filler(*mesh, *voidnode_predicate, *inserter);
119 ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape() ) );
120 CopyAtoms_withBonds copyMethod;
121 Filler::ClusterVector_t ClonedClusters;
122 successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters);
123 delete fillerFunction;
124
125 // append each cluster's atoms to clonedatoms (however not selected ones)
126 std::vector<const atom *> clonedatoms;
127 std::vector<AtomicInfo> clonedatominfos;
128 for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin();
129 iter != ClonedClusters.end(); ++iter) {
130 const AtomIdSet &atoms = (*iter)->getAtomIds();
131 clonedatoms.reserve(clonedatoms.size()+atoms.size());
132 for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter)
133 if (!filler->containsAtom(*atomiter)) {
134 clonedatoms.push_back( *atomiter );
135 clonedatominfos.push_back( AtomicInfo(*(*atomiter)) );
136 }
137 }
138 std::vector< BondInfo > clonedbonds;
139 StoreBondInformationFromAtoms(clonedatoms, clonedbonds);
140 LOG(2, "DEBUG: There are " << clonedatominfos.size() << " newly created atoms with "
141 << clonedbonds.size()/2 << " bonds.");
142
143 if (!successflag) {
144 ELOG(1, "Insertion failed, removing inserted clusters, translating original one back");
145 RemoveAtomsFromAtomicInfo(clonedatominfos);
146 clonedatoms.clear();
147 SetAtomsFromAtomicInfo(movedatoms);
148 } else {
149 std::vector<Vector> MovedToVector(filler->size(), zeroVec);
150 std::transform(filler->begin(), filler->end(), MovedToVector.begin(),
151 boost::bind(&AtomInfo::getPosition, _1) );
152 UndoState = new FillSphericalSurfaceState(clonedatominfos,clonedbonds,movedatoms,MovedToVector,params);
153 }
154 }
155
156 // remove
157 delete mesh;
158 delete inserter;
159 delete voidnode_predicate;
160 }
161
162 if (successflag)
163 return Action::state_ptr(UndoState);
164 else
165 return Action::failure;
166}
167
168Action::state_ptr FillSphericalSurfaceAction::performUndo(Action::state_ptr _state) {
169 FillSphericalSurfaceState *state = assert_cast<FillSphericalSurfaceState*>(_state.get());
170
171 // remove all created atoms
172 RemoveAtomsFromAtomicInfo(state->clonedatoms);
173 // add the original cluster
174 SetAtomsFromAtomicInfo(state->movedatoms);
175
176 return Action::state_ptr(_state);
177}
178
179Action::state_ptr FillSphericalSurfaceAction::performRedo(Action::state_ptr _state){
180 FillSphericalSurfaceState *state = assert_cast<FillSphericalSurfaceState*>(_state.get());
181
182 // place filler cluster again at new spot
183 ResetAtomPosition(state->movedatoms, state->MovedToVector);
184
185 // re-create all clusters
186 bool statusflag = AddAtomsFromAtomicInfo(state->clonedatoms);
187
188 // re-create the bonds
189 statusflag = statusflag && AddBondsFromBondInfo(state->clonedbonds);
190 if (statusflag)
191 return Action::state_ptr(_state);
192 else
193 return Action::failure;
194}
195
196bool FillSphericalSurfaceAction::canUndo() {
197 return true;
198}
199
200bool FillSphericalSurfaceAction::shouldUndo() {
201 return true;
202}
203/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.