You are here

EnergyMethodCreator error when writing custom energy method

3 posts / 0 new
Last post
EnergyMethodCreator error when writing custom energy method
#1

Hi,

I have been trying to write a custom energy method class  following the workshop #11 from the Gray lab and this tutorial http://graylab.jhu.edu/pyrosetta/downloads/scripts/test/T850_SubClassing.py . Here is what I have:

import rosetta, pyrosetta
from rosetta import *
from pyrosetta import *
from rosetta.core.scoring import *
from rosetta.core.scoring.methods import ContextIndependentOneBodyEnergy


@pyrosetta.EnergyMethod()
class interfaceScoring(ContextIndependentOneBodyEnergy) :


    def __init(self):
        print('interfaceScoring::__init__!')
        print self.creator()
        ContextIndependentOneBodyEnergy.__init__(self,self.creator())

    def residue_energy(self, rsd, pose, emap):
        emap.get().set(self.scoreType,-1.0)

 and then calling from another class:

#invoke the packer
pose_design = standard_packer_task(self.pose)

# create an empty ScoreFunction
scorefxn = ScoreFunction()

interf_score = interfaceScoring.scoreType
scorefxn.set_weight(interf_score,1.0)

# setting the mover
packmover = protocols.simple_moves.PackRotamersMover(scorefxn, pose_design)

which returns this error:
 

 scorefxn.set_weight(interf_score,1.0)
  File "/usr/local/lib/python2.7/dist-packages/pyrosetta-4.0-py2.7.egg/pyrosetta/__init__.py", line 514, in create_energy_method
    e = self.EnergyMethodClass()
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy(: core::scoring::methods::EnergyMethodCreator)
    2. rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy(arg0: rosetta.core.scoring.methods.ContextIndependentOneBodyEnergy)

I have also tried to build a custom EnergyCreator without relying on the EnergyMethod() decoration, but it still fails. Any clue on why I get an empty creator and why this piece of code is not working for me ? FYI, I am using pyrosetta 4 and rosetta release of 2017.13.59376. Thanks!

Category: 
Post Situation: 
Mon, 2017-12-11 15:46
furybubu

Looks like you have a typo:

You have:

@pyrosetta.EnergyMethod()
class interfaceScoring(ContextIndependentOneBodyEnergy) :


    def __init(self):
        print('interfaceScoring::__init__!')
        print self.creator()
        ContextIndependentOneBodyEnergy.__init__(self,self.creator())

 

But you misspelt the name of the function.  It should be __init__ (with two underscores before and two underscores after):

So, the code should be:

@pyrosetta.EnergyMethod()
class interfaceScoring(ContextIndependentOneBodyEnergy) :


    def __init__(self):
        print('interfaceScoring::__init__!')
        print self.creator()
        ContextIndependentOneBodyEnergy.__init__(self,self.creator())

 

There may be other typos (I didn't try to run the code).  Hope that helps.

- Andrew

Tue, 2017-12-12 05:44
SenyorDrew

Oops, indeed,  I cannot believe I made this typo. Everything works fine now. Thanks for spotting this.

Tue, 2017-12-12 10:04
furybubu