Single-chain table inversion python implementation code