Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
rev: v1.4.0
hooks:
- id: detect-secrets
stages: [pre-commit]
stages: [commit]
exclude: '.*\.(lock|ipynb)$'
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
Expand All @@ -36,7 +36,7 @@ repos:
hooks:
- id: tests
name: tests
stages: [pre-push]
stages: [push]
language: system
entry: uv run pytest
types: [python]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dev = [
"matplotlib>=3.0.0",
"py3Dmol>=2.2.1",
"pint>=0.24.4",
"qcinf>=0.2.1",
"qcinf[all]>=0.2.1",
]

docs = [
Expand Down
11 changes: 10 additions & 1 deletion src/qcio/models/structure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from collections import Counter
from collections import Counter, defaultdict
from pathlib import Path
from typing import TYPE_CHECKING, Any, ClassVar

Expand Down Expand Up @@ -279,6 +279,15 @@ def adjacency_matrix(self) -> np.ndarray:
adj[j, i] = order
return adj

@property
def adjacency_dict(self) -> dict[int, list[int]]:
"""Return adjacency dictionary where each key maps to a list of bonded atom indices."""
adjacency = defaultdict(list)
for i, j, _ in self.connectivity:
adjacency[i].append(j)
adjacency[j].append(i)
return adjacency

@classmethod
def from_xyz(
cls,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def test_to_from_file_json(test_data_dir, tmp_path):
assert caffeine_copy.charge == caffeine.charge


def test_adjacency_matrix(water):
expected = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 0]])
assert np.array_equal(expected, water.adjacency_matrix)


def test_adjacency_dict(water):
expected = {0: [1, 2], 1: [0], 2: [0]}
assert expected == water.adjacency_dict


def test_structure_model_dump_connectivity(water):
# Test that connectivity is a list of lists of floats
# Must cast all to the same type as toml cannot handle mixed types
Expand Down
45 changes: 42 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading