MolecularDynamicsErrorPredictionHook

class MolecularDynamicsErrorPredictionHook(mtp_error_prediction_parameters=None)

Measurement hook for molecular dynamics simulations using MomentTensorPotentials with error prediction via query-by-committee models.

Parameters:

mtp_error_prediction_parameters (MTPErrorPredictionParameters) – The parameters that specify the details of the error prediction for the MomentTensorPotential MD Error Prediction Hook Function.

callInterval()
Returns:

The call interval of this hook function.

Return type:

int

measurementNames()
Returns:

The names of all measured properties.

Type:

list of type str

uniqueString()

Return a unique string representing the state of the object.

Usage Examples

Set up a molecular dynamics simulation with error prediction for the energy and forces values during the simulation of a cobalt disicilide structure using a pretrained MTP containing committee potentials.

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

# Set tags for fixed atoms
cosi2.addTags('fixed', [0, 4, 12, 16])


# Load the pretrained MTP containing committee potentials and set up a calculator
potentialSet = QuantumATK_MTP_CoSi_2022_12()
calculator = TremoloXCalculator(parameters=potentialSet)


# Set Calculator
cosi2.setCalculator(calculator)
nlsave('CoSi2_MD_ErrorPrediction.hdf5', cosi2)


# The MolecularDynamicsErrorPredictionHook takes an MTPErrorPredictionParameters object as input.
mtp_error_prediction_parameters = MTPErrorPredictionParameters(
    predict_energy_error=True,
    predict_forces_error=True,
    check_interval=1,
    write_atomic_error_estimates=True,
    stop_simulation_energy_threshold=None,
    stop_simulation_force_threshold=None
)

# MolecularDynamicsErrorPredictionHook
molecular_dynamics_error_prediction_hook = MolecularDynamicsErrorPredictionHook(
    mtp_error_prediction_parameters=mtp_error_prediction_parameters
)

# HookFunctions
pre_step_hooks = []
post_step_hooks = []
measurement_hooks = [
    molecular_dynamics_error_prediction_hook,
]
hook_functions = HookFunctions(
    pre_step_hooks=pre_step_hooks,
    post_step_hooks=post_step_hooks,
    measurement_hooks=measurement_hooks,
)
nlsave('CoSi2_MD_ErrorPrediction.hdf5', hook_functions)

# Constraints
fix_atom_indices_0 = cosi2.indicesFromTags(['fixed'])
constraints = [FixStrain(True, True, True), FixAtomConstraints(fix_atom_indices_0)]

# Set up MolecularDynamics with the error prediction hook
md_trajectory = MolecularDynamics(
    configuration=cosi2,
    constraints=constraints,
    log_interval=1,
    trajectory_filename='CoSi2_MD_ErrorPrediction.hdf5',
    hook_functions=hook_functions,
    trajectory_object_id='md',
)

The script is available for download: CoSi2_MD_ErrorPrediction.py.

Notes

The MolecularDynamicsErrorPredictionHook class can be used to estimate errors of the energy and forces values determined via molecular dynamics simulations performed with MTPs containing committee models. The hook function uses a query-by-committee approach for estimating molecular dynamics energy and force errors which is consistent with the ActiveLearningSimulation extrapolation grade. The ensemble standard deviation of the forces prediction is used as a measure of extrapolation, which can be interpreted as a prediction of the forces error in the configuration [1].

MTPs with committee models can either be found in many of the pretrained MTPs or trained customly. The supported pretrained MTPs all contain 6 committee models and includes the phrasing Supports MTP error prediction in their descriptions. A custom MTP can be trained by setting a non-zero committee_size parameter in MomentTensorPotentialTraining. Training custom MTPs with committee models is not the default.

There are a number of options that can be set via the MTPErrorPredictionParameters class which influences the hook behaviour.

The error prediction results are stored in the MD trajectory output. In the GUI, the system-wide error predictions are, if computed, readily available in the MDTrajectory Analyzer under the names Energy error prediction and Forces error prediction. If present, the atomic force error predictions are available by opening the MDTrajectory with the Viewer and coloring the atoms via the Atomic forces error predictions option.