soinn implementation of python version.