Beispiel #1
0
    def test_symbolic_fourier_components(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir,'crys.xsf'))
        
        
        
        rand_k = np.random.rand(3)
        rand_real_fc = np.random.rand(3).reshape((1,3))+0.j # make array complex
        
        mm = MM(1)
        mm.k=np.array(rand_k)
        mm.fc_set(rand_real_fc)
        m.mm = mm
        
        
        m.add_muon([0.1,0.1,0.1])

        r = locfield(m, 's',[10,10,10],40)[0]

        if have_sympy:
            smm = SMM(1,"x,y,z")
            smm.k=np.array(rand_k)
            smm.set_symFC("[[x,y,z]]")
            smm.set_params(rand_real_fc[0].real.tolist())
    
            m.mm = smm
    
            r2 = locfield(m, 's',[10,10,10],40)[0]
    
            self.assertAlmostEqual( r.D[0], r2.D[0], places=10, msg=None, delta=None)
            self.assertAlmostEqual( r.D[1], r2.D[1], places=10, msg=None, delta=None)
            self.assertAlmostEqual( r.D[2], r2.D[2], places=7, msg=None, delta=None)           
Beispiel #2
0
    def test_mcif(self):
        m = Sample()
        load_mcif(m, os.path.join(self._stdir, 'Cd2Os2O7.mcif'))
        m.add_muon([float(x) for x in '0.125 0.125 0.125'.split()])

        # distance is l(Os1-H) =  2.20122(0) Å
        r1 = locfield(m, 's', [1, 1, 1], 2.3, 4, 2.3)
        r1[0].ACont = 1.

        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T, np.zeros(3), decimal=7)

        # distance to nnn is l(Os1-H) =  5.53962(0) Å
        r1 = locfield(m, 's', [3, 3, 3], 5.54, 4, 2.3)
        r1[0].ACont = 1.

        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T, np.zeros(3), decimal=7)

        # now use a funny cell
        r1 = locfield(m, 's', [
            np.random.randint(3, 10),
            np.random.randint(3, 10),
            np.random.randint(3, 10)
        ], 5.54, 4, 2.3)
        r1[0].ACont = 1.

        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T, np.zeros(3), decimal=7)
Beispiel #3
0
 def test_mcif(self):
     m = Sample()
     load_mcif(m, os.path.join(self._stdir,'Cd2Os2O7.mcif'))
     m.add_muon([ float(x) for x in '0.125 0.125 0.125'.split() ])
     
     # distance is l(Os1-H) =  2.20122(0) Å
     r1 = locfield(m, 's',[1,1,1],2.3,4,2.3)
     r1[0].ACont = 1.
     
     # total field is 0
     np.testing.assert_array_almost_equal(r1[0].T,np.zeros(3),decimal=7)
     
     
     # distance to nnn is l(Os1-H) =  5.53962(0) Å
     r1 = locfield(m, 's',[3,3,3],5.54,4,2.3)
     r1[0].ACont = 1.
     
     # total field is 0
     np.testing.assert_array_almost_equal(r1[0].T,np.zeros(3),decimal=7)
     
     # now use a funny cell
     r1 = locfield(m, 's',[np.random.randint(3,10),np.random.randint(3,10),np.random.randint(3,10)],5.54,4,2.3)
     r1[0].ACont = 1.
     
     # total field is 0
     np.testing.assert_array_almost_equal(r1[0].T,np.zeros(3),decimal=7)
Beispiel #4
0
    def test_compare_ass_and_rass(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir, 'crys2.xsf'))
        mm = MM(9)
        mm.k = np.array(np.random.rand(3))
        mm.fc_set(
            (np.random.rand(27) + 1.j * np.random.rand(27)).reshape(9, 3))
        m.mm = mm
        m.add_muon(np.random.rand(3))
        m.add_muon(np.random.rand(3))
        r1 = locfield(m, 's', [10, 10, 10], 20)
        r2 = locfield(m, 'r', [10, 10, 10], 20, axis=[1, 1, 1], nangles=1)

        r1[0].ACont = 1.0
        r2[0].ACont = 1.0
        r1[1].ACont = 1.0
        r2[1].ACont = 1.0

        min_oom = min(self.oom(r1[0].T), self.oom(r2[0].T[0]))
        np.testing.assert_array_almost_equal(r1[0].T,
                                             r2[0].T[0],
                                             decimal=6 - min_oom)

        min_oom = min(self.oom(r1[1].T), self.oom(r2[1].T[0]))
        np.testing.assert_array_almost_equal(r1[1].T,
                                             r2[1].T[0],
                                             decimal=6 - min_oom)
Beispiel #5
0
 def test_double_moment(self):
     m = Sample()
     load_xsf(m, os.path.join(self._stdir, 'crys.xsf'))
     mm = MM(1)
     mm.k = np.array([0., 0., 0.])
     mm.fc_set(np.array([[0. + 0j, 0., 1. + 0.j]]))
     m.mm = mm
     m.add_muon([0.1, 0.1, 0.1])
     r = locfield(m, 's', [1, 1, 1], 4)[0]
     m.mm.fc_set(np.array([[0. + 0j, 0. + 0.j, 2. + 0.j]]))
     r2 = locfield(m, 's', [1, 1, 1], 4)[0]
     # r should be: [0 tesla, 11.4226 milliteslas, 11.4226 milliteslas]
     #
     #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(2.5^2+2.5^2+2.5^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(atan(sqrt(2)))⋅([1,1,1]/sqrt(3))−1bohr_magneton⋅[1,0,0])
     #
     #
     self.assertAlmostEqual(r.D[0],
                            0.5 * r2.D[0],
                            places=10,
                            msg=None,
                            delta=None)
     self.assertAlmostEqual(r.D[1],
                            0.5 * r2.D[1],
                            places=10,
                            msg=None,
                            delta=None)
     self.assertAlmostEqual(r.D[2],
                            0.5 * r2.D[2],
                            places=7,
                            msg=None,
                            delta=None)
Beispiel #6
0
    def test_compare_rass_and_incass(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir,'crys.xsf'))
        mm = MM(1)
        # define three orthogonal vectors
        rp1 = np.random.rand(3)   # used for k
        r2 = np.random.rand(3)
        rp2 = np.cross(rp1,r2)
        rp3 = np.cross(rp1,rp2)
        
        # normalize a and b vectors
        rp2 /= np.linalg.norm(rp2)
        rp3 /= np.linalg.norm(rp3)
        
        #chose a random value for stag moment
        stm = np.random.ranf()*10.
        rp2 *= stm
        rp3 *= stm
        
        mm.k=np.array(rp1)
        mm.fc_set((rp2+1.j*rp3).reshape(1,3))
        m.mm = mm
        m.add_muon(np.random.rand(3))
        m.add_muon(np.random.rand(3))
        r1 = locfield(m, 's',[50,50,50],50)
        r2 = locfield(m, 'r',[50,50,50],50,nangles=1200,axis=rp1)
        r3 = locfield(m, 'i',[50,50,50],50,nangles=1200)

        r1[0].ACont = 1.0
        r2[0].ACont = 1.0
        r3[0].ACont = 1.0
        r1[1].ACont = 1.0
        r2[1].ACont = 1.0
        r3[1].ACont = 1.0
        
        min_oom = min(self.oom(r1[0].T), self.oom(r2[0].T[0]))
        np.testing.assert_array_almost_equal(r1[0].T,r2[0].T[0],decimal=7-min_oom)
        min_oom = min(self.oom(r1[1].T), self.oom(r2[1].T[0]))
        np.testing.assert_array_almost_equal(r1[1].T,r2[1].T[0],decimal=7-min_oom)
        
        r2_norms = np.apply_along_axis(np.linalg.norm, 1, r2[0].D)
        r3_norms = np.apply_along_axis(np.linalg.norm, 1, r3[0].D)
        
        min_oom=min(self.oom(np.max(r2_norms)), self.oom(np.max(r3_norms)))
        np.testing.assert_array_almost_equal(np.max(r2_norms),np.max(r3_norms),decimal=4-min_oom)
        
        min_oom=min(self.oom(np.min(r2_norms)), self.oom(np.min(r3_norms)))
        np.testing.assert_array_almost_equal(np.min(r2_norms),np.min(r3_norms),decimal=4-min_oom)

        r2_norms = np.apply_along_axis(np.linalg.norm, 1, r2[1].T)
        r3_norms = np.apply_along_axis(np.linalg.norm, 1, r3[1].T)
        
        min_oom=min(self.oom(np.max(r2_norms)), self.oom(np.max(r3_norms)))
        np.testing.assert_array_almost_equal(np.max(r2_norms),np.max(r2_norms),decimal=5-min_oom)
        
        min_oom=min(self.oom(np.min(r2_norms)), self.oom(np.min(r3_norms)))
        np.testing.assert_array_almost_equal(np.min(r3_norms),np.min(r3_norms),decimal=5-min_oom)
Beispiel #7
0
    def test_rotation(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir,'crys3.xsf'))
        mm = MM(1)
        mm.k=np.array([0.,0.,0.])
        mm.fc_set(np.array([[0.+0j,1.+0.j,0.+0.j]]))
        m.mm = mm
        m.add_muon([0.0,0.001,0.0])
        r = locfield(m, 'r',[1,1,1],1.2,nnn=0,nangles=300,axis=[1,0,0])[0]

        # r for angle = 0 should be: [0 T, 1.8548 T, 0 T]
        #
        #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(1^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(0)⋅([0,1,0]/sqrt(1))−1bohr_magneton⋅[0,1,0])
        #
        #
        # r for angle = 90 should be: [0 T, 0 T, −0.927401 T]
        # 
        #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(1^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(pi/2)⋅([0,1,0]/sqrt(1))−1bohr_magneton⋅[0,0,1])
        #
        # Opposite moments produce opposite fields. 150 is half of 300
        np.testing.assert_array_almost_equal(r.D[0],-r.D[150],decimal=7)
        np.testing.assert_array_almost_equal(r.D[0],np.array([0., 1.8548018,0.]),decimal=7)
        np.testing.assert_array_almost_equal(r.D[75],np.array([0., 0,-0.9274009]),decimal=6)
        
        rnorms = np.apply_along_axis(np.linalg.norm,1,r.T-r.L)
        self.assertAlmostEqual( np.min(rnorms), 0.9274009 ,places=6, msg=None, delta=None)
        self.assertAlmostEqual( np.max(rnorms), 1.8548018 ,places=6, msg=None, delta=None)

        r = locfield(m, 'r',[5,1,1],1.5,nnn=0,nangles=300,axis=[1,0,0])[0]
        np.testing.assert_array_almost_equal(r.D[0],-r.D[150],decimal=7)
        np.testing.assert_array_almost_equal(r.D[0],np.array([0., 2.18268753,0.]),decimal=7)
        np.testing.assert_array_almost_equal(r.D[75],np.array([0., 0,-1.58317237]),decimal=6)
        
        rnorms = np.apply_along_axis(np.linalg.norm,1,r.T-r.L)
        self.assertAlmostEqual( np.min(rnorms), 1.58317237 ,places=6, msg=None, delta=None)
        self.assertAlmostEqual( np.max(rnorms), 2.18268753 ,places=6, msg=None, delta=None)
        
        # Now test incomm
        mm = MM(1)
        mm.k=np.array([0.,0.,0.])
        mm.fc_set(np.array([[0.+0j,1.+0.j,0.+1.j]]))
        m.mm = mm
        i = locfield(m, 'i',[1,1,1],1.2,nnn=0,nangles=300)[0]
        
        inorms = np.apply_along_axis(np.linalg.norm,1,i.T-i.L)
        
        self.assertAlmostEqual( np.min(inorms), 0.9274009 ,places=6, msg=None, delta=None)
        self.assertAlmostEqual( np.max(inorms), 1.8548018 ,places=6, msg=None, delta=None)
        
        i = locfield(m, 'i',[5,1,1],1.5,nnn=0,nangles=300)[0]
        
        rnorms = np.apply_along_axis(np.linalg.norm,1,i.T-i.L)
        self.assertAlmostEqual( np.min(rnorms), 1.58317237 ,places=6, msg=None, delta=None)
        self.assertAlmostEqual( np.max(rnorms), 2.18268753 ,places=6, msg=None, delta=None)        
