From 619cfbda01612d557f06aafa3c6a3eb438c508b0 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Wed, 10 Aug 2016 20:47:26 +0200 Subject: [PATCH] directly connect OverallBackboneScorer with its BackboneScoreEnv to the ModellingHandle --- modelling/pymod/_pipeline.py | 2 +- modelling/pymod/export_model.cc | 39 +++++++++++++++++++++++++++++++++ modelling/src/model.cc | 36 ++++++++++++++++++++++++++++++ modelling/src/model.hh | 7 ++++++ 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/modelling/pymod/_pipeline.py b/modelling/pymod/_pipeline.py index 779ecc7a..ea3a0339 100644 --- a/modelling/pymod/_pipeline.py +++ b/modelling/pymod/_pipeline.py @@ -4,7 +4,7 @@ as argument. ''' # internal -from promod3 import loop, sidechain, core +from promod3 import loop, sidechain, core, scoring from _modelling import * from _closegaps import * from _ring_punches import * diff --git a/modelling/pymod/export_model.cc b/modelling/pymod/export_model.cc index 22b369ed..1de295e8 100644 --- a/modelling/pymod/export_model.cc +++ b/modelling/pymod/export_model.cc @@ -13,12 +13,45 @@ ModellingHandle (*BuildRawModelHandleList)(const ost::seq::AlignmentList&, = &BuildRawModel; namespace { + int WrapCountEnclosedGaps(ModellingHandle& mhandle, const StructuralGap& gap) { return CountEnclosedGaps(mhandle, gap, false); } + int WrapCountEnclosedIns(ModellingHandle& mhandle, const StructuralGap& gap) { return CountEnclosedGaps(mhandle, gap, true); } + +promod3::scoring::BackboneOverallScorerPtr +WrapGetBackboneScorer(ModellingHandle& mhandle){ + if(!mhandle.backbone_scorer){ + String err = "backbone_scorer must first be properly initialized "; + err += "before it can be used!"; + throw promod3::Error(err); + } + return mhandle.backbone_scorer; +} + +void WrapSetBackboneScorer(ModellingHandle& mhandle, + promod3::scoring::BackboneOverallScorerPtr scorer){ + mhandle.backbone_scorer = scorer; +} + +promod3::scoring::BackboneScoreEnvPtr +WrapGetBackboneScorerEnv(ModellingHandle& mhandle){ + if(!mhandle.backbone_scorer_env){ + String err = "backbone_scorer_env must first be properly initialized "; + err += "before it can be used!"; + throw promod3::Error(err); + } + return mhandle.backbone_scorer_env; +} + +void WrapSetBackboneScorerEnv(ModellingHandle& mhandle, + promod3::scoring::BackboneScoreEnvPtr env){ + mhandle.backbone_scorer_env = env; +} + } // anon ns void export_model() @@ -27,12 +60,18 @@ void export_model() .def_readwrite("model", &ModellingHandle::model) .def_readwrite("gaps", &ModellingHandle::gaps) .def_readwrite("seqres", &ModellingHandle::seqres) + .add_property("backbone_scorer", &WrapGetBackboneScorer, + &WrapSetBackboneScorer) + .add_property("backbone_scorer_env", &WrapGetBackboneScorerEnv, + &WrapSetBackboneScorerEnv) ; + def("ClearGaps", ClearGaps, (arg("mhandle"),arg("gap"))); def("CountEnclosedGaps", WrapCountEnclosedGaps, (arg("mhandle"),arg("gap"))); def("CountEnclosedInsertions", WrapCountEnclosedIns, (arg("mhandle"),arg("gap"))); def("MergeGaps", MergeGaps, (arg("mhandle"),arg("index"))); def("RemoveTerminalGaps", RemoveTerminalGaps, (arg("mhandle"))); + def("SetupDefaultBackboneScorer", &SetupDefaultBackboneScorer,(arg("mhandle"))); def("BuildRawModel", BuildRawModelHandle, (arg("aln"), arg("include_ligands")=false, diff --git a/modelling/src/model.cc b/modelling/src/model.cc index 23fb93f3..8d7b32f7 100644 --- a/modelling/src/model.cc +++ b/modelling/src/model.cc @@ -11,12 +11,17 @@ #include <ost/conop/compound_lib.hh> #include <promod3/core/geom_base.hh> #include <promod3/core/runtime_profiling.hh> +#include <promod3/scoring/scoring_object_loader.hh> +#include <promod3/scoring/pairwise_score.hh> +#include <promod3/scoring/density_score.hh> +#include <promod3/scoring/clash_score.hh> #include "model.hh" using namespace ost::mol; using namespace ost; using namespace ost::seq; using namespace ost::conop; +using namespace promod3::scoring; namespace promod3 { namespace modelling { @@ -202,6 +207,37 @@ int RemoveTerminalGaps(ModellingHandle& mhandle) { return removed_gaps; } +template <typename ScorerPtr> +void AttachScorer(BackboneOverallScorerPtr overall_scorer, + ScorerPtr scorer, + BackboneScoreEnvPtr env, + const String& score_name){ + scorer->AttachEnvironment(*env); + (*overall_scorer)[score_name] = scorer; +} + +void SetupDefaultBackboneScorer(ModellingHandle& mhandle){ + + //setup environment + BackboneScoreEnvPtr env(new BackboneScoreEnv(mhandle.seqres)); + env->SetInitialEnvironment(mhandle.model); + + BackboneOverallScorerPtr scorer(new BackboneOverallScorer); + + AttachScorer(scorer, LoadCBPackingScorer(), env, "cb_packing"); + AttachScorer(scorer, LoadCBetaScorer(), env, "cbeta"); + AttachScorer(scorer, LoadReducedScorer(), env, "reduced"); + AttachScorer(scorer, ClashScorerPtr(new ClashScorer), env, "clash"); + AttachScorer(scorer, LoadHBondScorer(), env, "hbond"); + AttachScorer(scorer, LoadSSAgreementScorer(), env, "ss_agreement"); + AttachScorer(scorer, LoadTorsionScorer(), env, "torsion"); + AttachScorer(scorer, PairwiseScorerPtr(new PairwiseScorer), env, "pairwise"); + AttachScorer(scorer, DensityScorerPtr(new DensityScorer), env, "density"); + + mhandle.backbone_scorer_env = env; + mhandle.backbone_scorer = scorer; +} + bool CopyConserved(ResidueView src_res, ResidueHandle dst_res, XCSEditor& edi, bool& has_cbeta) { diff --git a/modelling/src/model.hh b/modelling/src/model.hh index 31842714..bf2aaa8c 100644 --- a/modelling/src/model.hh +++ b/modelling/src/model.hh @@ -5,6 +5,8 @@ #include <ost/seq/sequence_list.hh> #include <promod3/core/message.hh> +#include <promod3/scoring/backbone_score_base.hh> +#include <promod3/scoring/backbone_overall_scorer.hh> #include "gap.hh" @@ -30,6 +32,8 @@ struct ModellingHandle { ost::mol::EntityHandle model; StructuralGapList gaps; ost::seq::SequenceList seqres; + promod3::scoring::BackboneScoreEnvPtr backbone_scorer_env; + promod3::scoring::BackboneOverallScorerPtr backbone_scorer; }; // see Python doc @@ -45,6 +49,9 @@ void MergeGaps(ModellingHandle& mhandle, uint index); // see Python doc int RemoveTerminalGaps(ModellingHandle& mhandle); +//see Python doc +void SetupDefaultBackboneScorer(ModellingHandle& mhandle); + /// \brief copies all atom of src_res to dst_res /// \param has_cbeta will be set to true if the src_res has a cbeta and the // dst_residue is not a glycine -- GitLab