changing energy to more general hamiltonians

top to bottom done