source: src/Fragmentation/Summation/SetValues/Fragment.cpp@ 16c6f7

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 16c6f7 was 6829d2, checked in by Frederik Heber <heber@…>, 8 years ago

MPQCData additionally stores the atomic number per nuclei.

  • in case of DoSampleValenceOnly the charge does not represent the atomic number and moreover it is no longer unique. However, we need this unique association for fitting potentials to the fragment results.
  • TESTFIX: set all tests to XFAIL that parse either fragmentation results or homologies.
  • TESTFIX: needed to adapt HomologyContainerUnitTest which uses FragmentStub.
  • TESTFIX: needed to adapt FragmentUnitTest.
  • Property mode set to 100644
File size: 6.1 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(
57 const positions_t &_positions,
58 const atomicnumbers_t &_atomicnumbers,
59 const charges_t &_charges)
60{
61 ASSERT( _positions.size() == _charges.size(),
62 "Fragment::Fragment() - given charges and positions don't match in size.");
63 positions_t::const_iterator piter = _positions.begin();
64 atomicnumbers_t::const_iterator aiter = _atomicnumbers.begin();
65 charges_t::const_iterator citer = _charges.begin();
66 for (;piter != _positions.end(); ++piter, ++aiter, ++citer)
67 nuclei.push_back( createNucleus(*piter, *aiter, *citer) );
68}
69
70
71Fragment& Fragment::operator+=(const Fragment &other)
72{
73 for (nuclei_t::const_iterator iter = other.nuclei.begin();
74 iter != other.nuclei.end(); ++iter) {
75 if (!containsNuclei(*iter)) {
76 nuclei.push_back(*iter);
77 }
78 }
79 return *this;
80}
81
82Fragment& Fragment::operator=(const Fragment &other)
83{
84 if (this != &other) {
85 nuclei.clear();
86 nuclei = other.nuclei;
87 }
88 return *this;
89}
90
91Fragment& Fragment::operator-=(const Fragment &other)
92{
93 for (nuclei_t::const_iterator iter = other.nuclei.begin();
94 iter != other.nuclei.end(); ++iter)
95 removeNuclei(*iter);
96 return *this;
97}
98
99bool Fragment::containsNuclei(const nucleus_t &n) const
100{
101 for (nuclei_t::const_iterator iter = nuclei.begin();
102 iter != nuclei.end(); ++iter)
103 if (Fragment::isPositionEqual(iter->first, n.first))
104 return true;
105 return false;
106}
107
108void Fragment::removeNuclei(const nucleus_t &n)
109{
110 for (nuclei_t::iterator iter = nuclei.begin();
111 iter != nuclei.end(); ++iter)
112 if (Fragment::isPositionEqual(iter->first, n.first)) {
113 nuclei.erase(iter);
114 break;
115 }
116}
117
118Fragment::positions_t Fragment::getPositions() const
119{
120 positions_t positions;
121 for (nuclei_t::const_iterator iter = nuclei.begin();
122 iter != nuclei.end(); ++iter)
123 positions.push_back(iter->first);
124 return positions;
125}
126
127Fragment::atomicnumbers_t Fragment::getAtomicNumbers() const
128{
129 atomicnumbers_t positions;
130 for (nuclei_t::const_iterator iter = nuclei.begin();
131 iter != nuclei.end(); ++iter)
132 positions.push_back(iter->second.first);
133 return positions;
134}
135
136Fragment::charges_t Fragment::getCharges() const
137{
138 charges_t charges;
139 for (nuclei_t::const_iterator iter = nuclei.begin();
140 iter != nuclei.end(); ++iter)
141 charges.push_back(iter->second.second);
142 return charges;
143}
144
145Fragment::nucleus_t Fragment::createNucleus(
146 const position_t &position,
147 const atomicNumber_t &atomicnumber,
148 const double charge)
149{
150 return nucleus_t( make_pair( position, std::make_pair(atomicnumber, charge) ) );
151}
152
153bool Fragment::isPositionEqual(const position_t &a, const position_t &b)
154{
155 bool status = true;
156 for (size_t i=0;i<3;++i)
157 status &= fabs(a[i] - b[i]) < std::numeric_limits<double>::epsilon();
158 return status;
159}
160
161bool Fragment::operator==(const Fragment& other) const
162{
163 bool status = true;
164 // compare sizes
165 if (nuclei.size() != other.nuclei.size()) {
166 return false;
167 } else {
168 // if equal, sort, and compare each nuclei
169 Fragment::nuclei_t thisnuclei(nuclei);
170 Fragment::nuclei_t othernuclei(other.nuclei);
171 std::sort(thisnuclei.begin(), thisnuclei.end());
172 std::sort(othernuclei.begin(), othernuclei.end());
173 Fragment::nuclei_t::const_iterator iter = thisnuclei.begin();
174 Fragment::nuclei_t::const_iterator oiter = othernuclei.begin();
175 for (; iter != thisnuclei.end(); ++iter,++oiter)
176 status &= (*iter == *oiter);
177 }
178 return status;
179}
180
181std::ostream & operator<<(std::ostream &ost, const Fragment &f)
182{
183 size_t NucleiCounter = 1;
184 for (Fragment::nuclei_t::const_iterator iter = f.nuclei.begin();
185 iter != f.nuclei.end(); ++iter)
186 ost << "[" << NucleiCounter++ << "]:" << *iter << ", ";
187 return ost;
188}
189
190std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n)
191{
192 ost << n.first << " with Z of " << n.second.first << " charge " << n.second.second;
193 return ost;
194}
195
196bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b)
197{
198 bool status = true;
199 // check positions
200 status &= Fragment::isPositionEqual(a.first, b.first);
201 status &= (a.second.first == b.second.first);
202 status &= fabs(a.second.second - b.second.second) < std::numeric_limits<double>::epsilon();
203 return status;
204}
205
206template<> Fragment ZeroInstance<Fragment>()
207{
208 Fragment::positions_t positions;
209 Fragment::atomicnumbers_t atomicnumbers;
210 Fragment::charges_t charges;
211 Fragment returnvalue(positions, atomicnumbers, charges);
212 return returnvalue;
213}
214
215// below is not needed as we have above static ZeroInstace instantiating the code
216
217//// we need to explicitly instantiate the serialization functions
218//BOOST_CLASS_EXPORT_IMPLEMENT(Fragment)
Note: See TracBrowser for help on using the repository browser.