source: src/AtomIdSet.cpp@ 34e74fd

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 34e74fd was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 5.8 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 "World.hpp"
45
46atom * FromIdToAtom::operator()(atomId_t id) const {
47 return World::getInstance().getAtom(AtomById(id));
48}
49
50/** Constructor for class AtomIdSet.
51 *
52 * @param _atoms atoms to put into this set
53 */
54AtomIdSet::AtomIdSet(const atomIdSet &_atoms) :
55 atoms(_atoms)
56{}
57
58/** Constructor for class AtomIdSet.
59 *
60 * @param _atoms atoms to put into this set
61 */
62AtomIdSet::AtomIdSet(const std::vector<atom *> &_atoms)
63{
64 BOOST_FOREACH(const atom * _atom, _atoms) {
65 insert(_atom->getId());
66 }
67}
68
69/** Constructor for class AtomIdSet.
70 *
71 */
72AtomIdSet::AtomIdSet()
73{}
74
75/** Destructor for class AtomIdSet.
76 *
77 */
78AtomIdSet::~AtomIdSet()
79{}
80
81/** Returns iterator to first atim via a transform_iterator.
82 *
83 * @return iterator to first atom in this set
84 */
85AtomIdSet::iterator AtomIdSet::begin(){
86 return iterator(atoms.begin(), FromIdToAtom());
87}
88
89/** Returns constant iterator to first atim via a transform_iterator.
90 *
91 * @return const iterator to first atom in this set
92 */
93AtomIdSet::const_iterator AtomIdSet::begin() const{
94 return const_iterator(atoms.begin(), FromIdToAtom());
95}
96
97/** Returns iterator to one beyond last atom via a transform_iterator.
98 *
99 * @return iterator to one beyond last atom in this set
100 */
101AtomIdSet::iterator AtomIdSet::end(){
102 return iterator(atoms.end(), FromIdToAtom());
103}
104
105/** Returns constant iterator to one beyond last atom via a transform_iterator.
106 *
107 * @return const iterator to one beyond last atom in this set
108 */
109AtomIdSet::const_iterator AtomIdSet::end() const{
110 return const_iterator(atoms.end(), FromIdToAtom());
111}
112
113/** Returns true if this set is empty.
114 *
115 * @return true - set is empty, false - there is at least one atom
116 */
117bool AtomIdSet::empty() const
118{
119 return (atoms.empty());
120}
121
122/** Returns the number of members of this set.
123 *
124 * @return number of members in set
125 */
126size_t AtomIdSet::size() const
127{
128 // set has unique members, hence just return its size
129 return atoms.size();
130}
131
132/** Predicate whether given atomic id is contained.
133 *
134 * @param id id to check
135 * @return true - is contained, false - is not
136 */
137bool AtomIdSet::contains(const atomId_t &id) const
138{
139 return (atoms.find(id) != atoms.end());
140}
141
142/** Predicate whether given atom is contained.
143 *
144 * @param key atom to check
145 * @return true - is contained, false - is not
146 */
147bool AtomIdSet::contains(const atom * const key) const
148{
149 return contains(key->getId());
150}
151
152/** Returns the iterator to the atom \a *key.
153 *
154 * @param key atom to find
155 * @return iterator to atom if found, to end() - else
156 */
157AtomIdSet::const_iterator AtomIdSet::find(const atom * const key) const
158{
159 return find(key->getId());
160}
161
162/** Returns the iterator to the atom \a *key.
163 *
164 * @param id atomic id to find
165 * @return iterator to atom if found, to end() - else
166 */
167AtomIdSet::const_iterator AtomIdSet::find(const atomId_t &id) const
168{
169 return const_iterator(atoms.find(id), FromIdToAtom());
170}
171
172/** Inserts a given atom into the set.
173 *
174 * @param key atom to insert
175 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
176 */
177std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atom * const key)
178{
179 std::pair<atomIdSet::iterator, bool> iter =
180 atoms.insert(key->getId());
181 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
182
183 return retiter;
184}
185
186/** Inserts a given atom into the set.
187 *
188 * @param id atomic id to insert
189 * @return pair of iterator and bool that states whether element is already present (true) or not (false)
190 */
191std::pair<AtomIdSet::iterator, bool> AtomIdSet::insert(const atomId_t &id)
192{
193 std::pair<atomIdSet::iterator, bool> iter =
194 atoms.insert(id);
195 std::pair<iterator, bool> retiter (std::make_pair(iterator(iter.first), iter.second));
196
197 return retiter;
198}
199
200AtomIdSet::const_iterator AtomIdSet::erase(AtomIdSet::const_iterator &loc)
201{
202 const_iterator iter = loc;
203 ++iter;
204 atom * const _atom = const_cast<atom *>(*loc);
205 atoms.erase( _atom->getId() );
206 return iter;
207}
208
209/** Erase an atom from the list.
210 *
211 * @param *key key to atom in list
212 * @return iterator to just after removed item (compliant with standard)
213 */
214AtomIdSet::const_iterator AtomIdSet::erase(const atom * const key)
215{
216 const_iterator iter = find(key);
217 if (iter != end()){
218 ++iter;
219 atoms.erase( key->getId() );
220 }
221 return iter;
222}
223
224/** Erase an atom from the list.
225 *
226 * @param id atomic id atom in list to erase
227 * @return iterator to just after removed item (compliant with standard)
228 */
229AtomIdSet::const_iterator AtomIdSet::erase(const atomId_t &id)
230{
231 atomIdSet::const_iterator iter = atoms.find(id);
232 if (iter != atoms.end()){
233 ++iter;
234 atoms.erase( id );
235 }
236 return iterator(iter, FromIdToAtom());
237}
Note: See TracBrowser for help on using the repository browser.