Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Oct 6, 2024
2 parents b524b8c + d4a8d31 commit 1e99670
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 186 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: build

on:
push:
branches: [ main ]
# Run when container or environment is changed
paths:
- containers/dockerfile_cpu
- environment.yml
# Allows workflow to be manually triggered
workflow_dispatch:

defaults:
run:
shell: bash -l {0}

env:
REGISTRY: ghcr.io
IMAGE_NAME: cmelab/grits
DOCKERFILE: containers/dockerfile_cpu

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Get Latest Version
id: latest-version
run: |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo $LATEST_TAG
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
# slice off the v, ie v0.7.2 -> 0.7.2
VERSION=${LATEST_TAG:1}
echo $VERSION
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Print Latest Version
run: echo ${{ steps.latest-version.outputs.VERSION }}

- name: Create fully qualified image registry path
id: fqirp
run: |
FQIRP=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.latest-version.outputs.VERSION }}
echo "FQIRP=$FQIRP" >> $GITHUB_OUTPUT
- name: Print FQIRP
run: echo ${{ steps.fqirp.outputs.FQIRP }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},prefix=v
${{ steps.latest-version.outputs.VERSION }}
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
file: ${{ env.DOCKERFILE }}
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.latest-version.outputs.VERSION }}
- name: Test image
run: |
docker run --rm ${{ steps.fqirp.outputs.FQIRP }} python -c "import grits; print(grits.__version__)"
- name: Push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ${{ env.DOCKERFILE }}
push: ${{ github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.latest-version.outputs.VERSION }}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.4.2
hooks:
- id: black
args: [--line-length=80]
Expand Down
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# GRiTS : Grits Reduces/Restores Topology with SMILES
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/grits/badges/version.svg)](https://anaconda.org/conda-forge/grits)
[![Docker Repository on Quay](https://quay.io/repository/cmelab/grits/status "Docker Repository on Quay")](https://quay.io/repository/cmelab/grits)
[![pytest](https://github.com/cmelab/grits/actions/workflows/pytest.yml/badge.svg)](https://github.com/cmelab/grits/actions/workflows/pytest.yml)
[![codecov](https://codecov.io/gh/cmelab/grits/branch/main/graph/badge.svg?token=lGG8Zf65HP)](https://codecov.io/gh/cmelab/grits)
[![Documentation Status](https://readthedocs.org/projects/grits/badge/?version=latest)](https://grits.readthedocs.io/en/latest/?badge=latest)
[![Docker build](https://github.com/cmelab/grits/actions/workflows/build.yml/badge.svg)](https://github.com/cmelab/grits/actions/workflows/build.yml)

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

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

To use GRiTS in a prebuilt container (using [Singularity](https://singularity.lbl.gov/)), run:
To use GRiTS in a prebuilt container (using [Apptainer](https://apptainer.org/)), run:
```bash
singularity pull docker://quay.io/cmelab/grits:latest
singularity exec grits_latest.sif bash
apptainer pull docker://ghcr.io/cmelab/grits:latest
apptainer run grits_latest.sif python
```

**Or** using [Docker](https://docs.docker.com/), run:
```bash
docker pull quay.io/cmelab/grits:latest
docker pull ghcr.io/cmelab/grits:latest
docker run -it cmelab/grits:latest
```

#### Custom install
To create a local environment with [conda](https://docs.conda.io/en/latest/miniconda.html), run:
#### Micromamba install
To create a local environment with [micromamba](https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html), run:
```bash
conda env create -f environment.yml
conda activate grits
```
With the `grits` environment active, install the package with pip:
```
pip install .
```
And to test your installation, run:
```
pytest
micromamba create grits -f environment.yml
micromamba activate grits
```
24 changes: 7 additions & 17 deletions containers/dockerfile_cpu
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
FROM mambaorg/micromamba:0.15.2
FROM mambaorg/micromamba:1.4.1

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

RUN micromamba install -y -n base -f /tmp/env.yml && \
micromamba clean --all --yes

COPY grits/ /tmp/grits/

COPY setup.py /tmp/

RUN ls -la /tmp
ENV PYTHONUNBUFFERED=1

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

RUN pytest -vx

USER root

RUN rm -r /tmp/*
RUN micromamba install -y -n base "grits==$VERSION" -f /tmp/env.yml && \
micromamba clean --all --yes

RUN python -c "import grits"
ARG MAMBA_DOCKERFILE_ACTIVATE=1
3 changes: 2 additions & 1 deletion docs/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ dependencies:
- numpydoc
- sphinx
- sphinx_rtd_theme
- cmeutils
- ele
- freud
- gsd
- mbuild
- mbuild>=0.17
- numpy
- openbabel
14 changes: 6 additions & 8 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ name: grits
channels:
- conda-forge
dependencies:
- python=3.10
- numpy
- cmeutils >=1.3.0
- ele
- freud>=2.13.1
- gsd>=3.0
- freud >=3.0
- gsd >=3.0
- jupyterlab
- mbuild
- mbuild >=0.17.1
- ele
- freud
- numpy
- openbabel
- pip
- pre-commit
- py3Dmol
- pytest
- pytest-cov
- rdkit
- cmeutils >= 1.2.0
- python >=3.10
15 changes: 8 additions & 7 deletions grits/coarsegrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import freud
import gsd.hoomd
import numpy as np
from cmeutils.gsd_utils import identify_snapshot_connections
from cmeutils.gsd_utils import get_molecule_cluster, identify_snapshot_connections
from ele import element_from_symbol
from mbuild import Compound, clone
from mbuild.utils.io import run_from_ipython
Expand All @@ -24,7 +24,6 @@
get_quaternion,
has_common_member,
has_number,
snap_molecules,
)

__all__ = ["CG_Compound", "CG_System", "Bead"]
Expand Down Expand Up @@ -362,7 +361,7 @@ def visualize(
if atom_names:
atomistic.save(
os.path.join(tmp_dir, "atomistic_tmp.mol2"),
show_ports=show_ports,
include_ports=show_ports,
overwrite=True,
)

Expand Down Expand Up @@ -397,7 +396,7 @@ def visualize(
simplefilter("ignore")
coarse.save(
os.path.join(tmp_dir, "coarse_tmp.mol2"),
show_ports=show_ports,
include_ports=show_ports,
overwrite=True,
)
with open(os.path.join(tmp_dir, "coarse_tmp.mol2"), "r") as f:
Expand Down Expand Up @@ -574,7 +573,7 @@ def _get_compounds(
conversion_dict[i].symbol for i in snap.particles.types
]
# Break apart the snapshot into separate molecules
molecules = snap_molecules(snap)
molecules = get_molecule_cluster(snap=snap)
mol_inds = []
for i in range(max(molecules) + 1):
mol_inds.append(np.where(molecules == i)[0])
Expand Down Expand Up @@ -667,7 +666,7 @@ def save_mapping(self, filename):
json.dump(self.mapping, f, cls=NumpyEncoder)
print(f"Mapping saved to {filename}")

def save(self, cg_gsdfile, start=0, stop=None):
def save(self, cg_gsdfile, start=0, stop=None, stride=1):
"""Save the coarse-grain system to a gsd file.
Does not calculate the image of the coarse-grain bead.
Expand All @@ -688,6 +687,8 @@ def save(self, cg_gsdfile, start=0, stop=None):
stop : int, default None
Where to stop reading the gsd trajectory the system was created
with. If None, will stop at the last frame.
stride : int, default 1
The step size to use when iterating through start:stop
"""
typeid = []
types = [i.split("...")[0] for i in self.mapping]
Expand Down Expand Up @@ -722,7 +723,7 @@ def save(self, cg_gsdfile, start=0, stop=None):
) as old:
# stop being None is fine; slicing [0:None] gives whole array,
# even in edge case where there's only one or two frames
for s in old[start:stop]:
for s in old[start:stop:stride]:
new_snap = gsd.hoomd.Frame()
position = []
mass = []
Expand Down
13 changes: 13 additions & 0 deletions grits/tests/test_coarsegrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ def test_benzene(self, tmp_path):
cg_json = tmp_path / "cg-benzene.json"
system.save_mapping(cg_json)

def test_stride(self, tmp_path):
gsdfile = path.join(asset_dir, "benzene-aa.gsd")
system = CG_System(
gsdfile,
beads={"_B": "c1ccccc1"},
conversion_dict=amber_dict,
mass_scale=12.011,
)
cg_gsd = tmp_path / "cg-benzene.gsd"
system.save(cg_gsdfile=cg_gsd, start=0, stop=-1, stride=2)
with gsd.hoomd.open(cg_gsd) as f:
assert len(f) == 3

def test_anisobenzene(self, tmp_path):
gsdfile = path.join(asset_dir, "benzene-aa.gsd")
system = CG_System(
Expand Down
17 changes: 0 additions & 17 deletions grits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ def comp_from_snapshot(snapshot, indices, length_scale=1.0, mass_scale=1.0):
return comp


def snap_molecules(snap):
"""Get the molecule indices based on bonding in a gsd.hoomd.Frame."""
system = freud.AABBQuery.from_system(snap)
n_query_points = n_points = snap.particles.N
query_point_indices = snap.bonds.group[:, 0]
point_indices = snap.bonds.group[:, 1]
distances = system.box.compute_distances(
system.points[query_point_indices], system.points[point_indices]
)
nlist = freud.NeighborList.from_arrays(
n_query_points, n_points, query_point_indices, point_indices, distances
)
cluster = freud.cluster.Cluster()
cluster.compute(system=system, neighbors=nlist)
return cluster.cluster_idx


def align(compound, particle, towards_compound, around=None):
"""Spin a compound such that particle points at towards_compound.
Expand Down
42 changes: 39 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=61.2", "versioningit"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "grits/__version__.py"
[project]
name = "grits"
description = "A toolkit for working with coarse-grained systems"
readme = "README.md"
authors = [{name = "Jenny Fothergill", email = "jennyfothergill@boisestate.edu"}]
license= {text = "GPLv3"}
classifiers=[
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
urls = {Homepage = "https://github.com/cmelab/grits"}
requires-python = ">=3.8"
dynamic = ["version"]

[tool.setuptools]
zip-safe = false
include-package-data = true
license-files = ["LICENSE"]

[tool.setuptools.packages]
find = {namespaces = false}

[tool.setuptools.package-data]
grits = ['"./compounds/*"']

[tool.versioningit]
default-version = "1+unknown"

[tool.versioningit.format]
distance = "{base_version}+{distance}.{vcs}{rev}"
dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"

[tool.versioningit.vcs]
method = "git"
match = ["*"]
default-tag = "0.0.0"
Loading

0 comments on commit 1e99670

Please sign in to comment.