sparc.io module
Providing a new bundled SPARC file format
- class sparc.io.SparcBundle(directory, mode='r', atoms=None, label=None, psp_dir=None, validator=<sparc.api.SparcAPI object>, cfg=<ase.config.Config object>)[source]
Bases:
object
Provide access to a calculation folder of SPARC as a simple bundle
The bundle can be optionally named as .sparc following the ASE’s .bundle format
Currently the write method only supports 1 image, while read method support reading atoms results in following conditions
No calculation (minimal): .ion + .inpt file –> 1 image
2) Single point calculation: .ion + .inpt + .out + .static –> 1 image with calc 3) Multiple SP calculations: chain all .out{digits} and .static{digitis} outputs 4) Relaxation: read from .geopt and .out (supporting chaining) 5) AIMD: read from .aimd and .out (support chaining)
- directory
Path to the directory containing SPARC files.
- Type:
Path
- mode
File access mode (‘r’, ‘w’, or ‘a’).
- Type:
str
- label
Name of the main SPARC file.
- Type:
str
- init_atoms
Initial atomic configuration.
- Type:
Atoms
- init_inputs
Initial input parameters.
- Type:
dict
- psp_data
Pseudopotential data.
- Type:
dict
- raw_results
Raw results from SPARC calculations.
- Type:
dict
- psp_dir
Directory containing pseudopotentials.
- Type:
Path
- sorting
Sort order for atoms.
- Type:
list
- last_image
Index of the last image in a series of calculations.
- Type:
int
- __find_psp_dir(psp_dir=None)
Finds the directory for SPARC pseudopotentials.
- _indir(ext, label=None, occur=0, d_format="{
02d}”): Finds a file with a specific extension in the bundle.
- _read_results_from_index(index, d_format="{
02d}”): Reads results from a specific calculation index.
- _make_singlepoint(calc_results, images, raw_results)[source]
Converts results and images to SinglePointDFTCalculators.
- _extract_static_results(raw_results, index="
“): Extracts results from static calculations.
- _extract_geopt_results(raw_results, index="
“): Extracts results from geometric optimization calculations.
- _extract_aimd_results(raw_results, index="
“): Extracts results from AIMD calculations.
- convert_to_ase(index=-1, include_all_files=False, **kwargs)[source]
Converts raw results to ASE Atoms with calculators.
- read_raw_results(include_all_files=False)[source]
Parses all files in the bundle and merges results.
- convert_to_ase(index=-1, include_all_files=False, **kwargs)[source]
Read the raw results from the bundle and create atoms with single point calculators
- Parameters:
index (int or str) – Index or slice of the image(s) to convert. Uses the same format as ase.io.read
include_all_files (bool) – If true, also read results with indexed suffices
- Returns:
ASE-atoms or images with single point results
- Return type:
Atoms or List[Atoms]
- psp_env = ['SPARC_PSP_PATH', 'SPARC_PP_PATH']
- read_psp_info()[source]
Parse the psp information from inpt file options The psp file locations are relative to the bundle.
If the files cannot be found, the dict will only contain the path
- read_raw_results(include_all_files=False)[source]
Parse all files using the given self.label. The results are merged dict from all file formats
- Parameters:
include_all_files (bool) – Whether to include output files with different suffices If true: include all files (e.g. SPARC.out, SPARC.out_01, SPARC.out_02, etc).
- Returns:
Dict containing all raw results. Only some of them will appear in the calculator’s results
- Return type:
dict or List
- Sets:
self.raw_results (dict or List): the same as the return value
#TODO: @TT 2024-11-01 allow accepting indices #TODO: @TT last_image is a bad name, it should refer to the occurance of images
the same goes with num_calculations
- property resort
Wrap the self.sorting dict. If sorting information does not exist, use the default slicing
- property sort
Wrap the self.sorting dict. If sorting information does not exist, use the default slicing
- sparc.io.read_sparc(filename, index=-1, include_all_files=True, **kwargs)[source]
Parse a SPARC bundle, return an Atoms object or list of Atoms (image) with embedded calculator result.
- Parameters:
filename (str or PosixPath) – Filename to the sparc bundle
index (int or str) – Index or slice of the images, following the ase.io.read convention
include_all_files (bool) – If true, parse all output files with indexed suffices
**kwargs – Additional parameters
- Returns:
Atoms or List[Atoms]
- sparc.io.write_sparc(filename, images, **kwargs)[source]
Write sparc file. Images can only be Atoms object or list of length 1
- Parameters:
filename (str or PosixPath) – Filename to the output sparc directory
images (Atoms or List(Atoms)) – Atoms object to be written. Only supports writting 1 Atoms
**kwargs – Additional parameters