Initializes all functions necessary for trajectory reweighting for
a single state point.
The initialized functions include a function that computes weights for a
given trajectory and a function that propagates the trajectory forward
if the statistical error does not allow a re-use of the trajectory.
The third and (optionally) forth function depends on the value of
safe_propagation. If set to True, only three functions are returned.
Additionally, the propagation function checks the neighbor list for
overflow and the trajectory for NaNs. However, in this case, the
propagation function is not jit-able. Instead, for
safe_propagation=False, the fourth function can be used as decorator
to extend a non-jitable outer function.
Parameters:
energy_fn_template (EnergyFnTemplate) – Energy function template to initialize a new
energy function with the current parameters.
simulator_template (Callable) – Template to create new simulators with different
energy functions.
Returns a tuple of function to apply the reweighting formalism.
The first function generates a reference trajectory, starting from
a reference simulator state.
The second function computes the weights given a reference trajectory
state.
The third function propagates the trajectory state, re-computing a
trajectory from the current energy parameters if the ESS drops below
a certain threshold.
The fourth function is only returned if safe_propagation=False.
params (Any) – Energy parameters to obtain the perturbed potential.
traj_state (TrajectoryState) – Trajectory of a sufficiently close potential. The
auxiliary quantities must contain the energy of the reference
trajectory (key: 'energy').
**kwargs – Additional arguments to be passed to the function.
Initializes reweighting based on a reference trajectory.
Instead of recomputing a trajectory, this function uses a precomputed
trajectory and quantities to estimate quantities for a different potential
model via the reweighing procedure.
# Initialize the reference reweighting methodinit_fn,compute_fn=init_reference_trajectory_reweight_fn(energy_fn_template,neighbour_fn,target_quantities,ref_kbt)# Provide the reference trajectory and reference quantitiesstate=init_fn(reference_trajectory,reference_quantities)# Compute the new quantitiesresults=compute_fn(state,new_energy_parameters)
Parameters:
energy_fn_template (EnergyFnTemplate) – Perturbed potential model
compute_fns (Dict[str, Callable]) – Functions to recompute quantities used in reweighting. The
energy is automatically recomputed. It is possible to add quantities
that are not contained in the reference quantities and required to
recompute quantities that depdend directly on the potential, i.e.
the pressure.
energy_batch_size (int) – Number of configurations to compute in parallel
dynamic_dropout (bool) – Issues a new dropout key for every state of the
trajectory.
reference_energy_fn_template (EnergyFnTemplate) – Energy function to re-compute the energies
of the potential used to generate the trajectory.
pressure_correction (bool) – Include the pressure in the Boltzmann factor for
the NPT ensemble.
Returns a dictionary containing the quantities obtained via reweighting,
the original quantities and the weights as well as the effective sample
size during the reweighting procedure.
Computes weights to reweight a trajectory from one thermodynamic
state point to another.
This function allows re-using an existing trajectory to compute
observables at slightly perturbed thermodynamic state points. The
reference trajectory can be generated at a constant state point or
at different state points, e.g. via non-equlinibrium MD. Both NVT and
NPT trajectories are supported, however reweighting currently only
allows reweighting into the same ensemble. For NVT, the trajectory can
be reweighted to a different temperature. For NPT, can be reweighted to
different kbT and/or pressure. We assume quantities not included in
‘targets’ to be constant over the trajectory, however this is not ensured
by the code.
Implemented are cases 1. - 4. of the reference [1].
Parameters:
traj – Reference trajectory to be reweighted
targets – Kwargs containing the targets under ‘kT’ and/or ‘pressure’.
If a keyword is not provided, the qunatity is assumed to be and
remain constant.
Returns:
A tuple (weights, n_eff). Weights can be used to compute
reweighted observables and n_eff judges the expected
statistical error from reweighting.
Initializes the free energy and entropy computation via the BAR approach.
The algorithm [2] uses the BAR method to derive
the free energy difference between two trajectories and additionally
derives the entropy difference via the thermodynamic relation
\(TdS = dU - dF\).
This implementation relies on the bisection method to solve the implicit
equation
\[\Delta F:\ \left\langle\frac{1}{1 + \exp(\beta\Delta U - \beta\Delta F)}\right\rangle_0 - \left\langle\frac{1}{1 + \exp(-\beta\Delta U + \beta\Delta F)}\right\rangle_1 = 0.\]
Parameters:
energy_fn_template (EnergyFnTemplate) – Function that returns a potential model when
called with a set of energy parameters.
Returns the new_traj with updated free energy and entropy difference.
These differences are updated by the differences between the old
and the new trajectory, such that these values resemble the
differences to the first trajectory that has been generated.