Skip to content

CLI

The command line interface for the HECSS sampler

Setup

Install the package and activate your virtual environment:

$ pip install hecss

Every transcript below is generated from a real command by python docs/gen_cli_examples.py; relative paths are to the repository root. Contributors can verify that the transcripts and figures are current with python docs/gen_cli_examples.py --check.

The sampling commands need VASP and a ./run-calc wrapper (described below). The post-processing commands run on the data shipped in example/ without VASP, so their output and plots are reproduced here.

Command line hecss sampler

The sampler is installed as the hecss_sampler command:

$ hecss_sampler -V

HECSS, version 0.7.0
High Efficiency Configuration Space Sampler
(C) 2021-2024 by Paweł T. Jochym
    License: GPL v3 or later
$ hecss_sampler --help

Usage: hecss-sampler [OPTIONS] FNAME

  Run HECSS sampler on the structure in the provided file (FNAME). Read the
  docs at: https://jochym.github.io/hecss/

  FNAME - Supercell structure file. The containing 
          directory must be readable by Vasp(restart).
          Usually this is a CONTCAR file for a supercell.

Options:
  -W, --workdir PATH      Work directory
  -l, --label TEXT        Label for the calculations.
  -T, --temp FLOAT        Target temperature in Kelvin.
  -w, --width FLOAT       Initial scale of the prior distribution
  -a, --ampl PATH         Initialise amplitude correction from the file.
  -s, --scale PATH        Save amplitude correction history
  -m, --symprec FLOAT     Symmetry search tolerance.
  -C, --calc TEXT         ASE calculator to be used for the job. Supported
                          calculators: VASP (default)
  -S, --setups TEXT       setups parameter of the calculator to force use of the
                          particular variants of pseudopotentials in the
                          calculations. By default pseudopotentials are guessed
                          from the POTCAR in the supercell directory.
  -n, --nodfset           Do not write DFSET file for ALAMODE
  -d, --dfset TEXT        Name of the DFSET file
  -N, --nsamples INTEGER  Number of samples to be generated
  -e, --neta INTEGER      Number of samples for width scale estimation (ignored
                          when -w is given)
  -c, --command TEXT      Command to run calculator
  -k, --nwork INTEGER     Parallel workers for width estimation only
                          (0=unlimited); sampling runs serially
  -p, --pbar / --no-pbar  Show or hide the progress bar (shown by default)
  -V, --version           Show the version and exit.
  -h, --help              Show this message and exit.

To use it you need to prepare:

  1. A run-calc script that starts the VASP calculation. Copy the example at example/scripts/run-calc.example to ./run-calc in the root of your project tree.
#!/bin/bash

# This script should run vasp in current directory
# and wait for the run to finish.
#
# A generic line using SLURM would look like this:
#
# sbatch [job_params] -W vasp_running_script
#
# The "-W" param makes the sbatch command wait for the job to finish.


JN=`pwd`
JN=`basename ${JN}`

# Partition of the cluster
PART=small

# Number of nodes
N=1

# Number of MPI tasks
ntask=64

# Name the job after directory if no label is passed as first argument
if [ "${1}." != "." ]; then
  JN=${1}
fi

sbatch -W -J ${JN} -p $PART -N $N -n $ntask run-vasp-script
  1. A directory with fully converged and optimized supercell structure which can be read in by the ASE Vasp(restart=...) command

  2. A directory for the generated samples.

The directory tree may look like this:

my_project ----- sc
             |
             +-- T_100
             |
             +-- T_200
             |
             +-- ...
             |
             +-- run-calc

You execute the sampler from the my_project directory (remember to activate your virtual environment first). Generation of N=30 samples at T=100K:

~$ cd my_project
~$ hecss_sampler -W T_100 -T 100 -N 30 -c ./run-calc sc/CONTCAR

The above command will put the generated samples inside the T_100 directory, together with the DFSET file with displacement-force data extracted from the calculation. The calculation may take a long time. Thus it is advisable to execute the hecss command inside screen (or some similar terminal multiplexer) to prevent the break of the calculation in case of session disconnection. The hecss command shows a progress to guide you through the calculation (ETA, time/it, data about last sample etc.). A real run is machine dependent, so its progress output is not captured here; use --help above for the full option list.

Width scale estimation

Calling the sampler with N=0 runs only width scale (eta) estimation procedure for the temperature range 0-T Kelvin. The calculated value may be used as the -w parameter in subsequent calculations. Possibly even for temperatures outside of this range. Passing -w explicitly disables this estimation.

~$ hecss_sampler -W TMP/cli -T 1000 -N 0 -e 10 -k 0 -c ./run-calc.sh example/VASP_3C-SiC/1x1x1/sc_1x1x1/CONTCAR

Calculating amplitude correction data

The amplitude correction data can be saved into the file (-s parameter) and used in subsequent calculations (see below). This will speed up the initial equilibration of the degrees of freedom. This will be merged with eta estimation in future versions.

~$ hecss_sampler -W TMP/cli -T 300 -N 10 -w 1.85 -c ./run-calc.sh -s scale.dat example/VASP_3C-SiC/1x1x1/sc_1x1x1/CONTCAR

Calculate initial amplitude correction

