Skip to content

Commit 1e99670

Browse files
committed
merge upstream
2 parents b524b8c + d4a8d31 commit 1e99670

11 files changed

+186
-186
lines changed

Diff for: .github/workflows/build.yml

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
# Run when container or environment is changed
7+
paths:
8+
- containers/dockerfile_cpu
9+
- environment.yml
10+
# Allows workflow to be manually triggered
11+
workflow_dispatch:
12+
13+
defaults:
14+
run:
15+
shell: bash -l {0}
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: cmelab/grits
20+
DOCKERFILE: containers/dockerfile_cpu
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@main
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Get Latest Version
36+
id: latest-version
37+
run: |
38+
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
39+
echo $LATEST_TAG
40+
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
41+
# slice off the v, ie v0.7.2 -> 0.7.2
42+
VERSION=${LATEST_TAG:1}
43+
echo $VERSION
44+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
45+
46+
- name: Print Latest Version
47+
run: echo ${{ steps.latest-version.outputs.VERSION }}
48+
49+
- name: Create fully qualified image registry path
50+
id: fqirp
51+
run: |
52+
FQIRP=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }}
53+
echo "FQIRP=$FQIRP" >> $GITHUB_OUTPUT
54+
55+
- name: Print FQIRP
56+
run: echo ${{ steps.fqirp.outputs.FQIRP }}
57+
58+
- name: Login to GitHub Container Registry
59+
uses: docker/login-action@v1
60+
with:
61+
registry: ${{ env.REGISTRY }}
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Extract metadata (tags, labels) for Docker
66+
id: meta
67+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
68+
with:
69+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
70+
tags: |
71+
type=semver,pattern={{version}},prefix=v
72+
${{ steps.latest-version.outputs.VERSION }}
73+
74+
- name: Build Docker Image
75+
uses: docker/build-push-action@v4
76+
with:
77+
context: .
78+
file: ${{ env.DOCKERFILE }}
79+
load: true
80+
push: false
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
build-args: |
84+
VERSION=${{ steps.latest-version.outputs.VERSION }}
85+
86+
- name: Test image
87+
run: |
88+
docker run --rm ${{ steps.fqirp.outputs.FQIRP }} python -c "import grits; print(grits.__version__)"
89+
90+
- name: Push Docker image
91+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
92+
with:
93+
context: .
94+
file: ${{ env.DOCKERFILE }}
95+
push: ${{ github.event_name == 'workflow_dispatch' }}
96+
tags: ${{ steps.meta.outputs.tags }}
97+
labels: ${{ steps.meta.outputs.labels }}
98+
build-args: |
99+
VERSION=${{ steps.latest-version.outputs.VERSION }}

Diff for: .pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v4.6.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/psf/black
9-
rev: 24.1.1
9+
rev: 24.4.2
1010
hooks:
1111
- id: black
1212
args: [--line-length=80]

