You are here

PyRosetta coding subtleties

3 posts / 0 new
Last post
PyRosetta coding subtleties
#1

This works:
rbptmvr=rigid.RigidBodyPerturbMover(2, rotation_magnitude, translation_magnitude)
sequence_mover.add_mover( rbptmvr )

This does not:
sequence_mover.add_mover( rigid.RigidBodyPerturbMover(2, rotation_magnitude, translation_magnitude) )

My question is, why is the intermediate reference necessary?
I feel as if there is something fundamental about how to code in PyRosetta that I'm missing.

The error is different depending on what is nested.
Here is an example caused by the second statement above:

Traceback (most recent call last):
File "./example.py.py", line 399, in
main()
File "./example.py.py", line 311, in main
random_mover.apply(new_pose)
Boost.Python.ArgumentError: Python argument types in
FaDockingSlideIntoContact.apply(FaDockingSlideIntoContact, PoseAP)
did not match C++ signature:
apply(FaDockingSlideIntoContact_exposer_callback {lvalue}, std::map, std::allocator > > >, std::less, std::allocator, std::allocator > > > > > > {lvalue} pmap)
apply(protocols::docking::FaDockingSlideIntoContact {lvalue}, std::map, std::allocator > > >, std::less, std::allocator, std::allocator > > > > > > {lvalue} pmap)
apply(FaDockingSlideIntoContact_exposer_callback {lvalue}, core::pose::Pose {lvalue} pose)
apply(protocols::docking::FaDockingSlideIntoContact {lvalue}, core::pose::Pose {lvalue} pose)

Post Situation: 
Wed, 2013-03-27 02:59
lah435

I don't know the answer, but I am always willing to speculate!

I think this is because the underlying C++ uses a lot of "smart pointers" with "reference counting" (wikipedia has sort-of-relevant explanations; the Rosetta MIE 2011 review has more I think), whereas python uses something else. I think when you do it on one line, python "optimizes out" creation of the pointer wrapper for the RigidBodyPerturbMover, then the latter goes out of scope in C++ and self-destructs, then when the SequenceMover wants to use it it's not there anymore. In the two line case, the python-level variable keeps the smart pointer alive.

Wed, 2013-03-27 06:44
smlewis

This is known issues and Steven explain the underlying reason for what happening inside. We planning to move Rosetta to use Boost smart pointer sometime in the future which we think should solve this.

Wed, 2013-03-27 10:13
Sergey