What is rocket science is that with a little bit of Python magic (see the code here), you can simply add memoization to any function with the @memoized decorator, e.g.
@memoized def calcHOMO(smiles): # Generate Gaussian input file with Open Babel # and run Gaussian to find the HOMO. return homoCalling this function with a SMILES string the first time would return the HOMO after 10 minutes. Calling it a second time would return the result instantly.
Update (11/05/2012): This feature is available in the Python standard library as of Python 3.2. See Andrew's comment below
I read in the change log that Python 3.2 even added functools.lru_cache which implements something like this as part of the standard library. It also supports a limited size cache, so you don't have to worry about your memo cache getting too large.
ReplyDeleteToo bad I'm still using Python 2.7. :)
Thanks for the info Andrew. I've updated the post.
ReplyDelete