Skip to content

API reference

The functions below are available directly from the mdcheck package.

Overall assessment

mdcheck.assess_trajectory_quality(timeseries_dict, time_coords=None, replica_dict=None, min_neff_pass=500.0, min_neff_warn=100.0, max_discard_warn=0.5)

Evaluates full molecular dynamics trajectory quality across all provided observables.

Parameters:

Name Type Description Default
timeseries_dict dict

Mapping of observable name -> 1D numpy array (e.g. {'RMSD': arr, 'Rg': arr, 'TotalEnergy': arr}).

required
time_coords ndarray

Array of timestamps corresponding to frames.

None
replica_dict dict

Mapping of observable name -> list of 1D arrays for replicas.

None
min_neff_pass float

Minimum effective sample size for PASS.

500.0
min_neff_warn float

Minimum effective sample size for WARNING.

100.0
max_discard_warn float

Maximum allowed equilibration fraction before WARNING.

0.50

Returns:

Name Type Description
report SimulationQualityReport

Consolidated quality report.

Equilibration

mdcheck.detect_equilibration(series, time_series=None, step_search=None, c_window=6.0)

Automatically detects the equilibration time (t_eq) of a timeseries by maximizing the effective sample size of the production region: t_eq = argmax_{t_0} N_eff(t_0) = argmax_{t_0} (N - t_0) / g(t_0)

Parameters:

Name Type Description Default
series ndarray

1D array of the observable (e.g., RMSD, Energy, Rg).

required
time_series ndarray

Array of corresponding timestamps (e.g. in ns or ps). If None, frame indices are used.

None
step_search int

