diff --git a/loop/src/backbone.cc b/loop/src/backbone.cc
index fa2909be4490dc4533e63cd91425c38a5f649c5b..8376a87cc960e14e826ce85fe25fc63e74e8c394 100644
--- a/loop/src/backbone.cc
+++ b/loop/src/backbone.cc
@@ -1036,17 +1036,9 @@ Real BackboneList::CARMSD(const BackboneList& other,
if (superposed_rmsd) {
// superpose CA positions
- core::EMatX3 pos_one = core::EMatX3::Zero(size(), 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(size(), 3);
-
- for (uint i = 0; i < size(); ++i) {
- core::EMatFillRow(pos_one, i, GetCA(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- core::EMatFillRow(pos_two, i, other.GetCA(i));
- }
-
+ core::EMatX3 pos_one, pos_two;
+ BackboneList::ExtractEigenCAPos(*this, pos_one);
+ BackboneList::ExtractEigenCAPos(other, pos_two);
return core::SuperposedRMSD(pos_one, pos_two);
} else {
@@ -1069,31 +1061,10 @@ Real BackboneList::RMSD(const BackboneList& other, bool superposed_rmsd) const {
if (empty()) return 0.0;
if (superposed_rmsd) {
- // superpose positions
- core::EMatX3 pos_one = core::EMatX3::Zero(5 * size(), 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(5 * size(), 3);
-
- uint base_idx;
- for(uint i = 0; i < size(); ++i){
- base_idx = 5*i;
- core::EMatFillRow(pos_one, base_idx, GetN(i));
- core::EMatFillRow(pos_one, base_idx + 1, GetCA(i));
- core::EMatFillRow(pos_one, base_idx + 2, GetCB(i));
- core::EMatFillRow(pos_one, base_idx + 3, GetC(i));
- core::EMatFillRow(pos_one, base_idx + 4, GetO(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- base_idx = 5*i;
- core::EMatFillRow(pos_two, base_idx, other.GetN(i));
- core::EMatFillRow(pos_two, base_idx + 1, other.GetCA(i));
- core::EMatFillRow(pos_two, base_idx + 2, other.GetCB(i));
- core::EMatFillRow(pos_two, base_idx + 3, other.GetC(i));
- core::EMatFillRow(pos_two, base_idx + 4, other.GetO(i));
- }
-
+ core::EMatX3 pos_one, pos_two;
+ BackboneList::ExtractEigenPos(*this, pos_one);
+ BackboneList::ExtractEigenPos(other, pos_two);
return core::SuperposedRMSD(pos_one, pos_two);
-
} else {
Real rmsd = 0.0;
@@ -1119,39 +1090,20 @@ geom::Mat4 BackboneList::GetTransform(const BackboneList& other) const {
"calculate the transform between them!");
}
- if(size() >= 3) {
- // superpose CA positions
- core::EMatX3 pos_one = core::EMatX3::Zero(size(), 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(size(), 3);
-
- for (uint i = 0; i < size(); ++i) {
- core::EMatFillRow(pos_one, i, GetCA(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- core::EMatFillRow(pos_two, i, other.GetCA(i));
- }
+ core::EMatX3 pos_one, pos_two;
- return core::MinRMSDSuperposition(pos_one, pos_two);
+ if(size() >= 3) {
+ // extract CA positions
+ BackboneList::ExtractEigenCAPos(*this, pos_one);
+ BackboneList::ExtractEigenCAPos(other, pos_two);
+
} else {
// superpose N, CA, C positions
- core::EMatX3 pos_one = core::EMatX3::Zero(size() * 3, 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(size() * 3, 3);
-
- for (uint i = 0; i < size(); ++i) {
- core::EMatFillRow(pos_one, i*3, GetN(i));
- core::EMatFillRow(pos_one, i*3+1, GetCA(i));
- core::EMatFillRow(pos_one, i*3+2, GetC(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- core::EMatFillRow(pos_two, i*3, other.GetN(i));
- core::EMatFillRow(pos_two, i*3+1, other.GetCA(i));
- core::EMatFillRow(pos_two, i*3+2, other.GetC(i));
- }
-
- return core::MinRMSDSuperposition(pos_one, pos_two);
+ BackboneList::ExtractEigenNCACPos(*this, pos_one);
+ BackboneList::ExtractEigenNCACPos(other, pos_two);
}
+
+ return core::MinRMSDSuperposition(pos_one, pos_two);
}
geom::Mat4 BackboneList::GetTransformIterative(const BackboneList& other,
@@ -1167,43 +1119,21 @@ geom::Mat4 BackboneList::GetTransformIterative(const BackboneList& other,
"calculate the transform between them!");
}
+ core::EMatX3 pos_one, pos_two;
+
if(size() >= 3) {
// superpose CA positions
- core::EMatX3 pos_one = core::EMatX3::Zero(size(), 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(size(), 3);
-
- for (uint i = 0; i < size(); ++i) {
- core::EMatFillRow(pos_one, i, GetCA(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- core::EMatFillRow(pos_two, i, other.GetCA(i));
- }
-
- std::vector<uint> empty_index_vec;
- return core::MinRMSDSuperposition(pos_one, pos_two, max_iterations,
- distance_thresh, empty_index_vec, false);
+ BackboneList::ExtractEigenCAPos(*this, pos_one);
+ BackboneList::ExtractEigenCAPos(other, pos_two);
} else {
// superpose N, CA, C positions
- core::EMatX3 pos_one = core::EMatX3::Zero(size() * 3, 3);
- core::EMatX3 pos_two = core::EMatX3::Zero(size() * 3, 3);
-
- for (uint i = 0; i < size(); ++i) {
- core::EMatFillRow(pos_one, i*3, GetN(i));
- core::EMatFillRow(pos_one, i*3+1, GetCA(i));
- core::EMatFillRow(pos_one, i*3+2, GetC(i));
- }
-
- for(uint i = 0; i < other.size(); ++i){
- core::EMatFillRow(pos_two, i*3, other.GetN(i));
- core::EMatFillRow(pos_two, i*3+1, other.GetCA(i));
- core::EMatFillRow(pos_two, i*3+2, other.GetC(i));
- }
-
- std::vector<uint> empty_index_vec;
- return core::MinRMSDSuperposition(pos_one, pos_two, max_iterations,
- distance_thresh, empty_index_vec, false);
+ BackboneList::ExtractEigenNCACPos(*this, pos_one);
+ BackboneList::ExtractEigenNCACPos(other, pos_two);
}
+
+ std::vector<uint> empty_index_vec;
+ return core::MinRMSDSuperposition(pos_one, pos_two, max_iterations,
+ distance_thresh, empty_index_vec, false);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1311,4 +1241,36 @@ Real BackboneList::ConstructFlankingAngle(const geom::Vec3& actual_o,
return std::atan2(geom::Dot(f,s), geom::Dot(f,r));
}
+void BackboneList::ExtractEigenCAPos(const BackboneList& bb_list,
+ core::EMatX3& pos) {
+ pos = core::EMatX3::Zero(bb_list.size(), 3);
+ for (uint i = 0; i < bb_list.size(); ++i) {
+ core::EMatFillRow(pos, i, bb_list.GetCA(i));
+ }
+}
+
+void BackboneList::ExtractEigenNCACPos(const BackboneList& bb_list,
+ core::EMatX3& pos) {
+ pos = core::EMatX3::Zero(bb_list.size() * 3, 3);
+
+ for (uint i = 0; i < bb_list.size(); ++i) {
+ core::EMatFillRow(pos, i*3, bb_list.GetN(i));
+ core::EMatFillRow(pos, i*3+1, bb_list.GetCA(i));
+ core::EMatFillRow(pos, i*3+2, bb_list.GetC(i));
+ }
+}
+
+void BackboneList::ExtractEigenPos(const BackboneList& bb_list,
+ core::EMatX3& pos) {
+ pos = core::EMatX3::Zero(bb_list.size() * 5, 3);
+
+ for (uint i = 0; i < bb_list.size(); ++i) {
+ core::EMatFillRow(pos, i*5, bb_list.GetN(i));
+ core::EMatFillRow(pos, i*5+1, bb_list.GetCA(i));
+ core::EMatFillRow(pos, i*5+2, bb_list.GetC(i));
+ core::EMatFillRow(pos, i*5+3, bb_list.GetCB(i));
+ core::EMatFillRow(pos, i*5+4, bb_list.GetO(i));
+ }
+}
+
}} // PM3-ns
diff --git a/loop/src/backbone.hh b/loop/src/backbone.hh
index b5549ece23e54475575145e6cd2577ff7fdf7faa..70e3cb15fe838860bc2d5a4ad506475dc376c4b8 100644
--- a/loop/src/backbone.hh
+++ b/loop/src/backbone.hh
@@ -330,6 +330,14 @@ public:
Real CARMSD(const BackboneList& other, bool superposed_rmsd = false) const;
Real RMSD(const BackboneList& other, bool superposed_rmsd = false) const;
+ // helpers to reduce code redundancy
+ static void ExtractEigenCAPos(const BackboneList& bb_list,
+ core::EMatX3& pos);
+ static void ExtractEigenNCACPos(const BackboneList& bb_list,
+ core::EMatX3& pos);
+ static void ExtractEigenPos(const BackboneList& bb_list,
+ core::EMatX3& pos);
+
// portable serialization
template <typename DS>
void Serialize(DS& ds) {
@@ -345,7 +353,7 @@ private:
const std::vector<Real>& psi_angles,
const std::vector<Real>& omega_angles);
- //helper to generate ideal angle for flanking rotation in Backrub
+ // helper to generate ideal angle for flanking rotation in Backrub
Real ConstructFlankingAngle(const geom::Vec3& actual_o,
const geom::Vec3& target_o,
const geom::Vec3& anchor_ca,