Beispiel #8
0
    def test_mcif3(self):
        m = Sample()
        load_mcif(m, os.path.join(self._stdir,'LiFeSO4F.mcif'))
        muon_set_frac(m, '0.25 0.25 0.25')
        
        # symmetry null
        r1 = locfield(m, 's',[np.random.randint(10,14),np.random.randint(10,14),np.random.randint(10,14)],22,4,10.)
        r1[0].ACont = 1.
        
        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T,np.zeros(3),decimal=7)      
        
        muon_reset(m)
        m.add_muon([float(x) for x in '0.15990  0.17820  0.14580'.split()])  # position of O3

        # one atom, distance is 2.14251 AA
        #  dipolar field should be:
        #
        #       def bfield(r,m):
        #           return 0.9274009*(3*r*np.dot(r,m)/(np.linalg.norm(r)**5)-m/(np.linalg.norm(r)**3))
        #       bfield(np.array([1.07574,1.59328,0.945826]),np.array([-1.70376,3.14961,-1.22045])) 
        #
        r1 = locfield(m, 's',[np.random.randint(1,4),np.random.randint(1,4),np.random.randint(1,4)],2.2,1,2.14251+20.*np.random.ranf())
        r1[0].ACont = 1.

        np.testing.assert_array_almost_equal(r1[0].D,np.array([0.29531083,  -0.09756855, 0.23347458]),decimal=6) 
        
        # contact field is (2/3)⋅magnetic_constant ([-1.70376 bohr_magneton ,3.14961bohr_magneton,-1.22045bohr_magneton])⋅(1angstrom^−3) =
        #   [-13.2372 T, 24.4705 T, -9.48213 T]
        
        np.testing.assert_array_almost_equal(r1[0].C,np.array([-13.2372 , 24.4705 , -9.48213]),decimal=4) 
        
        
        r2 = locfield(m, 's',[np.random.randint(3,5),np.random.randint(3,5),np.random.randint(3,5)],4.2,3,5.+20.*np.random.ranf())
        r2[0].ACont = 1.14299 # effective interaction increased since more nnn involved in acont
                                # still only 14% more
        
        # three atoms, distances are 2.14251 AA, 4.191093 AA, 4.19413AA
        #
        #      bfield(np.array([1.07574,1.59328,0.945826]),np.array([-1.70376,3.14961,-1.22045])) + \
        #      bfield(np.array([2.14396,2.77751,-2.29775]),np.array([1.70376,-3.14961,1.22045])) + \
        #      bfield(np.array([-2.28034,-2.66189,-2.29775]),np.array([1.70376,-3.14961,1.22045]))        
        
        np.testing.assert_array_almost_equal(r2[0].D,np.array([ 0.20781014, -0.07504131,  0.23329355]),decimal=6)
Beispiel #9
0
 def test_double_moment(self):
     m = Sample()
     load_xsf(m, os.path.join(self._stdir,'crys.xsf'))
     mm = MM(1)
     mm.k=np.array([0.,0.,0.])
     mm.fc_set(np.array([[0.+0j,0.,1.+0.j]]))
     m.mm = mm
     m.add_muon([0.1,0.1,0.1])
     r = locfield(m, 's',[1,1,1],4)[0]
     m.mm.fc_set(np.array([[0.+0j,0.+0.j,2.+0.j]]))
     r2 = locfield(m, 's',[1,1,1],4)[0]
     # r should be: [0 tesla, 11.4226 milliteslas, 11.4226 milliteslas]
     #
     #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(2.5^2+2.5^2+2.5^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(atan(sqrt(2)))⋅([1,1,1]/sqrt(3))−1bohr_magneton⋅[1,0,0])
     #
     #
     self.assertAlmostEqual( r.D[0], 0.5*r2.D[0], places=10, msg=None, delta=None)
     self.assertAlmostEqual( r.D[1], 0.5*r2.D[1], places=10, msg=None, delta=None)
     self.assertAlmostEqual( r.D[2], 0.5*r2.D[2], places=7, msg=None, delta=None)              
