redo calculate energy function