Skip to main content

Overview

The resources 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

The root directory path for AlphaFold 3 data resources. This is resolved at import time and points to the parent directory of the alphafold3.common module. Example:

Functions

filename

Returns the absolute path to an external resource.
str | os.PathLike[str]
required
The name of the resource corresponding to its path relative to the root of the repository
Returns: Absolute path as a string (POSIX format) Note: This function causes package file unpacking when used with packaged resources (e.g., .par files), which might be unfriendly on diskless machines. Example:

open_resource

Returns an open file object for the named 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 (returns TextIO)
  • 'rb': Read binary mode (returns BinaryIO)
Returns: An open file object (TextIO or BinaryIO depending on mode) Example:

get_resource_dir

Returns the full path to a resource directory.
str | os.PathLike[str]
required
The relative path to the directory from the repository root
Returns: An os.PathLike[str] object representing the full directory path Example:

walk

Walks the directory tree of resources similar to os.walk().
str
required
The relative path to walk from the repository root
Returns: An iterator yielding tuples of (dirpath, dirnames, filenames) for each directory in the tree
  • dirpath: String path to the directory
  • dirnames: List of subdirectory names
  • filenames: List of file names
Example:

Implementation Details

_DATA_ROOT

Internal constant that stores the resolved root path for AlphaFold 3 data. Uses 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:
  • Literal types for mode parameters
  • @typing.overload for function overloading
  • Final for constants
  • Iterator for generator returns
  • TextIO and BinaryIO for file objects

Best Practices

  1. Use context managers when opening resources with open_resource() to ensure proper file closure
  2. Prefer open_resource() over manually constructing paths with filename() + open()
  3. Cache resource paths if you need to access the same resource multiple times
  4. Be aware that filename() may cause package unpacking, which can be slow on the first call
  5. Use get_resource_dir() when you need to work with multiple files in the same directory