# -*- coding: utf-8 -*-
setVerbosity(MinimalLog)

# -------------------------------------------------------------
# Bulk Configuration
# -------------------------------------------------------------

# Set up lattice
lattice = Hexagonal(4.312520870282197*Angstrom, 17.171785381745117*Angstrom)

# Define elements
elements = [Germanium, Germanium, Antimony, Antimony, Tellurium, Tellurium,
            Tellurium, Tellurium, Tellurium]

# Define coordinates
fractional_coordinates = [[ 0.583333333333,  0.916666666667,  0.949743340975],
                          [ 0.916666666667,  0.583333333333,  0.153151659025],
                          [ 0.25          ,  0.25          ,  0.732138635328],
                          [ 0.25          ,  0.25          ,  0.370756364672],
                          [ 0.25          ,  0.25          ,  0.0514475     ],
                          [ 0.916666666667,  0.583333333333,  0.849836853001],
                          [ 0.583333333333,  0.916666666667,  0.253058146999],
                          [ 0.583333333333,  0.916666666667,  0.631492753008],
                          [ 0.916666666667,  0.583333333333,  0.471402246992]]

# Set up configuration
bulk_configuration = BulkConfiguration(
    bravais_lattice=lattice,
    elements=elements,
    fractional_coordinates=fractional_coordinates
    )

# -------------------------------------------------------------
# Calculator
# -------------------------------------------------------------
#----------------------------------------
# Exchange-Correlation
#----------------------------------------
exchange_correlation = HybridGGA.HSE06

k_point_sampling = KpointDensity(
    density_a=4.0*Angstrom,
    )
numerical_accuracy_parameters = NumericalAccuracyParameters(
    density_mesh_cutoff=120.0*Hartree,
    k_point_sampling=k_point_sampling,
    )

calculator = LCAOCalculator(
    exchange_correlation=exchange_correlation,
    numerical_accuracy_parameters=numerical_accuracy_parameters,
    )

bulk_configuration.setCalculator(calculator)
nlprint(bulk_configuration)
bulk_configuration.update()
nlsave('PBE-HSE.hdf5', bulk_configuration)

# -------------------------------------------------------------
# Total Energy
# -------------------------------------------------------------
total_energy = TotalEnergy(bulk_configuration)
nlsave('PBE-HSE.hdf5', total_energy)
nlprint(total_energy)

# -------------------------------------------------------------
# Bandstructure
# -------------------------------------------------------------
bandstructure = Bandstructure(
    configuration=bulk_configuration,
    route=['G', 'M', 'L', 'A', 'G', 'K', 'H', 'A'],
    points_per_segment=50,
    bands_above_fermi_level=All,
    method=Full,
    )
nlsave('PBE-HSE.hdf5', bandstructure)

# -------------------------------------------------------------
# Projected Density Of States
# -------------------------------------------------------------
kpoint_grid = KpointDensity(
    density_a=7.0*Angstrom,
    )

projected_density_of_states = ProjectedDensityOfStates(
    configuration=bulk_configuration,
    kpoints=kpoint_grid,
    projections=ProjectOnSites,
    energies=numpy.linspace(-8, 8, 601)*eV,
    energy_zero_parameter=FermiLevel,
    bands_above_fermi_level=All,
    spectrum_method=TetrahedronMethod,
)
nlsave('PBE-HSE.hdf5', projected_density_of_states)
