Beispiel #1
0
 def setUp(self):
     basis = Basis((1,1,1,0,0,-0.5), kind = 'triclinic', meta = {"Fermi": 0})
     
     kp_gamma = numpy.array((0,0,0))[numpy.newaxis,:]
     kp_m = numpy.array((0.5, 0.0, 0))[numpy.newaxis,:]
     kp_k = numpy.array((2./3, 1./3, 0))[numpy.newaxis,:]
     
     kp_path = numpy.linspace(0,1,30)[:,numpy.newaxis]
             
     kp_path = numpy.concatenate((
         kp_gamma*(1-kp_path) + kp_m*kp_path,
         kp_m*(1-kp_path) + kp_k*kp_path,
         kp_k*(1-kp_path) + kp_gamma*kp_path,
     ), axis = 0)
     
     k = basis.transform_to_cartesian(kp_path)*math.pi/3.**.5*2
     e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5
     
     self.cell = UnitCell(
         basis,
         kp_path,
         e[:,numpy.newaxis]*eV*[[-1.,1.]],
     )
     self.cell_weights = self.cell.values/self.cell.values.max()
     
     self.grid = Grid(
         basis,
         (numpy.linspace(0,1,30, endpoint = False)+1./60,numpy.linspace(0,1,30, endpoint = False)+1./60,(0,)),
         numpy.zeros((30,30,1,2), dtype = numpy.float64),
     )
     k = self.grid.cartesian()*math.pi/3.**.5*2
     e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5*eV
     
     self.grid.values[...,0] = -e
     self.grid.values[...,1] = e
Beispiel #2
0
    def setUp(self):
        self.cell = Cell(
            Basis.triclinic((2.5 * angstrom, 2.5 * angstrom, 10 * angstrom), (0, 0, .5)),
            (
                (1. / 3, 1. / 3, .5),
                (2. / 3, 2. / 3, .5),
            ),
            ['C'] * 2,
        )

        coords = (numpy.linspace(0, 1, 11, endpoint=False), numpy.linspace(0, 1, 13, endpoint=False),
                  numpy.linspace(0, 1, 17, endpoint=False))

        self.grid = Grid(
            self.cell,
            coords,
            numpy.zeros((11, 13, 17)),
        )
        self.grid = self.grid.copy(values=numpy.prod(numpy.sin(self.grid.explicit_coordinates * 2 * numpy.pi), axis=-1))
Beispiel #3
0
 def setUp(self):
     self.cell = UnitCell(
         Basis((2.5*angstrom,2.5*angstrom,10*angstrom,0,0,.5), kind = 'triclinic'),
         (
             (1./3,1./3,.5),
             (2./3,2./3,.5),
         ),
         'C',
     )
     
     coords = (numpy.linspace(0,1,11, endpoint = False),numpy.linspace(0,1,13, endpoint = False),numpy.linspace(0,1,17, endpoint = False))
     
     self.grid = Grid(
         self.cell,
         coords,
         numpy.zeros((11,13,17)),
     )
     self.grid.values = numpy.prod(numpy.sin(self.grid.explicit_coordinates()*2*numpy.pi), axis = -1)
Beispiel #4
0
 def setUp(self):
     self.grid = Grid(
         Basis((1*angstrom,1*angstrom,1*angstrom,0,0,-0.5), kind = 'triclinic'),
         (
             numpy.linspace(0,1,30,endpoint = False),
             numpy.linspace(0,1,30,endpoint = False),
             numpy.linspace(0,1,30,endpoint = False),
         ),
         numpy.zeros((30,30,30)),
     )
     self.grid.values = numpy.prod(numpy.sin(self.grid.explicit_coordinates()*2*math.pi), axis = -1)
     
     self.wrong_grid = self.grid.copy()
     self.wrong_grid.values = self.wrong_grid.values[...,numpy.newaxis]*numpy.array(((((1,2),),),))
     
     self.wrong_dims = Grid(
         Basis(((1*angstrom,0),(0,1*angstrom))),
         (
             numpy.linspace(0,1,30,endpoint = False),
             numpy.linspace(0,1,30,endpoint = False),
         ),
         numpy.zeros((30,30)),
     )
Beispiel #5
0
class Tests(unittest.TestCase):

    def setUp(self):
        self.cell = Cell(
            Basis.triclinic((2.5 * angstrom, 2.5 * angstrom, 10 * angstrom), (0, 0, .5)),
            (
                (1. / 3, 1. / 3, .5),
                (2. / 3, 2. / 3, .5),
            ),
            ['C'] * 2,
        )

        coords = (numpy.linspace(0, 1, 11, endpoint=False), numpy.linspace(0, 1, 13, endpoint=False),
                  numpy.linspace(0, 1, 17, endpoint=False))

        self.grid = Grid(
            self.cell,
            coords,
            numpy.zeros((11, 13, 17)),
        )
        self.grid = self.grid.copy(values=numpy.prod(numpy.sin(self.grid.explicit_coordinates * 2 * numpy.pi), axis=-1))

    def test_xsf_back_forth(self):
        c1 = self.cell
        cells = structure.xsf(xsf_structure(c1)).cells()
        assert len(cells) == 1
        c2 = cells[0]
        assert c1.size == c2.size
        testing.assert_allclose(c1.vectors / angstrom, c2.vectors / angstrom, atol=1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates)
        testing.assert_equal(c1.values, c2.values)

    def test_xsf_back_forth_multi(self):
        c1 = []
        for i in range(10):
            c = self.cell.copy(coordinates=self.cell.coordinates + (numpy.random.rand(*self.cell.coordinates.shape) - .5) / 10)
            c1.append(c)
        c2 = structure.xsf(xsf_structure(*c1)).cells()

        for i, j in zip(c1, c2):
            assert i.size == j.size
            testing.assert_allclose(i.vectors / angstrom, j.vectors / angstrom, atol=1e-6)
            testing.assert_allclose(i.coordinates, j.coordinates)
            testing.assert_equal(i.values, j.values)

    def test_xsf_grid_back_forth(self):
        data = xsf_grid(self.grid, self.cell)
        g = structure.xsf(data).grids()[0]
        testing.assert_allclose(self.grid.values, g.values, atol=1e-7)

    def test_qe_input(self):
        cell = Cell(Basis.orthorhombic((2.5 * angstrom, 2.5 * angstrom, 10 * angstrom)),
            (
                (1. / 3, 1. / 3, .5),
                (2. / 3, 2. / 3, .5),
            ),
            ['C'] * 2,
        )
        self.assertEqual(qe_input(
            cell=cell,
            relax_mask=3,
            parameters={"system": {"a": 3}, "control": {"b": "c"}, "random": {"d": True}},
            inline_parameters={"random": "hello"},
            pseudopotentials={"C": "C.UPF"},
            masses={"C": 3},
        ), "\n".join((
            "&CONTROL",
            "    b = 'c'",
            "/",
            "&SYSTEM",
            "    a = 3",
            "    ibrav = 0",
            "    nat = 2",
            "    ntyp = 1",
            "/",
            "ATOMIC_SPECIES",
            "    C  3.000 C.UPF",
            "ATOMIC_POSITIONS crystal",
            "     C 0.33333333333333 0.33333333333333 0.50000000000000 3 3 3",
            "     C 0.66666666666667 0.66666666666667 0.50000000000000 3 3 3",
            "CELL_PARAMETERS angstrom",
            "    2.50000000000000e+00 0.00000000000000e+00 0.00000000000000e+00",
            "    0.00000000000000e+00 2.50000000000000e+00 0.00000000000000e+00",
            "    0.00000000000000e+00 0.00000000000000e+00 1.00000000000000e+01",
            "RANDOM hello",
            "    d = .true.",
        )))
        self.assertEqual(qe_input(
            cell=cell,
            relax_mask=(0, 1),
            pseudopotentials={"C": "C.UPF"},
        ), "\n".join((
            "&SYSTEM",
            "    ibrav = 0",
            "    nat = 2",
            "    ntyp = 1",
            "/",
            "ATOMIC_SPECIES",
            "    C  12.011 C.UPF",
            "ATOMIC_POSITIONS crystal",
            "     C 0.33333333333333 0.33333333333333 0.50000000000000 0 0 0",
            "     C 0.66666666666667 0.66666666666667 0.50000000000000 1 1 1",
            "CELL_PARAMETERS angstrom",
            "    2.50000000000000e+00 0.00000000000000e+00 0.00000000000000e+00",
            "    0.00000000000000e+00 2.50000000000000e+00 0.00000000000000e+00",
            "    0.00000000000000e+00 0.00000000000000e+00 1.00000000000000e+01",
        )))

        self.assertEqual(qe_input(
            parameters=dict(
                inputpp=dict(plot_num=3, prefix="tmd"),
                plot=dict(fileout='something.xsf', iflag=3),
            )
        ), "\n".join((
            "&INPUTPP",
            "    plot_num = 3",
            "    prefix = 'tmd'",
            "/",
            "&PLOT",
            "    fileout = 'something.xsf'",
            "    iflag = 3",
            "/",
        )))


    def test_wan90_input(self):
        _g = (2, 3, 2)
        self.maxDiff = None
        grid = uniform_grid(_g).reshape(-1, 3)
        cell = Cell(Basis.orthorhombic((2.5 * angstrom, 2.5 * angstrom, 10 * angstrom)),
            (
                (1. / 3, 1. / 3, .5),
                (2. / 3, 2. / 3, .5),
            ),
            ['C'] * 2,
        )
        self.assertEqual(wannier90_input(
            cell=cell,
            kpts=grid,
            kp_grid=_g,
            parameters={"some_str": "abc", "some_int": 3, "some_float": 3.0, "some_bool": True},
            block_parameters={"some_block": "some_block"},
        ), "\n".join((
            "mp_grid = 2 3 2",
            "some_bool = .true.",
            "some_float = 3.000000e+00",
            "some_int = 3",
            "some_str = abc",
            "begin atoms_frac",
            "    C 0.3333333333 0.3333333333 0.5000000000",
            "    C 0.6666666667 0.6666666667 0.5000000000",
            "end atoms_frac",
            "begin kpoints",
            "    0.0000000000 0.0000000000 0.0000000000",
            "    0.0000000000 0.0000000000 0.5000000000",
            "    0.0000000000 0.3333333333 0.0000000000",
            "    0.0000000000 0.3333333333 0.5000000000",
            "    0.0000000000 0.6666666667 0.0000000000",
            "    0.0000000000 0.6666666667 0.5000000000",
            "    0.5000000000 0.0000000000 0.0000000000",
            "    0.5000000000 0.0000000000 0.5000000000",
            "    0.5000000000 0.3333333333 0.0000000000",
            "    0.5000000000 0.3333333333 0.5000000000",
            "    0.5000000000 0.6666666667 0.0000000000",
            "    0.5000000000 0.6666666667 0.5000000000",
            "end kpoints",
            "begin some_block",
            "    some_block",
            "end some_block",
            "begin unit_cell_cart",
            "    2.5000000000 0.0000000000 0.0000000000",
            "    0.0000000000 2.5000000000 0.0000000000",
            "    0.0000000000 0.0000000000 10.0000000000",
            "end unit_cell_cart",
        )))

    def test_qe_back_forth(self):
        c1 = self.cell
        c2 = qe.input(qe_input(
            cell=c1,
            pseudopotentials={"C": "C.UPF"},
        )).cell()
        assert c1.size == c2.size
        testing.assert_allclose(c1.vectors / angstrom, c2.vectors / angstrom, atol=1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates)
        testing.assert_equal(c1.values, c2.values)

    def test_siesta_not_raises(self):
        siesta_input(self.cell)

    def test_openmx_back_forth(self):
        c1 = self.cell
        c2 = openmx.input(openmx_input(
            c1,
            populations={"C": "2 2"},
        )).cell()
        assert c1.size == c2.size
        testing.assert_allclose(c1.vectors / angstrom, c2.vectors / angstrom, atol=1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol=1e-6)
        testing.assert_equal(c1.values, c2.values)

    def test_openmx_back_forth_negf_0(self):
        c1 = self.cell
        c2 = openmx.input(openmx_input(
            c1,
            l=c1,
            r=c1,
            populations={"C": "2 2"},
        )).cell(l=c1, r=c1)
        assert c1.size == c2.size
        testing.assert_allclose(c1.vectors / angstrom, c2.vectors / angstrom, atol=1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol=1e-6)
        testing.assert_equal(c1.values, c2.values)

    def test_openmx_back_forth_negf_1(self):
        c1 = self.cell.repeated(2, 1, 1)
        l = self.cell
        r = self.cell.repeated(3, 1, 1)
        c2 = openmx.input(openmx_input(
            c1,
            l=l,
            r=r,
            populations={"C": "2 2"},
        )).cell(l=l, r=r)
        assert c1.size == c2.size
        testing.assert_allclose(c1.vectors / angstrom, c2.vectors / angstrom, atol=1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol=1e-6)
        testing.assert_equal(c1.values, c2.values)

    def test_json(self):
        data = loads(json_structure(self.cell))
        another_data = loads(json_structure([self.cell, self.cell]))
        self.assertEqual(another_data, [data, data])
