Python implementation of folding, with relatively simple fortran subroutine