source: src/Actions/FillAction/FillSurfaceAction.cpp@ 060c7d

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 060c7d was 09eaac, checked in by Frederik Heber <heber@…>, 12 years ago

FillSphericalSurfaceAction > FillSurfaceAction (using shape factory)

  • Property mode set to 100644
File size: 6.9 KB
RevLine 
[2db053]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[2db053]21 */
22
23/*
[09eaac]24 * FillSurfaceAction.cpp
[2db053]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
[42b6de]37#include "Actions/UndoRedoHelpers.hpp"
[80ca29]38#include "Atom/atom.hpp"
[42b6de]39#include "Atom/AtomicInfo.hpp"
[cb7676]40#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
[2db053]41#include "CodePatterns/Log.hpp"
42#include "Filling/Cluster.hpp"
43#include "Filling/Filler.hpp"
44#include "Filling/Inserter/Inserter.hpp"
[cb7676]45#include "Filling/Inserter/SurfaceInserter.hpp"
[2db053]46#include "Filling/Mesh/MeshAdaptor.hpp"
47#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
[cb7676]48#include "molecule.hpp"
[2db053]49#include "Shapes/BaseShapes.hpp"
[09eaac]50#include "Shapes/ShapeFactory.hpp"
[2db053]51#include "World.hpp"
52
53
54#include <algorithm>
55#include <boost/foreach.hpp>
56#include <boost/function.hpp>
57#include <iostream>
58#include <string>
59#include <vector>
60
[09eaac]61#include "Actions/FillAction/FillSurfaceAction.hpp"
[2db053]62
63using namespace MoleCuilder;
64
65// and construct the stuff
[09eaac]66#include "FillSurfaceAction.def"
[2db053]67#include "Action_impl_pre.hpp"
68/** =========== define the function ====================== */
[09eaac]69Action::state_ptr FillSurfaceAction::performCall() {
[80ca29]70 // get the filler molecule
[cb7676]71 const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules();
[80ca29]72 std::vector<AtomicInfo> movedatoms;
[cb7676]73 if (molecules.size() != 1) {
74 ELOG(1, "No exactly one molecule selected, aborting,");
[2db053]75 return Action::failure;
76 }
[cb7676]77 molecule *filler = *(molecules.begin());
[80ca29]78 for(molecule::const_iterator iter = filler->begin(); iter != filler->end(); ++iter)
79 movedatoms.push_back( AtomicInfo(*(*iter)) );
[cb7676]80 LOG(1, "INFO: Chosen molecule has " << filler->size() << " atoms.");
81
82 // center filler's tip at origin
83 Vector max;
84 filler->CenterEdge(&max);
85
86 // determine center with respect to alignment axis
87 Vector sum = zeroVec;
88 for (molecule::iterator it2=filler->begin();it2 !=filler->end();++it2) {
[f10b0c]89 const Vector helper = (**it2).getPosition().partition(params.AlignedAxis.get()).second;
[cb7676]90 sum += helper;
91 }
92 sum *= 1./filler->size();
93
94 // translate molecule's closest atom to origin (such that is resides on the filler spot)
95 LOG(1, "DEBUG: molecule is off Alignment axis by " << sum << ", shifting ...");
96 {
97 Vector translater = -1.*sum;
98 filler->Translate(&translater);
[2db053]99 }
100
101 // create predicate, mesh, and filler
[09eaac]102 FillSurfaceState *UndoState = NULL;
[2db053]103 bool successflag = false;
104 {
105 FillPredicate *voidnode_predicate = new FillPredicate(
106 IsVoidNode_FillPredicate(
[f10b0c]107 Sphere(zeroVec, params.mindistance.get())
[2db053]108 )
109 );
[09eaac]110
111 Shape s = ShapeFactory::getInstance().produce();
112
[2db053]113 boost::function<const NodeSet ()> func =
[f10b0c]114 boost::bind(&Shape::getHomogeneousPointsOnSurface, boost::ref(s), params.N.get());
[2db053]115 Mesh *mesh = new MeshAdaptor(func);
116 Inserter *inserter = new Inserter(
[f10b0c]117 Inserter::impl_ptr(new SurfaceInserter(s, params.AlignedAxis.get())));
[2db053]118
119 // fill
120 {
121 Filler *fillerFunction = new Filler(*mesh, *voidnode_predicate, *inserter);
[cb7676]122 ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape() ) );
123 CopyAtoms_withBonds copyMethod;
[42b6de]124 Filler::ClusterVector_t ClonedClusters;
125 successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters);
[2db053]126 delete fillerFunction;
[42b6de]127
[80ca29]128 // append each cluster's atoms to clonedatoms (however not selected ones)
129 std::vector<const atom *> clonedatoms;
130 std::vector<AtomicInfo> clonedatominfos;
[42b6de]131 for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin();
132 iter != ClonedClusters.end(); ++iter) {
133 const AtomIdSet &atoms = (*iter)->getAtomIds();
134 clonedatoms.reserve(clonedatoms.size()+atoms.size());
135 for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter)
[80ca29]136 if (!filler->containsAtom(*atomiter)) {
137 clonedatoms.push_back( *atomiter );
138 clonedatominfos.push_back( AtomicInfo(*(*atomiter)) );
139 }
[42b6de]140 }
[80ca29]141 std::vector< BondInfo > clonedbonds;
142 StoreBondInformationFromAtoms(clonedatoms, clonedbonds);
143 LOG(2, "DEBUG: There are " << clonedatominfos.size() << " newly created atoms with "
144 << clonedbonds.size()/2 << " bonds.");
145
[42b6de]146 if (!successflag) {
[80ca29]147 ELOG(1, "Insertion failed, removing inserted clusters, translating original one back");
148 RemoveAtomsFromAtomicInfo(clonedatominfos);
[42b6de]149 clonedatoms.clear();
[80ca29]150 SetAtomsFromAtomicInfo(movedatoms);
151 } else {
152 std::vector<Vector> MovedToVector(filler->size(), zeroVec);
153 std::transform(filler->begin(), filler->end(), MovedToVector.begin(),
154 boost::bind(&AtomInfo::getPosition, _1) );
[09eaac]155 UndoState = new FillSurfaceState(clonedatominfos,clonedbonds,movedatoms,MovedToVector,params);
[42b6de]156 }
[2db053]157 }
158
159 // remove
160 delete mesh;
161 delete inserter;
162 delete voidnode_predicate;
163 }
164
165 if (successflag)
[80ca29]166 return Action::state_ptr(UndoState);
[2db053]167 else
168 return Action::failure;
169}
170
[09eaac]171Action::state_ptr FillSurfaceAction::performUndo(Action::state_ptr _state) {
172 FillSurfaceState *state = assert_cast<FillSurfaceState*>(_state.get());
[42b6de]173
174 // remove all created atoms
175 RemoveAtomsFromAtomicInfo(state->clonedatoms);
[80ca29]176 // add the original cluster
177 SetAtomsFromAtomicInfo(state->movedatoms);
[42b6de]178
179 return Action::state_ptr(_state);
[2db053]180}
181
[09eaac]182Action::state_ptr FillSurfaceAction::performRedo(Action::state_ptr _state){
183 FillSurfaceState *state = assert_cast<FillSurfaceState*>(_state.get());
[42b6de]184
[80ca29]185 // place filler cluster again at new spot
186 ResetAtomPosition(state->movedatoms, state->MovedToVector);
187
188 // re-create all clusters
189 bool statusflag = AddAtomsFromAtomicInfo(state->clonedatoms);
190
191 // re-create the bonds
192 statusflag = statusflag && AddBondsFromBondInfo(state->clonedbonds);
193 if (statusflag)
[42b6de]194 return Action::state_ptr(_state);
195 else
196 return Action::failure;
[2db053]197}
198
[09eaac]199bool FillSurfaceAction::canUndo() {
[42b6de]200 return true;
[2db053]201}
202
[09eaac]203bool FillSurfaceAction::shouldUndo() {
[42b6de]204 return true;
[2db053]205}
206/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.