Skip to content
Snippets Groups Projects
Commit 158358f7 authored by Marco Biasini's avatar Marco Biasini
Browse files

added python export for RuleBasedProcessor

parent f3914d5d
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,12 @@ set(OST_CONOP_PYMOD_SOURCES ...@@ -2,8 +2,12 @@ set(OST_CONOP_PYMOD_SOURCES
wrap_conop.cc wrap_conop.cc
export_builder.cc export_builder.cc
export_compound.cc export_compound.cc
export_processor.cc
export_rule_based.cc
export_heuristic.cc
export_amino_acids.cc export_amino_acids.cc
export_conop.cc export_conop.cc
export_diag.cc
export_rule_based.cc export_rule_based.cc
export_non_standard.cc export_non_standard.cc
export_ring_finder.cc export_ring_finder.cc
......
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2011 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
//
#include <boost/python.hpp>
#include <ost/conop/diag.hh>
using namespace ost;
using namespace boost::python;
using namespace ost::conop;
void export_diag() {
enum_<DiagType>("DiagType")
.value("DIAG_UNK_ATOM", DIAG_UNK_ATOM)
.value("DIAG_UNK_RESIDUE", DIAG_UNK_RESIDUE)
.value("(DIAG_MISSING_ATOM", DIAG_MISSING_ATOM)
.value("DIAG_NONSTD_RESIDUE", DIAG_NONSTD_RESIDUE)
.export_values()
;
class_<Diag>("Diag", init<DiagType,const char*>())
.def("__str__(self)__", &Diag::Format)
;
class_<Diagnostics, DiagnosticsPtr>("Diagnostics")
;
}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2011 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
//
#include <boost/python.hpp>
using namespace boost::python;
#include <ost/conop/processor.hh>
using namespace ost;
using namespace ost::conop;
struct PyProcessor : public Processor {};
struct WrappedProcessor : public PyProcessor, public wrapper<WrappedProcessor> {
WrappedProcessor(PyObject* self): self_(self)
{ }
virtual void DoProcess(DiagnosticsPtr diag, mol::EntityHandle ent) const
{
call_method<void>(self_, "DoProcess", diag, ent);
}
DiagnosticsPtr DoProcessDefault(DiagnosticsPtr diag,
mol::EntityHandle ent) const {
return DiagnosticsPtr();
}
ProcessorPtr Copy() const {
return call_method<ProcessorPtr>(self_, "Copy");
}
ProcessorPtr CopyDefault() const { return ProcessorPtr(); }
PyObject* self_;
};
void export_processor() {
class_<Processor, ProcessorPtr, boost::noncopyable>("_Processor", no_init)
.def("Copy", &Processor::Copy)
.add_property("strict_hydrogens", &Processor::GetStrictHydrogens,
&Processor::SetStrictHydrogens)
.add_property("connect", &Processor::GetConnect,
&Processor::SetConnect)
.add_property("assign_torsions", &Processor::GetAssignTorsions,
&Processor::SetAssignTorsions)
.add_property("unk_res_treatment", &Processor::GetUnkResidueTreatment,
&Processor::SetUnkResidueTreatment)
.add_property("unk_atom_treatment", &Processor::GetUnkAtomTreatment,
&Processor::SetUnkAtomTreatment)
.def("Process", &Processor::Process)
;
class_<PyProcessor, boost::noncopyable,
boost::shared_ptr<WrappedProcessor>,
bases<Processor> >("Processor")
.def("Copy", &WrappedProcessor::CopyDefault)
.def("DoProcess", &WrappedProcessor::DoProcessDefault)
;
}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2011 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <boost/python.hpp> #include <boost/python.hpp>
using namespace boost::python;
#include <ost/conop/rule_based.hh> #include <ost/conop/rule_based.hh>
using namespace boost::python;
using namespace ost::conop; using namespace ost::conop;
void export_rule_based() void export_rule_based() {
{
class_<RuleBasedProcessor>("RuleBasedProcessor", init<CompoundLibPtr>()) class_<RuleBasedProcessor, RuleBasedProcessorPtr,
.def("Process", &RuleBasedProcessor::Process) boost::noncopyable, bases<Processor> >("RuleBasedProcessor",
init<CompoundLibPtr>())
.add_property("fix_element", &RuleBasedProcessor::GetFixElement,
&RuleBasedProcessor::SetFixElement)
; ;
} }
...@@ -26,15 +26,18 @@ void export_Conop(); ...@@ -26,15 +26,18 @@ void export_Conop();
void export_RingFinder(); void export_RingFinder();
void export_AminoAcids(); void export_AminoAcids();
void export_NonStandard(); void export_NonStandard();
void export_processor();
void export_rule_based(); void export_rule_based();
void export_diag();
BOOST_PYTHON_MODULE(_ost_conop) BOOST_PYTHON_MODULE(_ost_conop)
{ {
export_Builder(); export_Builder();
export_Conop(); export_Conop();
export_processor();
export_rule_based(); export_rule_based();
export_Compound(); export_Compound();
export_RingFinder(); export_RingFinder();
export_AminoAcids(); export_AminoAcids();
export_NonStandard(); export_NonStandard();
export_diag();
} }
...@@ -30,6 +30,10 @@ namespace ost { namespace conop { ...@@ -30,6 +30,10 @@ namespace ost { namespace conop {
mol::AtomHandleList DLLEXPORT_OST_CONOP GetUnknownAtoms(mol::ResidueHandle res, mol::AtomHandleList DLLEXPORT_OST_CONOP GetUnknownAtoms(mol::ResidueHandle res,
CompoundPtr compound); CompoundPtr compound);
class RuleBasedProcessor;
typedef boost::shared_ptr<RuleBasedProcessor> RuleBasedProcessorPtr;
class DLLEXPORT_OST_CONOP RuleBasedProcessor : public Processor { class DLLEXPORT_OST_CONOP RuleBasedProcessor : public Processor {
public: public:
RuleBasedProcessor(CompoundLibPtr compound_lib): RuleBasedProcessor(CompoundLibPtr compound_lib):
......
...@@ -6,6 +6,7 @@ set(OST_CONOP_UNIT_TESTS ...@@ -6,6 +6,7 @@ set(OST_CONOP_UNIT_TESTS
helper.cc helper.cc
test_compound.py test_compound.py
test_cleanup.py test_cleanup.py
test_processor.py
test_nonstandard.py test_nonstandard.py
) )
......
import unittest
from ost import conop
class TestProcessor(unittest.TestCase):
def testPyWrap(self):
class MyProc(conop.Processor):
def __init__(self):
conop.Processor.__init__(self)
self.count =0
def DoProcess(self, diag, ent):
self.count+=1
p = MyProc()
ent = mol.CreateEntity()
p.Process(ent)
self.assertEqual(p.count, 1)
if __name__ == "__main__":
from ost import testutils
testutils.RunTests()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment