# -------------------------------------------------------------
# Two-probe Configuration
# -------------------------------------------------------------

# -------------------------------------------------------------
# Left Electrode
# -------------------------------------------------------------

# Set up lattice
vector_a = [8.65127, 0.0, 0.0]*Angstrom
vector_b = [-4.32564, 7.49222, 0.0]*Angstrom
vector_c = [0.0, 0.0, 7.06373620597]*Angstrom
left_electrode_lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
left_electrode_elements = [Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold]

# Define coordinates
left_electrode_coordinates = [[ 0.            ,  0.            ,  1.177246838306],
                              [ 2.883758230374,  0.            ,  1.177246838306],
                              [ 5.767516460748,  0.            ,  1.177246838306],
                              [-1.441879115187,  2.497407885876,  1.177246838306],
                              [ 1.441879115187,  2.497407885876,  1.177246838306],
                              [ 4.325637345561,  2.497407885876,  1.177246838306],
                              [-2.883758230374,  4.994815771753,  1.177246838306],
                              [-0.            ,  4.994815771753,  1.177246838306],
                              [ 2.883758230374,  4.994815771753,  1.177246838306],
                              [ 1.441879115187,  0.832469295292,  3.531825573629],
                              [ 4.325637345561,  0.832469295292,  3.531825573629],
                              [ 7.209395575935,  0.832469295292,  3.531825573629],
                              [-0.            ,  3.329877181169,  3.531825573629],
                              [ 2.883758230374,  3.329877181169,  3.531825573629],
                              [ 5.767516460748,  3.329877181169,  3.531825573629],
                              [-1.441879115187,  5.827285067045,  3.531825573629],
                              [ 1.441879115187,  5.827285067045,  3.531825573629],
                              [ 4.325637345561,  5.827285067045,  3.531825573629],
                              [-0.            ,  1.664938590584,  5.886404308952],
                              [ 2.883758230374,  1.664938590584,  5.886404308952],
                              [ 5.767516460748,  1.664938590584,  5.886404308952],
                              [-1.441879115187,  4.162346476461,  5.886404308952],
                              [ 1.441879115187,  4.162346476461,  5.886404308952],
                              [ 4.325637345561,  4.162346476461,  5.886404308952],
                              [-2.883758230374,  6.659754362337,  5.886404308952],
                              [-0.            ,  6.659754362337,  5.886404308952],
                              [ 2.883758230374,  6.659754362337,  5.886404308952]]*Angstrom

# Set up configuration
left_electrode = BulkConfiguration(
    bravais_lattice=left_electrode_lattice,
    elements=left_electrode_elements,
    cartesian_coordinates=left_electrode_coordinates
    )

# -------------------------------------------------------------
# Right Electrode
# -------------------------------------------------------------

# Set up lattice
vector_a = [8.65127, 0.0, 0.0]*Angstrom
vector_b = [-4.32564, 7.49222, 0.0]*Angstrom
vector_c = [0.0, 0.0, 7.06373620597]*Angstrom
right_electrode_lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
right_electrode_elements = [Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                            Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                            Gold, Gold, Gold, Gold, Gold]

# Define coordinates
right_electrode_coordinates = [[ 0.            ,  1.664938590584,  1.177331897016],
                               [ 2.883758230374,  1.664938590584,  1.177331897016],
                               [ 5.767516460748,  1.664938590584,  1.177331897016],
                               [-1.441879115187,  4.162346476461,  1.177331897016],
                               [ 1.441879115187,  4.162346476461,  1.177331897016],
                               [ 4.325637345561,  4.162346476461,  1.177331897016],
                               [-2.883758230374,  6.659754362337,  1.177331897016],
                               [-0.            ,  6.659754362337,  1.177331897016],
                               [ 2.883758230374,  6.659754362337,  1.177331897016],
                               [ 1.441879115187,  0.832469295292,  3.531910632339],
                               [ 4.325637345561,  0.832469295292,  3.531910632339],
                               [ 7.209395575935,  0.832469295292,  3.531910632339],
                               [-0.            ,  3.329877181169,  3.531910632339],
                               [ 2.883758230374,  3.329877181169,  3.531910632339],
                               [ 5.767516460748,  3.329877181169,  3.531910632339],
                               [-1.441879115187,  5.827285067045,  3.531910632339],
                               [ 1.441879115187,  5.827285067045,  3.531910632339],
                               [ 4.325637345561,  5.827285067045,  3.531910632339],
                               [ 0.            ,  0.            ,  5.886489367661],
                               [ 2.883758230374,  0.            ,  5.886489367661],
                               [ 5.767516460748,  0.            ,  5.886489367661],
                               [-1.441879115187,  2.497407885876,  5.886489367661],
                               [ 1.441879115187,  2.497407885876,  5.886489367661],
                               [ 4.325637345561,  2.497407885876,  5.886489367661],
                               [-2.883758230374,  4.994815771753,  5.886489367661],
                               [-0.            ,  4.994815771753,  5.886489367661],
                               [ 2.883758230374,  4.994815771753,  5.886489367661]]*Angstrom

