Loading...
Searching...
No Matches
KERNEL/global.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: global.h,v 1.25 2005/10/23 12:02:19 oliver Exp $
//
#ifndef BALL_KERNEL_GLOBAL_H
#define BALL_KERNEL_GLOBAL_H
#ifndef BALL_KERNEL_ATOM_H
# include <BALL/KERNEL/atom.h>
#endif
#ifndef BALL_KERNEL_BOND_H
# include <BALL/KERNEL/bond.h>
#endif
namespace BALL
{
template <class AtomContainerType>
void cloneBonds(const AtomContainerType& atom_container, AtomContainerType& cloned)
{
typedef HashMap<const Atom*, Atom*> AtomMap;
AtomMap atom_map;
std::list<const Bond*> bond_list;
// iterate over the two composite structures in parallel
// caveat: if the two composite structures are not isomorphous, bonds
// are created between unrelated atoms!
Atom::BondConstIterator bond_iter;
AtomConstIterator atom_iter_a(atom_container.beginAtom());
AtomIterator atom_iter_b(cloned.beginAtom());
for (; +atom_iter_a && +atom_iter_b; ++atom_iter_a, ++atom_iter_b)
{
// create a hash map containing a 1:1 relation for the atom pointers
// atom_map maps atom pointers of atom_container to atom pointers in cloned
atom_map.insert(std::pair<const Atom*, Atom*>(&*atom_iter_a, &*atom_iter_b));
// iterate over all bonds and store the bonds in a list
// to get each bond exactly once, we check the first atom
for (bond_iter = atom_iter_a->beginBond(); bond_iter != atom_iter_a->endBond(); ++bond_iter)
{
if (bond_iter->getFirstAtom() == &(*atom_iter_a))
{
bond_list.push_back(&(*bond_iter));
}
}
}
// iterate over all bonds and create a bond in the cloned structure
// if both atoms of the bond are contained in the cloned structure,
// thus preventing the copying of bonds between atoms of atom_container
// and atoms outside atom_container
std::list<const Bond*>::iterator list_iter = bond_list.begin();
for ( ; list_iter != bond_list.end(); ++list_iter)
{
if (atom_map.has((*list_iter)->getFirstAtom()) && atom_map.has((*list_iter)->getSecondAtom()))
{
Atom* a1 = atom_map[(*list_iter)->getFirstAtom()];
Atom* a2 = atom_map[(*list_iter)->getSecondAtom()];
Bond* tmp_bond = static_cast<Bond*>((*list_iter)->create(false, true));
tmp_bond->createBond(*tmp_bond, *a1, *a2);
*tmp_bond = **list_iter;
tmp_bond->setFirstAtom(a1);
tmp_bond->setSecondAtom(a2);
tmp_bond->finalize();
}
}
}
extern bool clone_bonds;
} // namespace BALL
#endif // BALL_KERNEL_GLOBAL_H
atom.h
bond.h
BALL::Atom
Definition atom.h:90
BALL::Atom::BondConstIterator
ConstRandomAccessIterator< Atom, Bond, BondIteratorPosition, BondIteratorTraits > BondConstIterator
Constant random access iterator for bonds.
Definition atom.h:904
BALL::Bond
Definition bond.h:57
BALL::Bond::setSecondAtom
void setSecondAtom(Atom *atom)
BALL::Bond::finalize
void finalize()
BALL::Bond::createBond
static Bond * createBond(Bond &bond, Atom &first, Atom &second)
BALL::Bond::setFirstAtom
void setFirstAtom(Atom *atom)
BALL::HashMap
HashMap class based on the STL map (containing serveral convenience functions).
Definition hashMap.h:74
BALL::clone_bonds
bool clone_bonds
BALL::cloneBonds
void cloneBonds(const AtomContainerType &atom_container, AtomContainerType &cloned)
Definition KERNEL/global.h:57
BALL
Definition constants.h:13
BALL::AtomIterator
BidirectionalIterator< Composite, Atom, Composite::CompositeIterator, AtomIteratorTraits > AtomIterator
Definition atomIterator.h:84
BALL::AtomConstIterator
ConstBidirectionalIterator< Composite, Atom, Composite::CompositeIterator, AtomIteratorTraits > AtomConstIterator
Definition atomIterator.h:90