hecss.monitor¶
plot_virial_stat plots the dimensional virial/T ratio by default, or the
sample-normalised 1/sqrt(virial) distribution with normalised=True, which
also returns an amplitude correction matrix. hecss.xscale.plot_virial_stat
is a deprecated alias for the latter and will be removed in 0.8.
Monitoring functions for HECSS sampler
THz = 1000000000000.0 * un._hplanck * un.J
module-attribute
¶
__all__ = ['plot_band_set', 'plot_bands', 'plot_bands_file', 'run_alamode', 'show_dc_conv', 'build_bnd_lst', 'build_omega', 'plot_omega', 'monitor_phonons', 'plot_stats', 'monitor_stats', 'moving_average', 'ewma', 'plot_hist', 'plot_virial_stat', 'plot_acceptance_history', 'plot_dofmu_stat', 'plot_xs_stat']
module-attribute
¶
build_bnd_lst(directory='phon', dfset='DFSET', prefix='cryst', kpath='cryst', sc='../sc/CONTCAR', order=1, cutoff=10, born=None, charge=None, verbose=False)
¶
Build a convergence series of phonon band structures.
For each sample count from 1 to the number of configurations in dfset,
run_alamode is called and the resulting band array is stored. Returns a
dictionary mapping the sample count to the band array.
Source code in hecss/monitor.py
build_omega(bl, kpnts)
¶
Convert a band convergence series into per-k-point frequencies.
bl is the dictionary returned by build_bnd_lst and kpnts supplies the
k-point labels and positions. Returns a dictionary mapping each k-point
label to an array whose first row is the sample count and whose rows are
frequency deviations from the last sample.
Source code in hecss/monitor.py
ewma(data, window)
¶
Return the exponentially weighted moving average of data.
data is a one-dimensional array and window controls the smoothing
through alpha = 2 / (window + 1). The result has the same length as
data.
Source code in hecss/monitor.py
monitor_phonons(directory='phon', dfset='DFSET', prefix='cryst', kpath='cryst', sc='../sc/CONTCAR', order=1, cutoff=10, born=None, charge=None, k_list=None, fig_out=None, once=False)
¶
Monitor phonon convergence as samples are added to a DFSET file.
The function waits for the first sample, runs ALAMODE, and refreshes a
two-panel figure with band convergence and frequency spread whenever the
DFSET file grows. k_list restricts the k points shown in the frequency
panel; fig_out, if provided, receives the figure objects. With
once=True the function returns after the first complete pass, otherwise
it loops until interrupted.
Source code in hecss/monitor.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
monitor_stats(T, dfset, plotchi2=False, sqrN=False, once=False)
¶
Monitor the energy distribution in a growing DFSET file.
Waits until the file contains at least three samples, then redraws
plot_stats whenever new samples appear. T is the target temperature in
kelvin; plotchi2 and sqrN are passed to plot_stats. With once=True
the function stops after a single update.
Source code in hecss/monitor.py
moving_average(x, w)
¶
Return a centred moving average of x over w points.
The result has length len(x) - w + 1.
plot_acceptance_history(smpl)
¶
Plot the approximate acceptance ratio over sampling steps.
The ratio is inferred from repeated configuration indices in the sample
list smpl.
Source code in hecss/monitor.py
plot_band_set(bnd, units=THz, lbl=None, **kwargs)
¶
Plot all bands in bnd against the k-path coordinates.
bnd[0] holds the path coordinate and bnd[1:] the bands in inverse
centimetres. units converts the frequency axis, lbl labels the first
band and **kwargs are passed to Matplotlib.
Source code in hecss/monitor.py
plot_bands(bnd, kpnts, units=THz, decorate=True, lbl=None, **kwargs)
¶
Plot a band structure with k-point labels and decorations.
kpnts is a (labels, positions) pair. With decorate=False the ticks,
grid lines and axis label are omitted. units selects the frequency unit
and lbl labels the curves.
Source code in hecss/monitor.py
plot_bands_file(fn, units=THz, decorate=True, lbl=None, **kwargs)
¶
Read an ALAMODE band file and plot it.
The first two lines of fn provide the k-point labels and positions; the
remaining columns are the bands. lbl defaults to the file name.
Source code in hecss/monitor.py
plot_dofmu_stat(cryst, dofmu, skip=10, window=10, normal=False)
¶
Plot smoothed virials per symmetry-connected degree of freedom.
dofmu is the history collected through the dofmu_list argument of
HECSS.sample. skip drops initial steps and window sets the smoothing
width. With normal=True a normal distribution is fitted to each group
instead of chi-squared.
Source code in hecss/monitor.py
plot_hist(v, el, n, l='', alpha=0.2, normal=True, df=3)
¶
Plot a normalised histogram of v with a fitted distribution.
el names the data set, n selects the Matplotlib colour, l is a label
suffix and alpha sets the transparency. With normal=True a normal
distribution is fitted; otherwise chi-squared with df degrees of freedom
is used. Returns (mean, standard deviation) of v.
Source code in hecss/monitor.py
plot_omega(omega)
¶
Plot frequency convergence versus sample count.
omega is the dictionary returned by build_omega; one curve with the
standard deviation of the frequencies is drawn for each k point.
Source code in hecss/monitor.py
plot_stats(confs, T=None, sqrN=False, show=True, plotchi2=False, show_samples=True)
¶
Plot the energy distribution of a configuration list.
confs is a list of sampler output tuples (n, i, x, f, e). The
histogram is compared with the target normal distribution for temperature
T in kelvin; when T is None it is inferred from the mean energy.
With sqrN=True Poisson error bars are drawn, plotchi2=True adds a
chi-squared fit, and show_samples=False hides the individual samples.
show=True calls Matplotlib's show() at the end. Samples are in
eV/atom. The function returns nothing and is silent for fewer than three
configurations.
Source code in hecss/monitor.py
plot_virial_stat(cryst, smpl, T=None, normal=False, normalised=False)
¶
Plot the virial distribution of width-estimation samples.
By default |displacement * force| / (kB*T) is plotted per element as
a dimensionless virial/T ratio and nothing is returned. With
normalised=True the virial is divided by its sample mean,
1/sqrt(virial) is plotted and an amplitude correction matrix with the
shape of cryst.get_positions() is returned for use as xscale_init.
normal selects a normal fit; otherwise chi-squared with
3 * natoms(element) degrees of freedom is used.
Source code in hecss/monitor.py
plot_xs_stat(cryst, xsl, skip=10, window=10)
¶
Plot smoothed amplitude-correction coefficients over a run.
xsl is the history collected through the xscale_list argument of
HECSS.sample. skip drops initial steps and window sets the smoothing
width.
Source code in hecss/monitor.py
run_alamode(d='phon', prefix='cryst', kpath='cryst', dfset='DFSET', sc='../sc/CONTCAR', o=1, n=0, c2=10, c3=6, born=None, charge=None, skip_fit=False, make_gen='make-gen.py', alm='alm', anphon='anphon')
¶
Run the external ALAMODE tools for a DFSET file.
d is the working directory, prefix the base name of the generated input
and output files, dfset the displacement-force data, sc the structure
file and kpath the k-path definition. o selects the fit order and n
the number of DFSET samples to use; c2/c3 are cutoff radii, and born
and charge enable Born effective charges. With skip_fit=True only the
phonon calculation is run.
make_gen, alm and anphon are paths to the external executables. Their
defaults are tool names resolved through PATH; pass explicit paths when the
tools are not on PATH.
Returns (success, fit, phon, alm, anphon); the four process results are
None when the corresponding step was skipped.
Source code in hecss/monitor.py
show_dc_conv(bl, kpnts, max_plots=4)
¶
Show band convergence by overlaying faded earlier results.
bl maps the number of DFSET samples to band arrays; the most recent set is
drawn in the foreground and at most max_plots earlier sets are faded out.