Skip to content

Commit

Permalink
get latest model function
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanqing-wang committed Jul 14, 2023
1 parent aed2898 commit 5c55f6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ We show that this approach is not only sufficiently expressive to reproduce lega
* `polynomial.py` higher order polynomials.


# Example: Deploy espaloma 0.2.0 pretrained force field to arbitrary MM system
# Example: Deploy latest espaloma pretrained force field to arbitrary MM system

```python
# imports
import os
import torch
import espaloma as esp

# grab pretrained model
if not os.path.exists("espaloma_model.pt"):
os.system("wget http://data.wangyq.net/espaloma_model.pt")

# define or load a molecule of interest via the Open Force Field toolkit
from openff.toolkit.topology import Molecule
molecule = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
Expand All @@ -61,7 +57,7 @@ molecule = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
molecule_graph = esp.Graph(molecule)

# apply a trained espaloma model to assign parameters
espaloma_model = torch.load("espaloma_model.pt")
espaloma_model = esp.get_latest_model()
espaloma_model(molecule_graph.heterograph)

# create an OpenMM System for the specified molecule
Expand Down
1 change: 1 addition & 0 deletions espaloma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .graphs.graph import Graph
from .metrics import GraphMetric
from .mm.geometry import *
from .graphs.deploy import get_latest_model

# Add imports here
# import espaloma
Expand Down
8 changes: 7 additions & 1 deletion espaloma/graphs/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
OPENMM_BOND_K_UNIT = OPENMM_ENERGY_UNIT / (OPENMM_LENGTH_UNIT**2)
OPENMM_ANGLE_K_UNIT = OPENMM_ENERGY_UNIT / (OPENMM_ANGLE_UNIT**2)

LATEST_URL = "https://github.com/choderalab/espaloma/"
"releases/latest/download/espaloma-latest.pt"

# =============================================================================
# MODULE FUNCTIONS
# =============================================================================

def get_latest_model();
model = torch.utils.model_zoo.load_url(LATEST_URL)
model.eval()
return model

def load_forcefield(forcefield="openff_unconstrained-2.0.0"):
# get a forcefield
Expand Down

0 comments on commit 5c55f6f

Please sign in to comment.