/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2012 University of Bonn. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* Fragment.cpp
*
* Created on: Aug 8, 2012
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include "Fragment.hpp"
#include "CodePatterns/Assert.hpp"
Fragment::Fragment()
{}
Fragment::Fragment(positions_t &_positions, charges_t &_charges)
{
ASSERT( _positions.size() == _charges.size(),
"Fragment::Fragment() - given charges and positions don't match in size.");
positions_t::const_iterator piter = _positions.begin();
charges_t::const_iterator citer = _charges.begin();
for (;piter != _positions.end(); ++piter, ++citer)
nuclei.push_back( make_pair( *piter, *citer) );
}
Fragment& Fragment::operator+=(const Fragment &other)
{
for (nuclei_t::const_iterator iter = other.nuclei.begin();
iter != other.nuclei.end(); ++iter) {
if (!containsNuclei(*iter)) {
nuclei.push_back(*iter);
}
}
return *this;
}
Fragment& Fragment::operator=(const Fragment &other)
{
nuclei.clear();
nuclei = other.nuclei;
return *this;
}
Fragment& Fragment::operator-=(const Fragment &other)
{
for (nuclei_t::const_iterator iter = other.nuclei.begin();
iter != other.nuclei.end(); ++iter)
removeNuclei(*iter);
return *this;
}
bool Fragment::containsNuclei(const nucleus_t &n) const
{
for (nuclei_t::const_iterator iter = nuclei.begin();
iter != nuclei.end(); ++iter) {
if (((*iter).first == n.first) && ((*iter).second == n.second))
return true;
}
return false;
}
void Fragment::removeNuclei(const nucleus_t &n)
{
for (nuclei_t::iterator iter = nuclei.begin();
iter != nuclei.end(); ++iter) {
if (((*iter).first == n.first) && ((*iter).second == n.second)) {
nuclei.erase(iter);
break;
}
}
}
template<> Fragment ZeroInstance()
{
Fragment::positions_t positions;
Fragment::charges_t charges;
Fragment returnvalue(positions, charges);
return returnvalue;
}