Select Git revision
export_model.cc
Studer Gabriel authored
export_model.cc 5.19 KiB
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <promod3/modelling/model.hh>
#include <promod3/core/export_helper.hh>
using namespace boost::python;
using namespace promod3::modelling;
ModellingHandle (*BuildRawModelHandle)(const ost::seq::AlignmentHandle&,
bool, const String&, bool)
= &BuildRawModel;
ModellingHandle (*BuildRawModelHandleList)(const ost::seq::AlignmentList&,
bool, const String&, bool)
= &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) {
throw promod3::Error("The backbone_scorer must be properly initialized "
"before it can be used!");
}
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) {
throw promod3::Error("The backbone_scorer_env must be properly initialized "
"before it can be used!");
}
return mhandle.backbone_scorer_env;
}
void WrapSetBackboneScorerEnv(ModellingHandle& mhandle,
promod3::scoring::BackboneScoreEnvPtr env) {
mhandle.backbone_scorer_env = env;
}
void WrapSetSequenceProfiles(ModellingHandle& mhandle,
const boost::python::list& profiles){
ost::seq::ProfileHandleList v_profiles;
promod3::core::ConvertListToVector(profiles, v_profiles);
SetSequenceProfiles(mhandle, v_profiles);
}
void WrapSetPsipredPredictions(ModellingHandle& mhandle,
const boost::python::list& predictions){
promod3::loop::PsipredPredictionList v_predictions;
promod3::core::ConvertListToVector(predictions, v_predictions);
SetPsipredPredictions(mhandle, v_predictions);
}
// not really needed in C++ as we can do the check below directly
bool WrapIsBackboneScorerSet(ModellingHandle& mhandle) {
return bool(mhandle.backbone_scorer);}
bool WrapIsBackboneScorerEnvSet(ModellingHandle& mhandle) {
return bool(mhandle.backbone_scorer_env);
}
} // anon ns
void export_model()
{
class_<ModellingHandle>("ModellingHandle", init<>())
.def("Copy",&ModellingHandle::Copy)
.def_readwrite("model", &ModellingHandle::model)
.def_readwrite("gaps", &ModellingHandle::gaps)
.def_readwrite("seqres", &ModellingHandle::seqres)
.def_readwrite("psipred_predictions", &ModellingHandle::psipred_predictions)
.def_readwrite("profiles", &ModellingHandle::profiles)
.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("ReorderGaps", &ReorderGaps, (arg("mhandle")));
def("SetupDefaultBackboneScorer", &SetupDefaultBackboneScorer, (arg("mhandle")));
def("SetSequenceProfiles", &WrapSetSequenceProfiles, (arg("mhandle"),arg("profiles")));
def("SetPsipredPredictions", &WrapSetPsipredPredictions, (arg("mhandle"),arg("psipred_predictions")));
def("MergeMHandle", &MergeMHandle, (arg("source_mhandle"),
arg("target_mhandle"),
arg("source_chain_idx"),
arg("target_chain_idx"),
arg("start_resnum"),
arg("end_resnum"),
arg("transform"),
arg("reset_scoring_env") = true));
def("IsBackboneScorerSet", &WrapIsBackboneScorerSet, (arg("mhandle")));
def("IsBackboneScorerEnvSet", &WrapIsBackboneScorerEnvSet, (arg("mhandle")));
def("BuildRawModel", BuildRawModelHandle,
(arg("aln"),
arg("include_ligands")=false,
arg("chain_names")="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz",
arg("spdbv_style")=false));
def("BuildRawModel", BuildRawModelHandleList,
(arg("aln"),
arg("include_ligands")=false,
arg("chain_names")="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz",
arg("spdbv_style")=false));
}