Beispiel #10
0
    def test_symbolic_fourier_components(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir, 'crys.xsf'))

        rand_k = np.random.rand(3)
        rand_real_fc = np.random.rand(3).reshape(
            (1, 3)) + 0.j  # make array complex

        mm = MM(1)
        mm.k = np.array(rand_k)
        mm.fc_set(rand_real_fc)
        m.mm = mm

        m.add_muon([0.1, 0.1, 0.1])

        r = locfield(m, 's', [10, 10, 10], 40)[0]

        if have_sympy:
            smm = SMM(1, "x,y,z")
            smm.k = np.array(rand_k)
            smm.set_symFC("[[x,y,z]]")
            smm.set_params(rand_real_fc[0].real.tolist())

            m.mm = smm

            r2 = locfield(m, 's', [10, 10, 10], 40)[0]

            self.assertAlmostEqual(r.D[0],
                                   r2.D[0],
                                   places=10,
                                   msg=None,
                                   delta=None)
            self.assertAlmostEqual(r.D[1],
                                   r2.D[1],
                                   places=10,
                                   msg=None,
                                   delta=None)
            self.assertAlmostEqual(r.D[2],
                                   r2.D[2],
                                   places=7,
                                   msg=None,
                                   delta=None)
Beispiel #11
0
 def test_mcif2(self):
     m = Sample()
     load_mcif(m, os.path.join(self._stdir,'ScMnO3.mcif'))
     m.add_muon( [float(x) for x in '0.66666666 0.33333333 0.25'.split()])
     
     # No contact
     r1 = locfield(m, 's',[np.random.randint(10,14),np.random.randint(10,14),np.random.randint(10,14)],22,4,0.3)
     r1[0].ACont = 1.
     
     # total field is 0
     np.testing.assert_array_almost_equal(r1[0].T,np.zeros(3),decimal=7)
Beispiel #12
0
 def test_one_dipole_outside(self):
     m = Sample()
     load_xsf(m, os.path.join(self._stdir, 'crys.xsf'))
     mm = MM(1)
     mm.k = np.array([0., 0., 0.])
     mm.fc_set(np.array([[1. + 0j, 0. + 1.j, 0. + 1.j]]))
     m.mm = mm
     m.add_muon([0.5, 0.5, 0.5])
     # the diagonal is 8.6603
     r = locfield(m, 's', [1, 1, 1], 8.66 / 2.)[0]
     self.assertEqual(np.sum(np.abs(r.D)), 0.)
Beispiel #13
0
 def test_one_dipole_outside(self):
     m = Sample()
     load_xsf(m, os.path.join(self._stdir,'crys.xsf'))
     mm = MM(1)
     mm.k=np.array([0.,0.,0.])
     mm.fc_set(np.array([[1.+0j,0.+1.j,0.+1.j]]))
     m.mm = mm
     m.add_muon([0.5,0.5,0.5])
     # the diagonal is 8.6603
     r = locfield(m, 's',[1,1,1],8.66/2.)[0]
     self.assertEqual( np.sum(np.abs(r.D)), 0.)
Beispiel #14
0
    def test_compare_ass_and_rass(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir,'crys2.xsf'))
        mm = MM(9)
        mm.k=np.array(np.random.rand(3))
        mm.fc_set((np.random.rand(27)+1.j*np.random.rand(27)).reshape(9,3))
        m.mm = mm
        m.add_muon(np.random.rand(3))
        m.add_muon(np.random.rand(3))
        r1 = locfield(m, 's',[10,10,10],20)
        r2 = locfield(m, 'r',[10,10,10],20,axis=[1,1,1],nangles=1)

        r1[0].ACont = 1.0
        r2[0].ACont = 1.0
        r1[1].ACont = 1.0
        r2[1].ACont = 1.0
        
        min_oom = min(self.oom(r1[0].T), self.oom(r2[0].T[0]))
        np.testing.assert_array_almost_equal(r1[0].T,r2[0].T[0],decimal=6-min_oom)
        
        min_oom = min(self.oom(r1[1].T), self.oom(r2[1].T[0]))
        np.testing.assert_array_almost_equal(r1[1].T,r2[1].T[0],decimal=6-min_oom)
Beispiel #15
0
    def test_mcif2(self):
        m = Sample()
        load_mcif(m, os.path.join(self._stdir, 'ScMnO3.mcif'))
        m.add_muon([float(x) for x in '0.66666666 0.33333333 0.25'.split()])

        # No contact
        r1 = locfield(m, 's', [
            np.random.randint(10, 14),
            np.random.randint(10, 14),
            np.random.randint(10, 14)
        ], 22, 4, 0.3)
        r1[0].ACont = 1.

        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T, np.zeros(3), decimal=7)
