Skip to content

Commit

Permalink
Merge branch 'cmelab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marjanalbooyeh authored May 1, 2024
2 parents 26af373 + 0245f75 commit 68777e1
Show file tree
Hide file tree
Showing 27 changed files with 1,853 additions and 452 deletions.
71 changes: 69 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,25 @@ on:
- flowermd/**
- environment-dev.yml
- .github/workflows/pytest.yml
# Allows workflow to be manually triggered
issue_comment:
types: [created]
branches: [ main ]
paths:
- flowermd/**
- environment-dev.yml
- .github/workflows/pytest.yml

workflow_dispatch:

jobs:
pytest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [macos-latest, macOS-13, ubuntu-latest]
python-version: ['3.10', '3.11']

runs-on: ${{ matrix.os }}

steps:
- name: Check out repository
Expand All @@ -29,6 +42,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v2
with:
environment-file: environment-dev.yml
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
miniforge-version: 4.9.2-4
use-mamba: true
Expand All @@ -46,3 +60,56 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml

test-tutorials:
if: ${{ github.event.issue.pull_request && github.event.comment.body== '/testtutorials'}}
runs-on: ubuntu-latest
steps:
- name: Put a reaction to the comment
run: gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_ID: ${{ github.event.comment.node_id }}
- name: Check if PR is open
run: |
STATE=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json state --jq .state)
if [ "$STATE" != "OPEN" ]; then
echo "Cannot build for closed PRs"
(
echo "**${{ github.workflow }}**"
echo "Cannot build Kuby for a closed PR. Use the `latest` version (built for the `master` branch) or create a new PR."
) | \
gh pr comment "${PR_NUMBER}" --repo ${{ github.repository }} -F -
gh api graphql --silent --raw-field query="mutation AddReaction {addReaction(input:{subjectId:\"$NODE_ID\",content:THUMBS_DOWN}){reaction{content}subject{id}}}"
gh api graphql --silent --raw-field query="mutation RemoveReaction {removeReaction(input:{subjectId:\"$NODE_ID\",content:EYES}){reaction{content}subject{id}}}"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
NODE_ID: ${{ github.event.comment.node_id }}
- name: Get PR HEAD Ref
id: getRef
run: echo "pr_ref=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json headRefOid | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}

- name: Check out repository
uses: actions/checkout@v2

- name: Build environment
uses: conda-incubator/setup-miniconda@v2
with:
environment-file: environment-dev.yml
miniforge-variant: Mambaforge
miniforge-version: 4.9.2-4
use-mamba: true

- name: Install package
shell: bash -l {0}
run: pip install .

- name: Run pytest on tutorials
shell: bash -l {0}
run: python -m pytest -rs -v --nbmake tutorials/
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ ci:

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
exclude: 'flowermd/tests/assets/.* | flowermd/assets/.*'
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
args: [ --line-length=80 ]
Expand All @@ -37,6 +37,7 @@ repos:
- id: flake8
args:
- --max-line-length=80
- --extend-ignore=E203
exclude: '__init__.py'

- repo: https://github.com/pycqa/pydocstyle
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This is bolstered by a library-based approach to system initialization, making
flowerMD agnostic to system identity, forcefield, and thermodynamic
ensemble, and allowing for growth on an as-needed basis.

flowerMD's design allows for creation of modules where an end-to-end interface is designed with a complex task in mind, such as fusion welding of polymers and surface wetting:

<img src='docs/images/interface.png' width='250' height='160'> <img src='docs/images/adhesion.png' width='250' height='160'> <img src='docs/images/tensile2.png' width='320' height='160'>

<img src='docs/images/surface-wetting.png' width='410' height='180'> <img src='docs/images/surface-wetting2.png' width='410' height='180'>

Installing flowermd
===================
Expand Down
Binary file modified docs/images/surface-wetting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/surface-wetting2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/tensile.mov
Binary file not shown.
7 changes: 4 additions & 3 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ dependencies:
- freud >=2.13.1
- gmso >=0.11.2
- gsd >=3.0
- grits=0.4.1
- hoomd=4.3
- mbuild >=0.16.4
- mbuild >=0.17.0
- numpy
- openbabel >=3
- pip
- pre-commit
- py3Dmol
- pytest
- pytest-cov
- python >=3.10
- nbmake
- python >=3.10, <3.12
- fresnel >=0.13.5
- cmeutils >=1.1.1
- grits >=0.3.0
6 changes: 3 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ dependencies:
- gmso >=0.11.2
- gsd >=3.0
- hoomd=4.3
- mbuild >=0.16.4
- mbuild >=0.17.0
- numpy
- openbabel >=3
- pip
- py3Dmol
- python >=3.10
- python >=3.10, <3.12
- fresnel >=0.13.5
- cmeutils >=1.1.1
- grits >=0.3.0
- grits =0.4.1
2 changes: 1 addition & 1 deletion flowermd/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (1, 2, 0)
VERSION = (1, 3, 0)

__version__ = ".".join(map(str, VERSION))
22 changes: 15 additions & 7 deletions flowermd/base/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import itertools
import os.path
import random
import warnings
from typing import List

import mbuild as mb
Expand Down Expand Up @@ -211,13 +212,20 @@ def _align_backbones_z_axis(self, heavy_atoms_only=False):
backbone_direction = np.array([0, 0, 1])
for mol in self.molecules:
if heavy_atoms_only:
positions = np.array(
[
p.xyz[0]
for p in mol.particles()
if p.element.symbol != "H"
]
)
try:
positions = np.array(
[
p.xyz[0]
for p in mol.particles()
if p.element.symbol != "H"
]
)
except AttributeError:
positions = mol.xyz
warnings.warn(
"No element information found."
"Using all particle positions to fit backbone axis."
)
else:
positions = mol.xyz
backbone = get_backbone_vector(positions)
Expand Down
38 changes: 35 additions & 3 deletions flowermd/base/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(
log_write_freq=1e3,
log_file_name="sim_data.txt",
thermostat=HOOMDThermostats.MTTK,
rigid_constraint=None,
):
if not isinstance(forcefield, Iterable) or isinstance(forcefield, str):
raise ValueError(
Expand Down Expand Up @@ -104,7 +105,17 @@ def __init__(
self._kT = None
self._reference_values = dict()
self._reference_values = reference_values
self._integrate_group = hoomd.filter.All()
if rigid_constraint and not isinstance(
rigid_constraint, hoomd.md.constrain.Rigid
):
raise ValueError(
"Invalid rigid constraint. Please provide a "
"hoomd.md.constrain.Rigid object."
)
self._rigid_constraint = rigid_constraint
self._integrate_group = self._create_integrate_group(
rigid=True if rigid_constraint else False
)
self._wall_forces = dict()
self._create_state(self.initial_state)
# Add a gsd and thermo props logger to sim operations
Expand Down Expand Up @@ -290,7 +301,16 @@ def volume(self):
def mass_reduced(self):
"""The total mass of the system in reduced units."""
with self.state.cpu_local_snapshot as snap:
return sum(snap.particles.mass)
if self._rigid_constraint:
last_body_tag = -1
for body_tag in snap.particles.body:
if body_tag > last_body_tag:
last_body_tag += 1
else:
break
return sum(snap.particles.mass[last_body_tag + 1 :])
else:
return sum(snap.particles.mass)

@property
def mass(self):
Expand Down Expand Up @@ -603,7 +623,14 @@ def set_integrator_method(self, integrator_method, method_kwargs):
"""
if not self.integrator: # Integrator and method not yet created
self.integrator = hoomd.md.Integrator(dt=self.dt)
self.integrator = hoomd.md.Integrator(
dt=self.dt,
integrate_rotational_dof=(
True if self._rigid_constraint else False
),
)
if self._rigid_constraint:
self.integrator.rigid = self._rigid_constraint
self.integrator.forces = self._forcefield
self.operations.add(self.integrator)
new_method = integrator_method(**method_kwargs)
Expand Down Expand Up @@ -1286,6 +1313,11 @@ def _lj_force(self):
][0]
return lj_force

def _create_integrate_group(self, rigid):
if rigid:
return hoomd.filter.Rigid(("center", "free"))
return hoomd.filter.All()

def _create_state(self, initial_state):
"""Create the simulation state.
Expand Down
12 changes: 12 additions & 0 deletions flowermd/base/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ class Pack(System):
The factor by which to expand the box for packing.
edge : float, default 0.2
The space (nm) between the edge of the box and the molecules.
overlap : float, default 0.2
Minimum separation (nm) between particles of different molecules.
.. warning::
Expand Down Expand Up @@ -670,6 +672,7 @@ def __init__(
packing_expand_factor=5,
edge=0.2,
overlap=0.2,
fix_orientation=False,
):
if not isinstance(density, u.array.unyt_quantity):
self.density = density * u.Unit("g") / u.Unit("cm**3")
Expand All @@ -682,6 +685,7 @@ def __init__(
self.packing_expand_factor = packing_expand_factor
self.edge = edge
self.overlap = overlap
self.fix_orientation = fix_orientation
super(Pack, self).__init__(molecules=molecules, base_units=base_units)

def _build_system(self):
Expand Down Expand Up @@ -709,6 +713,7 @@ def _build_system(self):
box=list(target_box * self.packing_expand_factor),
overlap=self.overlap,
edge=self.edge,
fix_orientation=self.fix_orientation,
)
return system

Expand All @@ -729,6 +734,13 @@ class Lattice(System):
basis_vector : array-like, default [0.5, 0.5, 0]
The vector between points in the unit cell.
Notes
-----
The system is built in a way that the long axis of the
molecules is aligned with the z direction, and the
lattice is made by repeating and translating in the
x and y directions.
"""

def __init__(
Expand Down
2 changes: 2 additions & 0 deletions flowermd/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BaseHOOMDForcefield,
BaseXMLForcefield,
BeadSpring,
EllipsoidForcefield,
FF_from_file,
KremerGrestBeadSpring,
TableForcefield,
Expand All @@ -17,6 +18,7 @@
PEEK,
PEKK,
PPS,
EllipsoidChain,
LJChain,
PEKK_meta,
PEKK_para,
Expand Down
Loading

0 comments on commit 68777e1

Please sign in to comment.