onsite_energy_modifier(is_double=False, **kwargs)

Modify the onsite energy, e.g. to apply an electric field

is_double : bool

Requires the model to use double precision floating point values. Defaults to single precision otherwise.


The function parameters must be a combination of any number of the following:

energy : ndarray
The onsite energy.
x, y, z : ndarray
Lattice site position.
sub_id : ndarray of int
Sublattice identifier: can be checked for equality with sublattice names specified in Lattice. For example, energy[sub_id == 'A'] = 0 will set the onsite energy only for sublattice A sites.
sites : Sites
Helper object. Can be used instead of x, y, z, sub_id. See Sites.

The function must return:

A modified potential argument or an ndarray of the same dtype and shape.


def wavy(a, b):
    def f(x, y):
        return np.sin(a * x)**2 + np.cos(b * y)**2
    return f

model = pb.Model(
    ... # lattice, shape, etc.
    wavy(a=0.6, b=0.9)