Overview
Theresources module provides utilities for accessing external resources such as data files and tools that are packaged with AlphaFold 3. It handles path resolution and file operations for resources stored within the AlphaFold 3 package structure.
Module Path: alphafold3.common.resources
Constants
ROOT
alphafold3.common module.
Example:
Functions
filename
str | os.PathLike[str]
required
The name of the resource corresponding to its path relative to the root of the repository
.par files), which might be unfriendly on diskless machines.
Example:
open_resource
str | os.PathLike[str]
required
The name of the resource corresponding to its path relative to the root of the repository
str
default:"'rb'"
The mode to use when opening the file:
'r'or'rt': Read text mode (returnsTextIO)'rb': Read binary mode (returnsBinaryIO)
TextIO or BinaryIO depending on mode)
Example:
get_resource_dir
str | os.PathLike[str]
required
The relative path to the directory from the repository root
os.PathLike[str] object representing the full directory path
Example:
walk
os.walk().
str
required
The relative path to walk from the repository root
(dirpath, dirnames, filenames) for each directory in the tree
dirpath: String path to the directorydirnames: List of subdirectory namesfilenames: List of file names
Implementation Details
_DATA_ROOT
importlib.resources to locate the package directory and resolves the parent directory.
Usage Examples
Loading Configuration Files
Loading Pickle Files
Finding All Resource Files
Working with Resource Directories
Combining with Other Utilities
Type Hints
The module uses proper type hints for better IDE support:Literaltypes for mode parameters@typing.overloadfor function overloadingFinalfor constantsIteratorfor generator returnsTextIOandBinaryIOfor file objects
Best Practices
- Use context managers when opening resources with
open_resource()to ensure proper file closure - Prefer
open_resource()over manually constructing paths withfilename()+open() - Cache resource paths if you need to access the same resource multiple times
- Be aware that
filename()may cause package unpacking, which can be slow on the first call - Use
get_resource_dir()when you need to work with multiple files in the same directory