# Set up configuration
right_electrode = BulkConfiguration(
    bravais_lattice=right_electrode_lattice,
    elements=right_electrode_elements,
    cartesian_coordinates=right_electrode_coordinates
    )

# -------------------------------------------------------------
# Central Region
# -------------------------------------------------------------

# Set up lattice
vector_a = [8.65127, 0.0, 0.0]*Angstrom
vector_b = [-4.32564, 7.49222, 0.0]*Angstrom
vector_c = [0.0, 0.0, 26.1842542284]*Angstrom
central_region_lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
central_region_elements = [Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Sulfur, Carbon, Hydrogen, Hydrogen, Carbon,
                           Carbon, Carbon, Carbon, Hydrogen, Hydrogen, Carbon, Sulfur, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold, Gold,
                           Gold, Gold]

# Define coordinates
central_region_coordinates = [[  0.            ,   0.            ,   1.177246838306],
                              [  2.883758230374,   0.            ,   1.177246838306],
                              [  5.767516460748,   0.            ,   1.177246838306],
                              [ -1.441879115187,   2.497407885876,   1.177246838306],
                              [  1.441879115187,   2.497407885876,   1.177246838306],
                              [  4.325637345561,   2.497407885876,   1.177246838306],
                              [ -2.883758230374,   4.994815771753,   1.177246838306],
                              [ -0.            ,   4.994815771753,   1.177246838306],
                              [  2.883758230374,   4.994815771753,   1.177246838306],
                              [  1.441879115187,   0.832469295292,   3.531825573629],
                              [  4.325637345561,   0.832469295292,   3.531825573629],
                              [  7.209395575935,   0.832469295292,   3.531825573629],
                              [ -0.            ,   3.329877181169,   3.531825573629],
                              [  2.883758230374,   3.329877181169,   3.531825573629],
                              [  5.767516460748,   3.329877181169,   3.531825573629],
                              [ -1.441879115187,   5.827285067045,   3.531825573629],
                              [  1.441879115187,   5.827285067045,   3.531825573629],
                              [  4.325637345561,   5.827285067045,   3.531825573629],
                              [ -0.            ,   1.664938590584,   5.886404308952],
                              [  2.883758230374,   1.664938590584,   5.886404308952],
                              [  5.767516460748,   1.664938590584,   5.886404308952],
                              [ -1.441879115187,   4.162346476461,   5.886404308952],
                              [  1.441879115187,   4.162346476461,   5.886404308952],
                              [  4.325637345561,   4.162346476461,   5.886404308952],
                              [ -2.883758230374,   6.659754362337,   5.886404308952],
                              [ -0.            ,   6.659754362337,   5.886404308952],
                              [  2.883758230374,   6.659754362337,   5.886404308952],
                              [  0.            ,   0.            ,   8.240983044274],
                              [  2.883758230374,   0.            ,   8.240983044274],
                              [  5.767516460748,   0.            ,   8.240983044274],
                              [ -1.441879115187,   2.497407885876,   8.240983044274],
                              [  1.441879115187,   2.497407885876,   8.240983044274],
                              [  4.325637345561,   2.497407885876,   8.240983044274],
                              [ -2.883758230374,   4.994815771753,   8.240983044274],
                              [ -0.            ,   4.994815771753,   8.240983044274],
                              [  2.883758230374,   4.994815771753,   8.240983044274],
                              [ -0.            ,   3.329877181169,   9.950983044274],
                              [  0.000167598274,   3.330000988149,  11.700983031869],
                              [  2.141113495536,   3.104457648599,  11.849212743505],
                              [ -2.140744100558,   3.555570150149,  11.849240681067],
                              [  1.19830836185 ,   3.203799621127,  12.396521536067],
                              [ -1.19793542389 ,   3.456256114907,  12.39656493323 ],
                              [  1.198435435614,   3.203780838187,  13.787656477468],
                              [ -1.197806007547,   3.456195085679,  13.787696164708],
                              [  2.141237198973,   3.10441690481 ,  14.335054536015],
                              [ -2.140622838979,   3.555422091299,  14.335071137123],
                              [  0.000320116744,   3.329990265468,  14.483271217051],
                              [ -0.            ,   3.329877181169,  16.233271184118],
                              [  0.            ,   0.            ,  17.943271184118],
                              [  2.883758230374,   0.            ,  17.943271184118],
                              [  5.767516460748,   0.            ,  17.943271184118],
                              [ -1.441879115187,   2.497407885876,  17.943271184118],
                              [  1.441879115187,   2.497407885876,  17.943271184118],
                              [  4.325637345561,   2.497407885876,  17.943271184118],
                              [ -2.883758230374,   4.994815771753,  17.943271184118],
                              [ -0.            ,   4.994815771753,  17.943271184118],
                              [  2.883758230374,   4.994815771753,  17.943271184118],
                              [  0.            ,   1.664938590584,  20.297849919441],
                              [  2.883758230374,   1.664938590584,  20.297849919441],
                              [  5.767516460748,   1.664938590584,  20.297849919441],
                              [ -1.441879115187,   4.162346476461,  20.297849919441],
                              [  1.441879115187,   4.162346476461,  20.297849919441],
                              [  4.325637345561,   4.162346476461,  20.297849919441],
                              [ -2.883758230374,   6.659754362337,  20.297849919441],
                              [ -0.            ,   6.659754362337,  20.297849919441],
                              [  2.883758230374,   6.659754362337,  20.297849919441],
                              [  1.441879115187,   0.832469295292,  22.652428654764],
                              [  4.325637345561,   0.832469295292,  22.652428654764],
                              [  7.209395575935,   0.832469295292,  22.652428654764],
                              [ -0.            ,   3.329877181169,  22.652428654764],
                              [  2.883758230374,   3.329877181169,  22.652428654764],
                              [  5.767516460748,   3.329877181169,  22.652428654764],
                              [ -1.441879115187,   5.827285067045,  22.652428654764],
                              [  1.441879115187,   5.827285067045,  22.652428654764],
                              [  4.325637345561,   5.827285067045,  22.652428654764],
                              [  0.            ,   0.            ,  25.007007390086],
                              [  2.883758230374,   0.            ,  25.007007390086],
                              [  5.767516460748,   0.            ,  25.007007390086],
                              [ -1.441879115187,   2.497407885876,  25.007007390086],
                              [  1.441879115187,   2.497407885876,  25.007007390086],
                              [  4.325637345561,   2.497407885876,  25.007007390086],
                              [ -2.883758230374,   4.994815771753,  25.007007390086],
                              [ -0.            ,   4.994815771753,  25.007007390086],
                              [  2.883758230374,   4.994815771753,  25.007007390086]]*Angstrom

