Skip to content

Commit

Permalink
Added qmllib dependency, and removed deprecated. Updated pre-commit (#…
Browse files Browse the repository at this point in the history
…110)

* Updated pre-commit and ran formatting

* Updated `qml`/`qmllib` dependency to the new package

* Updated actions to https://devguide.python.org/versions/ current live Pythons

* Updated actions to make tests work again
  • Loading branch information
charnley authored Nov 24, 2024
1 parent a543e55 commit 19cbe8a
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 43 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: rmsd-dev
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
- run: |
pip install git+https://github.com/qmlcode/qml@develop
- run: |
ls
pwd
which python
conda info
- run: |
make test
make test python=python
- run: |
pre-commit run --all-files
make format python=python
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: ^tests/resources/
Expand All @@ -21,7 +21,7 @@ repos:
args: ['--maxkb=3000']

- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.3.1
hooks:
- id: autoflake
name: Removes unused variables
Expand All @@ -46,7 +46,7 @@ repos:
]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
name: Fixes formatting
Expand All @@ -55,7 +55,7 @@ repos:


- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.1.1
hooks:
- id: flake8
name: Checks pep8 style
Expand Down
60 changes: 53 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
python=./env/bin/python

## Setup

env:
conda env create -f ./environment.yml -p ./env --quiet
./env/bin/python -m pip install -e .
conda env create -f ./environment.yaml -p ./env --quiet
${python} -m pre_commit install
${python} -m pip install -e .

## Development

env-qml:
./env/bin/pip install git+https://github.com/qmlcode/qml@develop
update-format:
${python} -m pre_commit autoupdate

format:
${python} -m pre_commit run --all-files

test:
python -m pytest -vrs tests
${python} -m pytest -rs ./tests

