magnopy.SpinHamiltonian.purge#
method
- SpinHamiltonian.purge(tolerance=None)[source]#
Removes parameters of the Hamiltonian that are smaller than the given tolerance.
Added in version 0.5.2.
- Parameters:
- tolerancefloat, default 1e-8 meV
Parameters with absolute value of all components smaller than the tolerance are removed. Expected to be non-negative. Expected to be in the same units as
SpinHamiltonian.units. Default value is \(10^{-8}\) meV (converted to the units of the Hamiltonian).
Examples
First lets create a Hamiltonian
>>> import numpy as np >>> import magnopy >>> cell = np.eye(3) >>> atoms = dict( ... names=["Fe"], positions=[[0, 0, 0]], spins=[5 / 2], g_factors=[2] ... ) >>> convention = magnopy.Convention( ... multiple_counting=True, spin_normalized=False, c22=1 ... ) >>> spinham = magnopy.SpinHamiltonian( ... cell=cell, atoms=atoms, convention=convention ... )
and add some parameters to it
>>> spinham.add( ... nus=[(1, 0, 0)], ... alphas=[0, 0], ... parameter=np.eye(3) * 1e-9, ... populate_equivalent=True, ... ) >>> spinham.add( ... nus=[(0, 1, 0)], ... alphas=[0, 0], ... parameter=np.eye(3) * 1e-7, ... populate_equivalent=True, ... )
There are four interaction parameters in the Hamiltonian
>>> len(spinham.parameters()) 4 >>> for nus, alphas, parameter in spinham.parameters(): ... print(nus, alphas) ((-1, 0, 0),) (0, 0) ((0, -1, 0),) (0, 0) ((0, 1, 0),) (0, 0) ((1, 0, 0),) (0, 0)
Now if we purge the Hamiltonian with the default tolerance of 1e-8 meV, then only two parameters remain
>>> spinham.purge() >>> len(spinham.parameters()) 2 >>> for nus, alphas, parameter in spinham.parameters(): ... print(nus, alphas) ((0, -1, 0),) (0, 0) ((0, 1, 0),) (0, 0)