Skip to content

Commit 73d9e8b

Browse files
Merge pull request #39 from cmelab/mosdef
MSIBI Revamp
2 parents fe2bd54 + 6904fc1 commit 73d9e8b

File tree

156 files changed

+3134
-113704
lines changed

Some content is hidden

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

156 files changed

+3134
-113704
lines changed

.codecov.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
comment:
2+
layout: "reach, diff, flags, files"
3+
behavior: default
4+
require_changes: false # if true: only post the comment if coverage changes
5+
require_base: no # [yes :: must have a base report to post]
6+
require_head: yes # [yes :: must have a head report to post]
7+
branches: # branch names that can post comment
8+
- "main"
9+
ignore:
10+
- "msibi/tests"
11+
- "setup.py"

.coveragerc

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/CI.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
pull_request:
8+
branches:
9+
- "main"
10+
schedule:
11+
- cron: "0 0 * * *"
12+
13+
jobs:
14+
test:
15+
if: github.event.pull_request.draft == false
16+
name: MSIBI Tests (python)
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest]
22+
python-version: ["3.10", "3.11", "3.12"]
23+
24+
defaults:
25+
run:
26+
shell: bash -l {0}
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
name: Checkout Branch / Pull Request
31+
32+
- name: Install Mamba
33+
uses: mamba-org/setup-micromamba@v2
34+
with:
35+
environment-file: environment-dev.yml
36+
create-args: >-
37+
python=${{ matrix.python-version }}
38+
39+
- name: Install Package
40+
run: python -m pip install -e .
41+
42+
- name: Test (OS -> ${{ matrix.os }} / Python -> ${{ matrix.python-version }})
43+
run: python -m pytest -v --cov=msibi --cov-report=xml --cov-append --cov-config=setup.cfg --color yes --pyargs msibi
44+
45+
- name: Upload Coverage Report
46+
uses: codecov/codecov-action@v5
47+
with:
48+
name: MSIBI-Coverage
49+
verbose: true
50+
51+
arch-test:
52+
if: github.event.pull_request.draft == false
53+
name: MSIBI Tests (arch)
54+
runs-on: ${{ matrix.os }}
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
os: [macOS-latest, ubuntu-latest]
59+
python-version: ["3.12"]
60+
61+
defaults:
62+
run:
63+
shell: bash -l {0}
64+
65+
steps:
66+
- uses: actions/checkout@v4
67+
name: Checkout Branch / Pull Request
68+
69+
- name: Install Mamba
70+
uses: mamba-org/setup-micromamba@v2
71+
with:
72+
environment-file: environment-dev.yml
73+
create-args: >-
74+
python=${{ matrix.python-version }}
75+
76+
- name: Install Package
77+
run: python -m pip install -e .
78+
79+
- name: Test (OS -> ${{ matrix.os }} / Python -> ${{ matrix.python-version }})
80+
run: python -m pytest -v --color yes --pyargs msibi

.github/workflows/codeql.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: "50 6 * * 0"
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ python ]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
queries: +security-and-quality
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2
40+
with:
41+
category: "/language:${{ matrix.language }}"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Default files
2+
*.ipynb
23
*.pyc
34
*.dcd
45
.DS_Store
56
*.egg-info
6-
7+
*.idea/
78
# Byte-compiled / optimized / DLL files
89
__pycache__/
910
*.py[cod]

.pre-commit-config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ci:
2+
autofix_commit_msg: |
3+
[pre-commit.ci] auto fixes from pre-commit.com hooks
4+
for more information, see https://pre-commit.ci
5+
autofix_prs: true
6+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
7+
autoupdate_schedule: weekly
8+
skip: [ ]
9+
submodules: false
10+
repos:
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.6.1 # Ruff version
13+
hooks:
14+
- id: ruff
15+
args: [--fix, --extend-ignore=E203]
16+
- id: ruff-format
17+
args: [--line-length=80]
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v4.6.0
20+
hooks:
21+
- id: check-yaml
22+
- id: end-of-file-fixer
23+
- id: trailing-whitespace
24+
exclude: 'msibi/tests/assets/.*'
25+
- repo: https://github.com/pycqa/isort
26+
rev: 5.13.2
27+
hooks:
28+
- id: isort
29+
name: isort (python)
30+
args:
31+
[ --profile=black, --line-length=80 ]
32+
exclude: 'msibi/tests/assets/.* '