# Set up configuration
central_region = BulkConfiguration(
    bravais_lattice=central_region_lattice,
    elements=central_region_elements,
    cartesian_coordinates=central_region_coordinates
    )

device_configuration = DeviceConfiguration(
    central_region,
    [left_electrode, right_electrode]
    )

# -------------------------------------------------------------
# Calculator
# -------------------------------------------------------------
#----------------------------------------
# Basis Set
#----------------------------------------
basis_set = [
    LDABasis.Hydrogen_DoubleZetaPolarized,
    LDABasis.Carbon_DoubleZetaPolarized,
    LDABasis.Sulfur_DoubleZetaPolarized,
    LDABasis.Gold_SingleZetaPolarized,
    ]

#----------------------------------------
# Numerical Accuracy Settings
#----------------------------------------
left_electrode_k_point_sampling = MonkhorstPackGrid(
    na=3,
    nb=3,
    nc=50,
    )
left_electrode_numerical_accuracy_parameters = NumericalAccuracyParameters(
    k_point_sampling=left_electrode_k_point_sampling,
    )

right_electrode_k_point_sampling = MonkhorstPackGrid(
    na=3,
    nb=3,
    nc=50,
    )
right_electrode_numerical_accuracy_parameters = NumericalAccuracyParameters(
    k_point_sampling=right_electrode_k_point_sampling,
    )

