From de0932e9ef0e13ab1d5bd6f7e4f0f9f2a50d2526 Mon Sep 17 00:00:00 2001
From: ansgar <ansgar@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Mon, 5 Apr 2010 21:42:56 +0000
Subject: [PATCH] added Bond::GetOther convenience method

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1922 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/mol/base/pymod/export_bond.cc |  3 +++
 modules/mol/base/src/bond_handle.cc   | 14 ++++++++++++++
 modules/mol/base/src/bond_handle.hh   |  5 +++++
 3 files changed, 22 insertions(+)

diff --git a/modules/mol/base/pymod/export_bond.cc b/modules/mol/base/pymod/export_bond.cc
index 8537b2a13..e22adf98e 100644
--- a/modules/mol/base/pymod/export_bond.cc
+++ b/modules/mol/base/pymod/export_bond.cc
@@ -41,6 +41,8 @@ void export_Bond()
                   make_function(&BondHandle::GetFirst))
     .add_property("second", 
                   make_function(&BondHandle::GetSecond))
+    .add_property("other", 
+                  make_function(&BondHandle::GetOther))
     .add_property("length", 
                   &BondHandle::GetLength)
     .add_property("bond_order",
@@ -48,6 +50,7 @@ void export_Bond()
                   &BondHandle::SetBondOrder)
     .def("GetFirst", &BondHandle::GetFirst)    
     .def("GetSecond",&BondHandle::GetSecond)
+    .def("GetOther",&BondHandle::GetOther)
     .def("GetLength",&BondHandle::GetLength)
     .def("GetBondOrder",&BondHandle::GetBondOrder)
     .def("SetBondOrder",&BondHandle::SetBondOrder)
diff --git a/modules/mol/base/src/bond_handle.cc b/modules/mol/base/src/bond_handle.cc
index 901a1ab4d..995f4d143 100644
--- a/modules/mol/base/src/bond_handle.cc
+++ b/modules/mol/base/src/bond_handle.cc
@@ -64,6 +64,20 @@ AtomHandle BondHandle::GetSecond() const
   return nrvo;
 }
 
+AtomHandle BondHandle::GetOther(const AtomHandle& a) const
+{
+  this->CheckValidity();
+  if(a.IsValid()) {
+    if(a.Impl()==impl_->GetFirst()) {
+      return GetSecond();
+    } else {
+      return GetFirst();
+    }
+  }
+  AtomHandle nrvo(impl_->GetFirst());
+  return nrvo;
+}
+
 geom::Vec3 BondHandle::GetPos() const
 {
   this->CheckValidity();  
diff --git a/modules/mol/base/src/bond_handle.hh b/modules/mol/base/src/bond_handle.hh
index ca3fc92f6..b23ca0679 100644
--- a/modules/mol/base/src/bond_handle.hh
+++ b/modules/mol/base/src/bond_handle.hh
@@ -73,6 +73,11 @@ public:
   /// \brief get second atom
   /// In python also available as the property second
   AtomHandle GetSecond() const;
+
+  /// \brief get other atom
+  /// Returns one of the two atoms that does not match the given one.
+  /// In python also available as the property other
+  AtomHandle GetOther(const AtomHandle& a) const;
   //@}
 
   /// \brief return midpoint between the two atoms (transformed coordinates)
-- 
GitLab