dcs package

Submodules

dcs.chimes module

class dcs.chimes.CLICommand

Bases: object

Chebyshev Interaction Model for Efficient Simulation (ChIMES)

static add_arguments(parser)

Sets up command line to run Chimes i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs chimes function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.chimes.chimes(trajfile=None, b2=12, b3=8, T=5)
Calculates force difference between DFT and DFTB (training set),

and fits the Chebyshev polynomials coefficients. Creates 3-chimes folder (inside 0-train directory) and writes params.txt file.

Args:

trajfile (list, optional): Trajectory file (ist of atoms objects) output from md simulation. Defaults to None. b2 (int, optional): Second body order of Chebyshev polynomial. Defaults to 12. b3 (int, optional): Third body order of Chebyshev polynomial. Defaults to 8. T (int, optional): Temperature for simulation in Kevin. Defaults to 5.

dcs.chimes.dftb_fmatch_input(T, frame)
Runs DFTB force calculations using frame from DFT;

calculates the force difference between DFT and DFTB. Creates a list with the chemical symbols, atomic positions, and force differences.

Args:

T (int): Temperature for DFTB simulation. frame (list): ASE atoms object with atomic positions, forces, energies, etc from DFT calculation.

Returns:

list: Contains the chemical symbols, atom positions, and difference in DFTB and DFT forces.

dcs.chimes.fm_setup_input(nframes, b2, b3, setsymbols, smax)

Writes force match setup input file (fm_setup.in) with given arguments.

Args:

nframes (int): Number of trajectories. b2 (int): Second body order of Chebyshev polynomial. b3 (int): Third body order of Chebyshev polynomial. setsymbols (set): Chemical symbols. smax (float): Half of the minimum cell length.

dcs.chimes.lsq()

Runs chimes_lsq binary and creates A and B matrices (A.txt, B.txt). Runs lsq fitting process and writes ChIMES coefficients to params.txt.

dcs.chimes.multi_fmatch(T)
Runs dftb_fmatch_input command for each trajectory, n processes at a time.

Returns tuple with trajectory information.

Args:

T (int): Temperature for DFTB simulation.

Returns:
tuple: (nframes, setsymbols, smax)

nframes (int) - Number of ASE atoms object. setsymbols (set) - Chemical symbols. smax (float) - Half of the minimum cell length.

dcs.chimes.rdf(smax, pair)
Finds the radial distribution function for elements defined in pair.

Analyses the RDF, and determines the min and max distances in a atomic pair interaction. Returns a tuple with mlambda, rmin and rmax.

Args:

smax (float): Half of the minimum cell length. pair (list): List with two chemical symbols of a pair interaction, e.g., [‘C’, ‘H’]

Returns:
tuple: (mlambda, rmin, rmax)

mlambda (float) - Morse lambda factor rmin (float) - Minimum distance considered in a atomic pair interaction. rmax (float) - Maximum distance considered in a atomic pair interaction.

dcs.chimes.run_md_input(folder)

Writes MD input file (run_md.in) if it does not exist in folder.

Args:

folder (str): Directory that contains params.txt file.

Raises:

Exception: Raises exception if there is no params.txt file in folder.

dcs.main module

dcs.main.main()

Looks up ase_main function, sets up command line.

dcs.md module

class dcs.md.CLICommand

Bases: object

Molecular dynamics with constant temperature

static add_arguments(parser)

Sets up command line to run molecular dynamics with constant temperature i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs md function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.md.md(optgeo=None, calc='vasp', T=300, md_size=[1, 1, 1], steps=5000, time_step=1, dump_interval=100)

Runs molecular dynamics simulation using vasp or castep (Creates 2-molecular_dynamics folder inside 0-train)

Args: optgeo (NoneType, optional): Optimized geometry file, only true if optgeo defined. Defaults to None. calc (str, optional): Specifies calculator. Options are ‘vasp’ or ‘castep’. Defaults to ‘vasp’. T (int, optional): Simulation temperature. Defaults to 300. md_size (list, optional): Size of supercell. Defaults to [1,1,1]. steps (int, optional): Maximum number of ionic steps. Defaults to 5000. time_step (int, optional): Md time step in fs. Defaults to 1. dump_interval (int, optional): Step size of frames to be saved in the trajectory file. Defaults to 100.

Raises: NotImplementedError: If calculator other than vasp or castep specified.

dcs.md.run_castep_md(atoms, T, steps, time_step, dump_interval)

Runs castep md calculation on atoms for specified intervals.

Args:

