Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions contents/quantum_systems/code/python/energy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np


def calculate_energy(wfc, H_k, H_r, dx):
"""Calculate the energy <Psi|H|Psi>."""
# Creating momentum conjugate wavefunctions
wfc_k = np.fft.fft(wfc)
wfc_c = np.conj(wfc)

# Finding the momentum and real-space energy terms
energy_k = 0.5 * wfc_c * np.fft.ifft((H_k ** 2) * wfc_k)
energy_r = wfc_c * H_r * wfc

# Integrating over all space
energy_final = sum(energy_k + energy_r).real

return energy_final * dx
2 changes: 2 additions & 0 deletions contents/quantum_systems/quantum_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ This ultimately looks like this:
{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/energy.jl)
{% sample lang="py" %}
[import:4-17, lang:"python"](code/python/energy.py)
{% endmethod %}

This calculation will be used in many different simulations of quantum systems to check our results.
Expand Down