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

Espaloma trained on QCArchive-derived bond/angle parameters #76

Open
bieniekmateusz opened this issue Jun 7, 2021 · 3 comments
Open

Comments

@bieniekmateusz
Copy link

bieniekmateusz commented Jun 7, 2021

We have derived molecule-specific bond/angle force field parameters for ~20K molecules hosted on QCArchive.

We would like to use these data to train espaloma to assign bond/angle parameters to any organic molecule outside the training set.

Please can you let us know if this sounds possible, and if so how we can get started with the code?

@djcole56
@jthorton

@yuanqing-wang
Copy link
Member

Sounds exciting! This is definitely doable.

It could be done as:

import espaloma as esp

# define a layer
layer = esp.nn.layers.dgl_legacy.gn("GraphConv")

# define a representation
representation = esp.nn.Sequential(
        layer,
        [32, 'relu', 32, 'relu', 32, 'relu']
)

# define a readout
readout = esp.nn.readout.janossy.JanossyPooling(
        in_features=32,
        out_features={
            2: ["k", "eq"],
        },
) 

net = torch.nn.Sequential(
    representation,
    readout
)

and then suppose you have a molecule, say methane, and you know that the reference force constant and equilibrium bond length, and you want the loss function to be simply the sum of the MSE loss:


g = esp.Graph("C")
g = net(g)
k_hat = g.nodes['n2'].data['k']
eq_hat = g.nodes['n2'].data['eq']

loss = torch.nn.MSELoss()(k_ref, k_hat) + torch.nn.MSELoss()(eq_ref, eq_hat)
loss.backward()

you can also look at this pre-defined loss function

class BondKMSE(GraphMetric):

@bieniekmateusz
Copy link
Author

bieniekmateusz commented Jul 13, 2021

Thanks @yuanqing-wang, would you mind double checking if I am not doing anything silly?

I was just trying to run the example you shared here, and run into this:

  File "python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "python3.9/site-packages/torch/nn/modules/container.py", line 119, in forward
    input = module(input)
  File "python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "python3.9/site-packages/espaloma/nn/sequential.py", line 119, in forward
    g_ = dgl.to_homo(g.edge_type_subgraph(["n1_neighbors_n1"]))
AttributeError: 'Graph' object has no attribute 'edge_type_subgraph'

Was that meant to be g_ = dgl.to_homo(g.heterograph.edge_type_subgraph(["n1_neighbors_n1"]))? It shows up in a ~3 other places.

@yuanqing-wang
Copy link
Member

Hi sorry for the late reply! If the graph you're having is a espaloma.Graph, which is a thin wrapper of dgl.graph then you would indeed need to convert it to dgl.graph by using g.heterograph!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants