How to downcast a TabulatedFunction class to a Continuos2DFunction class in Python?

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Xinqiang Ding
Posts: 33
Joined: Tue May 05, 2015 2:27 pm

How to downcast a TabulatedFunction class to a Continuos2DFunction class in Python?

Post by Xinqiang Ding » Wed Sep 06, 2017 11:27 am

Several Custom*Forces have the method getTabulatedFunction(). The method getTabulatedFunction returns an TabulatedFunction object. How can we call setFunctionParameters() on the returned TabulatedFunction object in Python? The TabulatedFunction class is a generic class and does not have the method setFunctionParameters(). Therefore, it has to be downcasted into the derived class Continuous2DFunction.

Thanks,
Xinqiang

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: How to downcast a TabulatedFunction class to a Continuos2DFunction class in Python?

Post by Peter Eastman » Wed Sep 06, 2017 11:51 am

That's a bug. It ought to return the correct subclass. It looks like the Python wrapper isn't handling that correctly. I'll see if I can fix it.

As a workaround, can you hold on to the original Continuous2DFunction object that you added to the force?

Peter

User avatar
Xinqiang Ding
Posts: 33
Joined: Tue May 05, 2015 2:27 pm

Re: How to downcast a TabulatedFunction class to a Continuos2DFunction class in Python?

Post by Xinqiang Ding » Wed Sep 06, 2017 2:14 pm

Yes. The workaround works. Thanks!
Xinqiang

User avatar
Peter Eastman
Posts: 2593
Joined: Thu Aug 09, 2007 1:25 pm

Re: How to downcast a TabulatedFunction class to a Continuos2DFunction class in Python?

Post by Peter Eastman » Wed Sep 06, 2017 2:21 pm

I just posted a pull request with the fix: https://github.com/pandegroup/openmm/pull/1891

Peter

POST REPLY