Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASE Calculator interface #215

Merged
merged 27 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
66f861e
initial interface commit
laserkelvin May 14, 2024
384fdd1
feat: exposing calculator in namespace
laserkelvin May 14, 2024
374c0b8
refactor: removing deprecated arg from Calculator inheritance
laserkelvin May 14, 2024
4fea98a
docs: added inline comments for calculate
laserkelvin May 14, 2024
55ab2c1
fix: correcting forces key to match what is expected by ase
laserkelvin May 14, 2024
dcbc0b8
fix: calling detach on forces
laserkelvin May 14, 2024
0837a0b
fix: calling detach on energy, just in case
laserkelvin May 14, 2024
46a954c
test: added unit tests for ase calculator
laserkelvin May 14, 2024
ad78c5b
refactor: making sure output heads are type cast correctly
laserkelvin May 14, 2024
b6595fc
test: removing dtype parametrization
laserkelvin May 14, 2024
5bd6117
docs: added descriptions of unit tests
laserkelvin May 14, 2024
59293c9
refactor: adding execption handling for no results saved
laserkelvin May 14, 2024
5f3dbcd
refactor: type checking to make sure the right class is passed
laserkelvin May 14, 2024
b4e2c29
feat: implemented constructor methods
laserkelvin May 14, 2024
2ac1af8
docs: add docstring to explain pipeline
laserkelvin May 14, 2024
e8fdea8
scripts: added example scripts for ase
laserkelvin May 15, 2024
affa5b4
refactor: allowing task to be multi task
laserkelvin May 15, 2024
9a0a26b
refactor: catching multi task case
laserkelvin May 15, 2024
597f533
cleanup: removing unused relaxation modules from ocp
laserkelvin May 15, 2024
f5d00fc
ci: adding pytest trigger for interfaces
laserkelvin May 15, 2024
7808a42
ci: rename workflow for interface pytest
laserkelvin May 15, 2024
fb935e1
feat: adding stress and dipole extraction in calculator
laserkelvin May 15, 2024
9be67ad
feat: adding support for a conversion factor configuration
laserkelvin May 15, 2024
aeed809
feat: adding conversion step to pipeline
laserkelvin May 15, 2024
24b2043
feat: added scalar regression constructor method
laserkelvin May 15, 2024
c11dbff
docs: added docstring description of the calculator
laserkelvin May 15, 2024
439b7b4
refactor: putting checkpoint path check into reusable function
laserkelvin May 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/run_pytest_interfaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run interface related PyTests
env:
COLUMNS: 120
on:
pull_request:
paths:
- 'matsciml/interfaces/**'
workflow_dispatch:
jobs:
interfaces-pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create/reuse micromamba env
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.7-0'
environment-file: conda.yml
init-shell: >-
bash
cache-environment: true
post-cleanup: 'all'
generate-run-shell: true
- name: Install current version of matsciml
run: |
pip install .
shell: micromamba-shell {0}
- name: Install PyTest
run: |
pip install pytest pytest-dependency pytest-pretty
shell: micromamba-shell {0}
- name: Print out environment
run: |
micromamba env export && pip freeze
shell: micromamba-shell {0}
- name: Run pytest in data
run: |
pytest -v -m "not lmdb and not slow and not remote_request" ./matsciml/interfaces
shell: micromamba-shell {0}
35 changes: 35 additions & 0 deletions examples/interfaces/ase_from_pretrained.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

from ase import Atoms, units
from ase.md.verlet import VelocityVerlet

from matsciml.interfaces.ase import MatSciMLCalculator
from matsciml.datasets.transforms import (
PeriodicPropertiesTransform,
PointCloudToGraphTransform,
)

"""
Demonstrates setting up a calculator from a pretrained
`ForceRegressionTask` checkpoint.

Substitute 'model.ckpt' for the path to a checkpoint file.
"""

d = 2.9
L = 10.0

atoms = Atoms("C", positions=[[0, L / 2, L / 2]], cell=[d, L, L], pbc=[1, 0, 0])

calc = MatSciMLCalculator.from_pretrained_force_regression(
"model.ckpt",
transforms=[
PeriodicPropertiesTransform(6.0, True),
PointCloudToGraphTransform("pyg"),
],
)
# set the calculator to matsciml
atoms.calc = calc
# run the simulation for 100 timesteps, with 5 femtosecond timesteps
dyn = VelocityVerlet(atoms, timestep=5 * units.fs, logfile="md.log")
dyn.run(100)
65 changes: 65 additions & 0 deletions examples/interfaces/ase_from_scratch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from __future__ import annotations

from ase import Atoms, units
from ase.md.verlet import VelocityVerlet
import pytorch_lightning as pl

from matsciml.lightning import MatSciMLDataModule
from matsciml.models.base import ForceRegressionTask
from matsciml.models.pyg import EGNN
from matsciml.interfaces.ase import MatSciMLCalculator
from matsciml.datasets.transforms import (
PeriodicPropertiesTransform,
PointCloudToGraphTransform,
)

"""
Demonstrates setting up a calculator from a `ForceRegressionTask`
trained from scratch - this is unlikely be the way you would actually
do this, but just demonstrates how the workflow is composed together
in a single file.
"""

task = ForceRegressionTask(
encoder_class=EGNN,
encoder_kwargs={"hidden_dim": 32, "output_dim": 32},
output_kwargs={"lazy": False, "input_dim": 32, "hidden_dim": 32, "num_hidden": 3},
)

transforms = [
PeriodicPropertiesTransform(6.0, True),
PointCloudToGraphTransform("pyg"),
]

dm = MatSciMLDataModule.from_devset(
"LiPSDataset", batch_size=8, num_workers=0, dset_kwargs={"transforms": transforms}
)

# run the training loop
trainer = pl.Trainer(
fast_dev_run=10,
logger=False,
enable_checkpointing=False,
)
trainer.fit(task, datamodule=dm)

# put it into eval for inference
task = task.eval()

# get a random frame from LiPS to do the propagation
frame = dm.dataset.__getitem__(52)
graph = frame["graph"]
atoms = Atoms(
positions=graph["pos"].numpy(),
cell=frame["cell"].numpy().squeeze(),
numbers=graph["atomic_numbers"].numpy(),
)

# instantiate calculator using the trained model
# reuse the same transforms as with the data module
calc = MatSciMLCalculator(task, transforms=transforms)
# set the calculator to matsciml
atoms.calc = calc
# run the simulation for 100 timesteps, with 5 femtosecond timesteps
dyn = VelocityVerlet(atoms, timestep=5 * units.fs, logfile="md.log")
dyn.run(100)
174 changes: 0 additions & 174 deletions matsciml/common/relaxation/ase_utils.py

This file was deleted.

60 changes: 0 additions & 60 deletions matsciml/common/relaxation/ml_relaxation.py

This file was deleted.

Empty file.
Loading
Loading