Added unit test for python module

This commit is contained in:
Maarten L. Hekkelman
2025-05-14 16:08:19 +02:00
parent ff471530ce
commit 152b8f1018
5 changed files with 96 additions and 18 deletions

View File

@@ -23,7 +23,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(Boost REQUIRED COMPONENTS python)
find_package(Boost 1.83 REQUIRED COMPONENTS python)
# ---------

View File

@@ -263,7 +263,7 @@ BOOST_PYTHON_MODULE(mkdssp)
.value("pp", dssp::helix_type::pp);
enum_<dssp::helix_position_type>("helix_position_type")
.value("None", dssp::helix_position_type::None)
.value("NoHelix", dssp::helix_position_type::None)
.value("Start", dssp::helix_position_type::Start)
.value("End", dssp::helix_position_type::End)
.value("StartAndEnd", dssp::helix_position_type::StartAndEnd)
@@ -274,7 +274,7 @@ BOOST_PYTHON_MODULE(mkdssp)
.value("anti_parallel", ladder_direction_type::antiparallel);
enum_<dssp::chain_break_type>("chain_break_type")
.value("None", dssp::chain_break_type::None)
.value("NoGap", dssp::chain_break_type::None)
.value("NewChain", dssp::chain_break_type::NewChain)
.value("Gap", dssp::chain_break_type::Gap);
@@ -313,20 +313,20 @@ BOOST_PYTHON_MODULE(mkdssp)
.add_property("nr", &dssp::residue_info::nr)
.add_property("type", &dssp::residue_info::type)
.add_property("ssBridgeNr", &dssp::residue_info::ssBridgeNr)
.def("helix", &dssp::residue_info::helix)
.def("helix", &dssp::residue_info::helix, args("helix_type"), "Return the position of this residue in a helix with type helix_type")
.add_property("is_alpha_helix_end_before_start", &dssp::residue_info::is_alpha_helix_end_before_start)
.add_property("bend", &dssp::residue_info::bend)
.add_property("accessibility", &dssp::residue_info::accessibility)
.def("bridge_partner", &dssp::residue_info::bridge_partner)
.def("bridge_partner", &dssp::residue_info::bridge_partner, args("indexnr"), "Return a tuple containing the residue, number and direction for the bridge partner with index indexnr")
.add_property("sheet", &dssp::residue_info::sheet)
.add_property("strand", &dssp::residue_info::strand)
.def("acceptor", &dssp::residue_info::acceptor)
.def("donor", &dssp::residue_info::donor);
.def("acceptor", &dssp::residue_info::acceptor, args("indexnr"), "Return a tuple containing the residue and bond energy for the acceptor with index indexnr")
.def("donor", &dssp::residue_info::donor, args("indexnr"), "Return a tuple containing the residue and bond energy for the donor with index indexnr");
class_<dssp_wrapper, boost::noncopyable>("dssp", init<std::string, optional<int, int, bool>>())
.add_property("statistics", &dssp_wrapper::get_statistics)
.def("__iter__", iterator<dssp_wrapper>())
.def("get", &dssp_wrapper::get);
.def("get", &dssp_wrapper::get, args("asym_id", "seq_id"), "Return the residue info object for the residue with specified asym_id and seq_id");
def("TestBond", test_bond_between_residues);
def("TestBond", test_bond_between_residues, args("a", "b"), "Returns true if residues a and b are bonded according to DSSP");
}

View File

@@ -1,4 +1,4 @@
import mkdssp
from mkdssp import dssp, helix_type, TestBond
import os
import gzip
@@ -7,7 +7,7 @@ file_path = os.path.join("..", "test", "1cbs.cif.gz")
with gzip.open(file_path, "rt") as f:
file_content = f.read()
dssp = mkdssp.dssp(file_content)
dssp = dssp(file_content)
print("residues: ", dssp.statistics.residues)
print("chains: ", dssp.statistics.chains)
@@ -43,10 +43,10 @@ for res in dssp:
print("nr", res.nr)
print("type", res.type)
print("ssBridgeNr", res.ssBridgeNr)
print("helix(_3_10)", res.helix(mkdssp.helix_type._3_10))
print("helix(alpha)", res.helix(mkdssp.helix_type.alpha))
print("helix(pi)", res.helix(mkdssp.helix_type.pi))
print("helix(pp)", res.helix(mkdssp.helix_type.pp))
print("helix(_3_10)", res.helix(helix_type._3_10))
print("helix(alpha)", res.helix(helix_type.alpha))
print("helix(pi)", res.helix(helix_type.pi))
print("helix(pp)", res.helix(helix_type.pp))
print("is_alpha_helix_end_before_start", res.is_alpha_helix_end_before_start)
print("bend", res.bend)
print("sheet", res.sheet)
@@ -61,15 +61,16 @@ for res in dssp:
(ri, e) = res.acceptor(i)
if ri != None:
print("acceptor ", i, ri.asym_id, ri.seq_id, ri.compound_id, e)
print("test bond: ", mkdssp.TestBond(res, ri))
print("test bond: ", TestBond(res, ri))
for i in range(0, 1):
(ri, e) = res.donor(i)
if ri != None:
print("donor ", i, ri.asym_id, ri.seq_id, ri.compound_id, e)
print("test bond: ", mkdssp.TestBond(res, ri))
print("test bond: ", TestBond(res, ri))
print("accessibility", res.accessibility)
break
print("count: ", count)
@@ -79,4 +80,4 @@ b = dssp.get('A', 6)
print ("a & b", a, b)
assert(mkdssp.TestBond(a, b))
assert(TestBond(a, b))