Translated to Python and optimised by Alistair Muldal, Department of Pharmacology, University of Oxford,