source: src/Filling/Cluster.cpp@ aec098

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

Added new class Cluster as atomIdset with a Shape.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 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 * Cluster.cpp
10 *
11 * Created on: Jan 16, 2012
12 * Author: heber
13 */
14
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#include "CodePatterns/MemDebug.hpp"
22
23#include <algorithm>
24#include <boost/bind.hpp>
25#include <boost/foreach.hpp>
26
27#include "Cluster.hpp"
28
29#include "CodePatterns/Assert.hpp"
30#include "CodePatterns/Log.hpp"
31
32#include "Atom/atom.hpp"
33#include "Descriptors/AtomIdDescriptor.hpp"
34#include "LinearAlgebra/RealSpaceMatrix.hpp"
35#include "LinearAlgebra/Vector.hpp"
36#include "Shapes/ShapeOps.hpp"
37#include "World.hpp"
38
39/** Constructor for class Cluster.
40 *
41 * @param _s Shape of this Cluster
42 */
43Cluster::Cluster(const Shape & _s) :
44 s(_s)
45{}
46
47/** Copy Constructor for class Cluster.
48 *
49 * Here, we do not check whether we atomds reside in the Shape or not, as
50 * this should have been validated in the instance to copy \a _cluster.
51 *
52 * @param _cluster instance to copy
53 */
54Cluster::Cluster(const Cluster & _cluster) :
55 atoms(_cluster.atoms),
56 s(_cluster.s)
57{}
58
59/** Constructor for class Cluster.
60 *
61 * @param _atoms list of atoms to place in this cluster
62 * @param _s Shape of this Cluster
63 */
64Cluster::Cluster(const atomIdSet & _atoms, const Shape & _s) :
65 s(_s)
66{
67 // make sure only those atoms are in Cluster that are also inside its Shape
68 std::vector<atomId_t> tempIds(_atoms.size(), (size_t)-1);
69 std::vector<atomId_t>::iterator iter =
70 std::remove_copy_if( _atoms.begin(), _atoms.end(), tempIds.begin(),
71 !boost::bind(&Cluster::IsInShape, this, _1) );
72 tempIds.erase( iter, tempIds.end() );
73 ASSERT( tempIds.size() == _atoms.size(),
74 "Cluster::Cluster() - at least one atom is not inside the Shape.");
75 atoms.insert( tempIds.begin(), tempIds.end() );
76 LOG(1, "INFO: New cluster has " << atoms.size() << " atoms.");
77}
78
79
80/** Destructor for class Cluster.
81 *
82 */
83Cluster::~Cluster()
84{}
85
86/** Inserts an atomic by its \a id into the Cluster.
87 *
88 * We check whether the atom is inside the given Shape \a s.
89 *
90 * @param id id to insert
91 */
92void Cluster::insert(const atomId_t id)
93{
94 const bool status = IsInShape(id);
95 ASSERT(status,
96 "Cluster::insert() - atomic id "+toString(id)+" is not contained in Shape.");
97 if (status) {
98 std::pair<atomIdSet::iterator, bool> inserter = atoms.insert(id);
99 ASSERT(inserter.second,
100 "Cluster::insert() - atomic id "+toString(id)+" is already present.");
101 }
102}
103
104/** Remove atom by its \a id from the cluster.
105 *
106 * @param id atom to remove
107 */
108void Cluster::erase(const atomId_t id)
109{
110 atomIdSet::iterator iter = atoms.find(id);
111 ASSERT(iter != atoms.end(),
112 "Cluster::erase() - atomic id "+toString(id)+" unknown in this Cluster.");
113 if (iter != atoms.end())
114 atoms.erase(iter);
115}
116
117/** Checks whether a given atom is within the shape \a s.
118 *
119 * @param id atomic id to check
120 * @return true - is in Shape, false - is not contained (or does not exist)
121 */
122bool Cluster::IsInShape(const atomId_t id) const
123{
124 const atom * const _atom = getAtomById(id);
125 if (_atom != NULL)
126 return s.isInside(_atom->getPosition());
127 else
128 return false;
129}
130
131/** Helper function for looking up atomic reference by its id.
132 *
133 * @param id id to look up
134 * @return reference to atom with this id
135 */
136atom * const Cluster::getAtomById(const atomId_t id) const
137{
138 atom * const _atom = World::getInstance().getAtom(AtomById(id));
139 ASSERT(_atom != NULL,
140 "Cluster::getAtomById() - id "+toString(id)+" is unknown to World.");
141 return _atom;
142}
143
144bool isNullAtom(const atom* _atom) {
145 return _atom == NULL;
146}
147
148/** Getter for the underlying true atoms refs.
149 *
150 * @return AtomVector filled with looked-up atom references
151 */
152Cluster::AtomVector Cluster::getAtomRefs() const
153{
154 AtomVector atomVector;
155 atomVector.reserve(atoms.size());
156 BOOST_FOREACH(atomId_t _id, atoms) {
157 atom * const _atom = World::getInstance().getAtom(AtomById(_id));
158 if (_atom != NULL)
159 atomVector.push_back( _atom );
160 else
161 ASSERT( false, "Cluster::getAtomRefs() - unknown id "+toString(_id)+".");
162 }
163 return atomVector;
164}
165
166/** Clone function for this instance.
167 *
168 * @param copyMethod functor that knows how to copy atoms
169 * @param offset Vector to translate new cluster relative to old one
170 * @return another instance with newly allocated atoms
171 */
172ClusterInterface::Cluster_impl Cluster::clone(
173 CopyAtomsInterface& copyMethod,
174 const Vector &offset) const
175{
176 LOG(2, "INFO: Clone this cluster with " << atoms.size() << " atoms.");
177 /// get another cluster instance
178 Cluster * clonedInstance = new Cluster(::translate(getShape(), offset));
179
180 /// copy and move atoms
181 copyMethod(getAtomRefs());
182 AtomVector CopiedAtoms = copyMethod.getCopiedAtoms();
183 BOOST_FOREACH( atom *_atom, CopiedAtoms) {
184 _atom->setPosition( _atom->getPosition() + offset );
185 }
186
187 /// fill copied atoms into new instance
188 // dont use a set here, makes life hard with STL algos
189 std::vector<atomId_t> Copies(CopiedAtoms.size(), (size_t)-1);
190 std::transform(CopiedAtoms.begin(), CopiedAtoms.end(), Copies.begin(),
191 boost::bind(&atom::getId, _1) );
192 clonedInstance->atoms.insert(Copies.begin(), Copies.end());
193
194 return ClusterInterface::Cluster_impl(clonedInstance);
195}
196
197/** Translate atoms inside Cluster and Shape.
198 *
199 * @param offset offset to translate by
200 */
201void Cluster::translate(const Vector &offset)
202{
203 // move atoms
204 AtomVector atomVector = getAtomRefs();
205 BOOST_FOREACH(atom *_atom, atomVector) {
206 _atom->setPosition(_atom->getPosition()+offset);
207 }
208 // translate shape
209 s = ::translate(s, offset);
210}
211
212/** Transform atoms inside Cluster and Shape.
213 *
214 * @param M transformation matrix
215 */
216void Cluster::transform(const RealSpaceMatrix &M)
217{
218 // transform atoms
219 AtomVector atomVector = getAtomRefs();
220 BOOST_FOREACH(atom *_atom, atomVector) {
221 _atom->setPosition( M * _atom->getPosition() );
222 }
223 // translate shape
224 s = ::transform(s, M);
225}
Note: See TracBrowser for help on using the repository browser.