Questions on Magnetic Moment calculation using CrystalField

Dear All,

I’m calculating magnetic moment using CrystalField package with known Stevens parameters, code as follows:

-----------------------------------------------------------
moment_T = cf.getMagneticMoment (Temperature = T , Hdir=[1,0,0], Hmag=0.1, Unit='bohr')
-----------------------------------------------------------

where ‘T’ is a temperature list and cf is already defined.
What disturbs me is that the result seems to be irrelevant to ‘Hmag’ value. And it seems the calculation is always using default field strength of 1 Tesla whatever input Hmag is.

How can I get the desired moment value using correct Hmag strength? And will this ‘bug’ affect my following physical properties fitting? Any guidance will be appreciated.

Mang thanks in advance
Cheng

Dear @chengsu,

sorry this is a bug in the code. The code silently discards the “Hmag” keyword argument.

I’ve created an issue for this:

so hopefully it will be fixed by the next release.

However, if you want to have something working now, you can use this work-around function:

from mantid.simpleapi import CreateWorkspace
from CrystalField import CrystalField, PhysicalProperties
import numpy as np

def mymagmom(cf, **kwargs):
    Hmag = kwargs.pop('Hmag')
    if not isinstance(T, str) or 'mantid' in type(T):
        twksp = CreateWorkspace(kwargs['Temperature'], kwargs['Temperature'], OutputWorkspace='_twksp')
    else:
        twksp = kwargs['Temperature']
    funstr = cf.makePhysicalPropertiesFunction(PhysicalProperties("M(T)", **kwargs)) + f',Hmag={Hmag}'
    return cf._calcSpectrum(funstr, twksp, 0)

cf = CrystalField('Ce', 'C4', Temperature=1, B20=0.2, B40=0.01, B44=-0.005)
T = np.linspace(1,300,100)
moment2_T0p1 = CreateWorkspace(*mymagmom(cf, Temperature = T , Hdir=[1,0,0], Hmag=0.1, Unit='bohr'))
moment2_T1 = CreateWorkspace(*mymagmom(cf, Temperature = T , Hdir=[1,0,0], Hmag=1, Unit='bohr'))
moment2_T10 = CreateWorkspace(*mymagmom(cf, Temperature = T , Hdir=[1,0,0], Hmag=10, Unit='bohr'))

Dear @chengsu

the fix has been merged to the main Mantid tree and is available in the nightly version if you upgrade.

Best wishes,

Duc.

Dear Duc

So happy to see your reply. Thank you very much for your generous help!

Best regards,
Cheng