Пример #1
0
 def setUp(self):
     basis = Basis((1,1,1,0,0,-0.5), kind = 'triclinic')
     
     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)
     
     d = (basis.transform_to_cartesian(kp_path)**2).sum(axis = 1)
     
     self.bands = UnitCell(
         basis,
         kp_path,
         ([[0,0,3]] + d[...,numpy.newaxis]*[[1,2,-3]])*eV,
     )
     self.bands.meta["Fermi"] = 1*eV
     self.weights = self.bands.values/self.bands.values.max()
     self.huge_bands = UnitCell(
         self.bands,
         kp_path,
         ([BandPlotTest.__pseudo_random__(0,1000,50)*10-5] + d[...,numpy.newaxis]*[BandPlotTest.__pseudo_random__(1000,2000,50)*20-10])*eV,
     )
Пример #2
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
Пример #3
0
 def test_bands(self):
     c = Basis(
         numpy.array(((1.000000, -0.577350, 0.000000),
                      (0.000000, 1.154701, 0.000000),
                      (0.000000, 0.000000, 0.158745))) * 2 * math.pi /
         5.999694 / numericalunits.aBohr)
     c = self.parser.bands(c)
     assert_standard_bands_path(c)
     assert c.values.shape == (400, 34)
     assert c.coordinates.shape == (400, 3)
     testing.assert_allclose(c.coordinates[0, :],
                             (0.500000, -0.288675, 0.000000))
     testing.assert_allclose(
         c.values[0, :],
         numpy.array(
             (0.500, -0.500, 0.185, -0.185, 0.248, -0.248, 0.067, -0.067,
              -0.498, 0.498, -0.498, 0.498, -0.500, 0.500, -0.499, 0.499,
              0.500, -0.500, 0.499, -0.499, -0.498, 0.498, -0.498, 0.498,
              0.499, -0.499, 0.499, -0.499, 0.496, -0.496, 0.496, -0.496,
              0.499, -0.499)) * numericalunits.eV)
     testing.assert_allclose(c.coordinates[-1, :],
                             (-0.503333, -0.282902, 0.000000))
     testing.assert_allclose(
         c.values[-1, :],
         numpy.array(
             (0.500, -0.500, 0.185, -0.185, -0.250, 0.247, -0.065, 0.069,
              0.497, -0.498, 0.498, -0.497, -0.500, 0.500, 0.499, -0.499,
              0.500, -0.500, -0.499, 0.499, -0.498, 0.498, -0.497, 0.498,
              0.499, -0.499, 0.499, -0.499, -0.496, 0.496, 0.496, -0.496,
              -0.499, 0.499)) * numericalunits.eV)
Пример #4
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,
        ).repeated(2, 2, 2)

        self.cell2 = Cell(
            Basis.triclinic(
                (3.9 * angstrom / 2, 3.9 * angstrom / 2, 3.9 * angstrom / 2),
                (.5, .5, .5)),
            (0, 0, 0),
            ['Si'],
        )
Пример #5
0
 def setUp(self):
     self.cell = Cell(
         Basis((3.19 * angstrom, 3.19 * angstrom, 10 * angstrom, 0, 0, .5),
               kind='triclinic'),
         (
             (1. / 3, 1. / 3, .5),
             (2. / 3, 2. / 3, .6),
             (2. / 3, 2. / 3, .4),
         ),
         ('Mo', 'S', 'S'),
     ).repeated(10, 10)
Пример #6
0
 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",
     )))
Пример #7
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))
Пример #8
0
    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",
            "/",
        )))
Пример #9
0
from dfttools.types import Basis, Cell
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 = Cell(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 = Cell.stack(*((mos2_rectangular,)*3 + (mos2_defect,) + (mos2_rectangular,)*3), vector = 'y')
Пример #10
0
from dfttools.types import Basis, Cell
from dfttools.presentation import svgwrite_unit_cell

from numericalunits import angstrom as a

si_basis = Basis((3.9 * a / 2, 3.9 * a / 2, 3.9 * a / 2, .5, .5, .5),
                 kind='triclinic')
si_cell = Cell(si_basis, (.5, .5, .5), 'Si')
svgwrite_unit_cell(si_cell, 'output.svg', size=(440, 360), show_cell=True)
Пример #11
0
from dfttools.types import Basis, Cell
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 Cell with correct kp-path
bands = Cell(
    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
Пример #12
0
from dfttools.types import Basis, Cell
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 = Cell(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)
Пример #13
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()