atoms (list): Atoms object involved in calc from ASE. T (int): Initial and final simulation temperature. steps (int): Maximum number of ionic steps, defines the total simulation time. time_step (int): md time step in fs. dump_interval (int): Step size of frames to be saved in the trajectory file.

dcs.md.run_vasp_md(atoms, T, steps, time_step, dump_interval)

Runs vasp md calculation on atoms for specified intervals.

Args:

atoms (list): Atoms object involved in calc from ASE. T (int): Initial and final simulation temperature. steps (int): Maximum number of ionic steps, defines the total simulation time. time_step (int): md time step in fs. dump_interval (int): Step size of frames to be saved in the trajectory file.

dcs.md.set_castep_pbc()

dcs.oclimax module

class dcs.oclimax.CLICommand

Bases: object

Run OCLIMAX simulations

static add_arguments(parser)

Sets up command line to run OCLIMAX i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs oclimax function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.oclimax.oclimax(params=None, task=0, e_unit=0)

Creates folder 3-oclimax, writes oclimax parameters file in folder and runs oclimax simulation.

Args:

params (str, optional): Oclimax parameters file defined in write_params function. Defaults to None. task (int, optional): Defines approximation method.

0:inc approx. 1:coh+inc. 2:single-xtal Q-E. 3:single-xtal Q-Q. Defaults to 0.

e_unit (int, optional): Defines energy unit. Defaults to 0.

dcs.oclimax.plot()

Creates plot using csv file (oclimax output with INS data) and saves as a png. Plots energy (meV) versus Normalized intensity.

dcs.oclimax.run_oclimax(params)
If convert.done file doesn’t exist, runs OCLIMAX convert. Converts input mesh to out.oclimax;

out.oclimax is the OCLIMAX format for mesh type files.

Args:

params (str): Oclimax parameters file name defined in write_params function.

dcs.oclimax.write_params(task, e_unit)

Creates parameters file for Oclimax.

Args:
task (int): Defines approximation method where

0:inc approx. 1:coh+inc. 2:single-xtal Q-E. 3:single-xtal Q-Q.

e_unit (int): Defines energy units such that 0:cm-1 1:meV 2:THz.

dcs.phonons module

class dcs.phonons.CLICommand

Bases: object

Calculate phonons

static add_arguments(parser)

Sets up command line to run phonopy i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs phonons function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.phonons.calculate_forces(mode, kwargs, dir)

Runs single point energy calculation.

Args:

kforce (list): Number of k points for force calculations. mode (str): Calculator used for task. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’. T (int, optional): Simulation temperature. Only used for DFTB+ and ChIMES. dir (str): Directory to change to and run calculator in.

dcs.phonons.calculate_mesh(mesh, mode)

Creates Phonopy force sets for specified calculator and runs mesh sampling phonon calculation.

Args:

mesh (list): Uniform meshes for each axis. mode (str): Calculator used for task. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’.

dcs.phonons.calculator_kwargs(kforce, mode, T, folder='.')
dcs.phonons.generate_supercell(dim, mode)

Reads in the molecule structure file and creates displacements.

Args:

dim (list): Dimensions of the supercell. mode (str): Calculator used for the task. Options are ‘dftbp’ or ‘chimes’.

dcs.phonons.multi_forces(kforce, mode, T, folder, mpi=False)
Calls calculate_forces function using parallel processing,

calculates forces for specified mode.

Args:

kforce (list): Number of k points for force calculations. mode (str): Calculator used for task. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’. mpi (bool, optional): Not currently implemented. Defaults to False.

dcs.phonons.organize_folders(mode)
Finds supercell displacement files and formats the name.

Creates directory with supercell displacement number,

and moves supercell displacement file into created directory.

Args:

mode (str): Calculator used for task. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’.

dcs.phonons.phonons(dim=[4, 4, 4], kforce=[1, 1, 1], mesh=[8, 8, 8], calc='dftbp', T=5)

Runs phonon supercell displacement calculations, populates 2-phonons folder with results.

Args:

dim (list, optional): Dimensions of the supercell. Defaults to [4, 4, 4]. kforce (list, optional): Number of k points for force calculations. Defaults to [1, 1, 1]. mesh (list, optional): Uniform meshes for each axis. Defaults to [8, 8, 8]. calc (str, optional): Calculator used for task. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’. Defaults to ‘dftbp’. T (int, optional): Simulation temperature. Defaults to 5K. Only used for DFTB+ and ChIMES.

Raises:

NotImplementedError: Raised if ‘calc’ specified is not available.

dcs.phonons.write_params(kforce, mode, T)

Writes json file with default arguments for the relaxation calculator.

dcs.relax module

class dcs.relax.CLICommand

Bases: object