Diff for: README.md

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# GRiTS : Grits Reduces/Restores Topology with SMILES
22
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/grits/badges/version.svg)](https://anaconda.org/conda-forge/grits)
3-
[![Docker Repository on Quay](https://quay.io/repository/cmelab/grits/status "Docker Repository on Quay")](https://quay.io/repository/cmelab/grits)
43
[![pytest](https://github.com/cmelab/grits/actions/workflows/pytest.yml/badge.svg)](https://github.com/cmelab/grits/actions/workflows/pytest.yml)
54
[![codecov](https://codecov.io/gh/cmelab/grits/branch/main/graph/badge.svg?token=lGG8Zf65HP)](https://codecov.io/gh/cmelab/grits)
5+
[![Documentation Status](https://readthedocs.org/projects/grits/badge/?version=latest)](https://grits.readthedocs.io/en/latest/?badge=latest)
6+
[![Docker build](https://github.com/cmelab/grits/actions/workflows/build.yml/badge.svg)](https://github.com/cmelab/grits/actions/workflows/build.yml)
67

78
![GRiTS workflow](/.github/grits.png)
89

@@ -11,29 +12,21 @@ GRiTS is a toolkit for working with coarse-grain systems. It uses [mBuild](https
1112
### Installation
1213
#### Using a container
1314

14-
To use GRiTS in a prebuilt container (using [Singularity](https://singularity.lbl.gov/)), run:
15+
To use GRiTS in a prebuilt container (using [Apptainer](https://apptainer.org/)), run:
1516
```bash
16-
singularity pull docker://quay.io/cmelab/grits:latest
17-
singularity exec grits_latest.sif bash
17+
apptainer pull docker://ghcr.io/cmelab/grits:latest
18+
apptainer run grits_latest.sif python
1819
```
1920

2021
**Or** using [Docker](https://docs.docker.com/), run:
2122
```bash
22-
docker pull quay.io/cmelab/grits:latest
23+
docker pull ghcr.io/cmelab/grits:latest
2324
docker run -it cmelab/grits:latest
2425
```
2526

26-
#### Custom install
27-
To create a local environment with [conda](https://docs.conda.io/en/latest/miniconda.html), run:
27+
#### Micromamba install
28+
To create a local environment with [micromamba](https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html), run:
2829
```bash
29-
conda env create -f environment.yml
30-
conda activate grits
31-
```
32-
With the `grits` environment active, install the package with pip:
33-
```
34-
pip install .
35-
```
36-
And to test your installation, run:
37-
```
38-
pytest
30+
micromamba create grits -f environment.yml
31+
micromamba activate grits
3932
```

Diff for: containers/dockerfile_cpu

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
FROM mambaorg/micromamba:0.15.2
1+
FROM mambaorg/micromamba:1.4.1
22

3-
COPY --chown=micromamba:micromamba environment.yml /tmp/env.yml
3+
ARG VERSION
44

5-
RUN micromamba install -y -n base -f /tmp/env.yml && \
6-
micromamba clean --all --yes
7-
8-
COPY grits/ /tmp/grits/
9-
10-
COPY setup.py /tmp/
11-
12-
RUN ls -la /tmp
5+
ENV PYTHONUNBUFFERED=1
136

14-
RUN python -m pip install /tmp
7+
COPY --chown=$MAMBA_USER:$MAMBA_USER environment.yml /tmp/env.yml
158

16-
RUN pytest -vx
17-
18-
USER root
19-
20-
RUN rm -r /tmp/*
9+
RUN micromamba install -y -n base "grits==$VERSION" -f /tmp/env.yml && \
10+
micromamba clean --all --yes
2111

22-
RUN python -c "import grits"
12+
ARG MAMBA_DOCKERFILE_ACTIVATE=1

Diff for: docs/environment-docs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ dependencies:
77
- numpydoc
88
- sphinx
99
- sphinx_rtd_theme
10+
- cmeutils
1011
- ele
1112
- freud
1213
- gsd
13-
- mbuild
14+
- mbuild>=0.17
1415
- numpy
1516
- openbabel

Diff for: environment.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ name: grits
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=3.10
6-
- numpy
5+
- cmeutils >=1.3.0
76
- ele
8-
- freud>=2.13.1
9-
- gsd>=3.0
7+
- freud >=3.0
8+
- gsd >=3.0
109
- jupyterlab
11-
- mbuild
10+
- mbuild >=0.17.1
1211
- ele
13-
- freud
12+
- numpy
1413
- openbabel
1514
- pip
1615
- pre-commit
1716
- py3Dmol
1817
- pytest
1918
- pytest-cov
20-
- rdkit
21-
- cmeutils >= 1.2.0
19+
- python >=3.10

Diff for: grits/coarsegrain.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import freud
1111
import gsd.hoomd
1212
import numpy as np
13-
from cmeutils.gsd_utils import identify_snapshot_connections
13+
from cmeutils.gsd_utils import get_molecule_cluster, identify_snapshot_connections
1414
from ele import element_from_symbol
1515
from mbuild import Compound, clone
1616
from mbuild.utils.io import run_from_ipython
@@ -24,7 +24,6 @@
2424
get_quaternion,
2525
has_common_member,
2626
has_number,
27-
snap_molecules,
2827
)
2928

3029
__all__ = ["CG_Compound", "CG_System", "Bead"]
@@ -362,7 +361,7 @@ def visualize(
362361
if atom_names:
363362
atomistic.save(
364363
os.path.join(tmp_dir, "atomistic_tmp.mol2"),
365-
show_ports=show_ports,
364+
include_ports=show_ports,
366365
overwrite=True,
367366
)
368367

@@ -397,7 +396,7 @@ def visualize(
397396
simplefilter("ignore")
398397
coarse.save(
399398
os.path.join(tmp_dir, "coarse_tmp.mol2"),
400-
show_ports=show_ports,
399+
include_ports=show_ports,
401400
overwrite=True,
402401
)
403402
with open(os.path.join(tmp_dir, "coarse_tmp.mol2"), "r") as f:
@@ -574,7 +573,7 @@ def _get_compounds(
574573
conversion_dict[i].symbol for i in snap.particles.types
575574
]
576575
# Break apart the snapshot into separate molecules
577-
molecules = snap_molecules(snap)
576+
molecules = get_molecule_cluster(snap=snap)
578577
mol_inds = []
579578
for i in range(max(molecules) + 1):
580579
mol_inds.append(np.where(molecules == i)[0])
@@ -667,7 +666,7 @@ def save_mapping(self, filename):
667666
json.dump(self.mapping, f, cls=NumpyEncoder)
668667
print(f"Mapping saved to {filename}")
669668

670-
def save(self, cg_gsdfile, start=0, stop=None):
669+
def save(self, cg_gsdfile, start=0, stop=None, stride=1):
671670
"""Save the coarse-grain system to a gsd file.
672671
673672
Does not calculate the image of the coarse-grain bead.
@@ -688,6 +687,8 @@ def save(self, cg_gsdfile, start=0, stop=None):
688687
stop : int, default None
689688
Where to stop reading the gsd trajectory the system was created
690689
with. If None, will stop at the last frame.
690+
stride : int, default 1
691+
The step size to use when iterating through start:stop
691692
"""
692693
typeid = []
693694
types = [i.split("...")[0] for i in self.mapping]
@@ -722,7 +723,7 @@ def save(self, cg_gsdfile, start=0, stop=None):
722723
) as old:
723724
# stop being None is fine; slicing [0:None] gives whole array,
724725
# even in edge case where there's only one or two frames
725-
for s in old[start:stop]:
726+
for s in old[start:stop:stride]:
726727
new_snap = gsd.hoomd.Frame()
727728
position = []
728729
mass = []

Diff for: grits/tests/test_coarsegrain.py

+13
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def test_benzene(self, tmp_path):
213213
cg_json = tmp_path / "cg-benzene.json"
214214
system.save_mapping(cg_json)
215215

216+
def test_stride(self, tmp_path):
217+
gsdfile = path.join(asset_dir, "benzene-aa.gsd")
218+
system = CG_System(
219+
gsdfile,
220+
beads={"_B": "c1ccccc1"},
221+
conversion_dict=amber_dict,
222+
mass_scale=12.011,
223+
)
224+
cg_gsd = tmp_path / "cg-benzene.gsd"
225+
system.save(cg_gsdfile=cg_gsd, start=0, stop=-1, stride=2)
226+
with gsd.hoomd.open(cg_gsd) as f:
227+
assert len(f) == 3
228+
216229
def test_anisobenzene(self, tmp_path):
217230
gsdfile = path.join(asset_dir, "benzene-aa.gsd")
218231
system = CG_System(

Diff for: grits/utils.py

-17
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,6 @@ def comp_from_snapshot(snapshot, indices, length_scale=1.0, mass_scale=1.0):
8282
return comp
8383

8484

85-
def snap_molecules(snap):
86-
"""Get the molecule indices based on bonding in a gsd.hoomd.Frame."""
87-
system = freud.AABBQuery.from_system(snap)
88-
n_query_points = n_points = snap.particles.N
89-
query_point_indices = snap.bonds.group[:, 0]
90-
point_indices = snap.bonds.group[:, 1]
91-
distances = system.box.compute_distances(
92-
system.points[query_point_indices], system.points[point_indices]
93-
)
94-
nlist = freud.NeighborList.from_arrays(
95-
n_query_points, n_points, query_point_indices, point_indices, distances
96-
)
97-
cluster = freud.cluster.Cluster()
98-
cluster.compute(system=system, neighbors=nlist)
99-
return cluster.cluster_idx
100-
101-
10285
def align(compound, particle, towards_compound, around=None):
10386
"""Spin a compound such that particle points at towards_compound.
10487

Diff for: pyproject.toml

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
[build-system]
2-
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
2+
requires = ["setuptools>=61.2", "versioningit"]
33
build-backend = "setuptools.build_meta"
44

5-
[tool.setuptools_scm]
6-
write_to = "grits/__version__.py"
5+
[project]
6+
name = "grits"
7+
description = "A toolkit for working with coarse-grained systems"
8+
readme = "README.md"
9+
authors = [{name = "Jenny Fothergill", email = "[email protected]"}]
10+
license= {text = "GPLv3"}
11+
classifiers=[
12+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
13+
"Programming Language :: Python",
14+
"Programming Language :: Python :: 3",
15+
]
16+
urls = {Homepage = "https://github.com/cmelab/grits"}
17+
requires-python = ">=3.8"
18+
dynamic = ["version"]
19+
20+
[tool.setuptools]
21+
zip-safe = false
22+
include-package-data = true
23+
license-files = ["LICENSE"]
24+
25+
[tool.setuptools.packages]
26+
find = {namespaces = false}
27+
28+
[tool.setuptools.package-data]
29+
grits = ['"./compounds/*"']
30+
31+
[tool.versioningit]
32+
default-version = "1+unknown"
33+
34+
[tool.versioningit.format]
35+
distance = "{base_version}+{distance}.{vcs}{rev}"
36+
dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
37+
distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
38+
39+
[tool.versioningit.vcs]
40+
method = "git"
41+
match = ["*"]
42+
default-tag = "0.0.0"

0 commit comments

Comments
 (0)