source: src/Fragmentation/Summation/SetValues/Fragment.cpp@ e0ae58d

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 e0ae58d was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * Fragment.cpp
26 *
27 * Created on: Aug 8, 2012
28 * Author: heber
29 */
30
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37// include headers that implement a archive in simple text format
38// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
39#include <boost/archive/text_oarchive.hpp>
40#include <boost/archive/text_iarchive.hpp>
41
42#include "CodePatterns/MemDebug.hpp"
43
44#include "Fragment.hpp"
45
46#include <algorithm>
47#include <cmath>
48#include <iostream>
49#include <limits>
50
51#include "CodePatterns/Assert.hpp"
52
53Fragment::Fragment()
54{}
55
56Fragment::Fragment(const positions_t &_positions, const charges_t &_charges)
57{
58 ASSERT( _positions.size() == _charges.size(),
59 "Fragment::Fragment() - given charges and positions don't match in size.");
60 positions_t::const_iterator piter = _positions.begin();
61 charges_t::const_iterator citer = _charges.begin();
62 for (;piter != _positions.end(); ++piter, ++citer)
63 nuclei.push_back( make_pair( *piter, *citer) );
64}
65
66
67Fragment& Fragment::operator+=(const Fragment &other)
68{
69 for (nuclei_t::const_iterator iter = other.nuclei.begin();
70 iter != other.nuclei.end(); ++iter) {
71 if (!containsNuclei(*iter)) {
72 nuclei.push_back(*iter);
73 }
74 }
75 return *this;
76}
77
78Fragment& Fragment::operator=(const Fragment &other)
79{
80 if (this != &other) {
81 nuclei.clear();
82 nuclei = other.nuclei;
83 }
84 return *this;
85}
86
87Fragment& Fragment::operator-=(const Fragment &other)
88{
89 for (nuclei_t::const_iterator iter = other.nuclei.begin();
90 iter != other.nuclei.end(); ++iter)
91 removeNuclei(*iter);
92 return *this;
93}
94
95bool Fragment::containsNuclei(const nucleus_t &n) const
96{
97 for (nuclei_t::const_iterator iter = nuclei.begin();
98 iter != nuclei.end(); ++iter)
99 if (Fragment::isPositionEqual(iter->first, n.first))
100 return true;
101 return false;
102}
103
104void Fragment::removeNuclei(const nucleus_t &n)
105{
106 for (nuclei_t::iterator iter = nuclei.begin();
107 iter != nuclei.end(); ++iter)
108 if (Fragment::isPositionEqual(iter->first, n.first)) {
109 nuclei.erase(iter);
110 break;
111 }
112}
113
114Fragment::positions_t Fragment::getPositions() const
115{
116 positions_t positions;
117 for (nuclei_t::const_iterator iter = nuclei.begin();
118 iter != nuclei.end(); ++iter)
119 positions.push_back(iter->first);
120 return positions;
121}
122
123Fragment::charges_t Fragment::getCharges() const
124{
125 charges_t charges;
126 for (nuclei_t::const_iterator iter = nuclei.begin();
127 iter != nuclei.end(); ++iter)
128 charges.push_back(iter->second);
129 return charges;
130}
131
132Fragment::nucleus_t Fragment::createNucleus(const position_t &position, const double charge)
133{
134 return nucleus_t( make_pair( position, charge ) );
135}
136
137bool Fragment::isPositionEqual(const position_t &a, const position_t &b)
138{
139 bool status = true;
140 for (size_t i=0;i<3;++i)
141 status &= fabs(a[i] - b[i]) < std::numeric_limits<double>::epsilon();
142 return status;
143}
144
145bool Fragment::operator==(const Fragment& other) const
146{
147 bool status = true;
148 // compare sizes
149 if (nuclei.size() != other.nuclei.size()) {
150 return false;
151 } else {
152 // if equal, sort, and compare each nuclei
153 Fragment::nuclei_t thisnuclei(nuclei);
154 Fragment::nuclei_t othernuclei(other.nuclei);
155 std::sort(thisnuclei.begin(), thisnuclei.end());
156 std::sort(othernuclei.begin(), othernuclei.end());
157 Fragment::nuclei_t::const_iterator iter = thisnuclei.begin();
158 Fragment::nuclei_t::const_iterator oiter = othernuclei.begin();
159 for (; iter != thisnuclei.end(); ++iter,++oiter)
160 status &= (*iter == *oiter);
161 }
162 return status;
163}
164
165std::ostream & operator<<(std::ostream &ost, const Fragment &f)
166{
167 size_t NucleiCounter = 1;
168 for (Fragment::nuclei_t::const_iterator iter = f.nuclei.begin();
169 iter != f.nuclei.end(); ++iter)
170 ost << "[" << NucleiCounter++ << "]:" << *iter << ", ";
171 return ost;
172}
173
174std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n)
175{
176 ost << n.first << " with charge " << n.second;
177 return ost;
178}
179
180bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b)
181{
182 bool status = true;
183 // check positions
184 status &= Fragment::isPositionEqual(a.first, b.first);
185 status &= fabs(a.second - b.second) < std::numeric_limits<double>::epsilon();
186 return status;
187}
188
189template<> Fragment ZeroInstance<Fragment>()
190{
191 Fragment::positions_t positions;
192 Fragment::charges_t charges;
193 Fragment returnvalue(positions, charges);
194 return returnvalue;
195}
196
197
198// we need to explicitly instantiate the serialization functions
199BOOST_CLASS_EXPORT_IMPLEMENT(Fragment)
Note: See TracBrowser for help on using the repository browser.