test-dist:
${python} -m twine check dist/*

types:
${python} -m monkeytype run $$(which ${pytest}) ./tests
${python} -m monkeytype list-modules | grep ${pkg} | parallel -j${j} "${python} -m monkeytype apply {} > /dev/null && echo {}"

cov:
${python} -m pytest --cov=${pkg} --cov-config .coveragerc --cov-report html tests

compile:
${python} _compile.py

build:
${python} -m build --sdist --skip-dependency-check .

upload:
${python} -m twine upload ./dist/*.tar.gz

## Version

## Github

## Clean

clean:
find ./rmsd/ -type f \
-name "*.so" \
-name "*.pyc" \
-name ".pyo" \
-delete
rm -rf ./rmsd/*.egg-info/
rm -rf *.whl
rm -rf ./build/ ./__pycache__/
rm -rf ./dist/

test-cov-html:
python -m pytest -vrs --cov=rmsd --cov-report html tests
clean-env:
rm -rf ./env/
rm ./.git/hooks/pre-commit
11 changes: 3 additions & 8 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ channels:
- defaults
- conda-forge
dependencies:
- matplotlib
- mypy
- numpy
- pre-commit
- pylint
- pytest
- pytest-cov
- scipy
- pip
- pip:
- -r requirements.txt
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "rmsd"
dynamic = ["version"]
authors = []
requires-python = ">=3.9"
readme="README.rst"
description="Calculate Root-mean-square deviation (RMSD) of two molecules, using rotation, in xyz or pdb format "
classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Chemistry",
]
keywords = ["pdb", "atoms", "kabsch", "reordering", "rotation", "xyz", "rmsd"]
dependencies=["numpy", "scipy"]

[project.urls]
Homepage = "https://github.com/charnley/rmsd"

[options.packages.find]
where="."

[tool.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
version = {attr = "rmsd.__version__"}
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
numpy
scipy
matplotlib
qmllib
mypy
numpy
pre-commit
pylint
pytest
pytest-cov
scipy
build
twine
monkeytype
34 changes: 18 additions & 16 deletions rmsd/calculate_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
from scipy.spatial.distance import cdist # type: ignore

try:
import qml # type: ignore
import qmllib # type: ignore
from qmllib.kernels import laplacian_kernel # type: ignore
from qmllib.representations import generate_fchl19 # type: ignore
except ImportError: # pragma: no cover
qml = None # pragma: no cover
qmllib = None # pragma: no cover


METHOD_KABSCH = "kabsch"
Expand Down Expand Up @@ -812,7 +814,7 @@ def hungarian_vectors(

if use_kernel:
# Calculate cost matrix from similarity kernel
K = qml.kernels.laplacian_kernel(p_vecs, q_vecs, sigma)
K = laplacian_kernel(p_vecs, q_vecs, sigma)
K *= -1.0
K += 1.0

Expand Down Expand Up @@ -858,13 +860,6 @@ def reorder_similarity(
coordinates of the atoms
"""

if qml is None:
raise ImportError( # pragma: no cover
"QML is not installed. Package is avaliable from"
"\n github.com/qmlcode/qml"
"\n pip install qml"
)

elements = np.unique(p_atoms)
n_atoms = p_atoms.shape[0]
distance_cut = 20.0
Expand All @@ -876,9 +871,9 @@ def reorder_similarity(
"acut": distance_cut,
}

p_vecs = qml.representations.generate_fchl_acsf(p_atoms, p_coord, **parameters)
p_vecs = generate_fchl19(p_atoms, p_coord, **parameters)

q_vecs = qml.representations.generate_fchl_acsf(q_atoms, q_coord, **parameters)
q_vecs = generate_fchl19(q_atoms, q_coord, **parameters)

# generate full view from q shape to fill in atom view on the fly
view_reorder = np.zeros(q_atoms.shape, dtype=int)
Expand Down Expand Up @@ -1837,7 +1832,7 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar
"error: Cannot reorder atoms and print structure, "
"when excluding atoms (such as --ignore-hydrogen)"
)
sys.exit()
sys.exit(5)

if (
args.use_reflections
Expand All @@ -1848,7 +1843,7 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar
"error: Cannot use reflections on atoms and print, "
"when excluding atoms (such as --ignore-hydrogen)"
)
sys.exit()
sys.exit(5)

# Check methods
args.rotation = args.rotation.lower()
Expand All @@ -1857,7 +1852,7 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar
f"error: Unknown rotation method: '{args.rotation}'. "
f"Please use {valid_rotation_methods}"
)
sys.exit()
sys.exit(5)

# Check reorder methods
args.reorder_method = args.reorder_method.lower()
Expand All @@ -1866,7 +1861,7 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar
f'error: Unknown reorder method: "{args.reorder_method}". '
f"Please use {valid_reorder_methods}"
)
sys.exit()
sys.exit(5)

# Check fileformat
if args.format is None:
Expand All @@ -1885,6 +1880,13 @@ def parse_arguments(arguments: Optional[Union[str, List[str]]] = None) -> argpar

args.format = ext

# Check QML is installed
if args.reorder_method == REORDER_QML and qmllib is None:
print(
"'qmllib' is not installed. Package is avaliable from: github.com/qmlcode/qmllib or pip install qmllib."
)
sys.exit(1)

return args


Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from context import RESOURCE_PATH, call_main

import rmsd as rmsdlib
from rmsd.calculate_rmsd import get_coordinates_pdb, get_coordinates_xyz, get_coordinates_xyz_lines
from rmsd.calculate_rmsd import get_coordinates_xyz_lines


def test_print_reflection_reorder() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reorder_print.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from context import RESOURCE_PATH, call_main
from context import RESOURCE_PATH

import rmsd as rmsdlib
from rmsd import get_coordinates_xyz, get_coordinates_xyz_lines
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reorder_qml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import rmsd as rmsdlib

qml = pytest.importorskip("qml")
qmllib = pytest.importorskip("qmllib")


def test_reorder_qml() -> None:
Expand Down

0 comments on commit 19cbe8a

Please sign in to comment.