Skip to content

Commit

Permalink
Merge branch 'duartegroup:main' into autode-update
Browse files Browse the repository at this point in the history
  • Loading branch information
juraskov authored Dec 6, 2024
2 parents e3709e8 + b99faae commit 44b9ea6
Show file tree
Hide file tree
Showing 71 changed files with 10,842 additions and 495 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
gha-dependencies:
patterns:
- '*'
5 changes: 4 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
pull_request:

env:
FORCE_COLOR: 1

jobs:
pre-commit:
env:
Expand All @@ -15,4 +18,4 @@ jobs:
uses: actions/checkout@v4

- name: Run pre-commit
uses: pre-commit/action@v3.0.0
uses: pre-commit/action@v3.0.1
76 changes: 60 additions & 16 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ on:
branches: [main]
pull_request:

env:
FORCE_COLOR: 1

jobs:
test:
name: GAP (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.9"]

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

steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1

- uses: mamba-org/setup-micromamba@v2
with:
# the create command looks like this:
# `micromamba create -n test-env python=3.9 -f environment.yml`
Expand All @@ -38,34 +41,75 @@ jobs:
run: ./install_gap.sh

- name: Test basic install
run: pytest --cov
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
flags: python-${{ matrix.python-version }}
token: ${{ secrets.CODECOV_TOKEN }}
slug: duartegroup/mlp-train

test-ace:
name: ACE (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-22.04"]
python-version: ["3.9"]

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

steps:
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@v2
with:
version: '1.6'

- uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment_ace.yml
environment-name: gha-test-env
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}
- name: ACE install
run: ./install_ace.sh

- name: Test ACE
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
flags: python-${{ matrix.python-version }}-ace
token: ${{ secrets.CODECOV_TOKEN }}
slug: duartegroup/mlp-train

test-mace:
name: MACE (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.9"]

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

steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1

- uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment_mace.yml
environment-name: gha-test-env
Expand All @@ -77,10 +121,10 @@ jobs:
run: ./install_mace.sh

- name: Test MACE install
run: pytest --cov
run: pytest --cov=mlptrain

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
flags: python-${{ matrix.python-version }}-mace
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ repos:
- id: no-commit-to-branch
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
exclude: examples/WTMetaD_paper/r2/free_energy/wtmetad_ib/accumulated_bias/bias_after_iter_15.dat
- id: check-added-large-files
args: ['--maxkb=500', '--enforce-all']
exclude: mlptrain/sampling/tests/data.zip
exclude: tests/data/data.zip
- id: check-yaml
- id: check-toml

Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![DOI](https://img.shields.io/badge/doi-10.6084/m9.figshare.25816864.v1-blue.svg?style=flat&labelColor=whitesmoke&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAAJsklEQVR42qWXd1DTaRrHf%2BiB2Hdt5zhrAUKz4IKEYu9IGiGFFJJQ0gkJCAKiWFDWBRdFhCQUF3UVdeVcRQEBxUI3yY9iEnQHb3bdW1fPubnyz%2F11M7lvEHfOQee2ZOYzPyDv%2B3yf9%2Fk95YX4fx%2BltfUt08GcFEuPR4U9hDDZ%2FVngIlhb%2FSiI6InkTgLzgDcgfvtnovhH4BzoVlrbwr55QnhCtBW4QHXnFrZbPBaQoBh4%2FSYH2EnpBEtqcDMVzB93wA%2F8AFwa23XFGcc8CkT3mxz%2BfXWtq9T9IQlLIXYEuHojudb%2BCM7Hgdq8ydi%2FAHiBXyY%2BLjwFlAEnS6Jnar%2FvnQVhvdzasad0eKvWZKe8hvDB2ofLZ%2FZEcWsh%2BhyIuyO5Bxs2iZIE4nRv7NWAb0EO8AC%2FWPxjYAWuOEX2MSXZVgPxzmRL3xKz3ScGpx6p6QnOx4mDIFqO0w6Q4fEhO5IzwxlSwyD2FYHzwAW%2BAZ4fEsf74gCumykwNHskLM7taQxLYjjIyy8MUtraGhTWdkfhkFJqtvuVl%2F9l2ZquDfEyrH8B0W06nnpH3JtIyRGpH1iJ6SfxDIHjRXHJmdQjLpfHeN54gnfFx4W9QRnovx%2FN20aXZeTD2J84hn3%2BqoF2Tqr14VqTPUCIcP%2B5%2Fly4qC%2BUL3sYxSvNj1NwsVYPsWdMUfomsdkYm3Tj0nbV0N1wRKwFe1MgKACDIBdMAhPE%2FwicwNWxll8Ag40w%2BFfhibJkGHmutjYeQ8gVlaN%2BjO51nDysa9TwNUFMqaGbKdR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fl6RDGn4Ti9B1oyYy%2BMP5G87D%2FCpRlvdnuy0PY6RC8BzTA40NXqckQ9TaOUDywkYsudxJzPgyDoAWn%2BB6nEFbaVxxC6UXjJiuDkW9TWq7uRBOJocky9iMfUhGpv%2FdQuVVIuGjYqACbXf8aa%2BPeYNIHZsM7l4s5gAQuUAzRUoT51hnH3EWofXf2vkD5HJJ33vwE%2FaEWp36GHr6GpMaH4AAPuqM5eabH%2FhfG9zcCz4nN6cPinuAw6IHwtvyB%2FdO1toZciBaPh25U0ducR2PI3Zl7mokyLWKkSnEDOg1x5fCsJE9EKhH7HwFNhWMGMS7%2BqxyYsbHHRUDUH4I%2FAheQY7wujJNnFUH4KdCju83riuQeHU9WEqNzjsJFuF%2FdTDAZ%2FK7%2F1WaAU%2BAWymT59pVMT4g2AxcwNa0XEBDdBDpAPvgDIH73R25teeuAF5ime2Ul0OUIiG4GpSAEJeYW9wDTf43wfwHgHLKJoPznkwAAAABJRU5ErkJggg%3D%3D)](https://doi.org/10.6084/m9.figshare.25816864.v1)
[![pytest CI](https://github.com/duartegroup/mlp-train/actions/workflows/pytest.yml/badge.svg?event=push)](https://github.com/duartegroup/mlp-train/actions/workflows/pytest.yml)
[![codecov](https://codecov.io/gh/duartegroup/mlp-train/branch/main/graph/badge.svg)](https://codecov.io/gh/duartegroup/mlp-train)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![License](https://img.shields.io/badge/License-MIT%202.0-blue.svg)](https://opensource.org/licenses/mit)
[![GitHub issues](https://img.shields.io/github/issues/duartegroup/mlp-train.svg)](https://github.com/duartegroup/mlp-train/issues)

# mlp-train
General machine learning potentials (MLP) training for molecular systems in gas phase and solution
Expand All @@ -16,7 +16,7 @@ Available models:

## Install

Each model is installed into individual conda environment:
Each model is installed into an individual conda environment:

```
# Install GAP
Expand All @@ -33,14 +33,19 @@ Each model is installed into individual conda environment:

- Units are: distance (Å), energy (eV), force (eV Å$`^{-1}`$), time (fs)

## Using with OpenMM (Experimental!)
## Using with OpenMM

The OpenMM backend only works with MACE at the moment. The necessary dependencies are installed automatically via conda:

```console
```
./install_mace.sh
```

Depending on your machine, you might need to prefix the command above with something like `CONDA_OVERRIDE_CUDA="11.2"` in two scenarios:

- To ensure an environment that is compatible with your CUDA driver.
- To force CUDA builds to be installed, even if the installation is being done from a CPU-only machine. This is typical in a situation where you are installing from a head node without GPUs but intend to run on GPUs and want to install the CUDA builds.

You should now be able to run `water_openmm.py` in `./examples` or run the jupyter notebook on Google Colab [`water_openmm_colab.ipynb`](./examples/water_openmm_colab.ipynb).

You can use OpenMM during active learning by passing the keyword argument `md_program="OpenMM"` to the `al_train` method.
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- cython
- dscribe=2.0
- matplotlib-base
- numpy
- numpy<2
- pytest=8
- pytest-cov=5
- py-plumed
Expand Down
2 changes: 1 addition & 1 deletion environment_ace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- cython
- dscribe=2.0
- matplotlib-base
- numpy
- numpy<2
- pytest=8
- pytest-cov=5
- py-plumed
Expand Down
19 changes: 5 additions & 14 deletions environment_mace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ dependencies:
- scipy
- xtb
- scikit-learn
- openmm
- openmm-torch
- openmm=8.1.2
- openmm-torch=1.4
- nnpops
# MACE dependencies
- pytorch=2.0
- torchvision
- torchaudio
- torch-ema
# TODO: You might also need CUDA-specific libraries,
# but that depends on CUDA version
# https://pytorch.org/get-started/locally/
# - pytorch-cuda=11.8
# - pytorch-cuda=12.1
- openmm-ml=1.2
- git
- pip:
- mace-torch
- openmmml@git+https://github.com/openmm/openmm-ml.git@main
- ase@git+https://gitlab.com/ase/ase.git@f2615a6e9a # For PLUMED
- mace-torch==0.3.6
9 changes: 9 additions & 0 deletions examples/WTMetaD_paper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Active learning meets metadynamics: Automated workflow for reactive machine learning potentials

This folder contains codes and initial files for various computational tasks discussed in the paper "Active learning meets metadynamics: Automated workflow for reactive machine learning potentials" ([https://chemrxiv.org/engage/chemrxiv/article-details/671fe54b98c8527d9ea7647a]).

The manuscript demonstrates three reactions: the SN2 reaction in implicit solvent (referred to as r1), rearrangement reaction in the gas phase (r2), and glycosylation reaction in explicit solvent (r3). Python scripts for each reaction can be found in the corresponding folders.

For r1 and r2, active learning (AL) was utilised with both WTMetaD-IB and downhill sampling methods to train the potential. Input geometries (as *.xyz files) and training script are located within folders named after the training methods, such as al_downhill.

In the case of r2, free energy calculations were performed using different enhanced sampling methods. All scripts can be found in the free_energy folder within the r2 directory. Within the free_energy folder, each enhanced sampling method is organised in separate folders containing Python scripts and necessary configuration files.
8 changes: 8 additions & 0 deletions examples/WTMetaD_paper/r1/al_downhill/r1_ts.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
6
Coordinates from ORCA-job sn2_nebts_NEB-CI_converged
C 0.02394151244587 -0.02273675265530 0.05167818806821
F -0.65299103371021 0.72656624059729 -1.73488992550113
Cl 0.68562794924814 -0.78844305036752 1.89308430540763
H 0.99880860408280 0.16036474652930 -0.38536247269303
H -0.52740777250600 0.82166542425637 0.44671920342826
H -0.52797925956060 -0.89741660836014 -0.27122929870995
31 changes: 31 additions & 0 deletions examples/WTMetaD_paper/r1/al_downhill/training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import mlptrain as mlt

mlt.Config.n_cores = 30
mlt.Config.orca_keywords = ['PBE0', 'def2-SVP', 'EnGrad', 'CPCM(Water)']

if __name__ == '__main__':
# Initialise the system
system = mlt.System(mlt.Molecule('r1_ts.xyz', charge=-1, mult=1), box=None)

# Define CV and attach an upper wall
avg_r = mlt.PlumedAverageCV(name='avg_r', atom_groups=((0, 1), (0, 2)))
avg_r.attach_upper_wall(location=2.5, kappa=1000)

# Define CVs for extra information
r_f = mlt.PlumedAverageCV(name='r_f', atom_groups=(0, 1))
r_cl = mlt.PlumedAverageCV(name='r_cl', atom_groups=(0, 2))

# Initialise PlumedBias
bias = mlt.PlumedBias(cvs=(avg_r, r_f, r_cl))

# Define the potential and train using Downhill AL (fix_init_config=True)
ace = mlt.potentials.ACE('r1_downhill', system=system)
ace.al_train(
method_name='orca',
temp=500,
n_configs_iter=5,
max_active_iters=50,
min_active_iters=20,
fix_init_config=True,
bias=bias,
)
8 changes: 8 additions & 0 deletions examples/WTMetaD_paper/r1/al_wtmetad/ch3cl_f.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
6

C 0.11150 0.23091 0.58288
F -0.88850 1.32101 -2.02704
Cl 0.64512 -0.39439 2.08233
H 1.02099 0.50449 -0.09172
H -0.45901 1.13911 0.74042
H -0.45901 -0.53348 0.04182
39 changes: 39 additions & 0 deletions examples/WTMetaD_paper/r1/al_wtmetad/training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import mlptrain as mlt

mlt.Config.n_cores = 20
mlt.Config.orca_keywords = ['PBE0', 'def2-SVP', 'EnGrad', 'CPCM(Water)']

if __name__ == '__main__':
system = mlt.System(
mlt.Molecule('ch3cl_f.xyz', charge=-1, mult=1), box=None
)

# Define CV and attach an upper wall
avg_r = mlt.PlumedAverageCV(name='avg_r', atom_groups=((0, 1), (0, 2)))
avg_r.attach_upper_wall(location=2.5, kappa=1000)

# Define CVs for extra information
r_f = mlt.PlumedAverageCV(name='r_f', atom_groups=(0, 1))
r_cl = mlt.PlumedAverageCV(name='r_cl', atom_groups=(0, 2))

# Define CV for WTMetaD AL (r_cl - r_f)
diff_r = mlt.PlumedDifferenceCV(
name='diff_r', atom_groups=((0, 2), (0, 1))
)

# Initialise PlumedBias for WTMetaD AL
bias = mlt.PlumedBias(cvs=(avg_r, r_f, r_cl, diff_r))
bias.initialise_for_metad_al(width=0.05, cvs=diff_r, biasfactor=100)

# Define the potential and train using WTMetaD AL (inherit_metad_bias=True)
ace = mlt.potentials.ACE('r1_wtmetad', system=system)
ace.al_train(
method_name='orca',
temp=300,
n_init_configs=5,
n_configs_iter=5,
max_active_iters=50,
min_active_iters=30,
inherit_metad_bias=True,
bias=bias,
)
35 changes: 35 additions & 0 deletions examples/WTMetaD_paper/r2/al_downhill/al_downhill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import autode as ade
import mlptrain as mlt

# ORCA PATH (change accordingly)
ade.Config.ORCA.path = '/usr/local/orca_5_0_3/orca'

mlt.Config.n_cores = 10
mlt.Config.orca_keywords = ['PBE0', 'D3BJ', 'def2-SVP', 'EnGrad']

if __name__ == '__main__':
system = mlt.System(mlt.Molecule('ts_r2.xyz', charge=0, mult=1), box=None)

# Define CVs for extra information
avg_r = mlt.PlumedAverageCV(name='avg_r', atom_groups=((14, 11), (14, 10)))
r_1 = mlt.PlumedAverageCV(name='r_1', atom_groups=(14, 11))
r_2 = mlt.PlumedAverageCV(name='r_2', atom_groups=(14, 10))
diff_r = mlt.PlumedDifferenceCV(
name='diff_r', atom_groups=((14, 11), (14, 10))
)

# Initialise PlumedBias
bias = mlt.PlumedBias(cvs=(avg_r, r_1, r_2, diff_r))

# Define the potential and train using Downhill AL (fix_init_config=True)
ace = mlt.potentials.ACE('r2_downhill', system=system)
ace.al_train(
method_name='orca',
temp=500,
n_init_configs=10,
n_configs_iter=10,
max_active_iters=50,
min_active_iters=20,
fix_init_config=True,
bias=bias,
)
Loading

0 comments on commit 44b9ea6

Please sign in to comment.