Beispiel #16
0
    def test_one_dipole_inside(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir, 'crys.xsf'))
        mm = MM(1)
        mm.k = np.array([0., 0., 0.])
        mm.fc_set(np.array([[1. + 0j, 0. + 0.j, 0. + 0.j]]))
        m.mm = mm
        m.add_muon([0.5, 0.5, 0.5])
        r = locfield(m, 's', [1, 1, 1], 8.67 / 2.)[0]

        # BDip should be: [0 tesla, 11.4226 milliteslas, 11.4226 milliteslas]
        #
        #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(2.5^2+2.5^2+2.5^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(atan(sqrt(2)))⋅([1,1,1]/sqrt(3))−1bohr_magneton⋅[1,0,0])
        #
        # BLor should be: [ 0.01138414 T, 0 , 0 ]
        #
        #    0.3333333333⋅magnetic_constant (1 bohr_magneton)/((4/3)pi(angstrom 8.67/2.)^3)
        #
        # BCont should be (Assuming ACont = 1 AA^-3 )
        #
        #	 (2/3)⋅magnetic_constant (1 bohr_magneton)⋅(1angstrom^−3) = 7.769376 T
        #

        self.assertAlmostEqual(r.D[0], 0., places=7, msg=None, delta=None)
        self.assertAlmostEqual(r.D[1], r.D[2], places=10, msg=None, delta=None)
        self.assertAlmostEqual(r.D[1],
                               11.4226e-3,
                               places=7,
                               msg=None,
                               delta=None)

        self.assertAlmostEqual(r.L[0],
                               0.01138414,
                               places=7,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(r.L[1], 0.0, places=7, msg=None, delta=None)
        self.assertAlmostEqual(r.L[2], 0.0, places=7, msg=None, delta=None)

        r.ACont = 1.  # Ang^-3

        self.assertAlmostEqual(r.C[0],
                               7.769376,
                               places=7,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(r.C[1], 0.0, places=7, msg=None, delta=None)
        self.assertAlmostEqual(r.C[2], 0.0, places=7, msg=None, delta=None)
Beispiel #17
0
 def test_one_dipole_inside(self):
     m = Sample()
     load_xsf(m, os.path.join(self._stdir,'crys.xsf'))
     mm = MM(1)
     mm.k=np.array([0.,0.,0.])
     mm.fc_set(np.array([[1.+0j,0.+0.j,0.+0.j]]))
     m.mm = mm
     m.add_muon([0.5,0.5,0.5])
     r = locfield(m,'s',[1,1,1],8.67/2.)[0]
     
     # BDip should be: [0 tesla, 11.4226 milliteslas, 11.4226 milliteslas]
     #
     #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(2.5^2+2.5^2+2.5^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(atan(sqrt(2)))⋅([1,1,1]/sqrt(3))−1bohr_magneton⋅[1,0,0])
     #
     # BLor should be: [ 0.01138414 T, 0 , 0 ]
     #
     #    0.3333333333⋅magnetic_constant (1 bohr_magneton)/((4/3)pi(angstrom 8.67/2.)^3)
     #
     # BCont should be (Assuming ACont = 1 AA^-3 )
     #
     #	 (2/3)⋅magnetic_constant (1 bohr_magneton)⋅(1angstrom^−3) = 7.769376 T
     #
     
     self.assertAlmostEqual( r.D[0], 0.,places=7, msg=None, delta=None)
     self.assertAlmostEqual( r.D[1], r.D[2], places=10, msg=None, delta=None)
     self.assertAlmostEqual( r.D[1], 11.4226e-3, places=7, msg=None, delta=None)
     
     self.assertAlmostEqual( r.L[0], 0.01138414  ,places=7, msg=None, delta=None)
     self.assertAlmostEqual( r.L[1], 0.0  ,places=7, msg=None, delta=None)
     self.assertAlmostEqual( r.L[2], 0.0  ,places=7, msg=None, delta=None)
     
     r.ACont = 1. # Ang^-3
     
     self.assertAlmostEqual( r.C[0], 7.769376  ,places=7, msg=None, delta=None)
     self.assertAlmostEqual( r.C[1], 0.0  ,places=7, msg=None, delta=None)
     self.assertAlmostEqual( r.C[2], 0.0  ,places=7, msg=None, delta=None)
Beispiel #18
0
    def test_locfield(self):

        self.sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        # sample, ctype, supercellsize, radius, nnn = 2, rcont = 10.0, nangles = None, axis = None):
        with self.assertRaises(TypeError):
            locfield(None, None, None, None)

        with self.assertRaises(TypeError):
            locfield(self.sample, None, None, None)

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', None, None)

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2, 2, 2], None)

        #with self.assertRaises(TypeError):
        #    locfield(self.sample, 's', [2,2,2], 3.)

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2, 2, 2], 3., '2a')

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2, 2, 2], 3., '2', '10b')

        with self.assertRaises(ValueError):
            locfield(self.sample, 'a', [2, 2, 2], 3.)

        with self.assertRaises(ValueError):
            locfield(self.sample, 'i', [2, 2, 2], 3.)

        with self.assertRaises(ValueError):
            locfield(self.sample, 's', [0, 2, 2], 3.)
