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

Feat/get recent #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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, map_location="cpu")
model.eval()
return model

def load_forcefield(forcefield="openff_unconstrained-2.0.0"):
# get a forcefield
Expand Down
5 changes: 1 addition & 4 deletions espaloma/graphs/tests/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ def test_butane_charge_nn():
the nn charge method"""
import torch
# Download serialized espaloma model
url = f'https://github.com/choderalab/espaloma/releases/download/0.3.0/espaloma-0.3.0rc1.pt'
espaloma_model_filepath = f'espaloma-0.3.0rc1.pt'
urllib.request.urlretrieve(url, filename=espaloma_model_filepath)
# Test deployment
ff = esp.graphs.legacy_force_field.LegacyForceField("openff-1.2.0")
g = esp.Graph("CCCC")
g = ff.parametrize(g)
# apply a trained espaloma model to assign parameters
net = torch.load(espaloma_model_filepath, map_location=torch.device('cpu'))
net = esp.get_latest_model()
net.eval()
net(g.heterograph)
esp.graphs.deploy.openmm_system_from_graph(g, suffix="_ref", charge_method="nn")
Expand Down