mindchemistry.cell.orb.GraphHead
- class mindchemistry.cell.orb.GraphHead(latent_dim, num_mlp_layers, mlp_hidden_dim, target_property_dim, node_aggregation='mean', dropout=None, compute_stress=False)[source]
Graph-level prediction head. Implements graph-level prediction head that can be attached to base models for predicting graph-level properties (e.g., stress tensor) from node features using aggregation and MLP.
- Parameters
latent_dim (int) – Input feature dimension for each node.
num_mlp_layers (int) – Number of hidden layers in MLP.
mlp_hidden_dim (int) – Hidden dimension size of MLP.
target_property_dim (int) – Output dimension of graph-level property.
node_aggregation (str, optional) – Aggregation method for node predictions, e.g.,
"mean"
or"sum"
. Default:"mean"
.dropout (Optional[float], optional) – Dropout rate for MLP. Default:
None
.compute_stress (bool, optional) – Whether to compute and output stress tensor. Default:
False
.
- Inputs:
node_features (dict) - Node feature dictionary, must contain key "feat" with shape \((n_{nodes}, latent\_dim)\).
n_node (Tensor) - Number of nodes in graph, shape \((1,)\).
- Outputs:
output (dict) - Dictionary containing key "stress_pred" with value of shape \((1, target\_property\_dim)\).
- Raises
ValueError – If required feature keys are missing in node_features.
- Supported Platforms:
Ascend
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor >>> from mindchemistry.cell.orb.gns import GraphHead >>> graph_head = GraphHead( ... latent_dim=256, ... num_mlp_layers=1, ... mlp_hidden_dim=256, ... target_property_dim=6, ... compute_stress=True, ... ) >>> n_atoms = 4 >>> n_node = Tensor([n_atoms], mindspore.int32) >>> atomic_numbers = Tensor(np.random.randint(1, 119, size=(n_atoms,), dtype=np.int32)) >>> atomic_numbers_embedding_np = np.zeros((n_atoms, 118), dtype=np.float32) >>> for i, num in enumerate(atomic_numbers.asnumpy()): ... atomic_numbers_embedding_np[i, num - 1] = 1.0 >>> node_features = { ... "atomic_numbers": atomic_numbers, ... "atomic_numbers_embedding": Tensor(atomic_numbers_embedding_np), ... "positions": Tensor(np.random.randn(n_atoms, 3).astype(np.float32)), ... "feat": Tensor(np.random.randn(n_atoms, 256).astype(np.float32)) ... } >>> output = graph_head(node_features, n_node) >>> print(output['stress_pred'].shape) (1, 6)
- predict(node_features, n_node, atomic_numbers=None)[source]
Predict graph-level attributes.
- Parameters
node_features – Node features tensor
n_node – Number of nodes
atomic_numbers – Optional atomic numbers for reference energy calculation
- Returns
Graph-level predictions of shape (n_graphs, target_property_dim). If compute_stress is True, this will be the stress tensor. If compute_stress is False, this will be the graph-level property (e.g., energy).
- Return type
probs