By saving the amplitude correction coefficients into the file with -s option of the sampler we can initialise following calculations with proper relations of relative displacement amplitudes. This may be also used to continue the calculations with minimal startup overhead.

$ calculate_xscale --help

Usage: calculate-xscale [OPTIONS] SUPERCELL SCALE

  Calculate initial values for amplitude correction coefficients  from the scale
  file data for the specified supercell.

Options:
  -o, --output PATH   Write output to the file.  [required]
  -s, --skip INTEGER  Skip this number of samples at the beginning
  -V, --version       Show the version and exit.
  -h, --help          Show this message and exit.

A short scale history is included with the docs, so the conversion itself can be demonstrated without VASP:

$ calculate_xscale -o TMP/cli/iscale.dat -s 1 example/VASP_3C-SiC/1x1x1/sc_1x1x1/CONTCAR docs/assets/cli/scale.dat

Done. The initial scale saved to: TMP/cli/iscale.dat

Continue the calculation

~$ hecss_sampler -W TMP/cli -T 300 -N 10 -w 1.85 -c ./run-calc.sh -s scale.dat -a TMP/cli/iscale.dat example/VASP_3C-SiC/1x1x1/sc_1x1x1/CONTCAR

Sampling re-shaping

The reshaper changes the sample set to any given temperature. The shipped DFSET file makes the example reproducible without VASP.

$ reshape_sample --help

Usage: reshape-sample [OPTIONS] DFSET [T]

  Reshape the sample to the normal distribution centered around mean energy
  (temperature), or around provided temperature T (Kelvin). The reshaping is
  done by adjusting weighting of the samples by repeating the ones which should
  be up-weighted.  The parameters are the variants of the weighting algorithm
  (see the docs).

  The procedure reads and produces a file with in the DFSET format. For the
  'check' function to work the parameter must point to the root directory  of
  the calculated samples. The checked directories will be in the form:
  '{root}/nnnn'.

  In check mode the raw file is *not* reshaped, just filtered.

Options:
  -N, --nmul INTEGER  Sample length multiplier (default: 4)
  -p, --prob FLOAT    Probability treshold (default: 0.25)
  -w                  Force non-zero weights for samples above probability
                      treshold. (default: True)
  -b                  Border samples account for the rest of domain
  -c, --check PATH    Check and skip unconverged samples in calc directory.
  -o, --output PATH   Write output to the file.  [required]
  -d                  Plot debug plots
  -V, --version       Show the version and exit.
  --help              Show this message and exit.
$ reshape_sample -o TMP/cli/DFSET_1200K.dat example/VASP_3C-SiC_calculated/2x2x2/T_1200K/DFSET.dat 1200

Done. Distribution reshaped to 1200.00 K.
Done. Saving to: TMP/cli/DFSET_1200K.dat

Command line statistics monitoring

This simple command line interface to the statistics plotting function allows for quick monitoring of the running calculation. If the sixelplot package is installed it is even possible to plot hi-res plots in the remote terminal supporting sixel standard (e.g. mlterm, xterm on Linux, iterm2 on OSX).

$ plot_stats --help

Usage: plot-stats [OPTIONS] DFSET [T]

  Plot the statistics of the samples from the DFSET file. Use T(K) as a
  reference target temperature. Optionally  write out the plot to the output
  graphics file.

Options:
  -n, --sqrn          Show sqrt(N) bars on the histogram.
  -s, --sixel         Use SixEl driver for terminal graphics.
  -w, --width FLOAT   Width of the figure.
  -h, --height FLOAT  Height of the figure.
  -o, --output PATH   Write output to the file.
  -x                  Make plot in an interactive window
  -V, --version       Show the version and exit.
  --help              Show this message and exit.
$ plot_stats -n -w 7 -h 4 -o docs/figures/cli-stats.png example/VASP_3C-SiC_calculated/2x2x2/T_1200K/DFSET.dat 1200

Sample statistics from the shipped 1200 K DFSET file

Command line phonon monitoring

This simple command line interface to the phonon plotting function allows for quick monitoring of the phonon calculation. If the sixelplot package is installed it is even possible to plot hi-res plots in the remote terminal supporting sixel standard (e.g. mlterm, xterm on Linux, iterm2 on OSX).

$ plot_bands --help

Usage: plot-bands [OPTIONS] [BANDS]...

  Plot the phonon dispersion from the file generated by ALAMODE. Optionally
  write out the plot to the output graphics file.

Options:
  -s, --sixel         Use SixEl driver for terminal graphics.
  -n, --nodecor       Decorate the plot.
  -w, --width FLOAT   Width of the figure.
  -h, --height FLOAT  Height of the figure.
  -o, --output PATH   Write output to the file.
  -l, --label TEXT    Label(s) for the plot. Comma-separated list
  -x                  Make plot in an interactive window
  -V, --version       Show the version and exit.
  --help              Show this message and exit.
$ plot_bands -w 7 -h 4 -l 300K,600K,3000K -o docs/figures/cli-bands.png example/VASP_3C-SiC_calculated/2x2x2/T_300K/phon/cryst.bands example/VASP_3C-SiC_calculated/2x2x2/T_600K/phon/cryst.bands example/VASP_3C-SiC_calculated/2x2x2/T_3000K/phon/cryst.bands

Phonon bands from the shipped 300 K, 600 K and 3000 K data