BALL 1.5.0
KERNEL/global.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4// $Id: global.h,v 1.25 2005/10/23 12:02:19 oliver Exp $
5//
6
7#ifndef BALL_KERNEL_GLOBAL_H
8#define BALL_KERNEL_GLOBAL_H
9
10#ifndef BALL_KERNEL_ATOM_H
11# include <BALL/KERNEL/atom.h>
12#endif
13
14#ifndef BALL_KERNEL_BOND_H
15# include <BALL/KERNEL/bond.h>
16#endif
17
18namespace BALL
19{
56 template <class AtomContainerType>
57 void cloneBonds(const AtomContainerType& atom_container, AtomContainerType& cloned)
58 {
59 typedef HashMap<const Atom*, Atom*> AtomMap;
60 AtomMap atom_map;
61
62 std::list<const Bond*> bond_list;
63
64 // iterate over the two composite structures in parallel
65 // caveat: if the two composite structures are not isomorphous, bonds
66 // are created between unrelated atoms!
67 Atom::BondConstIterator bond_iter;
68 AtomConstIterator atom_iter_a(atom_container.beginAtom());
69 AtomIterator atom_iter_b(cloned.beginAtom());
70
71 for (; +atom_iter_a && +atom_iter_b; ++atom_iter_a, ++atom_iter_b)
72 {
73 // create a hash map containing a 1:1 relation for the atom pointers
74 // atom_map maps atom pointers of atom_container to atom pointers in cloned
75 atom_map.insert(std::pair<const Atom*, Atom*>(&*atom_iter_a, &*atom_iter_b));
76
77 // iterate over all bonds and store the bonds in a list
78 // to get each bond exactly once, we check the first atom
79 for (bond_iter = atom_iter_a->beginBond(); bond_iter != atom_iter_a->endBond(); ++bond_iter)
80 {
81 if (bond_iter->getFirstAtom() == &(*atom_iter_a))
82 {
83 bond_list.push_back(&(*bond_iter));
84 }
85 }
86 }
87
88 // iterate over all bonds and create a bond in the cloned structure
89 // if both atoms of the bond are contained in the cloned structure,
90 // thus preventing the copying of bonds between atoms of atom_container
91 // and atoms outside atom_container
92 std::list<const Bond*>::iterator list_iter = bond_list.begin();
93 for ( ; list_iter != bond_list.end(); ++list_iter)
94 {
95 if (atom_map.has((*list_iter)->getFirstAtom()) && atom_map.has((*list_iter)->getSecondAtom()))
96 {
97 Atom* a1 = atom_map[(*list_iter)->getFirstAtom()];
98 Atom* a2 = atom_map[(*list_iter)->getSecondAtom()];
99 Bond* tmp_bond = static_cast<Bond*>((*list_iter)->create(false, true));
100 tmp_bond->createBond(*tmp_bond, *a1, *a2);
101 *tmp_bond = **list_iter;
102 tmp_bond->setFirstAtom(a1);
103 tmp_bond->setSecondAtom(a2);
104 tmp_bond->finalize();
105 }
106 }
107 }
108
114 extern bool clone_bonds;
115} // namespace BALL
116
117#endif // BALL_KERNEL_GLOBAL_H
bool clone_bonds
void cloneBonds(const AtomContainerType &atom_container, AtomContainerType &cloned)
Definition: KERNEL/global.h:57
Definition: constants.h:13
Mutable bidirectional iterator.
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:74
void setSecondAtom(Atom *atom)
void finalize()
static Bond * createBond(Bond &bond, Atom &first, Atom &second)
void setFirstAtom(Atom *atom)