magnopy.SpinHamiltonian.add_magnetic_field#

method

SpinHamiltonian.add_magnetic_field(B=None, alphas=None, h=None) None[source]#

Adds external magnetic field to the Hamiltonian.

Parameters:
B(3, ) array-like

See SpinHamiltonian.set_magnetic_field for details.

alphaslist of int, optional

See SpinHamiltonian.set_magnetic_field for details.

h(3, ) array-like

Deprecated since version 0.4.0: The argument will be removed in May of 2026. Use B instead.

Notes

The call spinham.add_magnetic_field(B = B, alphas = alphas) is equivalent to the call spinham.set_magnetic_field(B = B + spinham.magnetic_field, alphas = alphas).

In other words, this method "adds" the magnetic field to the Hamiltonian whether there was some magnetic field before or not.

On contrary, SpinHamiltonian.set_magnetic_field "sets" the magnetic field, i.e. replaces the previous magnetic field (if any).