Replace code that calculate quantum kinetic energy by function