Beispiel #19
0
    def test_compare_rass_and_incass(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir, 'crys.xsf'))
        mm = MM(1)
        # define three orthogonal vectors
        rp1 = np.random.rand(3)  # used for k
        r2 = np.random.rand(3)
        rp2 = np.cross(rp1, r2)
        rp3 = np.cross(rp1, rp2)

        # normalize a and b vectors
        rp2 /= np.linalg.norm(rp2)
        rp3 /= np.linalg.norm(rp3)

        #chose a random value for stag moment
        stm = np.random.ranf() * 10.
        rp2 *= stm
        rp3 *= stm

        mm.k = np.array(rp1)
        mm.fc_set((rp2 + 1.j * rp3).reshape(1, 3))
        m.mm = mm
        m.add_muon(np.random.rand(3))
        m.add_muon(np.random.rand(3))
        r1 = locfield(m, 's', [50, 50, 50], 50)
        r2 = locfield(m, 'r', [50, 50, 50], 50, nangles=1200, axis=rp1)
        r3 = locfield(m, 'i', [50, 50, 50], 50, nangles=1200)

        r1[0].ACont = 1.0
        r2[0].ACont = 1.0
        r3[0].ACont = 1.0
        r1[1].ACont = 1.0
        r2[1].ACont = 1.0
        r3[1].ACont = 1.0

        min_oom = min(self.oom(r1[0].T), self.oom(r2[0].T[0]))
        np.testing.assert_array_almost_equal(r1[0].T,
                                             r2[0].T[0],
                                             decimal=7 - min_oom)
        min_oom = min(self.oom(r1[1].T), self.oom(r2[1].T[0]))
        np.testing.assert_array_almost_equal(r1[1].T,
                                             r2[1].T[0],
                                             decimal=7 - min_oom)

        r2_norms = np.apply_along_axis(np.linalg.norm, 1, r2[0].D)
        r3_norms = np.apply_along_axis(np.linalg.norm, 1, r3[0].D)

        min_oom = min(self.oom(np.max(r2_norms)), self.oom(np.max(r3_norms)))
        np.testing.assert_array_almost_equal(np.max(r2_norms),
                                             np.max(r3_norms),
                                             decimal=4 - min_oom)

        min_oom = min(self.oom(np.min(r2_norms)), self.oom(np.min(r3_norms)))
        np.testing.assert_array_almost_equal(np.min(r2_norms),
                                             np.min(r3_norms),
                                             decimal=4 - min_oom)

        r2_norms = np.apply_along_axis(np.linalg.norm, 1, r2[1].T)
        r3_norms = np.apply_along_axis(np.linalg.norm, 1, r3[1].T)

        min_oom = min(self.oom(np.max(r2_norms)), self.oom(np.max(r3_norms)))
        np.testing.assert_array_almost_equal(np.max(r2_norms),
                                             np.max(r2_norms),
                                             decimal=5 - min_oom)

        min_oom = min(self.oom(np.min(r2_norms)), self.oom(np.min(r3_norms)))
        np.testing.assert_array_almost_equal(np.min(r3_norms),
                                             np.min(r3_norms),
                                             decimal=5 - min_oom)
Beispiel #20
0
    def test_mcif3(self):
        m = Sample()
        load_mcif(m, os.path.join(self._stdir, 'LiFeSO4F.mcif'))
        muon_set_frac(m, '0.25 0.25 0.25')

        # symmetry null
        r1 = locfield(m, 's', [
            np.random.randint(10, 14),
            np.random.randint(10, 14),
            np.random.randint(10, 14)
        ], 22, 4, 10.)
        r1[0].ACont = 1.

        # total field is 0
        np.testing.assert_array_almost_equal(r1[0].T, np.zeros(3), decimal=7)

        muon_reset(m)
        m.add_muon([float(x) for x in '0.15990  0.17820  0.14580'.split()
                    ])  # position of O3

        # one atom, distance is 2.14251 AA
        #  dipolar field should be:
        #
        #       def bfield(r,m):
        #           return 0.9274009*(3*r*np.dot(r,m)/(np.linalg.norm(r)**5)-m/(np.linalg.norm(r)**3))
        #       bfield(np.array([1.07574,1.59328,0.945826]),np.array([-1.70376,3.14961,-1.22045]))
        #
        r1 = locfield(m, 's', [
            np.random.randint(1, 4),
            np.random.randint(1, 4),
            np.random.randint(1, 4)
        ], 2.2, 1, 2.14251 + 20. * np.random.ranf())
        r1[0].ACont = 1.

        np.testing.assert_array_almost_equal(
            r1[0].D,
            np.array([0.29531083, -0.09756855, 0.23347458]),
            decimal=6)

        # contact field is (2/3)⋅magnetic_constant ([-1.70376 bohr_magneton ,3.14961bohr_magneton,-1.22045bohr_magneton])⋅(1angstrom^−3) =
        #   [-13.2372 T, 24.4705 T, -9.48213 T]

        np.testing.assert_array_almost_equal(
            r1[0].C, np.array([-13.2372, 24.4705, -9.48213]), decimal=4)

        r2 = locfield(m, 's', [
            np.random.randint(3, 5),
            np.random.randint(3, 5),
            np.random.randint(3, 5)
        ], 4.2, 3, 5. + 20. * np.random.ranf())
        r2[0].ACont = 1.14299  # effective interaction increased since more nnn involved in acont
        # still only 14% more

        # three atoms, distances are 2.14251 AA, 4.191093 AA, 4.19413AA
        #
        #      bfield(np.array([1.07574,1.59328,0.945826]),np.array([-1.70376,3.14961,-1.22045])) + \
        #      bfield(np.array([2.14396,2.77751,-2.29775]),np.array([1.70376,-3.14961,1.22045])) + \
        #      bfield(np.array([-2.28034,-2.66189,-2.29775]),np.array([1.70376,-3.14961,1.22045]))

        np.testing.assert_array_almost_equal(
            r2[0].D,
            np.array([0.20781014, -0.07504131, 0.23329355]),
            decimal=6)
                                      [0.0+0.j, 0.0+0.j, -0.6+0.j], [0.0+0.j, 0.0+0.j, -0.6+0.j], # magnetic Cu
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j],
                                      [0.0+0.j, 0.0+0.j,  0.0+0.j], [0.0+0.j, 0.0+0.j,   0.0+0.j] ])
la2cuo4.mm.desc = 'stripe along b with k = 0'


radius=find_largest_sphere(la2cuo4,[100, 100, 100])
print("Radius: ", radius)

print("Expected answer: [ 0.0035 -0.039  -0.0131] B_dip = 0.04127550110183053 T")


show_structure(la2cuo4,visualizationTool='V')
la2cuo4.current_mm_idx=0
r=locfield(la2cuo4, 's', [100, 100, 100] ,radius)
for v in r:
   print ("Calculated ",v.D, 'B_dip =',np.linalg.norm(v.D,axis=0),'T')
   # save_sample(la2cuo4,path+"La2CuO4-stripe-as-fm.yaml")
   #------------------------------------------------------------------------------------------------------------  
   #Experimental internal field at the muon B_dip+B_contact in range of 400-430 G.
   # or 6MHz i.e 410 Gauss from https://www.sciencedirect.com/science/article/pii/0375960187903823 
   #https://link.springer.com/article/10.1007/BF02396016 and   https://link.springer.com/article/10.1007/BF02060647
   
   
                FC for atom 1 Fe (3 real, [3 imag]): 0.00 0.00 2.22 
                 FC for atom 2 Fe (3 real, [3 imag]): 0.00 0.00 2.22 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

- 2.22 is the Fe experimental magnetic moment in Bohr magneton

-Both commands below can be used for visualization on interactive session with xcrysden 
show_cell(fe)                        
show_supercell(fe,[2,2,2]) 

"""



radius=find_largest_sphere(fe,[100, 100, 100])  
r=locfield(fe, 's', [100, 100, 100] ,radius) 

"""
- The find_largest_sphere func. is an experimental function. This func. has not been thoroughly tested, see documentation. 
-  s is for the summation method used. For help type 'help(locfield)' on the interactive python session after the locfield  must have been imported
-  [100, 100, 100] defines the supercell for the calculation
-  radius is the sphere radius
-  All the local fied contributions are contained in r, Bdipolar in r[i].D, BLorentz in r[i].L, BContact in r[i].C, Btotal in r[i].T
-  If r[i].Acont(Contact field term) is not defined r[i].C is all zero.
-  For Acont and its unit, see the documentation (http://muesr.readthedocs.io/en/latest/ContactTerm.html)  

"""


B_dip=np.zeros([len(fe.muons),3])
B_Lor=np.zeros([len(fe.muons),3])
Beispiel #23
0
    def test_rotation(self):
        m = Sample()
        load_xsf(m, os.path.join(self._stdir, 'crys3.xsf'))
        mm = MM(1)
        mm.k = np.array([0., 0., 0.])
        mm.fc_set(np.array([[0. + 0j, 1. + 0.j, 0. + 0.j]]))
        m.mm = mm
        m.add_muon([0.0, 0.001, 0.0])
        r = locfield(m,
                     'r', [1, 1, 1],
                     1.2,
                     nnn=0,
                     nangles=300,
                     axis=[1, 0, 0])[0]

        # r for angle = 0 should be: [0 T, 1.8548 T, 0 T]
        #
        #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(1^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(0)⋅([0,1,0]/sqrt(1))−1bohr_magneton⋅[0,1,0])
        #
        #
        # r for angle = 90 should be: [0 T, 0 T, −0.927401 T]
        #
        #    (magnetic_constant/4pi)⋅((1/(1angstrom⋅sqrt(1^2)))^3)⋅(3⋅(1 bohr_magneton)⋅cos(pi/2)⋅([0,1,0]/sqrt(1))−1bohr_magneton⋅[0,0,1])
        #
        # Opposite moments produce opposite fields. 150 is half of 300
        np.testing.assert_array_almost_equal(r.D[0], -r.D[150], decimal=7)
        np.testing.assert_array_almost_equal(r.D[0],
                                             np.array([0., 1.8548018, 0.]),
                                             decimal=7)
        np.testing.assert_array_almost_equal(r.D[75],
                                             np.array([0., 0, -0.9274009]),
                                             decimal=6)

        rnorms = np.apply_along_axis(np.linalg.norm, 1, r.T - r.L)
        self.assertAlmostEqual(np.min(rnorms),
                               0.9274009,
                               places=6,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(np.max(rnorms),
                               1.8548018,
                               places=6,
                               msg=None,
                               delta=None)

        r = locfield(m,
                     'r', [5, 1, 1],
                     1.5,
                     nnn=0,
                     nangles=300,
                     axis=[1, 0, 0])[0]
        np.testing.assert_array_almost_equal(r.D[0], -r.D[150], decimal=7)
        np.testing.assert_array_almost_equal(r.D[0],
                                             np.array([0., 2.18268753, 0.]),
                                             decimal=7)
        np.testing.assert_array_almost_equal(r.D[75],
                                             np.array([0., 0, -1.58317237]),
                                             decimal=6)

        rnorms = np.apply_along_axis(np.linalg.norm, 1, r.T - r.L)
        self.assertAlmostEqual(np.min(rnorms),
                               1.58317237,
                               places=6,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(np.max(rnorms),
                               2.18268753,
                               places=6,
                               msg=None,
                               delta=None)

        # Now test incomm
        mm = MM(1)
        mm.k = np.array([0., 0., 0.])
        mm.fc_set(np.array([[0. + 0j, 1. + 0.j, 0. + 1.j]]))
        m.mm = mm
        i = locfield(m, 'i', [1, 1, 1], 1.2, nnn=0, nangles=300)[0]

        inorms = np.apply_along_axis(np.linalg.norm, 1, i.T - i.L)

        self.assertAlmostEqual(np.min(inorms),
                               0.9274009,
                               places=6,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(np.max(inorms),
                               1.8548018,
                               places=6,
                               msg=None,
                               delta=None)

        i = locfield(m, 'i', [5, 1, 1], 1.5, nnn=0, nangles=300)[0]

        rnorms = np.apply_along_axis(np.linalg.norm, 1, i.T - i.L)
        self.assertAlmostEqual(np.min(rnorms),
                               1.58317237,
                               places=6,
                               msg=None,
                               delta=None)
        self.assertAlmostEqual(np.max(rnorms),
                               2.18268753,
                               places=6,
                               msg=None,
                               delta=None)
# set muon positions in lattice coordinates
smpl.add_muon([0.1225,0.3772,0.8679])
smpl.add_muon([0.0416,0.2500,0.9172])
smpl.add_muon([0.3901,0.2500,0.3599])
smpl.add_muon([0.8146,0.0404,0.8914])


print('Local fields at the muon sites (Tesla/Bohr Magneton):')
# calculate magnetic fields, the output is a list of LocalFields objects
#  (one for each muon site) that contain information on Total, Dipolar, 
#  Lorentz and Fermi Contact fields (for the Contact term please read the
#  documentation carefully!)
#  
#  The parameters of the following function are:
#            sample   type of calculation     supercell    Lorentz radius
r = locfield( smpl,          's',           [100,100,100],       40)

# we report the results in T/mu_B (same as the paper cited above)
print(r[0].T/4.19, "Norm {: 0.4f}".format(np.linalg.norm(r[0].T/4.19)))
print(r[1].T/4.19, "Norm {: 0.4f}".format(np.linalg.norm(r[1].T/4.19)))
print(r[2].T/4.19, "Norm {: 0.4f}".format(np.linalg.norm(r[2].T/4.19)))
print(r[3].T/4.19, "Norm {: 0.4f}".format(np.linalg.norm(r[3].T/4.19)))


# ==== Now Automatically ====

print('Now automatic run...\n')


# create a new magnetic model for the sample
smpl.new_mm()
s.mm.k = k_rlu
s.mm.fc = RH_FCs

s.new_mm()
s.mm.desc = "Left handed spiral"
s.mm.k = k_rlu
s.mm.fc = LH_FCs



s.add_muon([0.532, 0.532, 0.532])
muon_find_equiv(s)

# For Reft Handed
s.current_mm_idx = 1;      # N.B.: indexes start from 0 but idx=0 is the transverse field!
r_RH = locfield(s, 'i',[50,50,50],100,nnn=3,nangles=360)

s.current_mm_idx = 2;
r_LH = locfield(s, 'i',[50,50,50],100,nnn=3,nangles=360)


for i in range(4):
    r_RH[i].ACont = -0.066
    r_LH[i].ACont = -0.066


# Two subplots, unpack the axes array immediately
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(10,5))

ax1.set_title('right-handed')
ax2.set_title('left-handed')
# according to CoF2.cif (setting with a,b equal, c shorter, type cif to check)
# H-M P4_2/mnm group 136, six atoms in the cell, in this order
# Co at 0.00000 0.00000 0.00000 (2b site)  
# the symmetry replica is generated at 0.5000 0.5000 0.5000
# http://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-normsets?&norgens=&gnum=136 
# F at 0.30600 0.30600 0.00000  (4f site)
# the symmetry replicas are generated at 1--x 1-x 0, 0.5+x 0.5-x, 0.5, 0.5-x,0.5+x, 0.5
cof.mm.fc= np.array([[0.0+0.j, 0.0+0.j, 2.6+0.j],[0.0+0.j, 0.0+0.j, -2.6+0.j], 
                              [0.0+0.j, 0.0+0.j, 0.0+0.j],[0.0+0.j, 0.0+0.j,  0.0+0.j],
                              [0.0+0.j, 0.0+0.j, 0.0+0.j],[0.0+0.j, 0.0+0.j,  0.0+0.j] ])

show_structure(cof,visualizationTool='V')  # show_structure(cof,supercell=[1,1,2],visualizationTool='V')
n=18

radius=find_largest_sphere(cof,[n,n,n]) 
B_dip = np.linalg.norm(locfield(cof, 's', [n,n,n] ,radius)[0].D,axis=0)
print('R = {:.1f}, B_dip = {:.4f} T'.format(radius,B_dip))
npoints = 11
n = np.logspace(0.53,2,npoints,dtype=int)
k = -1
B_dip = np.zeros(npoints)
R = np.zeros(npoints)
for m in n:
     k += 1
     radius=find_largest_sphere(cof,[m,m,m])
     r=locfield(cof, 's', [m, m, m] ,radius) #
     R[k] = radius
     B_dip[k] =np.linalg.norm(r[0].D,axis=0)
fig,ax = P.subplots()
ax.plot(R,B_dip,'bo',label='sum')
ax.plot(R,R-R+0.265,'b--',label='exp')
Beispiel #27
0
    def test_locfield(self):
        
        self.sample._reset(cell=True,muon=True,sym=True,magdefs=True)
      
        # sample, ctype, supercellsize, radius, nnn = 2, rcont = 10.0, nangles = None, axis = None):
        with self.assertRaises(TypeError):
            locfield(None, None, None, None)
        
        with self.assertRaises(TypeError):
            locfield(self.sample, None, None, None)

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', None, None)
            
        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2,2,2], None)

        #with self.assertRaises(TypeError):
        #    locfield(self.sample, 's', [2,2,2], 3.)

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2,2,2], 3., '2a')

        with self.assertRaises(TypeError):
            locfield(self.sample, 's', [2,2,2], 3., '2', '10b')

        with self.assertRaises(ValueError):
            locfield(self.sample, 'a', [2,2,2], 3.)
            
        with self.assertRaises(ValueError):
            locfield(self.sample, 'i', [2,2,2], 3.)

        with self.assertRaises(ValueError):
            locfield(self.sample, 's', [0,2,2], 3.)