- Timestamp:
- Apr 6, 2012, 11:44:50 AM (13 years ago)
- Branches:
- 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
- Children:
- cc9119
- Parents:
- 57dd40
- git-author:
- Frederik Heber <heber@…> (04/05/12 09:38:33)
- git-committer:
- Frederik Heber <heber@…> (04/06/12 11:44:50)
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/FillAction/FillRegularGridAction.cpp
r57dd40 r42b6de 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include "Actions/UndoRedoHelpers.hpp" 22 23 #include "Atom/atom.hpp" 24 #include "Atom/AtomicInfo.hpp" 23 25 #include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp" 24 26 #include "CodePatterns/Log.hpp" … … 65 67 getParametersfromValueStorage(); 66 68 67 // get all present atoms for UndoState68 AtomVector presentatoms = World::getInstance().getAllAtoms();69 70 69 // get the filler molecule and move to origin 71 70 const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules(); … … 100 99 101 100 // create predicate, mesh, and filler 101 std::vector<AtomicInfo> clonedatoms; 102 102 bool successflag = false; 103 103 { … … 125 125 ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape()) ); 126 126 CopyAtoms_withBonds copyMethod; 127 successflag = (*fillerFunction)(copyMethod, cluster); 127 Filler::ClusterVector_t ClonedClusters; 128 successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters); 128 129 delete fillerFunction; 130 131 // append each cluster's atoms to clonedatoms 132 for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin(); 133 iter != ClonedClusters.end(); ++iter) { 134 const AtomIdSet &atoms = (*iter)->getAtomIds(); 135 clonedatoms.reserve(clonedatoms.size()+atoms.size()); 136 for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter) 137 clonedatoms.push_back( AtomicInfo(*(*atomiter)) ); 138 } 139 if (!successflag) { 140 ELOG(1, "Insertion failed, removing inserted clusters again."); 141 RemoveAtomsFromAtomicInfo(clonedatoms); 142 clonedatoms.clear(); 143 } 129 144 } 130 145 … … 138 153 } 139 154 140 // generate list of newly created atoms141 // (we can in general remove more quickly from a list than a vector)142 AtomVector filleratoms = World::getInstance().getAllAtoms();143 // LOG(0, filleratoms.size() << " atoms are present.");144 std::list<atom *> filleratoms_list;145 std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list ));146 // LOG(0, filleratoms_list.size() << " atoms have been copied.");147 for (AtomVector::const_iterator iter = presentatoms.begin();148 iter != presentatoms.end();149 ++iter) {150 filleratoms_list.remove(*iter);151 }152 // LOG(0, filleratoms_list.size() << " atoms left after removal.");153 filleratoms.clear();154 std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));155 156 // LOG(0, filleratoms.size() << " atoms have been inserted.");157 158 155 if (successflag) 159 return Action::state_ptr(new FillRegularGridState( filleratoms,params));156 return Action::state_ptr(new FillRegularGridState(clonedatoms,params)); 160 157 else 161 158 return Action::failure; … … 163 160 164 161 Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) { 165 // FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get()); 166 // 167 // BOOST_FOREACH(atom *_atom, state->filleratoms) { 168 // World::getInstance().destroyAtom(Walker); 169 // } 170 // 171 // // as atoms and atoms from state are removed, we have to create a new one 172 // std::vector<atom*> filleratoms; 173 // return Action::state_ptr(new FillRegularGridState(filleratoms,state->params)); 174 return Action::failure; 162 FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get()); 163 164 // remove all created atoms 165 RemoveAtomsFromAtomicInfo(state->clonedatoms); 166 167 return Action::state_ptr(_state); 175 168 } 176 169 177 170 Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){ 178 //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());171 FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get()); 179 172 180 return Action::failure; 181 //return Action::state_ptr(_state); 173 if (AddAtomsFromAtomicInfo(state->clonedatoms)) 174 return Action::state_ptr(_state); 175 else 176 return Action::failure; 182 177 } 183 178 184 179 bool FillRegularGridAction::canUndo() { 185 return false;180 return true; 186 181 } 187 182 188 183 bool FillRegularGridAction::shouldUndo() { 189 return false;184 return true; 190 185 } 191 186 /** =========== end of function ====================== */ -
src/Actions/FillAction/FillRegularGridAction.def
r57dd40 r42b6de 18 18 #define paramreferences (counts)(offset)(mindistance)(SphereRadius)(RandAtomDisplacement)(RandMoleculeDisplacement)(DoRotate) 19 19 20 #define statetypes (std::vector< atom *>)21 #define statereferences ( filleratoms)20 #define statetypes (std::vector<AtomicInfo>) 21 #define statereferences (clonedatoms) 22 22 23 23 // some defines for all the names, you may use ACTION, STATE and PARAMS -
src/Actions/FillAction/FillSphericalSurfaceAction.cpp
r57dd40 r42b6de 20 20 #include "CodePatterns/MemDebug.hpp" 21 21 22 #include "Actions/UndoRedoHelpers.hpp" 23 #include "Atom/AtomicInfo.hpp" 22 24 #include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp" 23 25 #include "CodePatterns/Log.hpp" … … 82 84 83 85 // create predicate, mesh, and filler 86 std::vector<AtomicInfo> clonedatoms; 84 87 bool successflag = false; 85 88 { … … 101 104 ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape() ) ); 102 105 CopyAtoms_withBonds copyMethod; 103 successflag = (*fillerFunction)(copyMethod, cluster); 106 Filler::ClusterVector_t ClonedClusters; 107 successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters); 104 108 delete fillerFunction; 109 110 // append each cluster's atoms to clonedatoms 111 for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin(); 112 iter != ClonedClusters.end(); ++iter) { 113 const AtomIdSet &atoms = (*iter)->getAtomIds(); 114 clonedatoms.reserve(clonedatoms.size()+atoms.size()); 115 for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter) 116 clonedatoms.push_back( AtomicInfo(*(*atomiter)) ); 117 } 118 if (!successflag) { 119 ELOG(1, "Insertion failed, removing inserted clusters again."); 120 RemoveAtomsFromAtomicInfo(clonedatoms); 121 clonedatoms.clear(); 122 } 105 123 } 124 106 125 107 126 // remove … … 112 131 113 132 if (successflag) 114 return Action::s uccess;133 return Action::state_ptr(new FillSphericalSurfaceState(clonedatoms,params)); 115 134 else 116 135 return Action::failure; … … 118 137 119 138 Action::state_ptr FillSphericalSurfaceAction::performUndo(Action::state_ptr _state) { 120 return Action::failure; 139 FillSphericalSurfaceState *state = assert_cast<FillSphericalSurfaceState*>(_state.get()); 140 141 // remove all created atoms 142 RemoveAtomsFromAtomicInfo(state->clonedatoms); 143 144 return Action::state_ptr(_state); 121 145 } 122 146 123 147 Action::state_ptr FillSphericalSurfaceAction::performRedo(Action::state_ptr _state){ 124 return Action::failure; 148 FillSphericalSurfaceState *state = assert_cast<FillSphericalSurfaceState*>(_state.get()); 149 150 if (AddAtomsFromAtomicInfo(state->clonedatoms)) 151 return Action::state_ptr(_state); 152 else 153 return Action::failure; 125 154 } 126 155 127 156 bool FillSphericalSurfaceAction::canUndo() { 128 return false;157 return true; 129 158 } 130 159 131 160 bool FillSphericalSurfaceAction::shouldUndo() { 132 return false;161 return true; 133 162 } 134 163 /** =========== end of function ====================== */ -
src/Actions/FillAction/FillSphericalSurfaceAction.def
r57dd40 r42b6de 7 7 8 8 // all includes and forward declarations necessary for non-integral types below 9 class atom; 10 9 #include <vector> 10 #include "Atom/AtomicInfo.hpp" 11 11 #include "LinearAlgebra/Vector.hpp" 12 12 … … 20 20 #define paramreferences (center)(radius)(N)(mindistance)(AlignedAxis) 21 21 22 # undef statetypes23 # undef statereferences22 #define statetypes (std::vector<AtomicInfo>) 23 #define statereferences (clonedatoms) 24 24 25 25 // some defines for all the names, you may use ACTION, STATE and PARAMS -
src/Filling/Filler.cpp
r57dd40 r42b6de 46 46 47 47 48 /** Constructor for class Filler.49 *50 * \note We store inverted \a _predicate because we need it only for51 * remove_copy_if which works in this inverted way as desired.52 *53 * @param _mesh Mesh with a NodeSet that fills its Shape54 * @param _predicate predicate construct to check at each Node55 * @param _inserter inserter which places the cloned cluster56 */57 48 Filler::Filler(const Mesh &_mesh, const FillPredicate &_predicate, const Inserter &_inserter) : 58 49 mesh(_mesh), … … 61 52 {} 62 53 63 /** Destructor for class Filler.64 *65 */66 54 Filler::~Filler() 67 55 {} 68 56 69 /** Fill in the desired Cluster at each remaining node.70 *71 * \note The cluster is non-const because it is moved to the first vacant node.72 *73 * @param copyMethod functor that knows how to copy atoms.74 * @param cluster set of atomic ids contained in a specific Shape to fill each Node with75 * @return true - at least one node has been filled, false - no node filled76 */77 57 bool Filler::operator()( 78 58 CopyAtomsInterface ©Method, 79 ClusterInterface::Cluster_impl cluster) const 59 ClusterInterface::Cluster_impl cluster, 60 ClusterVector_t &ClonedClusters) const 80 61 { 81 62 const NodeSet &nodes = mesh.getNodes(); … … 126 107 127 108 // clone clusters 128 std::vector<ClusterInterface::Cluster_impl> clusters(FillNodes.size());109 ClonedClusters.resize(FillNodes.size()); 129 110 { 130 std::vector<ClusterInterface::Cluster_impl>::iterator clusteriter = clusters.begin();111 std::vector<ClusterInterface::Cluster_impl>::iterator clusteriter = ClonedClusters.begin(); 131 112 *clusteriter = cluster; 132 113 clusteriter++; … … 140 121 // returns true, we'll have the iterator pointing at first cluster 141 122 std::vector<ClusterInterface::Cluster_impl>::const_iterator inserteriter = 142 std::search( clusters.begin(), clusters.end(), FillNodes.begin(), FillNodes.end(),123 std::search(ClonedClusters.begin(), ClonedClusters.end(), FillNodes.begin(), FillNodes.end(), 143 124 boost::bind(&Inserter::operator(), boost::cref(inserter), _1, _2)); 144 if( inserteriter != clusters.begin()) {125 if( inserteriter != ClonedClusters.begin()) { 145 126 ELOG(1, "Not all cloned clusters could be successfully inserted."); 146 127 return false; … … 150 131 // create molecules for each cluster and fill in atoms 151 132 { 152 std::vector<molecule *> molecules( clusters.size()-1, NULL);133 std::vector<molecule *> molecules(ClonedClusters.size()-1, NULL); 153 134 std::generate_n(molecules.begin(), FillNodes.size()-1, 154 135 boost::bind(&World::createMolecule, World::getPointer()) ); 155 std::vector<ClusterInterface::Cluster_impl>::const_iterator clusteriter = clusters.begin();136 std::vector<ClusterInterface::Cluster_impl>::const_iterator clusteriter = ClonedClusters.begin(); 156 137 ++clusteriter; 157 138 std::vector<molecule *>::iterator moliter = molecules.begin(); … … 164 145 165 146 // give final statment on whether at least \a single cluster has been placed 166 if ( FillNodes.size() != 0) 167 return true; 168 else 169 return false; 147 return ( FillNodes.size() != 0); 170 148 } 171 149 -
src/Filling/Filler.hpp
r57dd40 r42b6de 14 14 #include <config.h> 15 15 #endif 16 17 #include <vector> 16 18 17 19 #include "Cluster.hpp" … … 32 34 { 33 35 public: 36 /** Constructor for class Filler. 37 * 38 * \note We store inverted \a _predicate because we need it only for 39 * remove_copy_if which works in this inverted way as desired. 40 * 41 * @param _mesh Mesh with a NodeSet that fills its Shape 42 * @param _predicate predicate construct to check at each Node 43 * @param _inserter inserter which places the cloned cluster 44 */ 34 45 Filler(const Mesh &_mesh, const FillPredicate &_predicate, const Inserter &_inserter); 46 47 /** Destructor for class Filler. 48 * 49 */ 35 50 ~Filler(); 36 51 37 bool operator()(CopyAtomsInterface ©Method, ClusterInterface::Cluster_impl cluster) const; 52 //!> typedef Vector of clusters as return type for operator() 53 typedef std::vector<ClusterInterface::Cluster_impl> ClusterVector_t; 54 55 /** Fill in the desired Cluster at each remaining node. 56 * 57 * \note The cluster is non-const because it is moved to the first vacant node. 58 * 59 * @param copyMethod functor that knows how to copy atoms. 60 * @param cluster set of atomic ids contained in a specific Shape to fill each Node with 61 * @param ClonedClusters reference to vector of clusters, that is filled with created clones 62 * @return true - all clusters inserted succesfully, else - insertion failed 63 */ 64 bool operator()(CopyAtomsInterface ©Method, ClusterInterface::Cluster_impl cluster, ClusterVector_t &ClonedClusters) const; 38 65 39 66 private: 67 40 68 //!> mesh is the set of points filling a Shape 41 69 const Mesh mesh; -
src/Filling/unittests/FillerUnitTest.cpp
r57dd40 r42b6de 115 115 { 116 116 CopyAtoms_Simple copyMethod; 117 (*filler)(copyMethod, *cluster); 117 Filler::ClusterVector_t ClonedClusters; 118 (*filler)(copyMethod, *cluster, ClonedClusters); 118 119 119 120 // one atom at 5 nodes added 121 CPPUNIT_ASSERT_EQUAL( mesh->getNodes().size(), ClonedClusters.size() ); 120 122 CPPUNIT_ASSERT_EQUAL( mesh->getNodes().size()*2, World::getInstance().getAllAtoms().size() ); 121 123 }
Note:
See TracChangeset
for help on using the changeset viewer.