The Python code to be optimized calculates the Accessible Surface Area (ASA) of a molecule. The ASA quantifies the surface area of a molecule that is open or available to a solvent and has many uses in biology and biochemistry. For the purposes of this recipe, a deeper background into the ASA is unnecessary. However, for those curious, I highly recommend that you read Bosco K. Ho's excellent post about both this code and the ASA. He is the author of the original code that was written for clarity and accuracy but not speed.
For the purpose of optimization, this code was going to be integrated into a web application that would compute the ASA for a molecule upon an upload by the user. As all calculations were computed synchronously, the longer the code takes, the longer the user waits for a result.
In this recipe, we are going to read through the critical portions of the code, which are contained primarily in the asa.py
source file, in order to gain an understanding...