Skip to content
Snippets Groups Projects
Commit eaa33ff4 authored by Rafal Gumienny's avatar Rafal Gumienny
Browse files

feat: SCHWED-3126 Expose Molck and MolckSettings to python

parent 70d09c52
Branches
Tags
No related merge requests found
......@@ -16,14 +16,109 @@
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <stdexcept>
#include <boost/python.hpp>
#include <boost/python/raw_function.hpp>
using namespace boost::python;
#include <ost/mol/alg/molck.hh>
using namespace ost::mol::alg;
namespace {
object MolckSettingsInitWrapper(tuple args, dict kwargs){
object self = args[0];
args = tuple(args.slice(1,_));
bool rm_unk_atoms = false;
if(kwargs.contains("rm_unk_atoms")){
rm_unk_atoms = extract<bool>(kwargs["rm_unk_atoms"]);
kwargs["rm_unk_atoms"].del();
}
bool rm_non_std = false;
if(kwargs.contains("rm_non_std")){
rm_non_std = extract<bool>(kwargs["rm_non_std"]);
kwargs["rm_non_std"].del();
}
bool rm_hyd_atoms = true;
if(kwargs.contains("rm_hyd_atoms")){
rm_hyd_atoms = extract<bool>(kwargs["rm_hyd_atoms"]);
kwargs["rm_hyd_atoms"].del();
}
bool rm_oxt_atoms = false;
if(kwargs.contains("rm_oxt_atoms")){
rm_oxt_atoms = extract<bool>(kwargs["rm_oxt_atoms"]);
kwargs["rm_oxt_atoms"].del();
}
bool rm_zero_occ_atoms = false;
if(kwargs.contains("rm_zero_occ_atoms")){
rm_zero_occ_atoms = extract<bool>(kwargs["rm_zero_occ_atoms"]);
kwargs["rm_zero_occ_atoms"].del();
}
bool colored = false;
if(kwargs.contains("colored")){
colored = extract<bool>(kwargs["colored"]);
kwargs["colored"].del();
}
bool map_nonstd_res = true;
if(kwargs.contains("map_nonstd_res")){
map_nonstd_res = extract<bool>(kwargs["map_nonstd_res"]);
kwargs["map_nonstd_res"].del();
}
bool assign_elem = true;
if(kwargs.contains("assign_elem")){
assign_elem = extract<bool>(kwargs["assign_elem"]);
kwargs["assign_elem"].del();
}
if(len(kwargs) > 0){
std::stringstream ss;
ss << "Invalid keywords observed when setting up MolckSettings! ";
ss << "Or did you pass the same keyword twice? ";
ss << "Valid keywords are: rm_unk_atoms, rm_non_std, rm_hyd_atoms, ";
ss << "rm_oxt_atoms, rm_zero_occ_atoms, colored, map_nonstd_res, ";
ss << "assign_elem!";
throw std::invalid_argument(ss.str());
}
return self.attr("__init__")(rm_unk_atoms,
rm_non_std,
rm_hyd_atoms,
rm_oxt_atoms,
rm_zero_occ_atoms,
colored,
map_nonstd_res,
assign_elem);
}}
void export_Molck()
{
// def("load_compound_lib", &ost::mol::alg::load_compound_lib,
// (arg("custom_path")));
}
class_<MolckSettings>("MolckSettings", no_init)
.def("__init__", raw_function(MolckSettingsInitWrapper))
.def(init<bool , bool, bool, bool, bool, bool, bool, bool>())
.def("ToString", &MolckSettings::ToString)
.def("__repr__", &MolckSettings::ToString)
.def("__str__", &MolckSettings::ToString)
.def_readwrite("rm_unk_atoms", &MolckSettings::rm_unk_atoms)
.def_readwrite("rm_non_std", &MolckSettings::rm_non_std)
.def_readwrite("rm_hyd_atoms", &MolckSettings::rm_hyd_atoms)
.def_readwrite("rm_oxt_atoms", &MolckSettings::rm_oxt_atoms)
.def_readwrite("rm_zero_occ_atoms", &MolckSettings::rm_zero_occ_atoms)
.def_readwrite("colored", &MolckSettings::colored)
.def_readwrite("map_nonstd_res", &MolckSettings::map_nonstd_res)
.def_readwrite("assign_elem", &MolckSettings::assign_elem)
;
def("Molck", &Molck, (arg("ent"), arg("lib"), arg("settings")));
}
\ No newline at end of file
#include <string>
#include <ost/mol/entity_handle.hh>
#include <ost/conop/compound_lib.hh>
namespace {
inline std::string BoolToString(bool b)
{
return b ? "True" : "False";
}
}
namespace ost { namespace mol{ namespace alg {
struct MolckSettings;
......@@ -25,6 +34,39 @@ struct MolckSettings{
map_nonstd_res(true), // Map non standard residues back to standard ones (e.g.: MSE->MET,SEP->SER,etc.)
assign_elem(true){} // Clean up element column
MolckSettings(bool init_rm_unk_atoms,
bool init_rm_non_std,
bool init_rm_hyd_atoms,
bool init_rm_oxt_atoms,
bool init_rm_zero_occ_atoms,
bool init_colored,
bool init_map_nonstd_res,
bool init_assign_elem){
rm_unk_atoms = init_rm_unk_atoms;
rm_non_std = init_rm_non_std;
rm_hyd_atoms = init_rm_hyd_atoms;
rm_oxt_atoms = init_rm_oxt_atoms;
rm_zero_occ_atoms = init_rm_zero_occ_atoms;
colored = init_colored;
map_nonstd_res = init_map_nonstd_res;
assign_elem = init_assign_elem;
}
public:
std::string ToString(){
std::string rep = "MolckSettings(rm_unk_atoms=" + BoolToString(rm_unk_atoms) +
", rm_unk_atoms=" + BoolToString(rm_unk_atoms) +
", rm_non_std=" + BoolToString(rm_non_std) +
", rm_hyd_atoms=" + BoolToString(rm_hyd_atoms) +
", rm_oxt_atoms=" + BoolToString(rm_oxt_atoms) +
", rm_zero_occ_atoms=" + BoolToString(rm_zero_occ_atoms) +
", colored=" + BoolToString(colored) +
", map_nonstd_res=" + BoolToString(map_nonstd_res) +
", assign_elem=" + BoolToString(assign_elem) +
")";
return rep;
}
};
ost::mol::EntityHandle MapNonStandardResidues(ost::mol::EntityHandle& ent,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment