Exemplo n.º 1
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)
Exemplo n.º 2
0
from dfttools.types import Basis, UnitCell
from dfttools.presentation import svgwrite_unit_cell

from numericalunits import angstrom as a

graphene_basis = Basis(
    (2.46*a, 2.46*a, 6.7*a, 0,0,.5),
    kind = 'triclinic'
)

# Unit cell
graphene_cell = UnitCell(graphene_basis, (
    (1./3,1./3,.5),
    (2./3,2./3,.5),
), ('C','C'))

# Moire matching vectors
moire = [1, 26, 6, 23]

# A top layer
l1 = graphene_cell.supercell(
    (moire[0],moire[1],0),
    (-moire[1],moire[0]+moire[1],0),
    (0,0,1)
)

# A bottom layer
l2 = graphene_cell.supercell(
    (moire[2],moire[3],0),
    (-moire[3],moire[2]+moire[3],0),
    (0,0,1)
Exemplo n.º 3
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})

# G-K path
kp = numpy.linspace(0,1,100)[:,numpy.newaxis] * numpy.array(((1./3,2./3,0),))

# A dummy grid UnitCell with correct kp-path
bands = UnitCell(
    basis,
    kp,
    numpy.zeros((100,2), dtype = numpy.float64),
)

# Calculate graphene band
k = bands.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
bands.values[...,0] = -e
bands.values[...,1] = e

# Assign some weights
weights = bands.values.copy()
weights -= weights.min()
weights /= weights.max()
Exemplo n.º 4
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)
Exemplo n.º 5
0
from dfttools.types import Basis, UnitCell
from dfttools.presentation import svgwrite_unit_cell

from numericalunits import angstrom as a

mos2_basis = Basis(
    (3.19*a, 3.19*a, 20*a, 0,0,.5),
    kind = 'triclinic'
)
d = 1.57722483162840/20

# Unit cell with 3 atoms
mos2_cell = UnitCell(mos2_basis, (
    (1./3,1./3,.5),
    (2./3,2./3,0.5+d),
    (2./3,2./3,0.5-d),
), ('Mo','S','S'))

# Rectangular supercell with 6 atoms
mos2_rectangular = mos2_cell.supercell(
    (1,0,0),
    (-1,2,0),
    (0,0,1)
)

# Rectangular sheet with a defect
mos2_defect = mos2_rectangular.normalized()
mos2_defect.discard((mos2_defect.values == "S") * (mos2_defect.coordinates[:,1] < .5) * (mos2_defect.coordinates[:,2] < .5))

# Prepare a sheet
mos2_sheet = UnitCell.stack(*((mos2_rectangular,)*3 + (mos2_defect,) + (mos2_rectangular,)*3), vector = 'y')