# Set minimal log verbosity
setVerbosity(MinimalLog)

# %% Quartz (1)

# Set up lattice
vector_a = [9.832, 0.0, 0.0]*Angstrom
vector_b = [0.0, -8.514761770008601, 0.0]*Angstrom
vector_c = [0.0, 0.0, 10.8108]*Angstrom
lattice = UnitCell(vector_a, vector_b, vector_c)

# Define elements
elements = [Silicon, Silicon, Silicon, Silicon, Silicon, Silicon, Silicon,
            Silicon, Silicon, Silicon, Silicon, Silicon, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Silicon, Silicon,
            Silicon, Silicon, Silicon, Silicon, Silicon, Silicon, Silicon,
            Silicon, Silicon, Silicon, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen, Oxygen,
            Oxygen, Oxygen, Oxygen]

# Define coordinates
fractional_coordinates = [[ 0.117425      ,  0.23485       ,  0.            ],
                          [ 0.117425      ,  0.23485       ,  0.5           ],
                          [ 0.617425      ,  0.23485       ,  0.            ],
                          [ 0.617425      ,  0.23485       ,  0.5           ],
                          [ 0.117425      ,  0.76515       ,  0.333333333333],
                          [ 0.117425      ,  0.76515       ,  0.833333333333],
                          [ 0.617425      ,  0.76515       ,  0.333333333333],
                          [ 0.617425      ,  0.76515       ,  0.833333333333],
                          [ 0.26515       ,  0.            ,  0.166666666667],
                          [ 0.26515       ,  0.            ,  0.666666666667],
                          [ 0.76515       ,  0.            ,  0.166666666667],
                          [ 0.76515       ,  0.            ,  0.666666666667],
                          [ 0.1701        ,  0.0733        ,  0.05955       ],
                          [ 0.1701        ,  0.0733        ,  0.55955       ],
                          [ 0.6701        ,  0.0733        ,  0.05955       ],
                          [ 0.6701        ,  0.0733        ,  0.55955       ],
                          [ 0.1701        ,  0.9267        ,  0.2737835     ],
                          [ 0.1701        ,  0.9267        ,  0.7737835     ],
                          [ 0.6701        ,  0.9267        ,  0.2737835     ],
                          [ 0.6701        ,  0.9267        ,  0.7737835     ],
                          [ 0.219925      ,  0.29325       ,  0.3928835     ],
                          [ 0.219925      ,  0.29325       ,  0.8928835     ],
                          [ 0.719925      ,  0.29325       ,  0.3928835     ],
                          [ 0.719925      ,  0.29325       ,  0.8928835     ],
                          [ 0.359975      ,  0.86655       ,  0.1071165     ],
                          [ 0.359975      ,  0.86655       ,  0.6071165     ],
                          [ 0.859975      ,  0.86655       ,  0.1071165     ],
                          [ 0.859975      ,  0.86655       ,  0.6071165     ],
                          [ 0.359975      ,  0.13345       ,  0.2262165     ],
                          [ 0.359975      ,  0.13345       ,  0.7262165     ],
                          [ 0.859975      ,  0.13345       ,  0.2262165     ],
                          [ 0.859975      ,  0.13345       ,  0.7262165     ],
                          [ 0.219925      ,  0.70675       ,  0.44045       ],
                          [ 0.219925      ,  0.70675       ,  0.94045       ],
                          [ 0.719925      ,  0.70675       ,  0.44045       ],
                          [ 0.719925      ,  0.70675       ,  0.94045       ],
                          [ 0.367425      ,  0.73485       ,  0.            ],
                          [ 0.367425      ,  0.73485       ,  0.5           ],
                          [ 0.867425      ,  0.73485       ,  0.            ],
                          [ 0.867425      ,  0.73485       ,  0.5           ],
                          [ 0.367425      ,  0.26515       ,  0.333333333333],
                          [ 0.367425      ,  0.26515       ,  0.833333333333],
                          [ 0.867425      ,  0.26515       ,  0.333333333333],
                          [ 0.867425      ,  0.26515       ,  0.833333333333],
                          [ 0.01515       ,  0.5           ,  0.166666666667],
                          [ 0.01515       ,  0.5           ,  0.666666666667],
                          [ 0.51515       ,  0.5           ,  0.166666666667],
                          [ 0.51515       ,  0.5           ,  0.666666666667],
                          [ 0.4201        ,  0.5733        ,  0.05955       ],
                          [ 0.4201        ,  0.5733        ,  0.55955       ],
                          [ 0.9201        ,  0.5733        ,  0.05955       ],
                          [ 0.9201        ,  0.5733        ,  0.55955       ],
                          [ 0.4201        ,  0.4267        ,  0.2737835     ],
                          [ 0.4201        ,  0.4267        ,  0.7737835     ],
                          [ 0.9201        ,  0.4267        ,  0.2737835     ],
                          [ 0.9201        ,  0.4267        ,  0.7737835     ],
                          [ 0.469925      ,  0.79325       ,  0.3928835     ],
                          [ 0.469925      ,  0.79325       ,  0.8928835     ],
                          [ 0.969925      ,  0.79325       ,  0.3928835     ],
                          [ 0.969925      ,  0.79325       ,  0.8928835     ],
                          [ 0.109975      ,  0.36655       ,  0.1071165     ],
                          [ 0.109975      ,  0.36655       ,  0.6071165     ],
                          [ 0.609975      ,  0.36655       ,  0.1071165     ],
                          [ 0.609975      ,  0.36655       ,  0.6071165     ],
                          [ 0.109975      ,  0.63345       ,  0.2262165     ],
                          [ 0.109975      ,  0.63345       ,  0.7262165     ],
                          [ 0.609975      ,  0.63345       ,  0.2262165     ],
                          [ 0.609975      ,  0.63345       ,  0.7262165     ],
                          [ 0.469925      ,  0.20675       ,  0.44045       ],
                          [ 0.469925      ,  0.20675       ,  0.94045       ],
                          [ 0.969925      ,  0.20675       ,  0.44045       ],
                          [ 0.969925      ,  0.20675       ,  0.94045       ]]

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

quartz_1_name = "Quartz (1)"


# %% Set LCAOCalculator

# %% LCAOCalculator

density_mesh_cutoff = calculateDefaultDensityMeshCutoff(
    calculator_type=LCAOCalculator,
    configuration=quartz_1,
    basis_set=None,
    wave_function_cutoff=None,
)

k_point_sampling = KpointDensity(
    density_a=5.0 * Angstrom,
    density_b=5.0 * Angstrom,
    density_c=5.0 * Angstrom,
)

numerical_accuracy_parameters = NumericalAccuracyParameters(
    density_mesh_cutoff=density_mesh_cutoff, k_point_sampling=k_point_sampling
)

density_matrix_method = DiagonalizationSolver(optimize_for_speed_over_memory=True)

algorithm_parameters = AlgorithmParameters(density_matrix_method=density_matrix_method)

calculator = LCAOCalculator(
    numerical_accuracy_parameters=numerical_accuracy_parameters,
    checkpoint_handler=NoCheckpointHandler,
    algorithm_parameters=algorithm_parameters,
)


# %% Set Calculator
quartz_1 = quartz_1.repeat(2, 3, 2)
quartz_1.setCalculator(calculator)
quartz_1.update()

nlsave('Quartz_1_2_results.hdf5', quartz_1)
