Skip to content

Commit 22295bc

Browse files
committed
add lru cache for get_residue_constants
1 parent 2aac06d commit 22295bc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

alphafold3_pytorch/common/biomolecule.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import annotations
12
"""A generic `Biomolecule` data structure for parsing macromolecular structures."""
23

34
import collections
45
import dataclasses
56
import functools
67
import io
78
import random
8-
from functools import partial
9+
from functools import partial, lru_cache
910
from types import ModuleType
1011
from beartype.typing import Any, Dict, List, Optional, Set, Tuple
1112

@@ -553,11 +554,14 @@ def create_spatial_crop_masks(
553554
return m_ks
554555

555556

557+
@lru_cache(maxsize = 512)
556558
@typecheck
557559
def get_residue_constants(
558-
res_chem_type: Optional[str] = None, res_chem_index: Optional[IntType] = None
560+
res_chem_type: str | None = None,
561+
res_chem_index: IntType | None = None
559562
) -> ModuleType:
560563
"""Returns the corresponding residue constants for a given residue chemical type."""
564+
561565
assert exists(res_chem_type) or exists(
562566
res_chem_index
563567
), "Either `res_chem_type` or `res_chem_index` must be provided."

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "alphafold3-pytorch"
3-
version = "0.5.43"
3+
version = "0.5.44"
44
description = "Alphafold 3 - Pytorch"
55
authors = [
66
{ name = "Phil Wang", email = "[email protected]" },

0 commit comments

Comments
 (0)