1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
"""Confidence score utilities for foldit-runner plugins.
This module provides utilities for extracting and normalizing confidence scores
from model outputs. pLDDT (predicted Local Distance Difference Test) values
are commonly on a 0-100 scale, which we normalize to 0-1 for consistency.
Usage:
from confidence_utils import plddt_to_confidence, extract_mean_plddt
# Convert pLDDT array to confidence
confidence = plddt_to_confidence(plddt_array)
# Extract from model output dict
confidence = extract_mean_plddt(output_dict)
"""
=
"""Convert pLDDT values to a confidence score in [0, 1].
Handles various input types:
- Scalar float/int
- Python list
- NumPy array
- Tensor-like objects with .mean() method (PyTorch, MLX)
Args:
plddt: pLDDT values (0-100 scale by default)
scale: Scale factor to divide by (default: 100.0 for pLDDT)
Returns:
float: Mean confidence score in [0, 1] range
Example:
# From tensor with .mean()
confidence = plddt_to_confidence(model_output["plddt"])
# From list
confidence = plddt_to_confidence([85.2, 90.1, 78.5])
# From scalar
confidence = plddt_to_confidence(87.5)
"""
return 0.0
# Handle tensor-like objects with .mean() method (PyTorch, MLX, etc.)
=
# Handle numpy arrays
=
# Handle lists/sequences
=
# Handle scalar
=
return 0.0
# Normalize to [0, 1]
= /
# Ensure result is a Python float (not numpy scalar)
return
"""Extract mean pLDDT confidence from a model output dictionary.
Tries to extract from mean_plddt first, falls back to computing mean
from per-residue pLDDT values.
Args:
output: Dictionary from model output
mean_key: Key for pre-computed mean pLDDT (default: "mean_plddt")
per_residue_key: Key for per-residue pLDDT array (default: "plddt")
default: Default value if neither key exists (default: 0.0)
Returns:
float: Mean confidence score in [0, 1] range
Example:
output = model(**inputs)
confidence = extract_mean_plddt(output)
"""
return
return
return