Skip to content
Snippets Groups Projects
Commit 0e2bb8ba authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

Simplified interface of SidechainReconstructor::Reconstruct to get loop data from linked env.

parent 092ba23a
No related branches found
No related tags found
No related merge requests found
......@@ -22,17 +22,18 @@ WrapGetDisulfidResIndices(const SidechainReconstructionData& sc_rec_data) {
return return_list;
}
template<typename PosDataType> SidechainReconstructionDataPtr
WrapReconstruct(SidechainReconstructor& sc_rec, const PosDataType& pos_data,
uint start_resnum, uint chain_idx) {
return sc_rec.Reconstruct(pos_data, start_resnum, chain_idx);
SidechainReconstructionDataPtr
WrapReconstruct(SidechainReconstructor& sc_rec, uint start_resnum,
uint num_residues, uint chain_idx) {
return sc_rec.Reconstruct(start_resnum, num_residues, chain_idx);
}
template<typename PosDataType> SidechainReconstructionDataPtr
WrapReconstructRN(SidechainReconstructor& sc_rec, const PosDataType& pos_data,
const ost::mol::ResNum& start_resnum, uint chain_idx) {
SidechainReconstructionDataPtr
WrapReconstructRN(SidechainReconstructor& sc_rec,
const ost::mol::ResNum& start_resnum,
uint num_residues, uint chain_idx) {
uint num = start_resnum.GetNum();
return sc_rec.Reconstruct(pos_data, num, chain_idx);
return sc_rec.Reconstruct(num, num_residues, chain_idx);
}
template<typename LibType> void
......@@ -62,14 +63,10 @@ void export_SidechainReconstructor() {
arg("cutoff")=20, arg("graph_max_complexity")=100000000,
arg("graph_intial_epsilon")=0.02, arg("disulfid_max_distance")=8,
arg("disulfid_score_thresh")=45)))
.def("Reconstruct", WrapReconstruct<loop::BackboneList>,
(arg("bb_list"), arg("start_resnum"), arg("chain_idx")=0))
.def("Reconstruct", WrapReconstructRN<loop::BackboneList>,
(arg("bb_list"), arg("start_resnum"), arg("chain_idx")=0))
.def("Reconstruct", WrapReconstruct<loop::AllAtomPositions>,
(arg("new_pos"), arg("start_resnum"), arg("chain_idx")=0))
.def("Reconstruct", WrapReconstructRN<loop::AllAtomPositions>,
(arg("new_pos"), arg("start_resnum"), arg("chain_idx")=0))
.def("Reconstruct", WrapReconstruct,
(arg("start_resnum"), arg("num_residues"), arg("chain_idx")=0))
.def("Reconstruct", WrapReconstructRN,
(arg("start_resnum"), arg("num_residues"), arg("chain_idx")=0))
.def("AttachEnvironment", WrapAttachEnvironment<bool>,
(arg("env"), arg("use_frm")=true, arg("use_bbdep_lib")=true,
arg("consider_hbonds")=true))
......
......@@ -8,22 +8,7 @@ namespace promod3 { namespace sidechain {
namespace {
// to distinguish BackboneList / AllAtomPositions
uint GetPosDataSize_(const loop::BackboneList& bb_list) {
return bb_list.size();
}
uint GetPosDataSize_(const loop::AllAtomPositions& new_pos) {
return new_pos.GetNumResidues();
}
const geom::Vec3&
GetCxPos_(const loop::BackboneList& bb_list, uint res_idx) {
// use CA for GLY, CB otherwise
if (bb_list.GetAA(res_idx) == ost::conop::GLY) {
return bb_list.GetCA(res_idx);
} else {
return bb_list.GetCB(res_idx);
}
}
// HELPERS
const geom::Vec3&
GetCxPos_(const loop::AllAtomPositions& new_pos, uint res_idx) {
// use CA for GLY, CB otherwise
......@@ -43,15 +28,50 @@ GetCxPos_(const loop::AllAtomPositions& new_pos, uint res_idx) {
} // anon ns
SidechainReconstructionDataPtr
SidechainReconstructor::Reconstruct(const loop::BackboneList& bb_list,
uint start_resnum, uint chain_idx) const {
return Reconstruct_(bb_list, start_resnum, chain_idx);
}
SidechainReconstructor::Reconstruct(uint start_resnum, uint num_residues,
uint chain_idx) const {
promod3::core::ScopedTimerPtr prof = core::StaticRuntimeProfiler::StartScoped(
"SidechainReconstructor::Reconstruct", 2);
SidechainReconstructionDataPtr
SidechainReconstructor::Reconstruct(const loop::AllAtomPositions& new_pos,
uint start_resnum, uint chain_idx) const {
return Reconstruct_(new_pos, start_resnum, chain_idx);
if (!attached_environment_) {
throw promod3::Error("Can only reconstruct sidechains when environment is "
"attached!");
}
// prepare result
SidechainReconstructionDataPtr res(new SidechainReconstructionData());
res->env_pos.reset(new loop::AllAtomEnvPositions);
std::vector<uint>& res_indices = res->env_pos->res_indices;
res->loop_length = num_residues;
// get loop indices
res_indices = idx_handler_->ToIdxVector(start_resnum, res->loop_length,
chain_idx);
// get surrounding
std::set<uint> nb_indices;
const uint n_stem_idx = res->GetNStemIdx();
const uint c_stem_idx = res->GetCStemIdx();
ScCBetaSpatialOrganizer::WithinResult within_result;
std::pair<ScCBetaSpatialOrganizerItem*,Real>* a;
for (uint i = 0; i < res->loop_length; ++i) {
const uint res_idx = res_indices[i];
within_result = env_->FindWithin(GetCxPos_(*all_pos_, res_idx), cutoff_);
a = within_result.first;
for (uint j = 0; j < within_result.second; ++j) {
const uint other_res_idx = a[j].first->res_idx;
if (other_res_idx < n_stem_idx || other_res_idx > c_stem_idx) {
nb_indices.insert(a[j].first->res_idx);
}
}
}
// append unique surrounding residue indices (first loop part, then rest)
res_indices.insert(res_indices.end(), nb_indices.begin(), nb_indices.end());
// solve system
if (env_->HasFRMRotamers()) SolveSystem_<FRMRotamerGroup>(res);
else SolveSystem_<RRMRotamerGroup>(res);
return res;
}
void SidechainReconstructor::AttachEnvironment(loop::AllAtomEnv& env,
......@@ -125,52 +145,6 @@ void SidechainReconstructor::SetEnvData_(loop::AllAtomEnv& env) {
// NOTE: it's ok to have private template functions...
template<typename PosDataType> SidechainReconstructionDataPtr
SidechainReconstructor::Reconstruct_(const PosDataType& pos_data,
uint start_resnum, uint chain_idx) const {
promod3::core::ScopedTimerPtr prof = core::StaticRuntimeProfiler::StartScoped(
"SidechainReconstructor::Reconstruct", 2);
if (!attached_environment_) {
throw promod3::Error("Can only reconstruct sidechains when environment is "
"attached!");
}
// prepare result
SidechainReconstructionDataPtr res(new SidechainReconstructionData());
res->env_pos.reset(new loop::AllAtomEnvPositions);
std::vector<uint>& res_indices = res->env_pos->res_indices;
res->loop_length = GetPosDataSize_(pos_data);
// get loop indices
res_indices = idx_handler_->ToIdxVector(start_resnum, res->loop_length,
chain_idx);
// get surrounding
std::set<uint> nb_indices;
const uint n_stem_idx = res->GetNStemIdx();
const uint c_stem_idx = res->GetCStemIdx();
ScCBetaSpatialOrganizer::WithinResult within_result;
std::pair<ScCBetaSpatialOrganizerItem*,Real>* a;
for (uint res_idx = 0; res_idx < res->loop_length; ++res_idx) {
within_result = env_->FindWithin(GetCxPos_(pos_data, res_idx), cutoff_);
a = within_result.first;
for (uint j = 0; j < within_result.second; ++j) {
const uint other_res_idx = a[j].first->res_idx;
if (other_res_idx < n_stem_idx || other_res_idx > c_stem_idx) {
nb_indices.insert(a[j].first->res_idx);
}
}
}
// append unique surrounding residue indices (first loop part, then rest)
res_indices.insert(res_indices.end(), nb_indices.begin(), nb_indices.end());
// solve system
if (env_->HasFRMRotamers()) SolveSystem_<FRMRotamerGroup>(res);
else SolveSystem_<RRMRotamerGroup>(res);
return res;
}
template<typename RotamerGroup> void SidechainReconstructor::BuildDisulfids_(
SidechainReconstructionDataPtr res,
std::vector<uint>& cys_indices,
......
......@@ -49,11 +49,7 @@ public:
// reconstruct sidechains for a loop (must be in environment!)
SidechainReconstructionDataPtr
Reconstruct(const loop::BackboneList& bb_list, uint start_resnum,
uint chain_idx = 0) const;
SidechainReconstructionDataPtr
Reconstruct(const loop::AllAtomPositions& new_pos, uint start_resnum,
uint chain_idx = 0) const;
Reconstruct(uint start_resnum, uint num_residues, uint chain_idx = 0) const;
// options as in SidechainEnvListener (only used if no listener there yet!)
void AttachEnvironment(loop::AllAtomEnv& env, bool use_frm = true,
......
......@@ -22,7 +22,7 @@ class SidechainTests(unittest.TestCase):
self.assertTrue(a.IsValid())
self.assertLessEqual(geom.Length(a.pos - a_ref.pos), max_dist)
def CheckEnvVsPy(self, ent, all_pos, env, keep_sidechains, build_disulfids,
def CheckEnvVsPy(self, ent, env, keep_sidechains, build_disulfids,
rotamer_model, consider_hbonds, rotamer_library):
# reconstruct sidechains for full OST entity
ent_py = ent.Copy()
......@@ -38,16 +38,9 @@ class SidechainTests(unittest.TestCase):
sc_rec.AttachEnvironment(env, use_frm=(rotamer_model=="frm"),
consider_hbonds=consider_hbonds,
rotamer_library=rotamer_library)
res = sc_rec.Reconstruct(all_pos, 1)
res = sc_rec.Reconstruct(1, ent.residue_count)
ent_cc = res.env_pos.all_pos.ToEntity()
self.CheckDistances(ent_cc, ent_py)
def InitEnvObjects(self, ent):
seqres_str = ''.join([r.one_letter_code for r in ent.residues])
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
all_pos = loop.AllAtomPositions(ent.residues)
return all_pos, env
#######################################################################
def testReconstruct(self):
......@@ -71,32 +64,31 @@ class SidechainTests(unittest.TestCase):
seqres_str = ''.join([r.one_letter_code for r in ent.residues])
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
all_pos = loop.AllAtomPositions(ent.residues)
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=False,
self.CheckEnvVsPy(ent, env, keep_sidechains=False,
build_disulfids=False, rotamer_model="rrm",
consider_hbonds=False,
rotamer_library=self.rotamer_library)
# reuse env with keep_sidechains=True
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=True,
self.CheckEnvVsPy(ent, env, keep_sidechains=True,
build_disulfids=False, rotamer_model="rrm",
consider_hbonds=False,
rotamer_library=self.rotamer_library)
# vary one by one (need to reset env to get new stuff)
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=True,
self.CheckEnvVsPy(ent, env, keep_sidechains=True,
build_disulfids=False, rotamer_model="frm",
consider_hbonds=False,
rotamer_library=self.rotamer_library)
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=True,
self.CheckEnvVsPy(ent, env, keep_sidechains=True,
build_disulfids=False, rotamer_model="rrm",
consider_hbonds=True,
rotamer_library=self.rotamer_library)
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=True,
self.CheckEnvVsPy(ent, env, keep_sidechains=True,
build_disulfids=False, rotamer_model="rrm",
consider_hbonds=False,
rotamer_library=self.bbdep_rotamer_library)
......@@ -106,8 +98,7 @@ class SidechainTests(unittest.TestCase):
seqres_str = ''.join([r.one_letter_code for r in ent.residues])
env = loop.AllAtomEnv(seqres_str)
env.SetInitialEnvironment(ent)
all_pos = loop.AllAtomPositions(ent.residues)
self.CheckEnvVsPy(ent, all_pos, env, keep_sidechains=True,
self.CheckEnvVsPy(ent, env, keep_sidechains=True,
build_disulfids=True, rotamer_model="rrm",
consider_hbonds=False,
rotamer_library=self.rotamer_library)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment