Пример #1
0
class TestMuon(unittest.TestCase):
 
    def setUp(self):
        self._sample = Sample()
       
        self._sample._reset(cell=True,sym=True,magdefs=True,muon=True)
        
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice,0) # selectd index 0
    
        if atoms:
            self._sample._reset(muon=True,sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError
    
    def test_dftgrid(self):
        # get a 64x64x64 grid independently on the atoms position
        r = build_uniform_grid(self._sample,4,-1.)
        # check that positions are inequivalent
        self.assertEqual(len(self._sample.sym.equivalent_sites(r)[0]),64)

        # same as above but missing the origin already occupied by Co!
        r = build_uniform_grid(self._sample,4,0.000000001)
        # check that positions are inequivalent
        self.assertEqual(len(self._sample.sym.equivalent_sites(r)[0]),60)

        # empty set becouse all too close
        r = build_uniform_grid(self._sample,4,2.0)
        self.assertEqual(len(r),0)
Пример #2
0
class TestMuon(unittest.TestCase):
    def setUp(self):
        self._sample = Sample()

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

        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice, 0)  # selectd index 0

        if atoms:
            self._sample._reset(muon=True, sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError

    def test_dftgrid(self):
        # get a 64x64x64 grid independently on the atoms position
        r = build_uniform_grid(self._sample, 4, -1.)
        # check that positions are inequivalent
        self.assertEqual(len(self._sample.sym.equivalent_sites(r)[0]), 64)

        # same as above but missing the origin already occupied by Co!
        r = build_uniform_grid(self._sample, 4, 0.000000001)
        # check that positions are inequivalent
        self.assertEqual(len(self._sample.sym.equivalent_sites(r)[0]), 60)

        # empty set becouse all too close
        r = build_uniform_grid(self._sample, 4, 2.0)
        self.assertEqual(len(r), 0)
Пример #3
0
class TestMuon(unittest.TestCase):
 
    def setUp(self):
        
        self._sample = Sample()
        
        self._sample._reset(cell=True,sym=True,magdefs=True,muon=True)
        
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice,0) # selectd index 0
        
        if atoms:
            self._sample._reset(muon=True,sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError
    
    def test_symsearch(self):
        
        if have_spg:
            # damn slow test!
            origsym = deepcopy(self._sample.sym)
            symsearch(self._sample)
            
            new_rotations, new_translations = self._sample.sym.get_op()
            self.assertEqual(len(new_rotations),len(origsym.get_op()[0]))
            
            for r, t in origsym.get_symop():
                ni = np.argwhere(np.all(new_rotations==r, axis=(1,2)))

                if len(ni) >= 1:
                    found = False
                    for i in ni:
                        # for some reason there is a rounding error so
                        # mod is done on 0.9999999... instead of 1
                        if np.allclose(np.mod(t,1-1e-13),np.mod(new_translations[i[0]],1-1e-13)):
                            found = True

                    if found == False:
                        raise RuntimeError
                        
                else:
                    raise RuntimeError
            
            
        else:
            self.assertFalse(symsearch(self._sample))
Пример #4
0
class TestSample(unittest.TestCase):
    def setUp(self):
        self._sample = Sample()

    def _set_a_cell(self):
        self._sample.cell = Atoms(symbols=['Co'],
                                  scaled_positions=[[0, 0, 0]],
                                  cell=[[3., 0, 0], [0, 3., 0], [0, 0, 3.]])

    def test_set_attribute(self):
        with self.assertRaises(TypeError):
            self._sample.blabla = 1

    def test_name_property(self):

        self.assertEqual(self._sample.name, "No name")

        self._sample.name = "test"

        self.assertEqual(self._sample.name, "test")

        #must be str or unicode
        with self.assertRaises(TypeError):
            self._sample.name = 1

        self.assertEqual(self._sample.name, "test")

        # test unicode
        self._sample.name = u"àèé"

    def test_muons_property(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)
        self._set_a_cell()

        with self.assertRaises(MuonError):
            self._sample.muons

    def test_add_muon_property(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        with self.assertRaises(CellError):
            self._sample.add_muon([0, 0, 0])

        self._set_a_cell()

        with self.assertRaises(TypeError):
            self._sample.add_muon('0 0 0')

        with self.assertRaises(ValueError):
            self._sample.add_muon([0, 0, 0, 0])
        with self.assertRaises(ValueError):
            self._sample.add_muon(np.array([0, 0, 0, 0]))

        self._sample.add_muon([0, 0, 0])
        np.testing.assert_array_equal(self._sample.muons[0], np.zeros(3))

        self._sample.add_muon([1, 1, 1])
        np.testing.assert_array_equal(self._sample.muons[1], np.ones(3))

        self._sample.add_muon([1, 1, 1], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[2], np.ones(3) / 3.)

        a = 4.0  # some lattice constant
        b = a / 2
        self._sample.cell = Atoms(symbols=['Au'],
                                  positions=[0, 0, 0],
                                  cell=[(0, b, b), (b, 0, b), (b, b, 0)],
                                  pbc=True)

        self._sample.add_muon([1., 1., 1.], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[3], np.ones(3) / 4.)

        self._sample.add_muon([.5, .5, .5], cartesian=False)
        self._sample.add_muon([2., 2., 2.], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[4],
                                      self._sample.muons[5])

    def test_mm_property(self):
        self._sample._reset(cell=True, magdefs=True, muon=True, sym=True)

        with self.assertRaises(MagDefError):
            self._sample.mm

        with self.assertRaises(CellError):
            self._sample.mm = MM(19)  # randomly large number

        self._sample._reset(magdefs=True)
        self._set_a_cell()
        with self.assertRaises(TypeError):
            self._sample.mm = 1

        self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
        self._sample.cell = Atoms(symbols=['C'],
                                  scaled_positions=[[0, 0, 0]],
                                  cell=[[3., 0, 0], [0, 3., 0], [0, 0, 3.]])

        with self.assertRaises(MagDefError):
            self._sample.mm = MM(198)  # randomly large number

        self._sample.mm = MM(1)

    def test_new_mm(self):
        self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
        with self.assertRaises(CellError):
            self._sample.new_mm()

        self._set_a_cell()

        self._sample.new_mm()
        self.assertTrue(isinstance(self._sample.mm, MM))
        self.assertEqual(len(self._sample.mm.fc), 1)

    def test_new_smm(self):
        if have_sympy:
            self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
            with self.assertRaises(CellError):
                self._sample.new_smm("x,y,z")

            # TODO TESTING
        else:
            pass

    def test_current_mm_idx_property(self):
        self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
        self._sample.cell = Atoms(symbols=['C'],
                                  scaled_positions=[[0, 0, 0]],
                                  cell=[[3., 0, 0], [0, 3., 0], [0, 0, 3.]])

        self._sample.new_mm()
        self._sample.mm.k = np.array([0, 0, 1.])
        self.assertEqual(self._sample.current_mm_idx, 0)
        self._sample.new_mm()
        self._sample.mm.k = np.array([0, 0, 2.])
        self.assertEqual(self._sample.current_mm_idx, 1)
        self._sample.new_mm()
        self._sample.mm.k = np.array([0, 0, 3.])
        self.assertEqual(self._sample.current_mm_idx, 2)

        self._sample.current_mm_idx = 0
        self.assertEqual(self._sample.current_mm_idx, 0)
        np.testing.assert_array_equal(self._sample.mm.k, np.array([0, 0, 1.]))

        with self.assertRaises(IndexError):
            self._sample.current_mm_idx = 3

        with self.assertRaises(IndexError):
            self._sample.current_mm_idx = -1

        self.assertEqual(self._sample.current_mm_idx, 0)

    def test_sym_property(self):

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

        with self.assertRaises(SymmetryError):
            self._sample.sym

        with self.assertRaises(TypeError):
            self._sample.sym = 1

        self._sample.sym = Spacegroup(113)

        self.assertEqual(self._sample.sym.no, 113)
        self.assertEqual(self._sample.sym.setting, 1)

    def test_cell_property(self):
        #needs better testing
        with self.assertRaises(CellError):
            self._sample.cell

        with self.assertRaises(TypeError):
            self._sample.cell = 1

        self._set_a_cell()
        current_cell = self._sample.cell
        self.assertEqual(current_cell.get_chemical_symbols(), ['Co'])
        current_cell.set_chemical_symbols(['Co'])
        self.assertEqual(current_cell.get_chemical_symbols(), ['Co'])

    def test_reset(self):

        # test cell reset
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            self._sample._reset(cell=True)
            assert len(w) == 3
            for wi in w:
                assert issubclass(wi.category, RuntimeWarning)

        self.assertEqual(self._sample._cell, None)
        with self.assertRaises(CellError):
            self._sample.cell

        # test magdef reset
        self._sample._reset(magdefs=True)
        self.assertEqual(self._sample._magdefs, [])
        self.assertEqual(self._sample._selected_mm, -1)
        with self.assertRaises(MagDefError):
            self._sample.mm

        # test muon reset
        self._set_a_cell()
        self._sample.add_muon([0, 1., 2])
        self._sample._reset(muon=True)
        self.assertEqual(self._sample._muon, [])
        with self.assertRaises(MuonError):
            self._sample.muons

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

        #test symmetry reset
        self._sample.sym = Spacegroup(113)
        self._sample._reset(sym=True)
        self.assertEqual(self._sample._sym, None)
        with self.assertRaises(SymmetryError):
            self._sample.sym

    # TODO
    def test_check_sym(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        with self.assertRaises(SymmetryError):
            self._sample._check_sym()

        # vary bad from user side
        self._sample._sym = 1
        with self.assertRaises(SymmetryError):
            self._sample._check_sym()

        self._sample.sym = Spacegroup(113)
        self.assertTrue(self._sample._check_sym())

    def test_check_lattice(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        with self.assertRaises(CellError):
            self._sample._check_lattice()

        self._set_a_cell()
        self.assertTrue(self._sample._check_lattice())
        self._sample._cell = 1
        with self.assertRaises(CellError):
            self._sample._check_lattice()

    def test_check_magdefs(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        with self.assertRaises(MagDefError):
            self._sample._check_magdefs()

        self._set_a_cell()
        self._sample.new_mm()
        self.assertTrue(self._sample._check_magdefs())

        self._sample._magdefs = 1
        with self.assertRaises(MagDefError):
            self._sample._check_magdefs()

    def test_check_muon(self):
        self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)

        with self.assertRaises(MuonError):
            self._sample._check_muon()

        self._set_a_cell()
        self._sample.add_muon(np.zeros(3))
        self.assertTrue(self._sample._check_muon())

        self._sample.add_muon(np.zeros(3))
        self._sample._muon[1] = 'a'
        with self.assertRaises(MuonError):
            self._sample._check_muon()
Пример #5
0
class TestSample(unittest.TestCase):
 
    def setUp(self):
        self._sample = Sample()
        
    def _set_a_cell(self):
        self._sample.cell = Atoms(symbols=['Co'],
                                  scaled_positions=[[0,0,0]],
                                  cell=[[3.,0,0],
                                        [0,3.,0],
                                        [0,0,3.]])
    def test_set_attribute(self):
        with self.assertRaises(TypeError):
            self._sample.blabla = 1
        
        
    def test_name_property(self):
        
        self.assertEqual(self._sample.name,"No name")
        
        self._sample.name = "test"
        
        self.assertEqual(self._sample.name,"test")
        
        #must be str or unicode
        with self.assertRaises(TypeError):
            self._sample.name = 1
            
        self.assertEqual(self._sample.name,"test")
        
        # test unicode
        self._sample.name = u"àèé"
        
    
    def test_muons_property(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        self._set_a_cell()
        
        with self.assertRaises(MuonError):
            self._sample.muons
            
        
        
        
    def test_add_muon_property(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)

        with self.assertRaises(CellError):
            self._sample.add_muon([0,0,0])
            
        self._set_a_cell()
        
        with self.assertRaises(TypeError):
            self._sample.add_muon('0 0 0')
            
        with self.assertRaises(ValueError):
            self._sample.add_muon([0,0,0,0])
        with self.assertRaises(ValueError):
            self._sample.add_muon(np.array([0,0,0,0]))
        
        self._sample.add_muon([0,0,0])
        np.testing.assert_array_equal(self._sample.muons[0], np.zeros(3))
        
        self._sample.add_muon([1,1,1])
        np.testing.assert_array_equal(self._sample.muons[1], np.ones(3))
        
        self._sample.add_muon([1,1,1], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[2], np.ones(3)/3.)
        
        a = 4.0  # some lattice constant
        b = a / 2
        self._sample.cell = Atoms(symbols=['Au'],
                                  positions=[0,0,0],
                                  cell=[(0, b, b), (b, 0, b), (b, b, 0)],
                                  pbc=True)
        
        self._sample.add_muon([1.,1.,1.], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[3], np.ones(3)/4.)
        
        self._sample.add_muon([.5,.5,.5], cartesian=False)
        self._sample.add_muon([2.,2.,2.], cartesian=True)
        np.testing.assert_array_equal(self._sample.muons[4], self._sample.muons[5])
        
        
    
    def test_mm_property(self):
        self._sample._reset(cell=True,magdefs=True,muon=True,sym=True)
        
        with self.assertRaises(MagDefError):
            self._sample.mm

        with self.assertRaises(CellError):
            self._sample.mm = MM(19) # randomly large number
                    
        
        self._sample._reset(magdefs=True)
        self._set_a_cell()
        with self.assertRaises(TypeError):
            self._sample.mm = 1
            
        self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
        self._sample.cell = Atoms(symbols=['C'],
                                  scaled_positions=[[0,0,0]],
                                  cell=[[3.,0,0],
                                        [0,3.,0],
                                        [0,0,3.]])
                                        
        with self.assertRaises(MagDefError):
            self._sample.mm = MM(198) # randomly large number        
            
        self._sample.mm = MM(1)
        

    def test_new_mm(self):
        self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
        with self.assertRaises(CellError):
            self._sample.new_mm()
        
        self._set_a_cell()
                                        
        self._sample.new_mm()            
        self.assertTrue(isinstance(self._sample.mm, MM))
        self.assertEqual(len(self._sample.mm.fc), 1)
        
        
    
    def test_new_smm(self):
        if have_sympy:
            self._sample._reset(magdefs=True, cell=True, muon=True, sym=True)
            with self.assertRaises(CellError):
                self._sample.new_smm("x,y,z")
            
            # TODO TESTING
        else:
            pass
            
    def test_current_mm_idx_property(self):
        self._sample._reset(magdefs=True, cell=True,muon=True, sym=True)
        self._sample.cell = Atoms(symbols=['C'],
                                  scaled_positions=[[0,0,0]],
                                  cell=[[3.,0,0],
                                        [0,3.,0],
                                        [0,0,3.]])        
        
        self._sample.new_mm()
        self._sample.mm.k=np.array([0,0,1.])
        self.assertEqual(self._sample.current_mm_idx,0)
        self._sample.new_mm()
        self._sample.mm.k=np.array([0,0,2.])
        self.assertEqual(self._sample.current_mm_idx,1)
        self._sample.new_mm()
        self._sample.mm.k=np.array([0,0,3.])
        self.assertEqual(self._sample.current_mm_idx,2)
        
        self._sample.current_mm_idx = 0
        self.assertEqual(self._sample.current_mm_idx,0)
        np.testing.assert_array_equal(self._sample.mm.k, np.array([0,0,1.]))
        
        with self.assertRaises(IndexError):
            self._sample.current_mm_idx = 3

        with self.assertRaises(IndexError):
            self._sample.current_mm_idx = -1

            
        self.assertEqual(self._sample.current_mm_idx,0)

        
    def test_sym_property(self):
        
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(SymmetryError):
            self._sample.sym
            
        with self.assertRaises(TypeError):
            self._sample.sym = 1
            
        self._sample.sym = Spacegroup(113)
        
        self.assertEqual(self._sample.sym.no,113)
        self.assertEqual(self._sample.sym.setting,1)
        

    def test_cell_property(self): 
        #needs better testing
        with self.assertRaises(CellError):
            self._sample.cell
            
        with self.assertRaises(TypeError):
            self._sample.cell = 1
            
        self._set_a_cell()
        current_cell = self._sample.cell
        self.assertEqual(current_cell.get_chemical_symbols(),['Co'])
        current_cell.set_chemical_symbols(['Co'])
        self.assertEqual(current_cell.get_chemical_symbols(),['Co'])

    def test_reset(self):
        
        # test cell reset
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            self._sample._reset(cell=True)
            assert len(w) == 3
            for wi in w:
                assert issubclass(wi.category, RuntimeWarning)
                
        self.assertEqual(self._sample._cell, None)
        with self.assertRaises(CellError):
            self._sample.cell
        
        # test magdef reset    
        self._sample._reset(magdefs=True)
        self.assertEqual(self._sample._magdefs, [])
        self.assertEqual(self._sample._selected_mm, -1)
        with self.assertRaises(MagDefError):
            self._sample.mm
            
        # test muon reset
        self._set_a_cell()
        self._sample.add_muon([0,1.,2])
        self._sample._reset(muon=True)
        self.assertEqual(self._sample._muon, [])
        with self.assertRaises(MuonError):
            self._sample.muons
        
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
            
        #test symmetry reset
        self._sample.sym = Spacegroup(113)
        self._sample._reset(sym=True)
        self.assertEqual(self._sample._sym, None)
        with self.assertRaises(SymmetryError):
            self._sample.sym
            
                       

    # TODO
    def test_check_sym(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(SymmetryError):
            self._sample._check_sym()
        
        # vary bad from user side
        self._sample._sym = 1
        with self.assertRaises(SymmetryError):
            self._sample._check_sym()
        
        self._sample.sym = Spacegroup(113)
        self.assertTrue(self._sample._check_sym())
        
    def test_check_lattice(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(CellError):
            self._sample._check_lattice()
        
        self._set_a_cell()
        self.assertTrue(self._sample._check_lattice())
        self._sample._cell = 1
        with self.assertRaises(CellError):
            self._sample._check_lattice()
        
            
        
    def test_check_magdefs(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(MagDefError):
            self._sample._check_magdefs()
            
        self._set_a_cell()
        self._sample.new_mm()
        self.assertTrue(self._sample._check_magdefs())
        
        self._sample._magdefs = 1
        with self.assertRaises(MagDefError):
            self._sample._check_magdefs()        
        
        
    def test_check_muon(self):
        self._sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(MuonError):
            self._sample._check_muon()

        self._set_a_cell()
        self._sample.add_muon(np.zeros(3))
        self.assertTrue(self._sample._check_muon())
        
        self._sample.add_muon(np.zeros(3))
        self._sample._muon[1] = 'a'
        with self.assertRaises(MuonError):
            self._sample._check_muon()        
Пример #6
0
class TestMuon(unittest.TestCase):
 
    def setUp(self):
        self._sample = Sample()
        
    def test_muon_set_frac(self):
        
        self._sample._reset(cell=True,sym=True,magdefs=True,muon=True)
        
        # check that missing cell raises error
        with self.assertRaises(CellError):
            muon_set_frac(self._sample, "0 0 0")
        
        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice,0) # selectd index 0
    
        if atoms:
            self._sample._reset(muon=True,sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError
            
        muon_set_frac(self._sample, "0 0 0")
        np.testing.assert_array_almost_equal(np.array([0,0,0.]),self._sample.muons[0])

        muon_set_frac(self._sample, "0.125 0.125 0.125")
        np.testing.assert_array_almost_equal(np.array([0.125,0.125,0.125]),self._sample.muons[1])
        
        

        
    
    def test_muon_reset(self):
        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice,0) # selectd index 0
    
        if atoms:
            self._sample._reset(muon=True,sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError
            
        muon_set_frac(self._sample, "0 0 0")
        np.testing.assert_array_almost_equal(np.array([0,0,0.]),self._sample.muons[0])

        muon_set_frac(self._sample, "0.125 0.125 0.125")
        np.testing.assert_array_almost_equal(np.array([0.125,0.125,0.125]),self._sample.muons[1])

    def test_find_equiv(self):
        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice,0) # selectd index 0
    
        if atoms:
            self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError        
        
        #tests throw error if no muon positions defined
        with self.assertRaises(MuonError):
            muon_find_equiv(self._sample)
        
        muon_set_frac(self._sample, "0 0 0")
        muon_find_equiv(self._sample)
        
        muon_positions = self._sample.muons
        
        self.assertEqual(len(muon_positions),atoms.get_number_of_atoms())
        for atm in atoms:
            self.assertTrue(np.any(np.all((muon_positions-atm[2])==0, axis=1)))
        
        self._sample._reset(muon=True)
        
        muon_set_frac(self._sample, "0.2 0.3 0.4")
        muon_find_equiv(self._sample)
        
        muon_positions = self._sample.muons
        #positions calculated with VESTA
        eqpositions = np.array([[ 0.200000  , 0.300000  , 0.400000],
                                [ 0.800000  , 0.700000  , 0.600000],
                                [ 0.800000  , 0.700000  , 0.400000],
                                [ 0.200000  , 0.300000  , 0.600000],
                                [ 0.800000  , 0.300000  , 0.600000],
                                [ 0.200000  , 0.700000  , 0.400000],
                                [ 0.200000  , 0.700000  , 0.600000],
                                [ 0.800000  , 0.300000  , 0.400000],
                                [ 0.400000  , 0.200000  , 0.300000],
                                [ 0.600000  , 0.800000  , 0.700000],
                                [ 0.400000  , 0.800000  , 0.700000],
                                [ 0.600000  , 0.200000  , 0.300000],
                                [ 0.600000  , 0.800000  , 0.300000],
                                [ 0.400000  , 0.200000  , 0.700000],
                                [ 0.600000  , 0.200000  , 0.700000],
                                [ 0.400000  , 0.800000  , 0.300000],
                                [ 0.300000  , 0.400000  , 0.200000],
                                [ 0.700000  , 0.600000  , 0.800000],
                                [ 0.700000  , 0.400000  , 0.800000],
                                [ 0.300000  , 0.600000  , 0.200000],
                                [ 0.300000  , 0.600000  , 0.800000],
                                [ 0.700000  , 0.400000  , 0.200000],
                                [ 0.700000  , 0.600000  , 0.200000],
                                [ 0.300000  , 0.400000  , 0.800000],
                                [ 0.300000  , 0.200000  , 0.600000],
                                [ 0.700000  , 0.800000  , 0.400000],
                                [ 0.700000  , 0.800000  , 0.600000],
                                [ 0.300000  , 0.200000  , 0.400000],
                                [ 0.300000  , 0.800000  , 0.400000],
                                [ 0.700000  , 0.200000  , 0.600000],
                                [ 0.700000  , 0.200000  , 0.400000],
                                [ 0.300000  , 0.800000  , 0.600000],
                                [ 0.200000  , 0.400000  , 0.700000],
                                [ 0.800000  , 0.600000  , 0.300000],
                                [ 0.800000  , 0.400000  , 0.300000],
                                [ 0.200000  , 0.600000  , 0.700000],
                                [ 0.800000  , 0.600000  , 0.700000],
                                [ 0.200000  , 0.400000  , 0.300000],
                                [ 0.200000  , 0.600000  , 0.300000],
                                [ 0.800000  , 0.400000  , 0.700000],
                                [ 0.400000  , 0.300000  , 0.800000],
                                [ 0.600000  , 0.700000  , 0.200000],
                                [ 0.400000  , 0.700000  , 0.200000],
                                [ 0.600000  , 0.300000  , 0.800000],
                                [ 0.600000  , 0.300000  , 0.200000],
                                [ 0.400000  , 0.700000  , 0.800000],
                                [ 0.600000  , 0.700000  , 0.800000],
                                [ 0.400000  , 0.300000  , 0.200000],
                                [ 0.200000  , 0.800000  , 0.900000],
                                [ 0.800000  , 0.200000  , 0.100000],
                                [ 0.800000  , 0.200000  , 0.900000],
                                [ 0.200000  , 0.800000  , 0.100000],
                                [ 0.800000  , 0.800000  , 0.100000],
                                [ 0.200000  , 0.200000  , 0.900000],
                                [ 0.200000  , 0.200000  , 0.100000],
                                [ 0.800000  , 0.800000  , 0.900000],
                                [ 0.300000  , 0.900000  , 0.700000],
                                [ 0.700000  , 0.100000  , 0.300000],
                                [ 0.700000  , 0.900000  , 0.300000],
                                [ 0.300000  , 0.100000  , 0.700000],
                                [ 0.300000  , 0.100000  , 0.300000],
                                [ 0.700000  , 0.900000  , 0.700000],
                                [ 0.700000  , 0.100000  , 0.700000],
                                [ 0.300000  , 0.900000  , 0.300000],
                                [ 0.300000  , 0.700000  , 0.100000],
                                [ 0.700000  , 0.300000  , 0.900000],
                                [ 0.700000  , 0.300000  , 0.100000],
                                [ 0.300000  , 0.700000  , 0.900000],
                                [ 0.300000  , 0.300000  , 0.900000],
                                [ 0.700000  , 0.700000  , 0.100000],
                                [ 0.700000  , 0.700000  , 0.900000],
                                [ 0.300000  , 0.300000  , 0.100000],
                                [ 0.200000  , 0.900000  , 0.200000],
                                [ 0.800000  , 0.100000  , 0.800000],
                                [ 0.800000  , 0.900000  , 0.800000],
                                [ 0.200000  , 0.100000  , 0.200000],
                                [ 0.800000  , 0.100000  , 0.200000],
                                [ 0.200000  , 0.900000  , 0.800000],
                                [ 0.200000  , 0.100000  , 0.800000],
                                [ 0.800000  , 0.900000  , 0.200000],
                                [ 0.900000  , 0.200000  , 0.800000],
                                [ 0.100000  , 0.800000  , 0.200000],
                                [ 0.900000  , 0.800000  , 0.200000],
                                [ 0.100000  , 0.200000  , 0.800000],
                                [ 0.100000  , 0.800000  , 0.800000],
                                [ 0.900000  , 0.200000  , 0.200000],
                                [ 0.100000  , 0.200000  , 0.200000],
                                [ 0.900000  , 0.800000  , 0.800000],
                                [ 0.900000  , 0.300000  , 0.300000],
                                [ 0.100000  , 0.700000  , 0.700000],
                                [ 0.900000  , 0.700000  , 0.700000],
                                [ 0.100000  , 0.300000  , 0.300000],
                                [ 0.100000  , 0.300000  , 0.700000],
                                [ 0.900000  , 0.700000  , 0.300000],
                                [ 0.100000  , 0.700000  , 0.300000],
                                [ 0.900000  , 0.300000  , 0.700000]])
        for p in eqpositions: 
            self.assertTrue(np.any(np.all(np.abs(muon_positions-p)<1e-10, axis=1)))
Пример #7
0
class TestCLFC(unittest.TestCase):
    def setUp(self):
        self.assertTrue(have_lfclib)
        self.sample = Sample()

    def _set_a_cell(self):
        self.sample.cell = Atoms(symbols=['Co'],
                                 scaled_positions=[[0, 0, 0]],
                                 cell=[[3., 0, 0], [0, 3., 0], [0, 0, 3.]])

    def test_find_largest_sphere(self):

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

        with self.assertRaises(CellError):
            find_largest_sphere(self.sample, [3, 3, 3])

        self._set_a_cell()

        with self.assertRaises(MuonError):
            find_largest_sphere(self.sample, [3, 3, 3])

        self.sample.add_muon([0.5, 0.5, 0.5])

        with self.assertRaises(TypeError):
            find_largest_sphere(self.sample, 1)

        with self.assertRaises(ValueError):
            find_largest_sphere(self.sample, [0, 1, 2])

        self.assertEqual(find_largest_sphere(self.sample, [1, 1, 1]), 1.5)
        self.sample.add_muon([1., 1., 1.], cartesian=True)
        self.assertEqual(find_largest_sphere(self.sample, [1, 1, 1]), 1.)

    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.)
Пример #8
0
class TestMuon(unittest.TestCase):
    def setUp(self):
        self._sample = Sample()

    def test_muon_set_frac(self):

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

        # check that missing cell raises error
        with self.assertRaises(CellError):
            muon_set_frac(self._sample, "0 0 0")

        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice, 0)  # selectd index 0

        if atoms:
            self._sample._reset(muon=True, sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError

        muon_set_frac(self._sample, "0 0 0")
        np.testing.assert_array_almost_equal(np.array([0, 0, 0.]),
                                             self._sample.muons[0])

        muon_set_frac(self._sample, "0.125 0.125 0.125")
        np.testing.assert_array_almost_equal(np.array([0.125, 0.125, 0.125]),
                                             self._sample.muons[1])

    def test_muon_reset(self):
        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice, 0)  # selectd index 0

        if atoms:
            self._sample._reset(muon=True, sym=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError

        muon_set_frac(self._sample, "0 0 0")
        np.testing.assert_array_almost_equal(np.array([0, 0, 0.]),
                                             self._sample.muons[0])

        muon_set_frac(self._sample, "0.125 0.125 0.125")
        np.testing.assert_array_almost_equal(np.array([0.125, 0.125, 0.125]),
                                             self._sample.muons[1])

    def test_find_equiv(self):
        # ugly way to load a lattice with its symetry
        co_lattice.seek(0)
        atoms, sym = read_cif(co_lattice, 0)  # selectd index 0

        if atoms:
            self._sample._reset(cell=True, muon=True, sym=True, magdefs=True)
            self._sample.cell = atoms
            self._sample.sym = sym
        else:
            raise RuntimeError

        #tests throw error if no muon positions defined
        with self.assertRaises(MuonError):
            muon_find_equiv(self._sample)

        muon_set_frac(self._sample, "0 0 0")
        muon_find_equiv(self._sample)

        muon_positions = self._sample.muons

        self.assertEqual(len(muon_positions), atoms.get_number_of_atoms())
        for atm in atoms:
            self.assertTrue(
                np.any(np.all((muon_positions - atm[2]) == 0, axis=1)))

        self._sample._reset(muon=True)

        muon_set_frac(self._sample, "0.2 0.3 0.4")
        muon_find_equiv(self._sample)

        muon_positions = self._sample.muons
        #positions calculated with VESTA
        eqpositions = np.array([[0.200000, 0.300000, 0.400000],
                                [0.800000, 0.700000, 0.600000],
                                [0.800000, 0.700000, 0.400000],
                                [0.200000, 0.300000, 0.600000],
                                [0.800000, 0.300000, 0.600000],
                                [0.200000, 0.700000, 0.400000],
                                [0.200000, 0.700000, 0.600000],
                                [0.800000, 0.300000, 0.400000],
                                [0.400000, 0.200000, 0.300000],
                                [0.600000, 0.800000, 0.700000],
                                [0.400000, 0.800000, 0.700000],
                                [0.600000, 0.200000, 0.300000],
                                [0.600000, 0.800000, 0.300000],
                                [0.400000, 0.200000, 0.700000],
                                [0.600000, 0.200000, 0.700000],
                                [0.400000, 0.800000, 0.300000],
                                [0.300000, 0.400000, 0.200000],
                                [0.700000, 0.600000, 0.800000],
                                [0.700000, 0.400000, 0.800000],
                                [0.300000, 0.600000, 0.200000],
                                [0.300000, 0.600000, 0.800000],
                                [0.700000, 0.400000, 0.200000],
                                [0.700000, 0.600000, 0.200000],
                                [0.300000, 0.400000, 0.800000],
                                [0.300000, 0.200000, 0.600000],
                                [0.700000, 0.800000, 0.400000],
                                [0.700000, 0.800000, 0.600000],
                                [0.300000, 0.200000, 0.400000],
                                [0.300000, 0.800000, 0.400000],
                                [0.700000, 0.200000, 0.600000],
                                [0.700000, 0.200000, 0.400000],
                                [0.300000, 0.800000, 0.600000],
                                [0.200000, 0.400000, 0.700000],
                                [0.800000, 0.600000, 0.300000],
                                [0.800000, 0.400000, 0.300000],
                                [0.200000, 0.600000, 0.700000],
                                [0.800000, 0.600000, 0.700000],
                                [0.200000, 0.400000, 0.300000],
                                [0.200000, 0.600000, 0.300000],
                                [0.800000, 0.400000, 0.700000],
                                [0.400000, 0.300000, 0.800000],
                                [0.600000, 0.700000, 0.200000],
                                [0.400000, 0.700000, 0.200000],
                                [0.600000, 0.300000, 0.800000],
                                [0.600000, 0.300000, 0.200000],
                                [0.400000, 0.700000, 0.800000],
                                [0.600000, 0.700000, 0.800000],
                                [0.400000, 0.300000, 0.200000],
                                [0.200000, 0.800000, 0.900000],
                                [0.800000, 0.200000, 0.100000],
                                [0.800000, 0.200000, 0.900000],
                                [0.200000, 0.800000, 0.100000],
                                [0.800000, 0.800000, 0.100000],
                                [0.200000, 0.200000, 0.900000],
                                [0.200000, 0.200000, 0.100000],
                                [0.800000, 0.800000, 0.900000],
                                [0.300000, 0.900000, 0.700000],
                                [0.700000, 0.100000, 0.300000],
                                [0.700000, 0.900000, 0.300000],
                                [0.300000, 0.100000, 0.700000],
                                [0.300000, 0.100000, 0.300000],
                                [0.700000, 0.900000, 0.700000],
                                [0.700000, 0.100000, 0.700000],
                                [0.300000, 0.900000, 0.300000],
                                [0.300000, 0.700000, 0.100000],
                                [0.700000, 0.300000, 0.900000],
                                [0.700000, 0.300000, 0.100000],
                                [0.300000, 0.700000, 0.900000],
                                [0.300000, 0.300000, 0.900000],
                                [0.700000, 0.700000, 0.100000],
                                [0.700000, 0.700000, 0.900000],
                                [0.300000, 0.300000, 0.100000],
                                [0.200000, 0.900000, 0.200000],
                                [0.800000, 0.100000, 0.800000],
                                [0.800000, 0.900000, 0.800000],
                                [0.200000, 0.100000, 0.200000],
                                [0.800000, 0.100000, 0.200000],
                                [0.200000, 0.900000, 0.800000],
                                [0.200000, 0.100000, 0.800000],
                                [0.800000, 0.900000, 0.200000],
                                [0.900000, 0.200000, 0.800000],
                                [0.100000, 0.800000, 0.200000],
                                [0.900000, 0.800000, 0.200000],
                                [0.100000, 0.200000, 0.800000],
                                [0.100000, 0.800000, 0.800000],
                                [0.900000, 0.200000, 0.200000],
                                [0.100000, 0.200000, 0.200000],
                                [0.900000, 0.800000, 0.800000],
                                [0.900000, 0.300000, 0.300000],
                                [0.100000, 0.700000, 0.700000],
                                [0.900000, 0.700000, 0.700000],
                                [0.100000, 0.300000, 0.300000],
                                [0.100000, 0.300000, 0.700000],
                                [0.900000, 0.700000, 0.300000],
                                [0.100000, 0.700000, 0.300000],
                                [0.900000, 0.300000, 0.700000]])
        for p in eqpositions:
            self.assertTrue(
                np.any(np.all(np.abs(muon_positions - p) < 1e-10, axis=1)))
Пример #9
0
class TestCLFC(unittest.TestCase):
 
    def setUp(self):
        self.assertTrue(have_lfclib)
        self.sample = Sample()

    def _set_a_cell(self):
        self.sample.cell = Atoms(symbols=['Co'],
                                  scaled_positions=[[0,0,0]],
                                  cell=[[3.,0,0],
                                        [0,3.,0],
                                        [0,0,3.]])
        
    def test_find_largest_sphere(self):
        
        self.sample._reset(cell=True,muon=True,sym=True,magdefs=True)
        
        with self.assertRaises(CellError):
            find_largest_sphere(self.sample,[3,3,3])
        
        
        
        self._set_a_cell() 

        with self.assertRaises(MuonError):
            find_largest_sphere(self.sample,[3,3,3])
        
        self.sample.add_muon([0.5,0.5,0.5])
        
        
        with self.assertRaises(TypeError):
            find_largest_sphere(self.sample,1)

        with self.assertRaises(ValueError):
            find_largest_sphere(self.sample,[0,1,2])
            
        self.assertEqual(find_largest_sphere(self.sample,[1,1,1]),1.5)
        self.sample.add_muon([1.,1.,1.],cartesian=True)
        self.assertEqual(find_largest_sphere(self.sample,[1,1,1]),1.)
        
    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.)