ported PotOwn fortran function. Some performance improves