MantisBT - PyRosetta
View Issue Details
0000116PyRosetta[All Projects] Crashpublic2012-09-27 17:062012-09-28 15:55
evanbaugh 
 
lowminoralways
newopen 
x86LinuxUbuntu
 
 
Constraint use in PyRosetta
ipython
0000116: PyRosetta Constraint bug
I cam across a bizarre bug today which has hampered me for a while (I just had no idea what was happening).

It seems that when you score a Pose with Constraints that were constructed in another namespace (such as a function) the scoring causes a SegFault

...I have no idea why this is happening...
from rosetta import *
init()

# example syntax to reproduce
# the first example here will work fine
#######################################

from rosetta.core.scoring.constraints import ConstantFunc, AtomPairConstraint

p = pose_from_sequence( 'AAA' ) # works on pose_from_pdb Pose's too
a1 = AtomID( 2 , 1 ) # residue 1 atom CA (2)
a2 = AtomID( 2 , 2 ) # residue 2 atom CA (2)
f = ConstantFunc( 0 ) # example function, has been seen with a few others

apc = AtomPairConstraint( a1 , a2 , f )
p.add_constraint( apc )

# make a scoring function
sc = ScoreFunction()
sc.set_weight( atom_pair_constraint , 1 )

sc( p )
# work's fine, all is well

#######################################
# the bad example

# make a demo function to generate the constraint
def make_constraint():
    a1 = AtomID( 2 , 1 ) # residue 1 atom CA (2)
    a2 = AtomID( 2 , 2 ) # residue 2 atom CA (2)
    f = ConstantFunc( 0 )

    apc = AtomPairConstraint( a1 , a2 , f )
    return apc

p = pose_from_sequence( 'AAA' )

apc = make_constraint()
p.add_constraint( apc )

sc( p ) # same ScoreFunction as above
# causes SeqFault

sometimes (at least with ConstantFunc) it returns a different error about not finding func and runs successfully on subsequent runs (I don't have the exact error now because of an annoying bug in mantis I just found...)
No tags attached.
Issue History
2012-09-27 17:06evanbaughNew Issue
2012-09-28 15:55mpacellaNote Added: 0000112

Notes
(0000112)
mpacella   
2012-09-28 15:55   
Update: I found a workaround to this, but I think the issue should still be considered a bug (especially the fact that PyRosetta segfaults instead of printing something helpful.

You can get around this if you return a deep copy of the AtomPairConstraint in your function. So the code looks exactly like it does in the original report but the return line should look like this:

return AtomPairConstraint( ape ) #returning a deep copy of the atom pair constraint

I'm not entirely sure why this is necessary. It seems like the local variable "ape" must get deallocated when the function exits, hence the segfault when the score function tries to find it. However, if you do:

ape = make_constraint() #using the buggy version of make_constraint()
print ape

you get a genuine AtomPairConstraint object, not a pointer...