# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Settings
# -------------------------------------------------------------
md_trajectory = nlread('Li04S_eq-300K.hdf5', MDTrajectory)[-1]
images = [910, 920, 930, 940, 950, 960, 970, 980, 990, 1000]

# -------------------------------------------------------------
# Looping over images
# -------------------------------------------------------------
for i in images:
    bulk_configuration = md_trajectory.image(i)

    # -------------------------------------------------------------
    # Calculator
    # -------------------------------------------------------------
    potentialSet = ReaxFF_LiS_2015(strict_bondpairs = None)
    calculator = TremoloXCalculator(parameters=potentialSet)
    calculator.setVerletListsDelta(0.25*Angstrom)

    bulk_configuration.setCalculator(calculator)
    bulk_configuration.update()

    # -------------------------------------------------------------
    # Optimize Geometry
    # -------------------------------------------------------------
    bulk_configuration = OptimizeGeometry(
        bulk_configuration,
        max_forces=0.01*eV/Ang,
        max_steps=1000,
        max_step_length=0.2*Ang,
        trajectory_filename=None,
        disable_stress=True,
        optimizer_method=LBFGS(),
    )
    nlsave('Li04S_relax.hdf5', bulk_configuration)
    nlprint(bulk_configuration)

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