magnopy.SpinHamiltonian.add_1#

method

SpinHamiltonian.add_1(alpha: int, parameter, units=None, when_present='raise error', replace=None) None#

Adds a (one spin & one site) parameter to the Hamiltonian.

Parameters:
alphaint

Index of an atom, with which the parameter is associated.

0 <= alpha < len(spinham.atoms.names).

parameter(3, ) array-like

Value of the parameter (\(3\times1\) vector). Given in the units of units.

unitsstr, optional

Added in version 0.3.0.

Units in which the parameter is given. Parameters have the the units of energy. By default assumes SpinHamiltonian.units. For the list of the supported units see Units of Hamiltonian's parameters. If given units are different from SpinHamiltonian.units, then the parameter's value will be converted automatically from units to SpinHamiltonian.units.

when_presentstr, default "raise error"

Added in version 0.4.0.

Action to take if an atom already has a parameter associated with it. Case-insensitive. Supported values are:

  • "raise error" (default): raises an error if an atom already has a parameter associated with it.

  • "replace": replace existing value of the parameter with the new one.

  • "add": add the value of the parameter to the existing one.

  • "mean": replace the value of the parameter with the arithmetic mean of existing and new parameters.

  • "skip": Leave existing parameter unchanged and continue without raising an error.

  • "skip": Leave existing parameter unchanged and continue without raising an error.

replacebool, default False

Whether to replace the value of the parameter if an atom already has a parameter associated with it.

Deprecated since version 0.4.0: The replace argument will be removed in May of 2026. Use modify="replace" instead.

Raises:
ValueError

If an atom already has a parameter associated with it and when_present="raise error".

ValueError

If when_present has an unsupported value.

See also

p1
remove_1