Skip to content

Commit

Permalink
Make CentroidLayer inherit from Layer
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Nov 25, 2023
1 parent aad5eca commit 62dfd4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
upload:
environment: PyPI
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
name: Upload
needs:
- sdist
Expand All @@ -123,7 +124,6 @@ jobs:
name: dist
path: dist
- name: Publish distributions to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

## 🗺️ Overview

[`foldseek`] is a method developed by van Kempen *et al.*[\[1\]](#ref1) for the fast
and accurate search of protein structures. In order to search proteins structures
at a large scale, it first encodes the 3D structure into sequences over a
structural alphabet, 3di, which captures tertiary amino acid interactions.
[`foldseek`](https://github.com/steineggerlab/foldseek) is a method developed
by van Kempen *et al.*[\[1\]](#ref1) for the fast and accurate search of
protein structures. In order to search proteins structures at a large scale,
it first encodes the 3D structure into sequences over a structural alphabet,
3di, which captures tertiary amino acid interactions.

`mini3di` is a pure-Python package to encode 3D structures of proteins into
the 3di alphabet, using the trained weights from the `foldseek` VQ-VAE model.
Expand Down
6 changes: 3 additions & 3 deletions mini3di/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def __call__(self, X: ArrayNxM[numpy.floating]) -> ArrayNxM[numpy.floating]:
return out


class CentroidLayer:
class CentroidLayer(Layer):
def __init__(self, centroids: ArrayNxM[numpy.floating]) -> None:
self.centroids = centroids
self.centroids = numpy.asarray(centroids)
self.r2 = numpy.sum(self.centroids**2, axis=1).reshape(-1, 1).T
def __call__(self, X: ArrayNxM[numpy.floating]) -> ArrayN[numpy.uint8]:
# compute pairwise squared distance matrix
r1 = numpy.sum(X * X, 1).reshape(-1, 1)
r1 = numpy.sum(X * X, axis=1).reshape(-1, 1)
D = r1 - 2 * X @ self.centroids.T + self.r2
# find closest centroid
states = numpy.empty(D.shape[0], dtype=numpy.uint8)
Expand Down

0 comments on commit 62dfd4f

Please sign in to comment.