# --------------------------------------------------------------
# AKMC
# --------------------------------------------------------------

# Reusing existing MarkovChain object if it already exists, otherwise a new one is created
if os.path.isfile('akmc_markov_chain.hdf5'):
    markov_chain = nlread('akmc_markov_chain.hdf5')[0]
else:
    markov_chain = MarkovChain(bulk_configuration, TotalEnergy(bulk_configuration).evaluate())

# Reusing existing KMC object if it already exists, otherwise a new one is created
if os.path.isfile('akmc_kmc.hdf5'):
    kmc = nlread('akmc_kmc.hdf5')[0]
else:
    kmc = None

# Modify the default maximum number of NEB images to 5.
saddle_search_parameters = SaddleSearchParameters(max_neb_images=5)

# Setup the AKMC simulation.
akmc = AdaptiveKineticMonteCarlo(markov_chain,
                                 calculator=calculator,
                                 kmc_temperature=300*Kelvin,
                                 md_temperature=1200*Kelvin,
                                 saddle_search_parameters=saddle_search_parameters,
                                 constraints=[0],
                                 confidence=0.99,
                                 write_searches=False,
                                 write_kmc=True,
                                 write_markov_chain=True,
                                 write_log=True)

# Run 100 saddle searches.
akmc.run(100)
