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

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

Placed Containers, Converter, and SetValues as subfolders into Summation.

  • also libMolecuilderFragmentationSummation is now a shared library, easing linkage to libMolecuilderJobs, and contains all of the three convenience libraries.
  • libMolecuilderFragmentationSetValues is now again convenience, as contained in ..Summation which in turn is shared.
  • KeySetsContainer right now is the link between lib..Summation and lib.. Fragmentation. Hence, we had to extract the module and change it into a shared library, as it is required by libMolecuilderJobs through ..Summation but also by ..Fragmentation that heavily relies on this container.
  • moved parseKeySetFile down into Fragmentation folder to KeySetsContainer, it is also contained in new shared library libMolecuilderFragmentation_ KeySetsContainer.
  • Property mode set to 100644
File size: 5.3 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 * Fragment.cpp
25 *
26 * Created on: Aug 8, 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 headers that implement a archive in simple text format
37// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
38#include <boost/archive/text_oarchive.hpp>
39#include <boost/archive/text_iarchive.hpp>
40
41#include "CodePatterns/MemDebug.hpp"
42
43#include "Fragment.hpp"
44
45#include <algorithm>
46#include <cmath>
47#include <iostream>
48#include <limits>
49
50#include "CodePatterns/Assert.hpp"
51
52Fragment::Fragment()
53{}
54
55Fragment::Fragment(const positions_t &_positions, const charges_t &_charges)
56{
57 ASSERT( _positions.size() == _charges.size(),
58 "Fragment::Fragment() - given charges and positions don't match in size.");
59 positions_t::const_iterator piter = _positions.begin();
60 charges_t::const_iterator citer = _charges.begin();
61 for (;piter != _positions.end(); ++piter, ++citer)
62 nuclei.push_back( make_pair( *piter, *citer) );
63}
64
65
66Fragment& Fragment::operator+=(const Fragment &other)
67{
68 for (nuclei_t::const_iterator iter = other.nuclei.begin();
69 iter != other.nuclei.end(); ++iter) {
70 if (!containsNuclei(*iter)) {
71 nuclei.push_back(*iter);
72 }
73 }
74 return *this;
75}
76
77Fragment& Fragment::operator=(const Fragment &other)
78{
79 if (this != &other) {
80 nuclei.clear();
81 nuclei = other.nuclei;
82 }
83 return *this;
84}
85
86Fragment& Fragment::operator-=(const Fragment &other)
87{
88 for (nuclei_t::const_iterator iter = other.nuclei.begin();
89 iter != other.nuclei.end(); ++iter)
90 removeNuclei(*iter);
91 return *this;
92}
93
94bool Fragment::containsNuclei(const nucleus_t &n) const
95{
96 for (nuclei_t::const_iterator iter = nuclei.begin();
97 iter != nuclei.end(); ++iter)
98 if (Fragment::isPositionEqual(iter->first, n.first))
99 return true;
100 return false;
101}
102
103void Fragment::removeNuclei(const nucleus_t &n)
104{
105 for (nuclei_t::iterator iter = nuclei.begin();
106 iter != nuclei.end(); ++iter)
107 if (Fragment::isPositionEqual(iter->first, n.first)) {
108 nuclei.erase(iter);
109 break;
110 }
111}
112
113Fragment::positions_t Fragment::getPositions() const
114{
115 positions_t positions;
116 for (nuclei_t::const_iterator iter = nuclei.begin();
117 iter != nuclei.end(); ++iter)
118 positions.push_back(iter->first);
119 return positions;
120}
121
122Fragment::charges_t Fragment::getCharges() const
123{
124 charges_t charges;
125 for (nuclei_t::const_iterator iter = nuclei.begin();
126 iter != nuclei.end(); ++iter)
127 charges.push_back(iter->second);
128 return charges;
129}
130
131Fragment::nucleus_t Fragment::createNucleus(const position_t &position, const double charge)
132{
133 return nucleus_t( make_pair( position, charge ) );
134}
135
136bool Fragment::isPositionEqual(const position_t &a, const position_t &b)
137{
138 bool status = true;
139 for (size_t i=0;i<3;++i)
140 status &= fabs(a[i] - b[i]) < std::numeric_limits<double>::epsilon();
141 return status;
142}
143
144bool Fragment::operator==(const Fragment& other) const
145{
146 bool status = true;
147 // compare sizes
148 if (nuclei.size() != other.nuclei.size()) {
149 return false;
150 } else {
151 // if equal, sort, and compare each nuclei
152 Fragment::nuclei_t thisnuclei(nuclei);
153 Fragment::nuclei_t othernuclei(other.nuclei);
154 std::sort(thisnuclei.begin(), thisnuclei.end());
155 std::sort(othernuclei.begin(), othernuclei.end());
156 Fragment::nuclei_t::const_iterator iter = thisnuclei.begin();
157 Fragment::nuclei_t::const_iterator oiter = othernuclei.begin();
158 for (; iter != thisnuclei.end(); ++iter,++oiter)
159 status &= (*iter == *oiter);
160 }
161 return status;
162}
163
164std::ostream & operator<<(std::ostream &ost, const Fragment &f)
165{
166 size_t NucleiCounter = 1;
167 for (Fragment::nuclei_t::const_iterator iter = f.nuclei.begin();
168 iter != f.nuclei.end(); ++iter)
169 ost << "[" << NucleiCounter++ << "]:" << *iter << ", ";
170 return ost;
171}
172
173std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n)
174{
175 ost << n.first << " with charge " << n.second;
176 return ost;
177}
178
179bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b)
180{
181 bool status = true;
182 // check positions
183 status &= Fragment::isPositionEqual(a.first, b.first);
184 status &= fabs(a.second - b.second) < std::numeric_limits<double>::epsilon();
185 return status;
186}
187
188template<> Fragment ZeroInstance<Fragment>()
189{
190 Fragment::positions_t positions;
191 Fragment::charges_t charges;
192 Fragment returnvalue(positions, charges);
193 return returnvalue;
194}
195
196
197// we need to explicitly instantiate the serialization functions
198BOOST_CLASS_EXPORT_IMPLEMENT(Fragment)
Note: See TracBrowser for help on using the repository browser.