tm-short-align 2026.12.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. tm_short_align-2026.12.4.0/CMakeLists.txt +173 -0
  2. tm_short_align-2026.12.4.0/CMakePresets.json +48 -0
  3. tm_short_align-2026.12.4.0/PKG-INFO +111 -0
  4. tm_short_align-2026.12.4.0/README.md +92 -0
  5. tm_short_align-2026.12.4.0/cmake/remove_rpath.cmake +9 -0
  6. tm_short_align-2026.12.4.0/pyproject.toml +58 -0
  7. tm_short_align-2026.12.4.0/tm_short_align/__init__.py +16 -0
  8. tm_short_align-2026.12.4.0/tm_short_align/_common.py +139 -0
  9. tm_short_align-2026.12.4.0/tm_short_align/_native_src/common/legacy_kabsch_3x3.hpp +281 -0
  10. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/backend.cpp +349 -0
  11. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/batch/evaluate_four.hpp +291 -0
  12. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/batch/search_four.hpp +301 -0
  13. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/batch/single_pair.hpp +166 -0
  14. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/batch/transitions.hpp +235 -0
  15. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/batch/workspace.hpp +61 -0
  16. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/core_internal.hpp +19 -0
  17. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/kernel.cpp +284 -0
  18. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/kernel.hpp +72 -0
  19. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/score_mode.hpp +131 -0
  20. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/aligned_allocator.hpp +80 -0
  21. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/evaluate_pose.hpp +289 -0
  22. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/fixed_correspondence.hpp +298 -0
  23. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/rigid_fit.hpp +201 -0
  24. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/seed_poses.hpp +266 -0
  25. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search/support.hpp +236 -0
  26. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_score/search_options.hpp +25 -0
  27. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/batch.cpp +1028 -0
  28. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/bindings.cpp +99 -0
  29. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/batch.cpp +477 -0
  30. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/gapless.cpp +360 -0
  31. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/score_order.hpp +62 -0
  32. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/topology.cpp +137 -0
  33. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/topology.hpp +23 -0
  34. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/zero_gap.cpp +610 -0
  35. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/zero_gap.hpp +22 -0
  36. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/correspondence_dp.cpp +56 -0
  37. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/internal.hpp +279 -0
  38. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/distance_kernels.cpp +628 -0
  39. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/distance_kernels.hpp +40 -0
  40. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/evaluate_search_pose.hpp +81 -0
  41. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/fit.cpp +237 -0
  42. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/fit_bank.hpp +239 -0
  43. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/fit_mode.hpp +22 -0
  44. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/fragment_search.cpp +344 -0
  45. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/full_search.cpp +230 -0
  46. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/geometry.hpp +114 -0
  47. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/refine.cpp +420 -0
  48. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/search.hpp +43 -0
  49. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/settings.hpp +15 -0
  50. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/transitions.hpp +269 -0
  51. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/pose/workspace.hpp +258 -0
  52. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/refinement.cpp +626 -0
  53. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/seeds.cpp +184 -0
  54. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/common/token_bank_io.cpp +93 -0
  55. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/common/token_bank_io.hpp +42 -0
  56. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/core.cpp +110 -0
  57. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/internal.hpp +24 -0
  58. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/spectral/spectral_internal.hpp +18 -0
  59. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/spectral/spectral_layout.cpp +192 -0
  60. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/spectral/spectral_token_bank.cpp +120 -0
  61. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/spectral/types.hpp +42 -0
  62. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/tm_pose_search.cpp +88 -0
  63. tm_short_align-2026.12.4.0/tm_short_align/_native_src/oracle/tm_short_align/native/types.hpp +510 -0
  64. tm_short_align-2026.12.4.0/tm_short_align/alignment/__init__.py +3 -0
  65. tm_short_align-2026.12.4.0/tm_short_align/alignment/api.py +161 -0
  66. tm_short_align-2026.12.4.0/tm_short_align/alignment/approximate.py +250 -0
  67. tm_short_align-2026.12.4.0/tm_short_align/alignment/common.py +158 -0
  68. tm_short_align-2026.12.4.0/tm_short_align/coordinates.py +40 -0
  69. tm_short_align-2026.12.4.0/tm_short_align/coverage.py +87 -0
  70. tm_short_align-2026.12.4.0/tm_short_align/diagnostics.py +35 -0
  71. tm_short_align-2026.12.4.0/tm_short_align/dtypes.py +26 -0
  72. tm_short_align-2026.12.4.0/tm_short_align/metrics/__init__.py +9 -0
  73. tm_short_align-2026.12.4.0/tm_short_align/metrics/api.py +257 -0
  74. tm_short_align-2026.12.4.0/tm_short_align/metrics/backend.py +71 -0
  75. tm_short_align-2026.12.4.0/tm_short_align/tm_score/__init__.py +3 -0
  76. tm_short_align-2026.12.4.0/tm_short_align/tm_score/backend.py +137 -0
  77. tm_short_align-2026.12.4.0/tm_short_align/tm_score/core.py +107 -0
  78. tm_short_align-2026.12.4.0/tm_short_align/tm_short_align/__init__.py +3 -0
  79. tm_short_align-2026.12.4.0/tm_short_align/tm_short_align/backend.py +488 -0
  80. tm_short_align-2026.12.4.0/tm_short_align/tm_short_align/models.py +126 -0
@@ -0,0 +1,173 @@
1
+ cmake_minimum_required(VERSION 3.26)
2
+
3
+ project(tm_short_align LANGUAGES CXX)
4
+
5
+ set(PYBIND11_FINDPYTHON ON)
6
+
7
+ option(TM_SHORT_ALIGN_ENABLE_IPO "Enable interprocedural optimization" OFF)
8
+ set(
9
+ TM_SHORT_ALIGN_OPTIMIZATION_LEVEL
10
+ ""
11
+ CACHE STRING
12
+ "Override the compiler optimization level (0, 1, 2, 3, s, or fast)"
13
+ )
14
+ set_property(
15
+ CACHE TM_SHORT_ALIGN_OPTIMIZATION_LEVEL
16
+ PROPERTY STRINGS "" 0 1 2 3 s fast
17
+ )
18
+
19
+ set(Python_FIND_STRATEGY LOCATION)
20
+ set(Python_FIND_VIRTUALENV FIRST)
21
+ find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
22
+
23
+ set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
24
+ find_package(pybind11 CONFIG REQUIRED)
25
+ find_package(OpenMP REQUIRED COMPONENTS CXX)
26
+
27
+ message(STATUS "Python executable: ${Python_EXECUTABLE}")
28
+
29
+ # Conda and other toolchains may inject build-host RPATH entries through
30
+ # LDFLAGS. Python extension wheels must not retain those absolute paths.
31
+ function(tm_short_align_remove_inherited_rpath variable_name)
32
+ set(value "${${variable_name}}")
33
+ string(
34
+ REGEX REPLACE
35
+ "(^|[ \t])-Wl,-rpath(,|=)[^ \t]+"
36
+ "\\1"
37
+ value
38
+ "${value}"
39
+ )
40
+ string(STRIP "${value}" value)
41
+ set("${variable_name}" "${value}" PARENT_SCOPE)
42
+ endfunction()
43
+
44
+ tm_short_align_remove_inherited_rpath(CMAKE_MODULE_LINKER_FLAGS)
45
+
46
+ set(
47
+ TM_SHORT_ALIGN_NATIVE_ROOT
48
+ "${CMAKE_CURRENT_SOURCE_DIR}/tm_short_align/_native_src"
49
+ )
50
+
51
+ if(NOT CMAKE_CXX_COMPILER_LAUNCHER)
52
+ find_program(TM_SHORT_ALIGN_CCACHE_EXECUTABLE ccache)
53
+ if(TM_SHORT_ALIGN_CCACHE_EXECUTABLE)
54
+ set(
55
+ CMAKE_CXX_COMPILER_LAUNCHER
56
+ "${TM_SHORT_ALIGN_CCACHE_EXECUTABLE}"
57
+ )
58
+ endif()
59
+ endif()
60
+
61
+ if(TM_SHORT_ALIGN_ENABLE_IPO)
62
+ include(CheckIPOSupported)
63
+ check_ipo_supported(
64
+ RESULT TM_SHORT_ALIGN_IPO_SUPPORTED
65
+ OUTPUT TM_SHORT_ALIGN_IPO_ERROR
66
+ )
67
+ if(NOT TM_SHORT_ALIGN_IPO_SUPPORTED)
68
+ message(FATAL_ERROR "IPO is not supported: ${TM_SHORT_ALIGN_IPO_ERROR}")
69
+ endif()
70
+ endif()
71
+
72
+ function(tm_short_align_configure_target target_name)
73
+ target_compile_features("${target_name}" PRIVATE cxx_std_20)
74
+ set_target_properties(
75
+ "${target_name}"
76
+ PROPERTIES
77
+ CXX_EXTENSIONS OFF
78
+ INTERPROCEDURAL_OPTIMIZATION "${TM_SHORT_ALIGN_ENABLE_IPO}"
79
+ )
80
+ target_include_directories(
81
+ "${target_name}"
82
+ PRIVATE "${TM_SHORT_ALIGN_NATIVE_ROOT}"
83
+ )
84
+ target_link_libraries("${target_name}" PRIVATE OpenMP::OpenMP_CXX)
85
+
86
+ if(TM_SHORT_ALIGN_OPTIMIZATION_LEVEL)
87
+ if(
88
+ NOT TM_SHORT_ALIGN_OPTIMIZATION_LEVEL
89
+ MATCHES "^(0|1|2|3|s|fast)$"
90
+ )
91
+ message(
92
+ FATAL_ERROR
93
+ "TM_SHORT_ALIGN_OPTIMIZATION_LEVEL must be "
94
+ "0, 1, 2, 3, s, or fast"
95
+ )
96
+ endif()
97
+ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
98
+ target_compile_options(
99
+ "${target_name}"
100
+ PRIVATE "-O${TM_SHORT_ALIGN_OPTIMIZATION_LEVEL}"
101
+ )
102
+ endif()
103
+ endif()
104
+ endfunction()
105
+
106
+ function(tm_short_align_add_module target_name python_module)
107
+ string(REPLACE "." ";" module_parts "${python_module}")
108
+ list(POP_BACK module_parts output_name)
109
+ string(JOIN "/" install_directory ${module_parts})
110
+
111
+ pybind11_add_module("${target_name}" MODULE NO_EXTRAS ${ARGN})
112
+ set_target_properties(
113
+ "${target_name}"
114
+ PROPERTIES
115
+ OUTPUT_NAME "${output_name}"
116
+ SKIP_BUILD_RPATH TRUE
117
+ BUILD_WITH_INSTALL_RPATH FALSE
118
+ INSTALL_RPATH ""
119
+ INSTALL_RPATH_USE_LINK_PATH FALSE
120
+ LIBRARY_OUTPUT_DIRECTORY
121
+ "${CMAKE_CURRENT_BINARY_DIR}/python/${install_directory}"
122
+ RUNTIME_OUTPUT_DIRECTORY
123
+ "${CMAKE_CURRENT_BINARY_DIR}/python/${install_directory}"
124
+ )
125
+ tm_short_align_configure_target("${target_name}")
126
+ if(UNIX AND NOT APPLE)
127
+ add_custom_command(
128
+ TARGET "${target_name}"
129
+ POST_BUILD
130
+ COMMAND
131
+ "${CMAKE_COMMAND}"
132
+ "-Dextension_file=$<TARGET_FILE:${target_name}>"
133
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/remove_rpath.cmake"
134
+ VERBATIM
135
+ )
136
+ endif()
137
+ install(
138
+ TARGETS "${target_name}"
139
+ LIBRARY DESTINATION "${install_directory}" COMPONENT python
140
+ RUNTIME DESTINATION "${install_directory}" COMPONENT python
141
+ )
142
+ endfunction()
143
+
144
+ tm_short_align_add_module(
145
+ tm_short_align_native_tm_score
146
+ tm_short_align.tm_score._native
147
+ tm_short_align/_native_src/oracle/tm_score/backend.cpp
148
+ tm_short_align/_native_src/oracle/tm_score/kernel.cpp
149
+ )
150
+
151
+ tm_short_align_add_module(
152
+ tm_short_align_native_alignment
153
+ tm_short_align.tm_short_align._native
154
+ tm_short_align/_native_src/oracle/tm_short_align/native/correspondence_dp.cpp
155
+ tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/batch.cpp
156
+ tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/gapless.cpp
157
+ tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/topology.cpp
158
+ tm_short_align/_native_src/oracle/tm_short_align/native/correspondence/zero_gap.cpp
159
+ tm_short_align/_native_src/oracle/tm_short_align/native/tm_pose_search.cpp
160
+ tm_short_align/_native_src/oracle/tm_short_align/native/pose/distance_kernels.cpp
161
+ tm_short_align/_native_src/oracle/tm_short_align/native/pose/fit.cpp
162
+ tm_short_align/_native_src/oracle/tm_short_align/native/pose/fragment_search.cpp
163
+ tm_short_align/_native_src/oracle/tm_short_align/native/pose/full_search.cpp
164
+ tm_short_align/_native_src/oracle/tm_short_align/native/pose/refine.cpp
165
+ tm_short_align/_native_src/oracle/tm_short_align/native/seeds.cpp
166
+ tm_short_align/_native_src/oracle/tm_short_align/native/refinement.cpp
167
+ tm_short_align/_native_src/oracle/tm_short_align/native/batch.cpp
168
+ tm_short_align/_native_src/oracle/tm_short_align/native/spectral/core.cpp
169
+ tm_short_align/_native_src/oracle/tm_short_align/native/spectral/common/token_bank_io.cpp
170
+ tm_short_align/_native_src/oracle/tm_short_align/native/spectral/spectral/spectral_layout.cpp
171
+ tm_short_align/_native_src/oracle/tm_short_align/native/spectral/spectral/spectral_token_bank.cpp
172
+ tm_short_align/_native_src/oracle/tm_short_align/native/bindings.cpp
173
+ )
@@ -0,0 +1,48 @@
1
+ {
2
+ "version": 6,
3
+ "cmakeMinimumRequired": {
4
+ "major": 3,
5
+ "minor": 26,
6
+ "patch": 0
7
+ },
8
+ "configurePresets": [
9
+ {
10
+ "name": "base",
11
+ "hidden": true,
12
+ "generator": "Ninja",
13
+ "binaryDir": "${sourceDir}/build/cmake-${presetName}",
14
+ "cacheVariables": {
15
+ "CMAKE_EXPORT_COMPILE_COMMANDS": true,
16
+ "TM_SHORT_ALIGN_ENABLE_IPO": false
17
+ }
18
+ },
19
+ {
20
+ "name": "development",
21
+ "displayName": "Development (fast compile)",
22
+ "inherits": "base",
23
+ "cacheVariables": {
24
+ "CMAKE_BUILD_TYPE": "RelWithDebInfo",
25
+ "TM_SHORT_ALIGN_OPTIMIZATION_LEVEL": "1"
26
+ }
27
+ },
28
+ {
29
+ "name": "release",
30
+ "displayName": "Release",
31
+ "inherits": "base",
32
+ "cacheVariables": {
33
+ "CMAKE_BUILD_TYPE": "Release",
34
+ "TM_SHORT_ALIGN_OPTIMIZATION_LEVEL": "3"
35
+ }
36
+ }
37
+ ],
38
+ "buildPresets": [
39
+ {
40
+ "name": "development",
41
+ "configurePreset": "development"
42
+ },
43
+ {
44
+ "name": "release",
45
+ "configurePreset": "release"
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.2
2
+ Name: tm-short-align
3
+ Version: 2026.12.4.0
4
+ Summary: TM-score, TM-short, and short-chain TM alignment
5
+ Keywords: structural-biology,tm-score,protein-alignment,peptide-alignment
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Science/Research
8
+ Classifier: Programming Language :: C++
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Scientific/Engineering
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: numpy>=1.24
18
+ Description-Content-Type: text/markdown
19
+
20
+ # TM-short-align
21
+
22
+ Standalone TM-score, TM-short, and short-chain alignment package. Its public
23
+ API follows the same structure as `nRMSD-short-align`: fixed-correspondence
24
+ metrics and correspondence alignment are separate top-level operations.
25
+ `align()` handles single, dense-batch, and heterogeneous-batch inputs;
26
+ `align_pairs()` handles sparse indexed pair batches.
27
+
28
+ ```python
29
+ from tm_short_align import align, align_pairs, short_score, tm_score
30
+
31
+ values = tm_score(
32
+ left,
33
+ right,
34
+ metric=("tm_score", "tm_short"),
35
+ )
36
+
37
+ result = align(
38
+ left,
39
+ right,
40
+ correspondence="gapless",
41
+ solver="approximate",
42
+ metric="tm_short",
43
+ coverage=0.8,
44
+ detail=True,
45
+ )
46
+
47
+ sparse_scores = align_pairs(
48
+ coordinates,
49
+ offsets,
50
+ pairs,
51
+ correspondence="ordered",
52
+ num_threads=0,
53
+ )
54
+
55
+ mapped = short_score(raw_tm, matched_length)
56
+ ```
57
+
58
+ The stable package-root API is:
59
+
60
+ ```python
61
+ from tm_short_align import (
62
+ align,
63
+ align_pairs,
64
+ backend_info,
65
+ short_score,
66
+ tm_score,
67
+ )
68
+ ```
69
+
70
+ - `tm_score()` evaluates an existing equal-length correspondence.
71
+ - `align()` optimizes an ordered or gapless correspondence.
72
+ - `align_pairs()` aligns sparse indexed node pairs while reusing each
73
+ referenced node's alignment features.
74
+ - `short_score()` maps a fixed-`d0` raw TM score to production TM-short.
75
+ - `backend_info()` reports the fixed-correspondence native backend.
76
+
77
+ `tm_score()` and `align()` accept a single pair, a dense batch, or
78
+ heterogeneous coordinate lists. `align_pairs()` instead accepts flat
79
+ `coordinates`, node `offsets`, and an integer `(pair_count, 2)` pair array.
80
+ Referenced nodes are deduplicated and grouped by length, so each node's
81
+ SeedBank is built once and reused by every incident pair. Native indexed-pair
82
+ batches access unique coordinates and SeedBanks through node indices without
83
+ materializing pair-sized feature copies. Pair groups are then dispatched to
84
+ native batches and restored to input order. OpenMP parallelism
85
+ is across nodes during feature preparation and across pairs during alignment;
86
+ one pair is not internally parallelized. `num_threads=0` selects up to eight
87
+ threads automatically. Alignment scores, poses, RMSD values, correspondence
88
+ search, and detailed per-match distances are produced by the C++ backend;
89
+ Python does not recompute detail distances with NumPy. Both native extensions
90
+ are mandatory; missing, incomplete, or stale extensions fail during import
91
+ instead of selecting a Python fallback.
92
+
93
+ Production algorithm schedules are intentionally not exposed as public API.
94
+ There is no legacy compatibility layer: callers must use the package-root
95
+ functions above. See `docs/api.md` for the complete contract.
96
+
97
+ Coordinates and reusable feature buffers use `float32`. Numerically sensitive
98
+ accumulation, poses, distances, RMSD values, and final scores use `float64`.
99
+
100
+ The package uses scikit-build-core and CMake to build both mandatory pybind11
101
+ extensions. For local development, install or refresh the redirect editable
102
+ build with:
103
+
104
+ ```bash
105
+ python -m pip install --no-build-isolation -e .
106
+ ```
107
+
108
+ The persistent build directory makes subsequent native rebuilds incremental.
109
+ Build release artifacts with `python -m build`; this creates the wheel from the
110
+ generated sdist. The Python wrappers reject incompatible native binaries
111
+ through internal ABI guards.
@@ -0,0 +1,92 @@
1
+ # TM-short-align
2
+
3
+ Standalone TM-score, TM-short, and short-chain alignment package. Its public
4
+ API follows the same structure as `nRMSD-short-align`: fixed-correspondence
5
+ metrics and correspondence alignment are separate top-level operations.
6
+ `align()` handles single, dense-batch, and heterogeneous-batch inputs;
7
+ `align_pairs()` handles sparse indexed pair batches.
8
+
9
+ ```python
10
+ from tm_short_align import align, align_pairs, short_score, tm_score
11
+
12
+ values = tm_score(
13
+ left,
14
+ right,
15
+ metric=("tm_score", "tm_short"),
16
+ )
17
+
18
+ result = align(
19
+ left,
20
+ right,
21
+ correspondence="gapless",
22
+ solver="approximate",
23
+ metric="tm_short",
24
+ coverage=0.8,
25
+ detail=True,
26
+ )
27
+
28
+ sparse_scores = align_pairs(
29
+ coordinates,
30
+ offsets,
31
+ pairs,
32
+ correspondence="ordered",
33
+ num_threads=0,
34
+ )
35
+
36
+ mapped = short_score(raw_tm, matched_length)
37
+ ```
38
+
39
+ The stable package-root API is:
40
+
41
+ ```python
42
+ from tm_short_align import (
43
+ align,
44
+ align_pairs,
45
+ backend_info,
46
+ short_score,
47
+ tm_score,
48
+ )
49
+ ```
50
+
51
+ - `tm_score()` evaluates an existing equal-length correspondence.
52
+ - `align()` optimizes an ordered or gapless correspondence.
53
+ - `align_pairs()` aligns sparse indexed node pairs while reusing each
54
+ referenced node's alignment features.
55
+ - `short_score()` maps a fixed-`d0` raw TM score to production TM-short.
56
+ - `backend_info()` reports the fixed-correspondence native backend.
57
+
58
+ `tm_score()` and `align()` accept a single pair, a dense batch, or
59
+ heterogeneous coordinate lists. `align_pairs()` instead accepts flat
60
+ `coordinates`, node `offsets`, and an integer `(pair_count, 2)` pair array.
61
+ Referenced nodes are deduplicated and grouped by length, so each node's
62
+ SeedBank is built once and reused by every incident pair. Native indexed-pair
63
+ batches access unique coordinates and SeedBanks through node indices without
64
+ materializing pair-sized feature copies. Pair groups are then dispatched to
65
+ native batches and restored to input order. OpenMP parallelism
66
+ is across nodes during feature preparation and across pairs during alignment;
67
+ one pair is not internally parallelized. `num_threads=0` selects up to eight
68
+ threads automatically. Alignment scores, poses, RMSD values, correspondence
69
+ search, and detailed per-match distances are produced by the C++ backend;
70
+ Python does not recompute detail distances with NumPy. Both native extensions
71
+ are mandatory; missing, incomplete, or stale extensions fail during import
72
+ instead of selecting a Python fallback.
73
+
74
+ Production algorithm schedules are intentionally not exposed as public API.
75
+ There is no legacy compatibility layer: callers must use the package-root
76
+ functions above. See `docs/api.md` for the complete contract.
77
+
78
+ Coordinates and reusable feature buffers use `float32`. Numerically sensitive
79
+ accumulation, poses, distances, RMSD values, and final scores use `float64`.
80
+
81
+ The package uses scikit-build-core and CMake to build both mandatory pybind11
82
+ extensions. For local development, install or refresh the redirect editable
83
+ build with:
84
+
85
+ ```bash
86
+ python -m pip install --no-build-isolation -e .
87
+ ```
88
+
89
+ The persistent build directory makes subsequent native rebuilds incremental.
90
+ Build release artifacts with `python -m build`; this creates the wheel from the
91
+ generated sdist. The Python wrappers reject incompatible native binaries
92
+ through internal ABI guards.
@@ -0,0 +1,9 @@
1
+ if(NOT DEFINED extension_file OR extension_file STREQUAL "")
2
+ message(FATAL_ERROR "extension_file is required")
3
+ endif()
4
+
5
+ if(NOT EXISTS "${extension_file}")
6
+ message(FATAL_ERROR "extension file does not exist: ${extension_file}")
7
+ endif()
8
+
9
+ file(RPATH_REMOVE FILE "${extension_file}")
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = [
3
+ 'scikit-build-core>=1.0',
4
+ 'pybind11>=2.10',
5
+ 'setuptools-scm>=9.2',
6
+ ]
7
+ build-backend = 'scikit_build_core.build'
8
+
9
+ [project]
10
+ name = 'tm-short-align'
11
+ dynamic = ['version']
12
+ description = 'TM-score, TM-short, and short-chain TM alignment'
13
+ readme = 'README.md'
14
+ requires-python = '>=3.10'
15
+ keywords = ['structural-biology', 'tm-score', 'protein-alignment', 'peptide-alignment']
16
+ classifiers = [
17
+ 'Development Status :: 3 - Alpha',
18
+ 'Intended Audience :: Science/Research',
19
+ 'Programming Language :: C++',
20
+ 'Programming Language :: Python :: 3',
21
+ 'Programming Language :: Python :: 3.10',
22
+ 'Programming Language :: Python :: 3.11',
23
+ 'Programming Language :: Python :: 3.12',
24
+ 'Programming Language :: Python :: 3.13',
25
+ 'Programming Language :: Python :: 3.14',
26
+ 'Topic :: Scientific/Engineering',
27
+ ]
28
+ dependencies = ['numpy>=1.24']
29
+
30
+ [[tool.dynamic-metadata]]
31
+ provider = 'scikit_build_core.metadata.setuptools_scm'
32
+
33
+ [tool.setuptools_scm]
34
+ version_scheme = 'calver-by-date'
35
+ local_scheme = 'no-local-version'
36
+ tag_regex = '^v(?P<version>\d{4}\.\d{1,2}\.\d{1,2}\.\d+)$'
37
+
38
+ [tool.scikit-build]
39
+ minimum-version = 'build-system.requires'
40
+ build-dir = 'build/scikit/{wheel_tag}/{build_type}'
41
+ wheel.packages = ['tm_short_align']
42
+ wheel.exclude = ['tm_short_align/_native_src/**']
43
+ cmake.build-type = 'Release'
44
+ sdist.inclusion-mode = 'explicit'
45
+ sdist.include = [
46
+ 'pyproject.toml',
47
+ 'CMakeLists.txt',
48
+ 'CMakePresets.json',
49
+ 'README.md',
50
+ 'cmake/**',
51
+ 'tm_short_align/**',
52
+ ]
53
+ sdist.exclude = [
54
+ 'build/**',
55
+ 'tm_short_align/**/*.so',
56
+ 'tm_short_align/**/*.pyd',
57
+ 'tm_short_align/**/__pycache__/**',
58
+ ]
@@ -0,0 +1,16 @@
1
+ """TM-score, TM-short, and configurable short-chain alignment."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .alignment.api import align, align_pairs
6
+ from .metrics.api import backend_info, tm_score
7
+ from .tm_score.core import short_score
8
+
9
+
10
+ __all__ = [
11
+ "align",
12
+ "align_pairs",
13
+ "backend_info",
14
+ "short_score",
15
+ "tm_score",
16
+ ]
@@ -0,0 +1,139 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ import numpy as np
6
+
7
+ from .coordinates import as_batch_coords
8
+
9
+
10
+ def _index_array(values: np.ndarray, name: str) -> np.ndarray:
11
+ array = np.asarray(values)
12
+ if array.dtype.kind not in "iu":
13
+ raise TypeError(f"{name} must contain integers")
14
+ if (
15
+ array.dtype.kind == "u"
16
+ and array.size
17
+ and int(array.max()) > np.iinfo(np.int64).max
18
+ ):
19
+ raise ValueError(f"{name} contains an index outside the int64 range")
20
+ return np.require(array, dtype=np.int64, requirements=["C", "A"])
21
+
22
+
23
+ def coordinate_lists(
24
+ coords_a: np.ndarray | list[np.ndarray],
25
+ coords_b: np.ndarray | list[np.ndarray],
26
+ ) -> tuple[bool, list[np.ndarray], list[np.ndarray]]:
27
+ """Normalize single, dense-batch, or heterogeneous coordinate inputs."""
28
+
29
+ single = (
30
+ isinstance(coords_a, np.ndarray)
31
+ and isinstance(coords_b, np.ndarray)
32
+ and coords_a.ndim == 2
33
+ and coords_b.ndim == 2
34
+ )
35
+ first = as_batch_coords([coords_a] if single else coords_a)
36
+ second = as_batch_coords([coords_b] if single else coords_b)
37
+ if len(first) != len(second):
38
+ raise ValueError(f"batch size mismatch: {len(first)} vs {len(second)}")
39
+ for name, batch in (("coords_a", first), ("coords_b", second)):
40
+ for index, coords in enumerate(batch):
41
+ if not np.isfinite(coords).all():
42
+ raise ValueError(f"{name}[{index}] contains non-finite coordinates")
43
+ return single, first, second
44
+
45
+
46
+ def group_pair_indices(
47
+ first: list[np.ndarray],
48
+ second: list[np.ndarray],
49
+ ) -> dict[tuple[int, int], list[int]]:
50
+ groups: dict[tuple[int, int], list[int]] = {}
51
+ for index, (coords_a, coords_b) in enumerate(zip(first, second, strict=True)):
52
+ key = (int(coords_a.shape[0]), int(coords_b.shape[0]))
53
+ groups.setdefault(key, []).append(index)
54
+ return groups
55
+
56
+
57
+ def sparse_coordinate_nodes(
58
+ coordinates: np.ndarray,
59
+ offsets: np.ndarray,
60
+ pairs: np.ndarray,
61
+ ) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
62
+ """Validate flat sparse coordinates and indexed node pairs."""
63
+
64
+ values = np.asarray(coordinates)
65
+ if not np.issubdtype(values.dtype, np.number) or np.iscomplexobj(values):
66
+ raise TypeError("coordinates must contain real numbers")
67
+ values = np.require(values, dtype=np.float32, requirements=["C", "A"])
68
+ if values.ndim != 2 or values.shape[1] != 3:
69
+ raise ValueError(
70
+ "coordinates must have shape (total_points, 3), "
71
+ f"got {values.shape}"
72
+ )
73
+ if not np.isfinite(values).all():
74
+ raise ValueError("coordinates contains non-finite values")
75
+
76
+ boundaries = _index_array(offsets, "offsets")
77
+ if boundaries.ndim != 1 or boundaries.size < 1:
78
+ raise ValueError("offsets must have shape (node_count + 1,)")
79
+ if boundaries[0] != 0 or boundaries[-1] != values.shape[0]:
80
+ raise ValueError("offsets must span the coordinate array")
81
+ lengths = np.diff(boundaries)
82
+ if np.any(lengths <= 0):
83
+ raise ValueError(
84
+ "offsets must describe nonempty nodes in increasing order"
85
+ )
86
+
87
+ pair_indices = _index_array(pairs, "pairs")
88
+ if pair_indices.ndim != 2 or pair_indices.shape[1] != 2:
89
+ raise ValueError("pairs must have shape (pair_count, 2)")
90
+ node_count = boundaries.size - 1
91
+ if pair_indices.size:
92
+ if int(pair_indices.min()) < 0 or int(pair_indices.max()) >= node_count:
93
+ raise ValueError("pairs contains an out-of-range node index")
94
+ return values, boundaries, pair_indices, lengths
95
+
96
+
97
+ def stack_if_uniform(values: list[np.ndarray]) -> list[np.ndarray] | np.ndarray:
98
+ if not values:
99
+ return values
100
+ shape = values[0].shape
101
+ if all(value.shape == shape for value in values):
102
+ return np.stack(values)
103
+ return values
104
+
105
+
106
+ def pack_values(values: list[Any]) -> Any:
107
+ """Pack homogeneous scalars/arrays while preserving heterogeneous arrays."""
108
+
109
+ if not values:
110
+ return np.empty(0)
111
+ if all(np.ndim(value) == 0 for value in values):
112
+ return np.asarray(values)
113
+ arrays = [np.asarray(value) for value in values]
114
+ return stack_if_uniform(arrays)
115
+
116
+
117
+ def unwrap_detail(detail: dict[str, Any]) -> dict[str, Any]:
118
+ output: dict[str, Any] = {}
119
+ for name, value in detail.items():
120
+ if isinstance(value, dict):
121
+ output[name] = unwrap_detail(value)
122
+ elif isinstance(value, np.ndarray) and value.ndim >= 1:
123
+ item = value[0]
124
+ output[name] = item.item() if isinstance(item, np.generic) else item
125
+ elif isinstance(value, list):
126
+ output[name] = value[0]
127
+ else:
128
+ output[name] = value
129
+ return output
130
+
131
+
132
+ __all__ = [
133
+ "coordinate_lists",
134
+ "group_pair_indices",
135
+ "pack_values",
136
+ "sparse_coordinate_nodes",
137
+ "stack_if_uniform",
138
+ "unwrap_detail",
139
+ ]