00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_KERNEL_GLOBAL_H
00008 #define BALL_KERNEL_GLOBAL_H
00009
00010 #ifndef BALL_KERNEL_ATOM_H
00011 # include <BALL/KERNEL/atom.h>
00012 #endif
00013
00014 #ifndef BALL_KERNEL_BOND_H
00015 # include <BALL/KERNEL/bond.h>
00016 #endif
00017
00018 namespace BALL
00019 {
00056 template <class AtomContainerType>
00057 void cloneBonds(const AtomContainerType& atom_container, AtomContainerType& cloned)
00058 {
00059 typedef HashMap<const Atom*, Atom*> AtomMap;
00060 AtomMap atom_map;
00061
00062 std::list<const Bond*> bond_list;
00063
00064
00065
00066
00067 Atom::BondConstIterator bond_iter;
00068 AtomConstIterator atom_iter_a(atom_container.beginAtom());
00069 AtomIterator atom_iter_b(cloned.beginAtom());
00070
00071 for (; +atom_iter_a && +atom_iter_b; ++atom_iter_a, ++atom_iter_b)
00072 {
00073
00074
00075 atom_map.insert(std::pair<const Atom*, Atom*>(&*atom_iter_a, &*atom_iter_b));
00076
00077
00078
00079 for (bond_iter = atom_iter_a->beginBond(); bond_iter != atom_iter_a->endBond(); ++bond_iter)
00080 {
00081 if (bond_iter->getFirstAtom() == &(*atom_iter_a))
00082 {
00083 bond_list.push_back(&(*bond_iter));
00084 }
00085 }
00086 }
00087
00088
00089
00090
00091
00092 std::list<const Bond*>::iterator list_iter = bond_list.begin();
00093 for ( ; list_iter != bond_list.end(); ++list_iter)
00094 {
00095 if (atom_map.has((*list_iter)->getFirstAtom()) && atom_map.has((*list_iter)->getSecondAtom()))
00096 {
00097 Atom* a1 = atom_map[(*list_iter)->getFirstAtom()];
00098 Atom* a2 = atom_map[(*list_iter)->getSecondAtom()];
00099 Bond* tmp_bond = static_cast<Bond*>((*list_iter)->create(false, true));
00100 tmp_bond->createBond(*tmp_bond, *a1, *a2);
00101 *tmp_bond = **list_iter;
00102 tmp_bond->setFirstAtom(a1);
00103 tmp_bond->setSecondAtom(a2);
00104 tmp_bond->finalize();
00105 }
00106 }
00107 }
00108
00114 extern bool clone_bonds;
00115 }
00116
00117 #endif // BALL_KERNEL_GLOBAL_H