Job¶
The Job
class is the base class defining a BigDFT calculation.
-
class
mybigdft.job.
Job
(name='', inputparams=None, posinp=None, run_dir=None, ref_data_dir=None, skip=False, pseudos=False)[source]¶ Bases:
object
This class is meant to define a BigDFT calculation.
run()
is its main method and it must be used in a context manager to ensure that the calculation is run the desired directory.You may pass input parameters and/or initial geometry (posinp). Make sure to at least provide initial positions, either via the posinp or the input parameters.
You may give a name for the calculation, used to name the input and output files written on disk (default naming conventions are used if not). You can also specify the directory where to run the calculation with run_dir.
A reference calculation may be given in order to copy its data directory to the present calculation (main use: restart from the wavefunctions of the reference calculation).
- Parameters
inputparams (InputParams or None) – BigDFT input parameters.
posinp (Posinp or None) – BigDFT initial geometry file.
name (str) – Prefix of the BigDFT calculation (used to define the input and output file names).
run_dir (str or None) – Folder where to run the calculation (default to current directory).
ref_data_dir (str) – Path to the data directory of a reference BigDFT calculation.
skip (bool) – If True, the calculation will be skipped. (Note: Might not be useful now, since we check for the existence of the logfile before running, which might be the actual check of the skip option of BigDFT.)
pseudos (bool) – If True, the pseudopotential files stored in $PSEUDODIR will be used to complete the job.
- Raises
ValueError – If no initial positions are given in the posinp or the input parameters.
A Job instance can be initialized by using a posinp only:
>>> from mybigdft import Posinp, Atom >>> pos = Posinp( ... [Atom('N', [2.9763078243490115e-23, 6.872205952043537e-23, ... 0.01071619987487793]), ... Atom('N', [-1.1043449194501671e-23, -4.873421744830746e-23, ... 1.104273796081543])], "angstroem", "free" ... ) >>> job = Job(posinp=pos, run_dir="tests")
Default values are therefore used for the input parameters:
>>> job.inputparams {}
Input and output file names are defined from the name passed as argument. Here, no name is passed, so that default names are used:
>>> job.input_name 'input.yaml' >>> job.posinp_name 'posinp.xyz' >>> job.logfile_name 'log.yaml'
The directories are defined from the run_dir argument:
>>> import os >>> os.getcwd() == job.init_dir True >>> os.path.basename(job.init_dir) != 'tests' True >>> os.path.basename(job.run_dir) 'tests'
There is no logfile associated to the job yet as it was not run:
>>> job.logfile == {} True
To run the job, do it from a context manager:
>>> with job as j: ... j.run() ... /.../tests Logfile log.yaml already exists! <BLANKLINE>
A logfile being found, it is read and not computed again:
>>> job.logfile == {} False
-
property
name
¶ - Returns
Base name of the calculation used to set the names of files and directories as well as the commands.
- Return type
str
-
property
inputparams
¶ - Returns
Input parameters of the calculation.
- Return type
-
property
logfile
¶ - Returns
Logfile of the calculation (output of the bigdft or bigdft-tool executable).
- Return type
Logfile or None
-
property
ref_data_dir
¶ - Returns
Reference directory where some relevant data (such as wavefunctions) is stored.
- Return type
str
-
property
pseudos
¶ - Returns
if True, the calculation uses the pseudopotential files in $PSEUDODIR (environment variable).
- Return type
bool
-
property
skip
¶ - Returns
If True, the calculation will be skipped. (Note: Might not be useful now, since we check for the existence of the logfile before running, which might be the actual check of the skip option of BigDFT.)
- Return type
bool
-
property
init_dir
¶ - Returns
Absolute path to the initial directory of the calculation (can differ from
run_dir()
).- Return type
str
-
property
run_dir
¶ - Returns
Absolute path to the directory where the calculation is run.
- Return type
str
-
property
data_dir
¶ - Returns
Absolute path to the data directory of the calculation.
- Return type
str
-
property
bigdft_tool_cmd
¶ - Returns
Base command to run the bigdft-tool executable.
- Return type
list
-
property
bigdft_cmd
¶ - Returns
Base command to run the bigdft executable.
- Return type
list
-
property
input_name
¶ - Returns
Name of the input parameters file.
- Return type
str
-
property
posinp_name
¶ - Returns
Name of the input position file.
- Return type
str
-
property
logfile_name
¶ - Returns
Name of the logfile.
- Return type
str
-
property
is_completed
¶ - Returns
True if the job has already run successfully.
- Return type
bool
-
__enter__
()[source]¶ When entering the context manager:
create the directory where the calculations must be run,
go to that directory.
-
run
(nmpi=1, nomp=1, force_run=False, dry_run=False, restart_if_incomplete=False, timeout=None)[source]¶ Run the BigDFT calculation if it was not already performed. The number of MPI and OpenMP tasks may be specified.
You may force the calculation to run even though it was previously successful (e.g., a logfile already exists) by setting force_run to True.
If dry_run is set to True, then bigdft-tool is run instead of the BigDFT executable.
If restart_if_incomplete is set to True, the previously existing logfile is removed and the calculation restarts.
- Parameters
nmpi (int) – Number of MPI tasks.
nomp (int) – Number of OpenMP tasks.
force_run (bool) – If True, the calculation is run even though a logfile already exists.
dry_run (bool) – If True, the input files are written on disk, but the bigdft-tool command is run instead of the bigdft one.
restart_if_incomplete (bool) – If True, the job is restarted if the existing logfile is incomplete.
timeout (float or int or None) – Number of minutes after which the job must be stopped.
-
write_input_files
()[source]¶ Write the input files on disk (there might be no posinp to write, since the initial positions can be defined in the input parameters).
-
clean
(data_dir=False, logfiles_dir=False)[source]¶ Delete all input and output files on disk as well as some directories if required.
- Parameters
data_dir (bool) – If True, removes the data directory that might exist.
logfiles (bool) – If True, removes the logfiles directory that might exist.
Warning
The directories are forced to be removed when the above- mentioned options are set to True: use with caution.