Optimize structure

static add_arguments(parser)

Sets up command line to run relax script i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs relax.py functions using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.relax.calculator_kwargs(krelax, fmax, geo, mode, T, folder='.')
dcs.relax.find_geo(folder)
Searches the current working directory for the molecular structure file.

Allowed file types are .cif, .gen, .sdf, or .xyz.

Args:

folder (str): The current working directory.

Returns:

str: Molecular structure file.

dcs.relax.relax(krelax=[6, 6, 6], fmax=0.05, geo=None, calc='dftbp', T=5)

Finds the geometry file and optimizes the structure using the specified calculator (Populates 1-optimization folder with results).

Args:

krelax (list, optional): Number of k points for relaxation. Defaults to [6, 6, 6]. fmax (float, optional): Maximum allowed force for convergence between atoms. Defaults to 0.01. geo (str, optional): Geometry file or structure.

Allowed file types are .cif, .gen, .sdf, or .xyz. Defaults to None.

calc (str, optional): Calculator used. Options are ‘dftbp’, ‘chimes’, or ‘vasp’. Defaults to ‘dftbp’. T (int, optional): Simulation temperature. Defaults to 5K. Only used for DFTB+ and ChIMES.

dcs.relax.relax_structure(krelax, fmax, geo, mode, T, folder)

Defines arguments for specified calculator and optimizes the structure.

Args:

krelax (list): Number of k points for relaxation. fmax (float): Maximum allowed force for convergence between atoms. geo (str): Geometry file or structure. Allowed file types are .cif, .gen, .sdf, or .xyz. mode (str): Calculator used. Options are ‘dftbp’, ‘chimes’, ‘vasp’, or ‘castep’. T (int, optional): Simulation temperature. Only used for DFTB+ and ChIMES.

Raises:

NotImplementedError: If specified calculator is not an option for mode, error raised.

dcs.relax.write_params(krelax, fmax, geo, mode, T)

Writes json file with default arguments for the relaxation calculator.

dcs.train module

class dcs.train.CLICommand

Bases: object

Workflow to run DFT-MD and train ChIMES model

static add_arguments(parser)

Sets up command line to run train script i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs train function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.train.train(dct=None)

Calls functions related to the training workflow (relax, md, chimes) with a timer using specified parameters in train_params.json, else with default parameters. Creates 0-train directory.

Args:

dct (dict, optional): JSON file with specified parameters for relax, md, and chimes functions. Defaults to ‘train_params.json’.

dcs.train.write_params()

Writes a json file with the arguments and default values for realx, md, and chimes functions.

dcs.workflow module

class dcs.workflow.CLICommand

Bases: object

Workflow to relax structure, calculate phonons and calculate INS spectrum

static add_arguments(parser)

Sets up command line to run workflow script i.e. recognize arguments and commands.

Args:

parser (argparse): Arguments to be added.

static run(args)

Runs workflow function using command line arguments.

Args:

args (argparse): Command line arguments added to parser using the function add_arguments.

dcs.workflow.workflow(dct=None)

Calls all workflow functions (relax, phonon, oclimax) with a timer using specified parameters in workflow_params.json, else with default parameters.

Args:

dct (dict, optional): Specified parameters for relax, phonons, and oclimax functions. Defaults to None.

dcs.workflow.write_params()

Writes json file with default arguments from relax, phonons, and oclimax scripts.

Module contents

dcs.chdir(folder)

Changes the working directory to folder if not already current wd.

Args:

folder (str): Name of folder to make wd.

dcs.done(mode)

Create .done file for task as f and closes.

Args:

mode (str): Name of task finished.

dcs.get_default_parameters(func)

Inspects function func for argument names and default arguments.

Args:

func (func): Input function to inspect.

Returns:

dict: Keys are argumnent names, values are the default arguments.

dcs.isdone(mode)

Checks for .done file.

Args:

mode (str): Calculator used for task/specified.

Returns:

bool: True if mode.done files exists, false if mode.done doesn’t exist.

dcs.mkdir(folder)

Creates folder in current wd unless OSError occurs.

Args:

folder (str): Name of folder to create.

dcs.mktempdir()

Creates a temporary directory.

Yields:

str: Temporary directory name.

dcs.out(task)

Creates .out and .err files for specified task.

Args:

task (str): Name of task.

dcs.read_json(filename)

Reads specified json file.

Args:

filename (str): Full name of json file.

Returns:

dict: Dictionary with data specified by json file.

dcs.write_json(filename, data)

Creates json file with specified name and data.

Args:

filename (string): Name of json file. Must include .json. data (dict): Dictionary with data.