.readthedocs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
formats:
3+
- htmlzip
4+
- pdf
5+
build:
6+
os: ubuntu-22.04
7+
tools:
8+
python: "mambaforge-4.10"
9+
10+
conda:
11+
environment: docs/environment-docs.yml
12+
13+
sphinx:
14+
builder: html
15+
configuration: docs/source/conf.py
16+
fail_on_warning: false

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 118 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,128 @@
1-
MultiState Iterative Boltzmann Inversion
1+
<img src="/docs/images/msibi.png" height="300">
2+
3+
# MultiState Iterative Boltzmann Inversion (MS-IBI)
24
----------------------------------------
3-
[![Build Status](https://travis-ci.org/mosdef-hub/msibi.svg?branch=master)](https://travis-ci.org/mosdef-hub/msibi)
4-
[![Coverage Status](https://coveralls.io/repos/ctk3b/msibi/badge.svg?branch=master)](https://coveralls.io/r/ctk3b/msibi?branch=master)
5+
[![pytest](https://github.com/mosdef-hub/msibi/actions/workflows/pytest.yml/badge.svg)](https://github.com/mosdef-hub/msibi/actions/workflows/pytest.yml)
6+
[![codecov](https://codecov.io/gh/mosdef-hub/msibi/branch/main/graph/badge.svg?token=7NFPBMBN0I)](https://codecov.io/gh/mosdef-hub/msibi)
7+
[![Citing MSIBI](https://img.shields.io/badge/DOI-10.1063%2F1.4880555-blue.svg)](http://dx.doi.org/10.1063/1.4880555)
58

6-
A package to help you manage and run pair potential optimizations using
7-
multistate iterative Boltzmann inversion.
9+
A package to help you manage and run coarse-grain potential optimizations using multistate iterative Boltzmann inversion.
810

9-
Install from source:
10-
```python
11+
## Installing MSIBI
12+
13+
### Install from conda-forge (Coming soon):
14+
```
15+
mamba install -c conda-forge msibi
16+
```
17+
18+
### Install from source:
19+
```bash
1120
git clone https://github.com/mosdef-hub/msibi.git
1221
cd msibi
22+
mamba env create -f environment.yml
23+
mamba activate msibi
1324
pip install .
1425
```
1526

27+
## Using MSIBI
28+
The MSIBI package is designed to be very object oriented. Any force optimization runs requires at least one `msibi.state.State` instance, `msibi.force.Force` instance and `msibi.optimize.MSIBI` instance. More state and forces can be added as needed. Multiple forces can be added with some held fixed while others are being optimized after each iteation. MSIBI is designed to allow for optimization of both intra-molecular and inter-molecular potentials.
29+
30+
MSIBI uses [Hoomd-Blue](https://hoomd-blue.readthedocs.io/en/latest/) to run optimization simulations. It is not required that you be familiar with Hoomd to use MSIBI as the simulation script is automatically generated and ran. However, it is required that you pass in the choice of [Hoomd method](https://hoomd-blue.readthedocs.io/en/latest/module-md-methods.html), [Hoomd neighbor list](https://hoomd-blue.readthedocs.io/en/latest/module-md-nlist.html), and [Hoomd thermostat](https://hoomd-blue.readthedocs.io/en/latest/module-md-methods-thermostats.html) to the `msibi.optimize.MSIBI` class. Since MSIBI utilizes Hoomd-Blue, this means that MSIBI can run on GPUs, see [Hoomd's installation guide](https://hoomd-blue.readthedocs.io/en/latest/installation.html) for instructions on ensuring your environment includes a GPU build of hoomd.
31+
32+
### Quick Example:
33+
Here is a simple example using MSIBI to learn a bond-stretching force from a single state point:
34+
35+
```python
36+
# This is the context/management class for MSIBI
37+
# Set simulation parameters, call `add_state` and `add_force` methods to store other MSIBI objects.
38+
optimizer = MSIBI(
39+
nlist=hoomd.md.nlist.Cell,
40+
integrator_method=hoomd.md.methods.ConstantVolume,
41+
thermostat=hoomd.md.methods.thermostats.MTTK,
42+
thermostat_kwargs={"tau": 0.1},
43+
method_kwargs={},
44+
dt=0.0001,
45+
gsd_period=int(1e3)
46+
)
47+
48+
# Create a State instance, pass in a path to the target trajectory
49+
stateA = State(name="A", kT=5.0, traj_file="cg_trajectory.gsd", alpha0=0.7, n_frames=100)
50+
51+
# For each force you want to optimize, create an instance, set optimize=True
52+
AA_bond = Bond(type1="A", type2="A", optimize=True, nbins=80)
53+
AA_bond.set_polynomial(x_min=0.0, x_max=0.5, x0=0.22, k2=100000, k3=0, k4=0)
54+
AA_bond.smoothing_window = 5
55+
AB_bond = Bond(type1="A", type2="B", optimize=True, nbins=80)
56+
AB_bond.set_polynomial(x_min=0.0, x_max=0.5, x0=0.22, k2=100000, k3=0, k4=0)
57+
AB_bond.smoothing_window = 5
58+
# Add all states and forces to the optimization class (MSIBI)
59+
optimizer.add_state(stateA)
60+
optimizer.add_force(AA_bond)
61+
optimizer.add_force(AB_bond)
62+
optimizer.run_optimization(n_iterations=10, n_steps=2e5)
63+
64+
# See distribution comparison
65+
AA_bond.plot_distribution_comparison(state=stateA)
66+
AB_bond.plot_distribution_comparison(state=stateA)
67+
68+
<<<<<<< HEAD
69+
# Run 20 MSIBI iterations
70+
optimizer.run_optimization(n_steps=2e6, n_iterations=20)
71+
pairAA.save_potential("pairAA.csv")
72+
```
1673

17-
#### Citation [![Citing MSIBI](https://img.shields.io/badge/DOI-10.1063%2F1.4880555-blue.svg)](http://dx.doi.org/10.1063/1.4880555)
74+
### Example: Multiple states, multiple forces
75+
- Here is an example of learning a pair potential using multiple state points and forces.
76+
- In this example, we set fixed bond and angle potentials that are included during iteration simulations.
77+
- The bond potential will set a fixed harmonic force, while the angle potential will be set from a table potential file.
78+
- This illustrates a use case of stringing together multiple MSIBI optimizations.
79+
- For example, one MSIBI optimization can be used to learn and obtain a coarse-grained angle potential table file which can then be set and held fixed while learning pair potentials in a subsequent MSIBI optimization.
80+
81+
```python
82+
import hoomd
83+
from msibi import MSIBI, State, Pair, Bond, Angle
84+
85+
optimizer = MSIBI(
86+
nlist=hoomd.md.nlist.Cell,
87+
integrator_method=hoomd.md.methods.ConstantVolume,
88+
thermostat=hoomd.md.methods.thermostats.MTTK,
89+
thermostat_kwargs={"tau": 0.1},
90+
method_kwargs={},
91+
dt=0.0001,
92+
gsd_period=int(1e4)
93+
)
94+
95+
# Create 3 State instances, pass in a path to the target trajectory
96+
stateA = State(name="A", kT=2.0, traj_file="stateA.gsd", alpha=0.2, n_frames=50)
97+
stateB = State(name="B", kT=4.0, traj_file="stateB.gsd", alpha=0.5, n_frames=50)
98+
stateC = State(name="C", kT=6.0, traj_file="stateC.gsd", alpha=0.3, n_frames=50)
99+
optimizer.add_state(stateA)
100+
optimizer.add_state(stateB)
101+
optimizer.add_state(stateC)
102+
103+
# Add bond and set a harmonic force (e.g. fit to Boltzmann inverse of the distribtion)
104+
bondAA = Bond(type1="A", type2="A", optimize=False)
105+
bondAA.set_harmonic(r0=1.4, k=200)
106+
optimize.add_force(bondAA)
107+
108+
# Add angle and load previously obtained table potential
109+
angleAA = Angle(type1="A", type2="A", type3="A", optimize=False)
110+
angleAA.set_from_file("angleAA.csv")
111+
optimize.add_force(angleAA)
112+
113+
# Create a Pair instance to be optimized.
114+
pairAA = Pair(type1="A", type2="A", optimize=True, r_cut=3.0, nbins=100)
115+
# Call the set_lj() method to set an initial guess potential
116+
pairAA.set_lj(r_min=0.001, r_cut=3.0, epsilon=1.0, sigma=1.0)
117+
optimizer.add_force(pairAA)
118+
119+
# Run 20 MSIBI iterations
120+
optimizer.run_optimization(n_steps=2e6, n_iterations=20)
121+
pairAA.save_potential("pairAA.csv")
122+
```
123+
124+
125+
## Citing MSIBI
18126
Details of the underlying method and its validation can be found [here](http://dx.doi.org/10.1063/1.4880555).
19127

20128
If you use this package, please cite the above paper. The BibTeX reference is
@@ -25,10 +133,7 @@ If you use this package, please cite the above paper. The BibTeX reference is
25133
journal = "The Journal of Chemical Physics",
26134
year = "2014",
27135
volume = "140",
28-
number = "22",
29-
doi = "http://dx.doi.org/10.1063/1.4880555"
136+
number = "22",
137+
doi = "http://dx.doi.org/10.1063/1.4880555"
30138
}
31139
```
32-
33-
34-

devtools/travis-ci/install.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)