BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: global.h,v 1.25 2005/10/23 12:02:19 oliver Exp $ 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 // iterate over the two composite structures in parallel 00065 // caveat: if the two composite structures are not isomorphous, bonds 00066 // are created between unrelated atoms! 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 // create a hash map containing a 1:1 relation for the atom pointers 00074 // atom_map maps atom pointers of atom_container to atom pointers in cloned 00075 atom_map.insert(std::pair<const Atom*, Atom*>(&*atom_iter_a, &*atom_iter_b)); 00076 00077 // iterate over all bonds and store the bonds in a list 00078 // to get each bond exactly once, we check the first atom 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 // iterate over all bonds and create a bond in the cloned structure 00089 // if both atoms of the bond are contained in the cloned structure, 00090 // thus preventing the copying of bonds between atoms of atom_container 00091 // and atoms outside atom_container 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 } // namespace BALL 00116 00117 #endif // BALL_KERNEL_GLOBAL_H