diff --git a/modules/conop/pymod/CMakeLists.txt b/modules/conop/pymod/CMakeLists.txt index 2ceff8be3d91299cbb5562bf446246ec37d01e12..3af9287193cc368b673e3279d939793cba5e3f5d 100644 --- a/modules/conop/pymod/CMakeLists.txt +++ b/modules/conop/pymod/CMakeLists.txt @@ -2,8 +2,12 @@ set(OST_CONOP_PYMOD_SOURCES wrap_conop.cc export_builder.cc export_compound.cc + export_processor.cc + export_rule_based.cc + export_heuristic.cc export_amino_acids.cc export_conop.cc + export_diag.cc export_rule_based.cc export_non_standard.cc export_ring_finder.cc diff --git a/modules/conop/pymod/export_diag.cc b/modules/conop/pymod/export_diag.cc new file mode 100644 index 0000000000000000000000000000000000000000..6155d63c71854e76517aa7a1732feb30ce352a72 --- /dev/null +++ b/modules/conop/pymod/export_diag.cc @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// 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") + ; +} + diff --git a/modules/conop/pymod/export_heuristic.cc b/modules/conop/pymod/export_heuristic.cc new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/modules/conop/pymod/export_processor.cc b/modules/conop/pymod/export_processor.cc new file mode 100644 index 0000000000000000000000000000000000000000..b69c0d1d8b800c77620a8031516b0a9acac7f8ac --- /dev/null +++ b/modules/conop/pymod/export_processor.cc @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// 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) + ; +} + diff --git a/modules/conop/pymod/export_rule_based.cc b/modules/conop/pymod/export_rule_based.cc index 06b0e7b26d344f0d46755f39a775d42907838001..ab3aefa415aa9323f2da3bcef6dd21d9acb8bf7a 100644 --- a/modules/conop/pymod/export_rule_based.cc +++ b/modules/conop/pymod/export_rule_based.cc @@ -1,12 +1,35 @@ +//------------------------------------------------------------------------------ +// 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/rule_based.hh> -using namespace boost::python; using namespace ost::conop; -void export_rule_based() -{ - class_<RuleBasedProcessor>("RuleBasedProcessor", init<CompoundLibPtr>()) - .def("Process", &RuleBasedProcessor::Process) +void export_rule_based() { + + class_<RuleBasedProcessor, RuleBasedProcessorPtr, + boost::noncopyable, bases<Processor> >("RuleBasedProcessor", + init<CompoundLibPtr>()) + .add_property("fix_element", &RuleBasedProcessor::GetFixElement, + &RuleBasedProcessor::SetFixElement) ; } + diff --git a/modules/conop/pymod/wrap_conop.cc b/modules/conop/pymod/wrap_conop.cc index 99ceec31604df60d6b4eac4df826155f2fdcbcf9..fc19e341c89673dcd72d2eff2b143df3da10fb2e 100644 --- a/modules/conop/pymod/wrap_conop.cc +++ b/modules/conop/pymod/wrap_conop.cc @@ -26,15 +26,18 @@ void export_Conop(); void export_RingFinder(); void export_AminoAcids(); void export_NonStandard(); - +void export_processor(); void export_rule_based(); +void export_diag(); BOOST_PYTHON_MODULE(_ost_conop) { export_Builder(); export_Conop(); + export_processor(); export_rule_based(); export_Compound(); export_RingFinder(); export_AminoAcids(); export_NonStandard(); + export_diag(); } diff --git a/modules/conop/src/rule_based.hh b/modules/conop/src/rule_based.hh index 4ea5246a61eb8ee3f88f74a9d3b9d5327f0d606f..f014fe9d5fd6b9d4b9e02a050d3405bc688b9ec0 100644 --- a/modules/conop/src/rule_based.hh +++ b/modules/conop/src/rule_based.hh @@ -30,6 +30,10 @@ namespace ost { namespace conop { mol::AtomHandleList DLLEXPORT_OST_CONOP GetUnknownAtoms(mol::ResidueHandle res, CompoundPtr compound); +class RuleBasedProcessor; + +typedef boost::shared_ptr<RuleBasedProcessor> RuleBasedProcessorPtr; + class DLLEXPORT_OST_CONOP RuleBasedProcessor : public Processor { public: RuleBasedProcessor(CompoundLibPtr compound_lib): diff --git a/modules/conop/tests/CMakeLists.txt b/modules/conop/tests/CMakeLists.txt index a318766e1c6355c55063b487c1a9c6c5b1a51e95..ebc0be35c585e31c4698e4a83d05779f1c2f9d58 100644 --- a/modules/conop/tests/CMakeLists.txt +++ b/modules/conop/tests/CMakeLists.txt @@ -6,6 +6,7 @@ set(OST_CONOP_UNIT_TESTS helper.cc test_compound.py test_cleanup.py + test_processor.py test_nonstandard.py ) diff --git a/modules/conop/tests/test_processor.py b/modules/conop/tests/test_processor.py new file mode 100644 index 0000000000000000000000000000000000000000..b8662c44283a2e4298d50281d88724e5295a8b5a --- /dev/null +++ b/modules/conop/tests/test_processor.py @@ -0,0 +1,21 @@ +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() + +