Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions ipd/sym/sym_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ def get_sym_frames(symid, opt, cenvec):
frames, _ = get_nneigh(allframes, min(len(allframes), opt.max_nsub))
return allframes, frames

def sym_redock(xyz, Lasu, frames, opt, **_):
def sym_redock(xyz, Lasu, frames, opt, mask=None, **_):
Copy link

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a detailed docstring for the 'mask' parameter in sym_redock (and in clash_error_comp) that specifies the expected type (1D th.Tensor or list), shape, and intended behavior, to improve clarity and maintainability.

Copilot uses AI. Check for mistakes.
# resolve clashes in placed subunits
# could probably use this to optimize the radius as well
def clash_error_comp(R0, T0, xyz, fit_tscale):
# mask: 1d th.Tensor or list
def clash_error_comp(R0, T0, xyz, fit_tscale, mask=None):
xyz0 = xyz[:Lasu]
xyz0_corr = xyz0.reshape(-1, 3) @ R0.T
xyz0_corr = xyz0_corr.reshape(xyz0.shape) + fit_tscale*T0
Expand All @@ -35,9 +36,18 @@ def clash_error_comp(R0, T0, xyz, fit_tscale):
Xsymmall = Xsymmall[:, 0, :]
dsymm = th.cdist(Xsymmall, Xsymmall, p=2)
dsymm_2 = dsymm.clone()
if mask is not None:
mask0 = mask[:Lasu.item()] if isinstance(Lasu, th.Tensor) else th.tensor(mask[:Lasu])
Copy link

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Ensure that 'Lasu' is always provided as an integer value (or explicitly converted) since it is used both for slicing and for controlling loop iterations; consider renaming or converting it to clearly indicate its role as a count of residues.

Copilot uses AI. Check for mistakes.
mask_dsymm = ~(mask0[None, :].expand(Lasu, Lasu))
mask_dsymm = mask_dsymm | mask_dsymm.T
# dsymm_2 = dsymm.clone().fill_diagonal_(9999) # avoid in-place operation
for i in range(0, len(Xsymmall), Lasu):
dsymm_2[i:i + Lasu, i:i + Lasu] = 9999
for i in range(0, len(Xsymmall), Lasu): # loop over rows
dsymm_2[i:i + Lasu, i:i + Lasu] = 9999 # masking intra-contact
if mask is not None:
for j in range(0, len(Xsymmall), Lasu): # loop over cols
if j == i: continue
# masking inter-contacts involving masked residues
dsymm_2[i:i + Lasu, j:j + Lasu][mask_dsymm] = 9999
clash = th.clamp(opt.fit_wclash - dsymm_2, min=0)
loss = th.sum(clash) / Lasu
return loss
Expand All @@ -54,7 +64,7 @@ def Q2R(Q):

def closure():
lbfgs.zero_grad()
loss = clash_error_comp(Q2R(Q0), T0, xyz, opt.fit_tscale)
loss = clash_error_comp(Q2R(Q0), T0, xyz, opt.fit_tscale, mask=mask)
loss.backward() #retain_graph=True)
return loss

Expand Down
17 changes: 17 additions & 0 deletions lib/evn/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BasedOnStyle: LLVM
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 90
AllowShortIfStatementsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AllowShortBlocksOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortLambdasOnASingleLine: true
AllowShortLoopsOnASingleLine: true
64 changes: 64 additions & 0 deletions lib/evn/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## 🚀 Summary

<!--
Explain what this PR does and why it matters.
Keep it short and focused.
-->

Closes #...

---

## 🔧 Type of change

<!-- Check the relevant boxes and update your PR title to follow Conventional Commits -->

- [ ] **feat**: A new feature
- [ ] **fix**: A bug fix
- [ ] **docs**: Documentation only changes
- [ ] **style**: Formatting, missing semi colons, etc
- [ ] **refactor**: Refactoring (no functional changes)
- [ ] **perf**: A code change that improves performance
- [ ] **test**: Adding or fixing tests
- [ ] **chore**: Maintenance and tooling
- [ ] **ci**: Changes to CI/CD configuration

---

## ✅ Checklist

- [ ] PR title uses [Conventional Commits](https://www.conventionalcommits.org/)
- [ ] Tests added or updated (if applicable)
- [ ] Documentation updated (if applicable)
- [ ] I have verified this builds and works as intended
- [ ] I’m ready for review!

---

## 🧪 Testing

<!--
Explain how you tested your changes.
List commands, CI results, or screenshots if helpful.
-->

---

## 📦 Release impact

> semantic-release will determine version bump automatically.

- [ ] BREAKING CHANGE (explain in footer below)
- [ ] This should trigger a **patch** release
- [ ] This should trigger a **minor** release
- [ ] This is internal only — no release needed

If this is a breaking change, explain why below.

---

## 📓 Notes for reviewer

<!--
Optional: anything you'd like the reviewer to focus on, be aware of, or follow up later.
-->
102 changes: 102 additions & 0 deletions lib/evn/.github/workflows/build_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build and upload to PyPI

on:
workflow_dispatch:
pull_request:
push:
# branches:
# - main
release:
types:
- published

jobs:
build_wheels:
name: Build wheels for ${{ matrix.os }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
os: [ linux-intel, linux-arm, macOS-intel, macOS-arm ]
# os: [ linux-intel, linux-arm, windows, macOS-intel, macOS-arm ]
include:
- archs: auto
platform: auto
- os: linux-intel
runs-on: ubuntu-latest
- os: linux-arm
runs-on: ubuntu-24.04-arm
# - os: windows
# runs-on: windows-latest
- os: macos-intel
# macos-13 was the last x86_64 runner
runs-on: macos-13
- os: macos-arm
# macos-14+ (including latest) are ARM64 runners
runs-on: macos-latest
archs: auto,universal2

steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.23.1
env:
CIBW_PLATFORM: ${{ matrix.platform }}
CIBW_ARCHS: ${{ matrix.archs }}
# Can also be configured directly, using `with:`
# with:
# package-dir: .
# output-dir: wheelhouse
# config-file: "{package}/pyproject.toml"

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.6.8"
enable-cache: true

- name: Test wheels
run: |
echo "Testing wheels with nox"
uv run --extra dev nox

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
# if: github.event_name == 'release' && github.event.action == 'published'
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
# with:
# To test: repository-url: https://test.pypi.org/legacy/
30 changes: 30 additions & 0 deletions lib/evn/.github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: codecov

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.13'

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tests with coverage
run: |
uv run --extra all pytest --cov --cov-branch --cov-report=xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
31 changes: 31 additions & 0 deletions lib/evn/.github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# .github/workflows/semantic-release.yaml

name: Semantic Release

on:
push:
branches: [main]

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write # for tag, changelog commit, release
issues: write # optional if you want to use release notes
pull-requests: write # optional
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint commit messages
uses: wagoid/commitlint-github-action@v5

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions lib/evn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
sublime_build.log*
wheelhouse
__pycache__
*.egg-info
*.egg
*.pyc
evn/_build
__pycache__
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

.doit.*
_build
*.sublime-workspace
/test-logs
.test*
*.orig
50 changes: 50 additions & 0 deletions lib/evn/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# .pre-commit-config.yaml
repos:
# ✅ Ruff: linter, formatter, isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, evn]

# ✅ Validate pyproject.toml metadata and structure
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.24.1
hooks:
- id: validate-pyproject
# Optional extra validations from SchemaStore:
additional_dependencies: ["validate-pyproject-schema-store[all]"]

# ✅ Check for trailing whitespace, tabs, EOFs
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

# ✅ Detect merge conflict markers
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict

# ✅ Commitizen: Conventional Commit linter (Python-native)
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.21.0
hooks:
- id: commitizen
stages: [commit-msg]
language_version: python3.12

- repo: https://github.com/christophmeissner/pytest-pre-commit
rev: 1.0.0
hooks:
- id: pytest
args: [--ignore,evn/format,--ignore,evn/tests/format]
additional_dependencies: ['assertpy', 'click', 'icecream', 'multipledispatch',
'PrettyPrintTree', 'pyyaml', 'rapidfuzz', 'rich', 'ruff',
'typing_extensions; python_version < "3.10"', 'wrapt','hypothesis', 'ninja_import', 'tomli']
pass_filenames: false
always_run: true
1 change: 1 addition & 0 deletions lib/evn/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13
Loading
Loading