Beispiel #6
0
from dfttools.types import Basis, Grid
from dfttools import presentation

from numericalunits import angstrom
from matplotlib import pyplot
import numpy

grid = Grid(
    Basis((1*angstrom,1*angstrom,1*angstrom,0,0,-0.5), kind = 'triclinic'),
    (
        numpy.linspace(0,1,30,endpoint = False),
        numpy.linspace(0,1,30,endpoint = False),
        numpy.linspace(0,1,30,endpoint = False),
    ),
    numpy.zeros((30,30,30)),
)
grid.values = numpy.prod(numpy.sin(grid.explicit_coordinates()*2*numpy.pi), axis = -1)

presentation.matplotlib_scalar(grid, pyplot.gca(), (0.1,0.1,0.1), 'z', show_cell = True)
pyplot.show()
Beispiel #7
0
from dfttools import presentation

from matplotlib import pyplot
from numericalunits import eV
import numpy

# A reciprocal basis
basis = Basis((1, 1, 1, 0, 0, -0.5), kind='triclinic', meta={"Fermi": 0})

# Grid shape
shape = (50, 50, 1)

# A dummy grid with correct grid coordinates and empty grid values
grid = Grid(
    basis,
    tuple(numpy.linspace(0, 1, x, endpoint=False) + .5 / x for x in shape),
    numpy.zeros(shape + (2, ), dtype=numpy.float64),
)

# Calculate graphene band
k = grid.cartesian() * numpy.pi / 3.**.5 * 2
e = (1 + 4 * numpy.cos(k[..., 1])**2 +
     4 * numpy.cos(k[..., 1]) * numpy.cos(k[..., 0] * 3.**.5))**.5 * eV

# Set the band values
grid.values[..., 0] = -e
grid.values[..., 1] = e

presentation.matplotlib_bands_density(grid,
                                      pyplot.gca(),
                                      200,
Beispiel #8
0
class BackForthTests(unittest.TestCase):
    
    def setUp(self):
        self.cell = UnitCell(
            Basis((2.5*angstrom,2.5*angstrom,10*angstrom,0,0,.5), kind = 'triclinic'),
            (
                (1./3,1./3,.5),
                (2./3,2./3,.5),
            ),
            'C',
        )
        
        coords = (numpy.linspace(0,1,11, endpoint = False),numpy.linspace(0,1,13, endpoint = False),numpy.linspace(0,1,17, endpoint = False))
        
        self.grid = Grid(
            self.cell,
            coords,
            numpy.zeros((11,13,17)),
        )
        self.grid.values = numpy.prod(numpy.sin(self.grid.explicit_coordinates()*2*numpy.pi), axis = -1)
        
    def test_xsf_back_forth(self):
        c1 = self.cell
        cells = structure.xsf(xsf_structure(c1)).unitCells()
        assert len(cells) == 1
        c2 = cells[0]
        assert c1.size() == c2.size()
        testing.assert_allclose(c1.vectors/angstrom, c2.vectors/angstrom, atol = 1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates)
        testing.assert_equal(c1.values, c2.values)
        
    def test_xsf_back_forth_multi(self):
        c1 = []
        for i in range(10):
            c = self.cell.copy()
            c.coordinates += (numpy.random.rand(*c.coordinates.shape)-.5)/10
            c1.append(c)
        c2 = structure.xsf(xsf_structure(*c1)).unitCells()
        
        for i,j in zip(c1,c2):
            assert i.size() == j.size()
            testing.assert_allclose(i.vectors/angstrom, j.vectors/angstrom, atol = 1e-6)
            testing.assert_allclose(i.coordinates, j.coordinates)
            testing.assert_equal(i.values, j.values)
            
    def test_xsf_grid_back_forth(self):
        data = xsf_grid(self.grid, self.cell)
        g = structure.xsf(data).grids()[0]
        testing.assert_allclose(self.grid.values, g.values, atol = 1e-7)

    def test_qe_back_forth(self):
        c1 = self.cell
        c2 = qe.input(qe_input(
            cell = c1,
            pseudopotentials = {"C":"C.UPF"},
        )).unitCell()
        assert c1.size() == c2.size()
        testing.assert_allclose(c1.vectors/angstrom, c2.vectors/angstrom, atol = 1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates)
        testing.assert_equal(c1.values, c2.values)

    def test_siesta_not_raises(self):
        siesta_input(self.cell)

    def test_openmx_back_forth(self):
        c1 = self.cell
        c2 = openmx.input(openmx_input(
            c1,
            populations = {"C": "2 2"},
        )).unitCell()
        assert c1.size() == c2.size()
        testing.assert_allclose(c1.vectors/angstrom, c2.vectors/angstrom, atol = 1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol = 1e-6)
        testing.assert_equal(c1.values, c2.values)

    def test_openmx_back_forth_negf_0(self):
        c1 = self.cell
        c2 = openmx.input(openmx_input(
            c1,
            l = c1,
            r = c1,
            populations = {"C": "2 2"},
        )).unitCell(l = c1, r = c1)
        assert c1.size() == c2.size()
        testing.assert_allclose(c1.vectors/angstrom, c2.vectors/angstrom, atol = 1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol = 1e-6)
        testing.assert_equal(c1.values, c2.values)
        
    def test_openmx_back_forth_negf_1(self):
        c1 = self.cell.repeated(2,1,1)
        l = self.cell
        r = self.cell.repeated(3,1,1)
        c2 = openmx.input(openmx_input(
            c1,
            l = l,
            r = r,
            populations = {"C": "2 2"},
        )).unitCell(l = l, r = r)
        assert c1.size() == c2.size()
        testing.assert_allclose(c1.vectors/angstrom, c2.vectors/angstrom, atol = 1e-6)
        testing.assert_allclose(c1.coordinates, c2.coordinates, rtol = 1e-6)
        testing.assert_equal(c1.values, c2.values)
Beispiel #9
0
from dfttools.types import Basis, Grid
from dfttools import presentation

from matplotlib import pyplot
from numericalunits import eV
import numpy

# A reciprocal basis
basis = Basis((1,1,1,0,0,-0.5), kind = 'triclinic', meta = {"Fermi": 0})

# Grid shape
shape = (50,50,1)

# A dummy grid with correct grid coordinates and empty grid values
grid = Grid(
    basis,
    tuple(numpy.linspace(0,1,x, endpoint = False)+.5/x for x in shape),
    numpy.zeros(shape+(2,), dtype = numpy.float64),
)

# Calculate graphene band
k = grid.cartesian()*numpy.pi/3.**.5*2
e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5*eV

# Set the band values
grid.values[...,0] = -e
grid.values[...,1] = e

presentation.matplotlib_bands_density(grid, pyplot.gca(), 200, energy_range = (-1, 1))
pyplot.show()
Beispiel #10
0
from dfttools.types import Basis, Grid
from dfttools import presentation

from numericalunits import angstrom
from matplotlib import pyplot
import numpy

grid = Grid(
    Basis((1 * angstrom, 1 * angstrom, 1 * angstrom, 0, 0, -0.5),
          kind='triclinic'),
    (
        numpy.linspace(0, 1, 30, endpoint=False),
        numpy.linspace(0, 1, 30, endpoint=False),
        numpy.linspace(0, 1, 30, endpoint=False),
    ),
    numpy.zeros((30, 30, 30)),
)
grid.values = numpy.prod(numpy.sin(grid.explicit_coordinates() * 2 * numpy.pi),
                         axis=-1)

presentation.matplotlib_scalar(grid,
                               pyplot.gca(), (0.1, 0.1, 0.1),
                               'z',
                               show_cell=True)
pyplot.show()
Beispiel #11
0
class ScalarGridPlotTest(unittest.TestCase):
    
    def setUp(self):
        self.grid = Grid(
            Basis((1*angstrom,1*angstrom,1*angstrom,0,0,-0.5), kind = 'triclinic'),
            (
                numpy.linspace(0,1,30,endpoint = False),
                numpy.linspace(0,1,30,endpoint = False),
                numpy.linspace(0,1,30,endpoint = False),
            ),
            numpy.zeros((30,30,30)),
        )
        self.grid.values = numpy.prod(numpy.sin(self.grid.explicit_coordinates()*2*math.pi), axis = -1)
        
        self.wrong_grid = self.grid.copy()
        self.wrong_grid.values = self.wrong_grid.values[...,numpy.newaxis]*numpy.array(((((1,2),),),))
        
        self.wrong_dims = Grid(
            Basis(((1*angstrom,0),(0,1*angstrom))),
            (
                numpy.linspace(0,1,30,endpoint = False),
                numpy.linspace(0,1,30,endpoint = False),
            ),
            numpy.zeros((30,30)),
        )
    
    @cleanup
    def test_plot(self):
            
        im = matplotlib_scalar(self.grid, pyplot.gca(), (0.1,0.1,0.1), 'z')
        
        axes = pyplot.gcf().axes
        assert len(axes) == 1
        axes = axes[0]
        
        ai = axes.findobj(AxesImage)
        assert len(ai) == 1
        ai = ai[0]
        assert ai == im
        
        testing.assert_allclose(axes.get_xlim(), (-0.55, 0.95))
        testing.assert_allclose(axes.get_ylim(), (-0.1*3.**.5/2, 0.9*3.**.5/2))
        
    @cleanup
    def test_plot_2(self):
        im = matplotlib_scalar(self.grid, pyplot.gca(), (0.1,0.1,0.1), 'z', ppu = 10)
        testing.assert_equal(im.get_size(), (round(10*3.**.5/2), 15))

    @cleanup
    def test_plot_3(self):
        im = matplotlib_scalar(self.grid, pyplot.gca(), (0.1,0.1,0.1), 'z', show_cell = True)
        l = list(i for i in pyplot.gca().get_children() if isinstance(i, Line2D))
        print len(l)
        assert len(l) == 12

    @cleanup
    def test_plot_error_0(self):
        with self.assertRaises(TypeError):
            matplotlib_scalar(self.wrong_grid, pyplot.gca(), (0.1,0.1,0.1), 'z')
            
    @cleanup
    def test_plot_error_1(self):
        with self.assertRaises(TypeError):
            matplotlib_scalar(self.wrong_dims, pyplot.gca(), (0.1,0.1,0.1), 'z')
Beispiel #12
0
class BandDensityPlotTest(unittest.TestCase):
    
    def setUp(self):
        basis = Basis((1,1,1,0,0,-0.5), kind = 'triclinic', meta = {"Fermi": 0})
        
        kp_gamma = numpy.array((0,0,0))[numpy.newaxis,:]
        kp_m = numpy.array((0.5, 0.0, 0))[numpy.newaxis,:]
        kp_k = numpy.array((2./3, 1./3, 0))[numpy.newaxis,:]
        
        kp_path = numpy.linspace(0,1,30)[:,numpy.newaxis]
                
        kp_path = numpy.concatenate((
            kp_gamma*(1-kp_path) + kp_m*kp_path,
            kp_m*(1-kp_path) + kp_k*kp_path,
            kp_k*(1-kp_path) + kp_gamma*kp_path,
        ), axis = 0)
        
        k = basis.transform_to_cartesian(kp_path)*math.pi/3.**.5*2
        e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5
        
        self.cell = UnitCell(
            basis,
            kp_path,
            e[:,numpy.newaxis]*eV*[[-1.,1.]],
        )
        self.cell_weights = self.cell.values/self.cell.values.max()
        
        self.grid = Grid(
            basis,
            (numpy.linspace(0,1,30, endpoint = False)+1./60,numpy.linspace(0,1,30, endpoint = False)+1./60,(0,)),
            numpy.zeros((30,30,1,2), dtype = numpy.float64),
        )
        k = self.grid.cartesian()*math.pi/3.**.5*2
        e = (1+4*numpy.cos(k[...,1])**2 + 4*numpy.cos(k[...,1])*numpy.cos(k[...,0]*3.**.5))**.5*eV
        
        self.grid.values[...,0] = -e
        self.grid.values[...,1] = e
        
    @cleanup
    def test_plot(self):
        rl = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False)
        assert len(rl) == 1
        rl = rl[0]
        
        axes = pyplot.gcf().axes
        assert len(axes) == 1
        axes = axes[0]

        testing.assert_allclose(axes.get_xlim(), (-3,3))
        
        l = list(i for i in axes.get_children() if isinstance(i, Line2D))
        assert len(l) == 1
        l = l[0]
        assert l == rl
        
        x,y = l.get_data()
        
        testing.assert_allclose(x, numpy.linspace(-3,3,100))
        assert numpy.all(y<10) and numpy.all(y>0)
        assert numpy.any(y>0.1)
        
    @cleanup
    def test_plot_weights(self):
        w1 = 0.3*numpy.ones(self.cell.values.shape)
        w2 = 0.7*numpy.ones(self.cell.values.shape)
        
        rl1 = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, weights = w1)[0]
        rl2 = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, weights = w2, on_top_of = w1)[0]
                
        x1,y1 = rl1.get_data()
        x2,y2 = rl2.get_data()
        
        testing.assert_allclose(x1, numpy.linspace(-3,3,100))
        testing.assert_allclose(x2, numpy.linspace(-3,3,100))
        testing.assert_allclose(y1, 0.3*y2)

    @cleanup
    def test_plot_fill(self):
        rpc = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, use_fill = True)
        
        axes = pyplot.gcf().axes
        assert len(axes) == 1
        axes = axes[0]
        
        pc = list(i for i in axes.get_children() if isinstance(i, PolyCollection))
        assert len(pc) == 1
        pc = pc[0]
        assert pc == rpc
        
        for p in rpc.get_paths():
            (xmin, ymin), (xmax, ymax) = p.get_extents().get_points()
            assert xmin>=-3.01
            assert ymin>=0
            assert xmax<=3.01
            assert ymax< 10
        
    @cleanup
    def test_plot_fill_weights(self):
        w1 = 0.3*numpy.ones(self.cell.values.shape)
        w2 = 0.7*numpy.ones(self.cell.values.shape)
        
        rpc1 = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, weights = w1, use_fill = True)
        rpc2 = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, weights = w2, on_top_of = w1, use_fill = True)
        
        for rpc in (rpc1,rpc2):
            for p in rpc.get_paths():
                (xmin, ymin), (xmax, ymax) = p.get_extents().get_points()
                assert xmin>=-3.01
                assert ymin>=0
                assert xmax<=3.01
                assert ymax< 10
        
    @cleanup
    def test_plot_fill_portrait(self):
        rpc = matplotlib_bands_density(self.cell, pyplot.gca(), 100, show_fermi = False, use_fill = True, orientation = "portrait")
        
        for p in rpc.get_paths():
            (xmin, ymin), (xmax, ymax) = p.get_extents().get_points()
            assert ymin>=-3.01
            assert xmin>=0
            assert ymax<=3.01
            assert xmax< 10
            
    @cleanup
    def test_units(self):
        matplotlib_bands_density(self.cell, pyplot.gca(), 100, units = "eV")
        
        assert pyplot.gca().get_xaxis().get_label().get_text().endswith("eV")
        assert pyplot.gca().get_yaxis().get_label().get_text().endswith("eV")
        
    @cleanup
    def test_custom_units(self):
        matplotlib_bands_density(self.cell, pyplot.gca(), 100, units = 2*Ry, units_name = "Hartree")
        
        assert pyplot.gca().get_xaxis().get_label().get_text().endswith("Hartree")
        assert pyplot.gca().get_yaxis().get_label().get_text().endswith("Hartree")

    @cleanup
    def test_unknown_units_landscape(self):
        matplotlib_bands_density(self.grid, pyplot.gca(), 100, units = 2*Ry, orientation = 'landscape')
        
        assert pyplot.gca().get_xaxis().get_label().get_text() == 'Energy'
        assert pyplot.gca().get_yaxis().get_label().get_text() == 'Density'
        
    @cleanup
    def test_unknown_units_portrait(self):
        matplotlib_bands_density(self.grid, pyplot.gca(), 100, units = 2*Ry, orientation = 'portrait')
        
        assert pyplot.gca().get_yaxis().get_label().get_text() == 'Energy'
        assert pyplot.gca().get_xaxis().get_label().get_text() == 'Density'
        
    @cleanup
    def test_portrait(self):
        rl = matplotlib_bands_density(self.cell, pyplot.gca(), 100, energy_range = (-3, 3), orientation = "portrait")[0]
        
        l = list(i for i in pyplot.gca().get_children() if isinstance(i, Line2D))
        assert len(l) == 2
        
        x,y = rl.get_data()
        
        testing.assert_equal(y, numpy.linspace(-3,3,100))
        assert numpy.all(x<10) and numpy.all(x>0)
        assert numpy.any(x>0.1)
        
    @cleanup
    def test_plot_grid(self):
        matplotlib_bands_density(self.grid, pyplot.gca(), 100, energy_range = (-3,3), show_fermi = False)
        matplotlib_bands_density(self.grid, pyplot.gca(), 100, energy_range = (-3,3), force_gaussian = True, show_fermi = False)
        
        l = list(i for i in pyplot.gca().get_children() if isinstance(i, Line2D))
        assert len(l) == 2

        yy = []
        
        for ll in l:
            
            x,y = ll.get_data()
            yy.append(y)
            
            testing.assert_equal(x, numpy.linspace(-3,3,100))
            assert numpy.all(y<10) and numpy.all(y>=0)
            assert numpy.any(y>0.1)

        assert (numpy.abs(yy[0]-yy[1])**2).sum()**.5/100 < 1e-2
        
    @cleanup
    def test_unknown_orientation(self):
        with self.assertRaises(ValueError):
            matplotlib_bands_density(self.cell, pyplot.gca(), 100, energy_range = (-3, 3), orientation = "unknown")