From 6674be51507be889ccbf4d87047816a2535a7300 Mon Sep 17 00:00:00 2001 From: Valerio Mariani <vmariani@localhost.localdomain> Date: Wed, 20 Jun 2012 20:53:46 +0200 Subject: [PATCH] Fixed problem with merged distance lists --- modules/mol/alg/src/local_dist_diff_test.cc | 27 ++++++++++++++++++--- modules/mol/alg/src/local_dist_diff_test.hh | 3 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/mol/alg/src/local_dist_diff_test.cc b/modules/mol/alg/src/local_dist_diff_test.cc index e495276da..06ca053ad 100644 --- a/modules/mol/alg/src/local_dist_diff_test.cc +++ b/modules/mol/alg/src/local_dist_diff_test.cc @@ -7,6 +7,13 @@ namespace ost { namespace mol { namespace alg { namespace { +bool is_distance_invalid(const std::pair<Real,Real>& value) +{ + if (value.first == -1.0 && value.second == -1) return true; + return false; +} + + // helper function String swapped_name(const String& name) { @@ -299,10 +306,10 @@ void merge_distance_lists(GlobalRDMap& ref_dist_map, const GlobalRDMap& new_dist // if you don't find it in the residue new, check that it is not missing because it is too long UniqueAtomIdentifier first_atom_to_find = ref_rd.first; UniqueAtomIdentifier second_atom_to_find = ref_rd.second; - // if both atoms are there, remove the distance from the ref_dist_map, + // if both atoms are there, remove the distance from the ref_dist_map (set it to invalid) if ((ref.FindAtom(first_atom_to_find.GetChainName(),first_atom_to_find.GetResNum(),first_atom_to_find.GetAtomName()).IsValid() && ref.FindAtom(second_atom_to_find.GetChainName(),second_atom_to_find.GetResNum(),second_atom_to_find.GetAtomName()).IsValid()) ) { - ref_dist_map_it->second.erase(ref_res_map_it); + ref_res_map_it->second = std::make_pair<Real,Real>(-1.0,-1.0); } } } @@ -336,11 +343,25 @@ void merge_distance_lists(GlobalRDMap& ref_dist_map, const GlobalRDMap& new_dist if (find_ref_res_ci == ref_dist_map.end()) { ref_dist_map[new_resnum] = new_dist_map_it->second; } - } + } + // finally, clean up the merged list by removing invalid distances + for (GlobalRDMap::const_iterator ref_dist_map_it = ref_dist_map.begin();ref_dist_map_it!=ref_dist_map.end();++ref_dist_map_it) { + ResidueRDMap new_residue_map; + for (ResidueRDMap::const_iterator res_ref_list_it = ref_dist_map_it->second.begin();res_ref_list_it!=ref_dist_map_it->second.end();++res_ref_list_it) { + if (is_distance_invalid(res_ref_list_it->second)) continue; + new_residue_map[res_ref_list_it->first]=res_ref_list_it->second; + } + ref_dist_map[ref_dist_map_it->first]=new_residue_map; + } } } +void UniqueAtomIdentifier::Print() const +{ + std::cout << chain_ << " " << residue_ << " " << residue_name_ << " " << atom_ << std::endl; +} + // helper function bool IsStandardResidue(String rn) { diff --git a/modules/mol/alg/src/local_dist_diff_test.hh b/modules/mol/alg/src/local_dist_diff_test.hh index ed6e10bad..6a2062fb4 100644 --- a/modules/mol/alg/src/local_dist_diff_test.hh +++ b/modules/mol/alg/src/local_dist_diff_test.hh @@ -49,6 +49,9 @@ public: /// \brief Returns the name of the atom, as a String String GetAtomName() const { return atom_; } + + /// \brief Prints the UniqueAtomIdentifier information to standard output + void Print() const; // required because UniqueAtomIdentifier is used as a key for a std::map bool operator==(const UniqueAtomIdentifier& rhs) const { -- GitLab