From 2607f68daabd9f1383c8c3d68dc6789f582c6411 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Tue, 17 Jan 2017 13:15:01 +0100
Subject: [PATCH] round to closest angular bin instead of simply rounding down
---
sidechain/doc/rotamer_lib.rst | 2 +-
sidechain/src/bb_dep_rotamer_lib.cc | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/sidechain/doc/rotamer_lib.rst b/sidechain/doc/rotamer_lib.rst
index ea0d4f1a..21ca7e4e 100644
--- a/sidechain/doc/rotamer_lib.rst
+++ b/sidechain/doc/rotamer_lib.rst
@@ -167,7 +167,7 @@ The Backbone Dependent Rotamer Library
The returned rotamers are either directly returned in the form as they are
added to the library or can be interpolated.
In the first option, *phi* and *psi* simply get transformed to the
- according bin using following formalism: bin = int((angle + pi)/bin_size).
+ according bin using following formalism: bin = round((angle + pi)/bin_size).
In case of interpolation, the chi angles and the according standard
deviations of the rotamers get bilinearly interpolated using the
corresponding rotamers with same configuration from the neighbouring bins.
diff --git a/sidechain/src/bb_dep_rotamer_lib.cc b/sidechain/src/bb_dep_rotamer_lib.cc
index 03ec1c9a..8abeaf7b 100644
--- a/sidechain/src/bb_dep_rotamer_lib.cc
+++ b/sidechain/src/bb_dep_rotamer_lib.cc
@@ -523,10 +523,14 @@ uint BBDepRotamerLib::GetBackboneBin(Real phi, Real psi) const{
phi += Real(M_PI);
psi += Real(M_PI);
- uint phi_bin = std::min(static_cast<uint>(phi / phi_bin_size_), phi_bins_ - 1);
- uint psi_bin = std::min(static_cast<uint>(psi / psi_bin_size_), psi_bins_ - 1);
+ // ugly round => round is in standard library c++ 11
+ uint phi_bin = std::floor(phi / phi_bin_size_ + Real(0.5));
+ uint psi_bin = std::floor(psi / psi_bin_size_ + Real(0.5));
+
+ if(phi_bin >= phi_bins_) phi_bin = 0;
+ if(psi_bin >= psi_bins_) psi_bin = 0;
- return psi_bin*phi_bins_+phi_bin;
+ return psi_bin*phi_bins_ + phi_bin;
}
void BBDepRotamerLib::GetBackboneBin(Real phi, Real psi, uint& bin00, uint& bin10,
--
GitLab