An Espaloma model is composed of three main stages:
- Representation Stage: Maps the molecular graph to atom latent representations using a Graph Neural Network (e.g.,
SAGEConv). - Readout Stage: Maps atom latent representations to specific molecular mechanics (MM) parameters (bonds, angles, torsions) using a pooling mechanism like
JanossyPooling. - Energy/Geometry Stage: Computes the energy and geometry from the parameters.
In the readout stage, you define the modular MM parameters the model will assign, such as atom hardness, electronegativity, and coefficients for bonds, angles, and torsions.
# Stage I: Graph -> Atom Latent Representation
representation = esp.nn.Sequential(
layer=esp.nn.layers.dgl_legacy.gn("SAGEConv"),
config=[128, "relu", 128, "relu", 128, "relu"],
)
# Stage II & III: Latent -> MM Parameters -> Energy
readout = esp.nn.readout.janossy.JanossyPooling(
in_features=128,
config=[128, "relu", 128, "relu", 128, "relu"],
out_features={
1: {"e": 1, "s": 1}, # atom hardness and electronegativity
2: {"log_coefficients": 2}, # bond linear combination
3: {"log_coefficients": 2}, # angle linear combination
4: {"k": 6}, # torsion barrier heights
},
)
espaloma_model = torch.nn.Sequential(
representation,
readout,
esp.nn.readout.janossy.ExpCoefficients(),
esp.mm.geometry.GeometryInGraph(),
esp.mm.energy.EnergyInGraph(),
)