From 636b6945b95c5f1ce851f067d63f33a936bbebd8 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Thu, 12 Jan 2017 10:30:07 +0100 Subject: [PATCH] Implement deep copy function in BackboneList The reason for that is a bug we observed when Python uses reference assignments of BackboneLists. --- loop/doc/backbone.rst | 6 ++++++ loop/pymod/export_backbone.cc | 6 ++++++ modelling/pymod/_closegaps.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/loop/doc/backbone.rst b/loop/doc/backbone.rst index 554bdea2..15288fb3 100644 --- a/loop/doc/backbone.rst +++ b/loop/doc/backbone.rst @@ -299,6 +299,12 @@ The BackboneList class Remove all residues from this list. + .. method:: Copy() + + Creates and returns a deep copy of this :class:`BackboneList`. This can be + useful, since Python uses reference assignments. + + :rtype: :class:`BackboneList` .. method:: ReconstructCBetaPositions() diff --git a/loop/pymod/export_backbone.cc b/loop/pymod/export_backbone.cc index 69a9c21b..6d97c8a7 100644 --- a/loop/pymod/export_backbone.cc +++ b/loop/pymod/export_backbone.cc @@ -66,6 +66,11 @@ BackboneListPtr FullInitWrapperRHList(const String& sequence, return p; } +BackboneListPtr WrapCopy(BackboneListPtr p){ + BackboneListPtr return_p(new BackboneList(*p)); + return return_p; +} + void InsertInto_int(BackboneListPtr p, ost::mol::ChainHandle& chain, uint start_resnum) { p->InsertInto(chain, start_resnum); @@ -156,6 +161,7 @@ void export_Backbone() { .def(init<const String&>()) .def("__init__", make_constructor(&FullInitWrapper)) .def("__init__", make_constructor(&FullInitWrapperRHList)) + .def("Copy", &WrapCopy) .def("ToDensity", &BackboneList::ToDensity, (arg("padding")=10.0, arg("sampling")=geom::Vec3(1.0,1.0,1.0), diff --git a/modelling/pymod/_closegaps.py b/modelling/pymod/_closegaps.py index 57219d00..abfc2afe 100644 --- a/modelling/pymod/_closegaps.py +++ b/modelling/pymod/_closegaps.py @@ -160,7 +160,7 @@ def _CloseLoopFrame(mhandle, gap_orig, actual_candidates, actual_extended_gaps, start_index = actual_extended_gaps[i].before.GetNumber().GetNum()\ - min_before_resnum for j, loop_candidate in enumerate(loop_candidates): - actual_frame_backbone_list = frame_backbone_list + actual_frame_backbone_list = frame_backbone_list.Copy() actual_frame_backbone_list.ReplaceFragment( loop_candidate, start_index, False) final_loop_candidates.Add(actual_frame_backbone_list) -- GitLab