script_maker2000.orca
This module provides functionality for working with ORCA files and preparing jobs for the ORCA module.
The module contains the following classes: - OrcaModule: A class for setting up ORCA files and preparing jobs for the ORCA module.
- class script_maker2000.orca.OrcaModule(main_config: dict, config_key: str)
Bases:
TemplateModule
Initializes an OrcaModule object.
This method sets up the orca files from the main config. Since different orca setups can be defined in the config, we need to pass the corresponding keyword (e.g., optimization or single_point).
- Args:
main_config (dict): The main configuration dictionary containing all the setup information. config_key (str): The key corresponding to the specific orca setup in the main configuration.
- Raises:
NotImplementedError: If a required method or feature is not implemented in a subclass.
- classmethod check_job_status(job: Job) str
Checks the status of a job by examining the ORCA output file and the SLURM file.
This function checks for various types of errors in the ORCA output file and the SLURM file. It returns a string indicating the status of the job: “success”, “missing_ram_error”, “walltime_error”, “missing_files_error”, or “unknown_error”.
- Args:
job (Job): The job object to check the status of.
- Returns:
str: A string indicating the status of the job.
- classmethod collect_results(job, key, results_dir=None) dict
Uses the cclib library to extract the results from the ORCA output file.
This function checks if the job’s status for the given key is “finished” and if the results directory is “finished”. If both conditions are met, it parses the output file and extracts the results. The results are then returned as a dictionary. If the conditions are not met, the function returns None.
- Args:
job (Job): The current job object to collect results from. key (str): The key of the job to collect results from. results_dir (str, optional): The directory where the results are stored. Defaults to “finished”.
- Returns:
dict: A dictionary containing the results extracted from the ORCA output file. If the job’s status for the given key is not “finished” or the results directory is not “finished”, returns None.
- create_orca_input_files(xyz_dict)
Creates ORCA input files based on the provided XYZ dictionary and internal configuration.
The internal configuration should include the following options:
method: The computational method to use.
basisset: The basis set to use.
additional_settings: Any additional settings for the calculation.
ram_per_core: The amount of RAM to allocate per core.
n_cores_per_calculation: The number of cores to use for the calculation.
args: Any additional arguments for the calculation.
- Args:
xyz_dict (dict): A dictionary containing XYZ coordinates for the molecules.
- Example for additional arguments in the internal configuration:
{“scf”: [“MAXITER 0”], “elprop”: [“Polar 1”,”Solver C”] }
- create_slurm_scripts(slurm_config=None) str | Path
Creates slurm scripts for each configuration in the slurm_config dictionary.
This function reads a slurm template file, replaces placeholders in the template with values from the slurm_config dictionary, and writes the resulting slurm script to a new file in the working directory.
- Args:
slurm_config (dict, optional): A dictionary containing slurm configurations. Each key is a filename stem and each value is a dictionary of placeholders and their replacements.
- Returns:
dict: A dictionary mapping filename stems to the paths of the created slurm scripts.
- prepare_jobs(input_dirs, **kwargs) dict
Prepares the jobs for the Orca module.
This method reads XYZ files from the input directories, creates ORCA input files and slurm scripts, and returns a dictionary mapping directory stems to directory paths.
- Args:
input_dirs (list): A list of directories to read the XYZ files from. kwargs: Arbitrary keyword arguments.
- Returns:
dict: A dictionary mapping directory stems to directory paths.
- prepare_slurm_script(orca_file_dict, override_settings=None) dict
Prepares a dictionary with the necessary variables to fill for a SLURM script.
Variables to fill:
__jobname (str): Job name.
__ntasks (int): Number of tasks.
__memcore (int): Memory per core.
__walltime (str): Wall time.
__scratchsize (int): Scratch size.
__input_dir (str): Full path to the original input directory.
__output_dir (str): Full path to the original output directory.
__input_file (str): Relative path to the input file (this gets copied).
__output_file (str): Saves the ORCA output (full path to the original directory).
__marked_files (str): File paths in the format “/home/usr/dir/{file1,file2,file3,file4}”.
- Args:
orca_file_dict (dict): Dictionary with ORCA file information. override_settings (dict, optional): Dictionary with settings to override.
Example: {“n_cores_per_calculation”: 8, “ram_per_core”: 8000, “walltime”: “24:00:00”}
- Returns:
dict: Dictionary with the variables to fill for the SLURM script.
- read_xyzs(input_files, charge_list, multiplicity_list)
Reads XYZ files and returns a dictionary with the file information.
This function reads each XYZ file in the input_files list, extracts the coordinates, and stores them in a dictionary along with the charge and multiplicity. The dictionary is keyed by the stem of the XYZ file path. Each XYZ file is then moved to a new directory in the working directory.
- Args:
input_files (list): A list of paths to the XYZ files. charge_list (list): A list of charges corresponding to the XYZ files. multiplicity_list (list): A list of multiplicities corresponding to the XYZ files.
- Returns:
dict: A dictionary containing the coordinates, charge, and multiplicity for each XYZ file, keyed by the stem of the XYZ file path.
- restart_jobs(reset_job_list, key)
Restarts a list of jobs that failed due to a walltime error.
This function iterates over the provided list of jobs, resetting each job and collecting the results. If the job failed due to a walltime error, it is skipped. Otherwise, the function collects the results of the job, creates a new XYZ input file based on the last coordinates of the job, and appends the job to a list of reset jobs. After all jobs have been processed, the function creates new ORCA input files and SLURM scripts for the reset jobs, and returns a tuple containing the list of reset jobs and a list of jobs that were not reset.
- Args:
job_list (list): A list of Job objects to be restarted. key (str): The key to use when collecting the results of each job.
- Returns:
- tuple: A tuple containing two lists. The first list contains the Job objects that were reset. The
second list contains the Job objects that were not reset.
- run_job(job) None
Submits a job to the server using the SLURM workload manager.
This function checks if the necessary SLURM and ORCA input files exist in the job’s input directory. If they do, it submits the job using the sbatch command. If the sbatch command is not found, it raises a ValueError. If the necessary input files are not found, it raises a FileNotFoundError.
- Args:
- job (Job): The job object to be submitted. The job object should have a current_dirs attribute
that is a dictionary with a key “input” that maps to the directory containing the job’s input files. The name of the job is assumed to be the stem of this directory.
- Raises:
ValueError: If the sbatch command is not found in the system’s PATH. FileNotFoundError: If the necessary SLURM or ORCA input files are not found in the job’s input directory.
- Returns:
- subprocess.CompletedProcess: The process object that was created by the subprocess.run command.
This object can be used to check if the job was submitted successfully.
- write_orca_scripts(orca_file_dict)
Writes ORCA input files for each entry in the orca_file_dict dictionary.
This function creates a new directory for each ORCA input file, writes the input data to the file, and stores the path of the created file in a dictionary.
- Args:
orca_file_dict (dict): A dictionary containing ORCA input data. Each key is a filename stem and each value is a list of lines to write to the file.
- Returns:
dict: A dictionary mapping filename stems to the paths of the created ORCA input files.