Skip to content

Commit b772a57

Browse files
authored
Merge pull request #28 from briling/python-api
Improve the api for integration with python * possibility to print to a variable * possibility to pass a molecule to main * possibility to read from stdin * build manylinux wheels
2 parents f7f9aff + e98ffbb commit b772a57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8360
-368
lines changed

.github/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
* Add partial extended xyz support (https://github.com/briling/v/pull/18)
66
* Add `j` hotkey to jump to a frame inside and CLI option `frame:%d` to start with a specific frame (https://github.com/briling/v/pull/5)
77
* Add `bmax` CLI argument for max. bond length (920202b)
8-
* Python integration (#22, see https://github.com/aligfellow/xyzrender)
8+
* Add `com` and `exitcom` CLI argument for `gui:0` and on-exit command sequences, respectively
9+
* Python integration (#28, see https://github.com/aligfellow/xyzrender)
910

1011
### Improvements
1112
* New colors by @iribirii (https://github.com/briling/v/pull/2, https://github.com/briling/v/pull/13, https://github.com/briling/v/pull/15)
1213
* Remove case sensitivity of xyz file inputs (https://github.com/briling/v/pull/9)
1314
* Add CLI option to disable centering of molecules (https://github.com/briling/v/pull/14)
1415
* Disable default rotation wrt inertia axis for z-matrix input and add a CLI option to force it (https://github.com/briling/v/pull/14)
16+
* Read molecules from the standard input
1517

1618
### Fixes
1719
* Exit correctly when window closed (https://github.com/briling/v/pull/10)
1820
* Fix chiral z-matrix input (https://github.com/briling/v/pull/14)
1921
* Fix NaNs when compute dihedrals (https://github.com/briling/v/pull/14)
2022

2123
### Still have to be done:
22-
* documentation for the python bindings
2324
* finish colors (#15)
2425
* ? extended xyz (#16, #17)
2526
* ? fix `readmore` bug (#7)
2627
* ? high-symmetry determination bugs (#21)
2728
* ? how to build on mac
2829

2930
**Full Changelog**: https://github.com/briling/v/compare/v2.0...v3.0rc3
31+

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint Python with Ruff
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
lint:
13+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.13'
22+
- name: Install Ruff
23+
run: pip install ruff
24+
- name: Run Ruff
25+
run: ruff check vmol/ examples/
26+
working-directory: ./python

.github/workflows/manual-build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
wheels:
8+
uses: ./.github/workflows/wheels.yml

.github/workflows/release.yml

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: release
22

3-
on: # triggered by push tagged commits to main
3+
on: # triggered by push tagged commits
44
push:
55
tags:
66
- 'v*'
@@ -12,44 +12,7 @@ permissions:
1212
jobs:
1313

1414
build_wheels:
15-
name: Build wheels on ${{ matrix.os }} for python ${{ matrix.py }}
16-
runs-on: ${{ matrix.os }}
17-
strategy:
18-
fail-fast: false
19-
matrix:
20-
os: [ubuntu-latest]
21-
py: ['3.11', '3.12', '3.13']
22-
23-
steps:
24-
25-
- name: install X11 dependencies
26-
if: ${{ runner.os == 'Linux' }}
27-
run: |
28-
sudo apt-get update
29-
sudo apt install -y libx11-dev libxpm-dev x11proto-dev
30-
31-
- uses: actions/checkout@v6
32-
with:
33-
persist-credentials: false
34-
35-
- uses: actions/setup-python@v6
36-
with:
37-
python-version: ${{ matrix.py }}
38-
39-
- name: install python
40-
run: pip install setuptools
41-
42-
- name: build wheels
43-
working-directory: ./python
44-
run: python setup.py bdist_wheel
45-
## we don't need the wheel name actually, the artifact name just has to be unique
46-
#run: python setup.py bdist_wheel | grep "creating 'dist" | sed -n "s/^creating 'dist\//WHEEL_NAME='/;s/\s.*$//p" >> "$GITHUB_ENV"
47-
48-
- uses: actions/upload-artifact@v6
49-
with:
50-
path: ./python/dist/*.whl
51-
name: ${{ matrix.os }}.${{ matrix.py }}
52-
15+
uses: ./.github/workflows/wheels.yml
5316

5417
build_exe:
5518
name: Build the executable file and shared library for ${{ matrix.os }}
@@ -79,6 +42,7 @@ jobs:
7942
./v
8043
./v.so
8144
name: ${{ matrix.os }}.exe
45+
if-no-files-found: error
8246

8347

8448
release:
@@ -89,10 +53,6 @@ jobs:
8953
contents: write
9054

9155
steps:
92-
- name: Check out the repo
93-
uses: actions/checkout@v6
94-
with:
95-
fetch-depth: 0
9656

9757
- uses: actions/download-artifact@v4
9858
with:

.github/workflows/wheels.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build wheels
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
package-dir:
7+
type: string
8+
required: false
9+
default: ./python
10+
output-dir:
11+
type: string
12+
required: false
13+
default: wheelhouse
14+
cibw-build:
15+
type: string
16+
required: false
17+
default: ""
18+
cibw-skip:
19+
type: string
20+
required: false
21+
default: "*-musllinux_*"
22+
upload-artifact:
23+
type: boolean
24+
required: false
25+
default: true
26+
27+
jobs:
28+
build_wheels:
29+
name: Build wheels
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
34+
- uses: actions/checkout@v6
35+
with:
36+
fetch-depth: 0
37+
persist-credentials: false
38+
39+
- name: Export git metadata
40+
shell: bash
41+
run: |
42+
set -euo pipefail
43+
echo "VMOL_GIT_HASH=${{ github.sha }}" >> "$GITHUB_ENV"
44+
echo "VMOL_GIT_BRANCH=${{ github.ref_name }}" >> "$GITHUB_ENV"
45+
echo "VMOL_GIT_DESCRIBE=$(git describe --tags --dirty 2>/dev/null || true)" >> "$GITHUB_ENV"
46+
47+
- uses: actions/setup-python@v6
48+
with:
49+
python-version: '3.13'
50+
51+
- name: Install cibuildwheel
52+
run: python -m pip install cibuildwheel==3.4.0
53+
54+
- name: Build wheels
55+
run: python -m cibuildwheel "${{ inputs.package-dir }}" --output-dir "${{ inputs.output-dir }}"
56+
env:
57+
CIBW_BUILD: ${{ inputs.cibw-build }}
58+
CIBW_SKIP: ${{ inputs.cibw-skip }}
59+
CIBW_BEFORE_ALL_LINUX: |
60+
if [ -f /etc/alpine-release ]; then # musllinux (Alpine)
61+
apk add --no-cache libx11-dev libxpm-dev pkgconf
62+
else # manylinux (AlmaLinux)
63+
/usr/bin/dnf -y install libX11-devel libXpm-devel pkgconf-pkg-config
64+
fi
65+
66+
- name: Upload wheels
67+
if: ${{ inputs.upload-artifact }}
68+
uses: actions/upload-artifact@v6
69+
with:
70+
name: vmol-wheels-${{ runner.os }}-${{ github.ref_name }}-${{ github.run_number }}
71+
path: ${{ inputs.output-dir }}/*.whl
72+
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
vmol.egg-info/
1010
python/build
1111
python/dist
12+
python/src

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ A simple X11 molecular viewer.
1818
- [`.xyz`](https://en.wikipedia.org/wiki/XYZ_file_format) files
1919
- [extended `.xyz`](https://github.com/libAtoms/extxyz) files (currently the extra columns are ignored)
2020

21+
## Python package (wrapper / API) available
22+
23+
See python package page
24+
[here.](python/README.md)
25+
26+
Provides wrapper scripts with a simple installation and
27+
allows to open unsupported file formats with `cclib`.
28+
2129
## Download [](#download)
2230
```
2331
wget https://github.com/briling/v/releases/download/v2.0/v.2.0 -O v
@@ -40,6 +48,8 @@ make v
4048
```
4149
./v file [file2 ... fileN] [options]
4250
```
51+
A filename `-` stands for the standard input.
52+
4353
Show the reference:
4454
```
4555
./v
@@ -66,8 +76,10 @@ Show the reference:
6676
| `shell:b%lf,%lf` | spheres radii in a.u. |
6777
| `shell:%lf,%lf` | spheres radii in Å |
6878
| `center:%d` | origin is geometric center (`1`, default) / center of mass (`2`) / as is (`0`) |
69-
| `inertia:1` | rotate molecules wrt axis of inertia |
79+
| `inertia:%d` | if rotate molecules wrt axis of inertia (`1`) or not (`0`, default) |
7080
| `gui:%d` | normal (default `1`) / headless (`0`) mode |
81+
| `com:%s` | command sequence for `gui:0` |
82+
| `exitcom:%s` | command sequence to run on exit (same as for `gui:0`) |
7183

7284
</details>
7385

@@ -116,12 +128,20 @@ One can also use the mouse to rotate the molecule and zoom in/out.
116128

117129
<details open><summary><strong>Headless mode (in development)</strong></summary>
118130

119-
If run in the headless mode with `gui:0`, the symbols from stdio are processed
131+
If run in the headless mode with `gui:0`, the symbols from the standard input are processed
120132
as if the corresponding keys were pressed in the normal mode.
121-
Right now, only `p`, `x`, `z`, and `.` are available. For example,
133+
Right now, only `p`, `x`, `z`, and `.` are available.
134+
Command-line option `com:%s` overrides the standard input.
135+
These examples are equivalent:
122136
```
123137
> echo . | ./v mol/mol0001.xyz gui:0
124138
D*h
139+
140+
> ./v mol/mol0001.xyz gui:0 com:.
141+
D*h
142+
143+
> cat mol/mol0001.xyz | ./v - gui:0 com:.
144+
D*h
125145
```
126146

127147
</details>

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ INCL=$(SRCDIRS:%=-I./%)
4949
allsrc=$(shell find $(SRCDIR) -type f -name '*.c')
5050
allobj=$(allsrc:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
5151
allpic=$(allsrc:$(SRCDIR)/%.c=$(PICDIR)/%.o)
52-
allmmd=$(allsrc:$(SRCDIR)/%.c=$(OBJDIR)/%.d)
52+
allmmd=$(shell find $(OBJDIR) -type f -name '*.d')
5353

5454
OBJDIRS=$(SRCDIRS:$(SRCDIR)%=$(OBJDIR)%)
5555
PICDIRS=$(SRCDIRS:$(SRCDIR)%=$(PICDIR)%)

0 commit comments

Comments
 (0)