source: src/AtomIdSet.cpp@ 748fc7

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 748fc7 was c1353f5, checked in by Frederik Heber <heber@…>, 11 years ago

Added AtomIdSet cstor that converts from a KeySet.

  • as this requires only KeySets header file, there are no dependency links.
  • 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 *
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 * AtomIdSet.cpp
25 *
26 * Created on: Feb 21, 2012
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "CodePatterns/MemDebug.hpp"
37
38#include "AtomIdSet.hpp"
39
40#include <boost/foreach.hpp>
41
42#include "Atom/atom.hpp"
43#include "Descriptors/AtomIdDescriptor.hpp"
44#include "Fragmentation/KeySet.hpp"
45#include "World.hpp"
46
47atom * FromIdToAtom::operator()(atomId_t id) const {
48 return World::getInstance().getAtom(AtomById(id));
49}
50
51/** Constructor for class AtomIdSet.
52 *
53 * @param _atoms atoms to put into this set
54 */
55AtomIdSet::AtomIdSet(const atomIdSet &_atoms) :
56 atoms(_atoms)
57{}
58
59/** Constructor for class AtomIdSet.
60 *
61 * @param _keyset keyset to put into this set
62 */
63AtomIdSet::AtomIdSet(const KeySet &_keyset) :
64 atoms(atomIdSet(_keyset.begin(), _keyset.end()))
65{}
66
67/** Constructor for class AtomIdSet.
68 *
69 * @param _atoms atoms to put into this set
70 */
71AtomIdSet::AtomIdSet(const std::vector<atom *> &_atoms)
72{
73 BOOST_FOREACH(const atom * _atom, _atoms) {
74 insert(_atom->getId());
75 }
76}
77
78/** Constructor for class AtomIdSet.
79 *
80 */
81AtomIdSet::AtomIdSet()
82{}
83
84/** Destructor for class AtomIdSet.
85 *
86 */
87AtomIdSet::~AtomIdSet()
88{}
89
90/** Returns iterator to first atim via a transform_iterator.
91 *
92 * @return iterator to first atom in this set
93 */
94AtomIdSet::iterator AtomIdSet::begin(){
95 return iterator(atoms.begin(), FromIdToAtom());
96}
97
98/** Returns constant iterator to first atim via a transform_iterator.
99 *
100 * @return const iterator to first atom in this set
101 */
102AtomIdSet::const_iterator AtomIdSet::begin() const{
103 return const_iterator(atoms.begin(), FromIdToAtom());
104}
105
106/** Returns iterator to one beyond last atom via a transform_iterator.
107 *
108 * @return iterator to one beyond last atom in this set
109 */
110AtomIdSet::iterator AtomIdSet::end(){
111 return iterator(atoms.end(), FromIdToAtom());
112}
113
114/** Returns constant iterator to one beyond last atom via a transform_iterator.
115 *
116 * @return const iterator to one beyond last atom in this set
117 */
118AtomIdSet::const_iterator AtomIdSet::end() const{
119 return const_iterator(atoms.end(), FromIdToAtom());
120}
121
122/** Returns true if this set is empty.
123 *
124 * @return true - set is empty, false - there is at least one atom
125 */
126bool AtomIdSet::empty() const
127{
128 return (atoms.empty());
129}
130
131/** Returns the number of members of this set.
132 *
133 * @return number of members in set
134 */
135size_t AtomIdSet::size() const
136{
137 // set has unique members, hence just return its size
138 return atoms.size();
139}
140
141/** Predicate whether given atomic id is contained.
142 *
143 * @param id id to check
144 * @return true - is contained, false - is not
145 */
146bool AtomIdSet::contains(const atomId_t &id) const
147{
148 return (atoms.find(id) != atoms.end());
149}
150
151/** Predicate whether given atom is contained.
152 *
153 * @param key atom to check
154 * @return true - is contained, false - is not
155 */
156bool AtomIdSet::contains(const atom * const key) const
157{
158 return contains(key->getId());
159}
160
161/** Returns the iterator to the atom \a *key.
162 *
163 * @param key atom to find
164 * @return iterator to atom if found, to end() - else
165 */
166AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
167{
168 return find(key->getId());
169}
170
171/** Returns the iterator to the atom \a *key.
172 *
173 * @param id atomic id to find
174 * @return iterator to atom if found, to end() - else
175 */
176AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
177{
178 return const_iterator(atoms.find(id), FromIdToAtom());
179}
180
181/** Inserts a given atom into the set.
182 *
183 * @param key atom to insert
184 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
185 */
186std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
187{
188 std::pair<atomIdSet::iterator, bool> iter =
189 atoms.insert(key->getId());
190 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
191
192 return retiter;
193}
194
195/** Inserts a given atom into the set.
196 *
197 * @param id atomic id to insert
198 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
199 */
200std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
201{
202 std::pair<atomIdSet::iterator, bool> iter =
203 atoms.insert(id);
204 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
205
206 return retiter;
207}
208
209AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
210{
211 const_iterator iter = loc;
212 ++iter;
213 atom * const _atom = const_cast<atom *>(*loc);
214 atoms.erase( _atom->getId() );
215 return iter;
216}
217
218/** Erase an atom from the list.
219 *
220 * @param *key key to atom in list
221 * @return iterator to just after removed item (compliant with standard)
222 */
223AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
224{
225 const_iterator iter = find(key);
226 if (iter != end()){
227 ++iter;
228 atoms.erase( key->getId() );
229 }
230 return iter;
231}
232
233/** Erase an atom from the list.
234 *
235 * @param id atomic id atom in list to erase
236 * @return iterator to just after removed item (compliant with standard)
237 */
238AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
239{
240 atomIdSet::const_iterator iter = atoms.find(id);
241 if (iter != atoms.end()){
242 ++iter;
243 atoms.erase( id );
244 }
245 return iterator(iter, FromIdToAtom());
246}
Note: See TracBrowser for help on using the repository browser.