source: src/Actions/FillAction/FillRegularGridAction.cpp@ 901d87

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

Refactored insertion of cluster into Inserter class.

  • 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/Inserter/SimpleInserter.hpp"
29#include "Filling/Mesh/CubeMesh.hpp"
30#include "Filling/Predicates/IsInsideSurface_FillPredicate.hpp"
31#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
32#include "Filling/Predicates/Ops_FillPredicate.hpp"
33#include "LinkedCell/linkedcell.hpp"
34#include "LinkedCell/PointCloudAdaptor.hpp"
35#include "molecule.hpp"
36#include "MoleculeListClass.hpp"
37#include "Parser/FormatParserInterface.hpp"
38#include "Parser/FormatParserStorage.hpp"
39#include "Shapes/BaseShapes.hpp"
40#include "Tesselation/tesselation.hpp"
41#include "Tesselation/BoundaryLineSet.hpp"
42#include "Tesselation/BoundaryTriangleSet.hpp"
43#include "Tesselation/CandidateForTesselation.hpp"
44#include "World.hpp"
45
46
47#include <algorithm>
48#include <iostream>
49#include <string>
50#include <vector>
51
52#include "Actions/FillAction/FillRegularGridAction.hpp"
53
54using namespace MoleCuilder;
55
56// and construct the stuff
57#include "FillRegularGridAction.def"
58#include "Action_impl_pre.hpp"
59/** =========== define the function ====================== */
60Action::state_ptr FillRegularGridAction::performCall() {
61 typedef std::vector<atom*> AtomVector;
62
63 // obtain information
64 getParametersfromValueStorage();
65
66 // get all present atoms for UndoState
67 AtomVector presentatoms = World::getInstance().getAllAtoms();
68
69 // get the filler molecule and move to origin
70 const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules();
71 if (molecules.size() != 1) {
72 ELOG(1, "No exactly one molecule selected, aborting,");
73 return Action::failure;
74 }
75 molecule *filler = *(molecules.begin());
76 LOG(1, "INFO: Chosen molecule has " << filler->size() << " atoms.");
77
78 // check for selected molecules and create surfaces from them
79 std::vector<atom *> atoms(World::getInstance().getSelectedAtoms());
80 FillPredicate * surface_predicate = NULL;
81 LinkedCell_deprecated * LC = NULL;
82 Tesselation * TesselStruct = NULL;
83 if (params.SphereRadius != 0.) {
84 if ( molecules.size() == 0) {
85 ELOG(1, "You have given a sphere radius " << params.SphereRadius
86 << " != 0, but have not select any molecules.");
87 }
88 // create adaptor for the selected atoms
89 PointCloudAdaptor< std::vector<atom *> > cloud(&atoms, std::string("Selected atoms"));
90
91 // create tesselation
92 LC = new LinkedCell_deprecated(cloud, 2.*params.SphereRadius);
93 TesselStruct = new Tesselation;
94 (*TesselStruct)(cloud, params.SphereRadius);
95
96 // and create predicate
97 surface_predicate = new FillPredicate( IsInsideSurface_FillPredicate( *TesselStruct, *LC ) );
98 }
99
100 // create predicate, mesh, and filler
101 {
102 FillPredicate *voidnode_predicate = new FillPredicate(
103 IsVoidNode_FillPredicate(
104 Sphere(zeroVec, params.mindistance)
105 )
106 );
107 FillPredicate Andpredicate = (*voidnode_predicate);
108 if (surface_predicate != NULL)
109 Andpredicate = (Andpredicate) && !(*surface_predicate);
110 Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
111
112 // fill
113 {
114 SimpleInserter inserter;
115 Filler *fillerFunction = new Filler(*mesh, Andpredicate, inserter);
116 ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape()) );
117 CopyAtoms_withBonds copyMethod;
118 (*fillerFunction)(copyMethod, cluster);
119 delete fillerFunction;
120 }
121
122 // remove
123 delete mesh;
124 delete voidnode_predicate;
125 delete surface_predicate;
126 delete LC;
127 delete TesselStruct;
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.