Skip to content

Commit

Permalink
Initial scaffolding and example
Browse files Browse the repository at this point in the history
  • Loading branch information
whitead committed Jul 11, 2024
1 parent 6aef325 commit 410b23d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/modal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Modal Deploy

on:
push:
branches:
- main
workflow_dispatch:

jobs:
modal_deply:
name: Deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip

- name: Install Modal
run: pip install -r dev-requirements.txt -r modal/requirements.txt

- name: Deploy job (wildcard for all files)
run: |
for file in $(find tools -type f -name 'modal.py'); do
modal deploy $file
done
env: # SEE: https://modal.com/docs/guide/environment_variables#runtime-environment-variables
MODAL_DEPLOY_TOKEN: ${{ secrets.MODAL_DEPLOY_TOKEN }}
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
MODAL_ENVIRONMENT: chemistry
91 changes: 91 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-yaml
exclude: "kubernetes.yaml$" # This line excludes kubernetes.yaml from being checked as it is WIP
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
exclude: .gitignore
- id: trailing-whitespace
exclude: .gitignore
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.3.2
hooks:
- id: prettier
- repo: https://github.com/google/yamlfmt
rev: v0.13.0
hooks:
- id: yamlfmt
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
exclude: poetry.lock
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: [".[toml]"]
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.1.0
hooks:
- id: sqlfluff-fix
- repo: https://github.com/hadolint/hadolint
rev: v2.13.0-beta
hooks:
- id: hadolint-docker
- repo: https://github.com/jsh9/markdown-toc-creator
rev: 0.0.6
hooks:
- id: markdown-toc-creator
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: check-mailmap
- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
hooks:
- id: poetry-check
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
hooks:
- id: mypy
additional_dependencies:
- types-requests
- types-fastapi
- repo: https://github.com/srstevenson/nb-clean
rev: 3.3.0
hooks:
- id: nb-clean
args: [--preserve-cell-outputs, --remove-empty-cells]
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject
additional_dependencies:
- "validate-pyproject-schema-store[all]>=2024.06.24" # Pin for Ruff's FURB154
26 changes: 26 additions & 0 deletions tools/cheminformatics/modal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from modal import App, web_endpoint
from modal import Image

rdkit_image = (
Image.debian_slim(python_version="3.12")
.pip_install("rdkit")
)
with rdkit_image.imports():
from rdkit import Chem, DataStructs
from rdkit.Chem import AllChem


app = App()

@app.function(image=rdkit_image)
@web_endpoint()
def tanimoto(s1: str, s2: str) -> float:
"""Calculate the Tanimoto similarity of two SMILES strings."""
try:
mol1 = Chem.MolFromSmiles(s1)
mol2 = Chem.MolFromSmiles(s2)
fp1 = AllChem.GetMorganFingerprintAsBitVect(mol1, 2, nBits=2048)
fp2 = AllChem.GetMorganFingerprintAsBitVect(mol2, 2, nBits=2048)
return DataStructs.TanimotoSimilarity(fp1, fp2)
except (TypeError, ValueError, AttributeError):
return "Error: Not a valid SMILES string"

0 comments on commit 410b23d

Please sign in to comment.