files
Utility functions for file and path handling.
check_logfile ¶
Check if a logfile has a given string (case-insensitive).
The compression suffix, e.g. .gz
, is automatically handled
and does not need to be specified.
Parameters:
Returns:
-
bool
–True if the string is found in the logfile, False otherwise.
Source code in quacc/utils/files.py
copy_decompress_files ¶
copy_decompress_files(
source_directory: SourceDirectory,
filenames: Filenames,
destination_directory: str | Path,
) -> None
Copy and decompress filenames
from the source_directory
to the destination
directory.
For example, to copy the files CHGCAR
and WAVECAR
from the source_directory
to
the destination
directory, use the following:
copy_decompress_files(
source_directory="/path/to/source",
filenames=["CHGCAR", "WAVECAR"],
destination="/path/to/destination",
)
This function also supports glob patterns for any of the entries within filenames
.
For example, to copy and decompress all files in the source_directory
with the
extension .gz
to the destination
directory, use the following:
copy_decompress_files(
source_directory="/path/to/source",
filenames=["*.gz"],
destination="/path/to/destination",
)
If a directory is specified in filenames
, that directory and its contents will be
copied and decompressed to the destination
directory.
For example, to recursively copy the entire directory prior_run
and decompress its
files from the source_directory
to the destination
directory, use the following:
copy_decompress_files(
source_directory="/path/to/source",
filenames=["prior_run"],
destination="/path/to/destination",
)
Sometimes, you may want to copy a directory but only keep some of the files for the
sake of saving space. In other words, you want to retain the tree structure of the
files with respect to some parent directory. To do this, you can specify the
tree to retain in the filenames
argument. For example, to copy and decompress the
files prior_run/CHGCAR
and prior_run/WAVECAR
from the source_directory
to the
destination
directory while the tree structure, use the following:
copy_decompress_files(
source_directory="/path/to/source",
filenames=["prior_run/CHGCAR", "prior_run/WAVECAR"],
destination="/path/to/destination",
)
Parameters:
-
source_directory
(SourceDirectory
) –Directory to copy files from.
-
filenames
(Filenames
) –Files to copy and decompress. Glob patterns are supported.
-
destination_directory
(str | Path
) –Destination directory.
Returns:
-
None
–
Source code in quacc/utils/files.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
find_recent_logfile ¶
Find the most recent logfile in a given directory.
Parameters:
-
directory
(Path | str
) –The path to the directory to search
-
logfile_extensions
(str | list[str]
) –The extension (or list of possible extensions) of the logfile to search for. For an exact match only, put in the full file name.
Returns:
-
logfile
–The path to the most recent logfile with the desired extension
Source code in quacc/utils/files.py
get_uri ¶
Return the URI path for a directory.
This allows files hosted on different file servers to have distinct locations.
Adapted from Atomate2.
Parameters:
Returns:
-
str
–Full URI path, e.g., "fileserver.host.com:/full/path/of/dir_name".
Source code in quacc/utils/files.py
load_yaml_calc ¶
Loads a YAML file containing calculator settings. This YAML loader looks for a special flag "parent" in the YAML file. If this flag is present, the YAML file specified in the "parent" flag is loaded and its contents are inherited by the child YAML file.
Parameters:
Returns:
-
dict
–The calculator configuration (i.e. settings).
Source code in quacc/utils/files.py
make_unique_dir ¶
Make a directory with a unique name.
Parameters:
-
base_path
(Path | str | None
, default:None
) –Path to the base directory.
-
prefix
(str | None
, default:None
) –Prefix to add to the directory name.
Returns:
-
Path
–Path to the job directory.
Source code in quacc/utils/files.py
safe_decompress_dir ¶
Recursively decompresses all files in a directory.
This is a wrapper around the decompress_file
function.
Args: path (str | Path): Path to parent directory.