device_k_point_sampling = MonkhorstPackGrid(
    na=3,
    nb=3,
    nc=50,
    )
device_numerical_accuracy_parameters = NumericalAccuracyParameters(
    k_point_sampling=device_k_point_sampling,
    )

#----------------------------------------
# Poisson Solver Settings
#----------------------------------------
left_electrode_poisson_solver = FastFourier2DSolver(
    boundary_conditions=[[PeriodicBoundaryCondition(),PeriodicBoundaryCondition()],
                         [PeriodicBoundaryCondition(),PeriodicBoundaryCondition()],
                         [PeriodicBoundaryCondition(),PeriodicBoundaryCondition()]]
    )

right_electrode_poisson_solver = FastFourier2DSolver(
    boundary_conditions=[[PeriodicBoundaryCondition(),PeriodicBoundaryCondition()],
                         [PeriodicBoundaryCondition(),PeriodicBoundaryCondition()],
                         [PeriodicBoundaryCondition(),PeriodicBoundaryCondition()]]
    )

#----------------------------------------
# Electrode Calculators
#----------------------------------------
left_electrode_calculator = LCAOCalculator(
    basis_set=basis_set,
    numerical_accuracy_parameters=left_electrode_numerical_accuracy_parameters,
    poisson_solver=left_electrode_poisson_solver,
    )

right_electrode_calculator = LCAOCalculator(
    basis_set=basis_set,
    numerical_accuracy_parameters=right_electrode_numerical_accuracy_parameters,
    poisson_solver=right_electrode_poisson_solver,
    )

#----------------------------------------
# Device Calculator
#----------------------------------------
calculator = DeviceLCAOCalculator(
    basis_set=basis_set,
    numerical_accuracy_parameters=device_numerical_accuracy_parameters,
    electrode_calculators=
        [left_electrode_calculator, right_electrode_calculator],
    )

device_configuration.setCalculator(calculator)
nlprint(device_configuration)
device_configuration.update()
nlsave('au-dtb-au.nc', device_configuration)

# -------------------------------------------------------------
# Device Density Of States
# -------------------------------------------------------------
kpoint_grid = MonkhorstPackGrid(
    na=3,
    nb=3,
    )

device_density_of_states = DeviceDensityOfStates(
    configuration=device_configuration,
    energies=numpy.linspace(-3,3,401)*eV,
    kpoints=kpoint_grid,
    contributions=All,
    energy_zero_parameter=AverageFermiLevel,
    infinitesimal=1e-06*eV,
    self_energy_calculator=RecursionSelfEnergy(),
    )
nlsave('au-dtb-au.nc', device_density_of_states)
nlprint(device_density_of_states)

# -------------------------------------------------------------
# Transmission Spectrum
# -------------------------------------------------------------
kpoint_grid = MonkhorstPackGrid(
    na=3,
    nb=3,
    )

transmission_spectrum = TransmissionSpectrum(
    configuration=device_configuration,
    energies=numpy.linspace(-3,3,401)*eV,
    kpoints=kpoint_grid,
    energy_zero_parameter=AverageFermiLevel,
    infinitesimal=1e-06*eV,
    self_energy_calculator=RecursionSelfEnergy(),
    )
nlsave('au-dtb-au.nc', transmission_spectrum)
nlprint(transmission_spectrum)