Stride of the initial grid of candidate cutoffs. By default max(10, N // 200), so that the cost does not grow with N: the grid is then refined around the best cutoff with strides step/10, step/100, ... down to 1 (about 250 evaluations in total). Pass step_search=10 to reproduce the exhaustive stride-10 search of version 1.0.0.

None
c_window float

Window parameter for autocorrelation time calculation.

6.0

Returns:

Name Type Description
result dict

Dictionary containing: - 't_eq_index': Index of first production frame - 't_eq_time': Timestamp of equilibration - 'n_total': Total number of frames - 'n_prod': Number of production frames - 'n_eff': Effective sample size in production - 'tau_int': Integrated autocorrelation time in production (frames) - 'g': Statistical inefficiency factor in production - 'fraction_discarded': Proportion of trajectory discarded as equilibration - 'neff_curve': Effective sample size as function of cutoff index

mdcheck.geweke_diagnostic(series, first_fraction=0.1, last_fraction=0.5)

Computes Geweke's stationarity diagnostic by comparing the sample mean of the first part of the chain with the last part of the chain.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array (typically in the production phase).

required
first_fraction float

Fraction of data in the early segment.

0.1
last_fraction float

Fraction of data in the late segment.

0.5

Returns:

Name Type Description
result dict

Contains 'z_score', 'p_value', and 'is_stationary' (p > 0.05).

Autocorrelation and effective sample size

mdcheck.integrated_autocorrelation_time(series, c_window=6.0, max_lag=None)

Calculates the integrated autocorrelation time (tau_int) using a self-consistent Madras-Sokal windowing procedure.

Formula: tau_int = 0.5 + sum_{k=1}^M C(k) where M is the smallest integer such that M >= c_window * tau_int.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array.

required
c_window float

Madras-Sokal window parameter (typically between 4.0 and 8.0).

6.0
max_lag int

Maximum lag to explore.

None

Returns:

Name Type Description
tau_int float

Integrated autocorrelation time in units of steps/frames.

g float

Statistical inefficiency factor g = 1 + 2 * tau_int.

window_m int

Window cutoff index M.

mdcheck.statistical_inefficiency(series, c_window=6.0)

Calculates the statistical inefficiency factor g.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array.

required
c_window float

Window parameter.

6.0

Returns:

Name Type Description
g float

Statistical inefficiency g = 1 + 2*tau_int.

mdcheck.effective_sample_size(series, c_window=6.0)

Computes effective sample size N_eff = N / g.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array.

required
c_window float

Madras-Sokal window parameter.

6.0

Returns:

Name Type Description
n_eff float

Effective number of uncorrelated samples.

tau_int float

Integrated autocorrelation time.

g float

Statistical inefficiency factor.

mdcheck.compute_autocorrelation(series, max_lag=None)

Computes the normalized autocorrelation function (ACF) of a 1D timeseries using FFT.

Parameters:

Name Type Description Default
series ndarray

1D array of timeseries values.

required
max_lag int

Maximum lag to compute. If None, computes for all possible lags.

None

Returns:

Name Type Description
acf ndarray

Normalized autocorrelation function with acf[0] = 1.0.

Drift and uncertainty

mdcheck.assess_drift(series, time_series=None, relative_drift_threshold_pass=0.05, relative_drift_threshold_warn=0.15)

Estimates systematic linear drift and tests for statistical stationarity in production.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array in production.

required
time_series ndarray

Corresponding time coordinates (e.g. ns).

None
relative_drift_threshold_pass float

Maximum acceptable |drift| / mean ratio (5% change over trajectory length).

0.05
relative_drift_threshold_warn float

Warning threshold (15% change).

0.15

Returns:

Name Type Description
result dict

Drift diagnostics, slope, p-value, relative change, and PASS/WARNING/FAIL status.

mdcheck.block_averaging(series, min_blocks=4, max_blocks=None)

Performs Flyvbjerg-Petersen block averaging to estimate the true standard error as a function of block size.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array.

required
min_blocks int

Minimum number of blocks to keep for valid variance estimation.

4
max_blocks int

Maximum number of blocks (default: n // 2).

None

Returns:

Name Type Description
block_sizes ndarray

Array of block sizes (number of frames per block).

std_errors ndarray

Estimated standard error of the mean for each block size.

mdcheck.bootstrap_ci(series, stat_func=np.mean, n_resamples=2000, confidence_level=0.95, block_size=None, random_state=42)

Computes moving-block bootstrap confidence intervals accounting for autocorrelation.

Parameters:

Name Type Description Default
series ndarray

1D timeseries array.

required
stat_func callable

Function computing the target statistic on a 1D array.

np.mean
n_resamples int

Number of bootstrap resamples.

2000
confidence_level float

Confidence level (e.g. 0.95 for 95% CI).

0.95
block_size int

Block length. If None, automatically determined as ceil(2 * tau_int). Note: blocks this short underestimate the variance of the mean for strongly correlated data; prefer inefficiency_corrected_ci for the mean.

None
random_state int

Random seed for reproducibility.

42

Returns:

Name Type Description
point_estimate float

Observed sample statistic.

ci_lower float

Lower bound of bootstrap confidence interval.

ci_upper float

Upper bound of bootstrap confidence interval.

mdcheck.core.bootstrap.inefficiency_corrected_ci(series, g=None, confidence_level=0.95)

Confidence interval for the mean of a correlated timeseries using the statistical inefficiency g: mean +/- t_{N_eff - 1} * s * sqrt(g / N), with N_eff = N / g.

On AR(1) benchmarks this interval attains nominal coverage, whereas the moving-block bootstrap with blocks of length ~2*tau_int underestimates the width by ~25% for strongly correlated data (see validation/validate_ar1.py).

Parameters:

Name Type Description Default
series ndarray

1D timeseries array (production region).

required
g float

Statistical inefficiency. Estimated with the Sokal window if None.

None
confidence_level float
0.95

Returns:

Type Description
point_estimate, ci_lower, ci_upper : float

Replicas

mdcheck.assess_replica_consistency(replica_data, replica_names=None, jsd_threshold_pass=0.15, jsd_threshold_warn=0.3, alpha_warn=0.05, alpha_fail=0.01)

Evaluates consistency across multiple replica trajectories.

Parameters:

Name Type Description Default
replica_data list of np.ndarray

List of 1D timeseries (one per replica).

required
replica_names list of str

Names or identifiers for each replica (e.g. ['R1', 'R2', 'R3']).

None
jsd_threshold_pass float

Descriptive JSD levels reported in 'jsd_flag'. They no longer set the status: histogram JSD between finite, autocorrelated samples of the same ensemble is biased upwards and exceeded 0.15 for every replica group in the OpenMM validation (validation/).

0.15
jsd_threshold_warn float

Descriptive JSD levels reported in 'jsd_flag'. They no longer set the status: histogram JSD between finite, autocorrelated samples of the same ensemble is biased upwards and exceeded 0.15 for every replica group in the OpenMM validation (validation/).

0.15
alpha_warn float

Significance levels of the heterogeneity test that sets the status.

0.05
alpha_fail float

Significance levels of the heterogeneity test that sets the status.

0.05
Notes

Status is set by Cochran's Q test for equality of replica means, Q = sum_i w_i (m_i - m_w)^2, w_i = 1 / SE_i^2, SE_i = s_i sqrt(g_i / n_i), which is chi^2 with k - 1 degrees of freedom when all replicas sample the same ensemble, so the false-alarm rate is alpha by construction. KS p-values assume independent samples and are reported for information only.

Returns:

Name Type Description
result dict

Multi-replica consistency metrics, pairwise matrix, and status.

mdcheck.jensen_shannon_distance(series_a, series_b, n_bins=50)

Calculates the Jensen-Shannon distance (square root of JSD, bounded in [0, 1]) between the empirical probability distributions of two replica timeseries.

Parameters:

Name Type Description Default
series_a ndarray

Data from replica A.

required
series_b ndarray

Data from replica B.

required
n_bins int

Number of histogram bins for discrete density estimation.

50

Returns:

Name Type Description
js_dist float

Jensen-Shannon distance in [0, 1]. Values < 0.15 indicate excellent overlap.

mdcheck.subspace_overlap_rmsip(eigenvectors_a, eigenvectors_b, n_modes=10)

Computes the Root-Mean-Square Inner Product (RMSIP) between the principal component subspaces of two trajectory replicas:

RMSIP = sqrt( (1 / s) * sum_{i=1}^s sum_{j=1}^s (v_i^A . v_j^B)^2 )

Parameters:

Name Type Description Default
eigenvectors_a ndarray

Matrix of eigenvectors from PCA of replica A (shape: [n_features, n_modes]).

required
eigenvectors_b ndarray

Matrix of eigenvectors from PCA of replica B (shape: [n_features, n_modes]).

required
n_modes int

Number of essential modes s to compare.

10

Returns:

Name Type Description
rmsip float

Subspace overlap in [0, 1]. RMSIP > 0.70 represents strong essential subspace convergence.

Parsers

mdcheck.parsers.generic.load_timeseries_file(filepath)

Universally loads a timeseries file with automated format detection (.xvg, LAMMPS log, OpenMM log, .csv, .tsv, .dat, .txt).

Parameters:

Name Type Description Default
filepath str

Path to the timeseries file.

required

Returns:

Name Type Description
time_coords ndarray

1D array of time coordinates.

series_dict dict

Mapping of column name -> 1D numpy array.

metadata dict

Metadata regarding the loaded file.