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

CGNN-3D: add filtering by node type #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions kinodata/model/complex_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,19 @@ def __init__(
interaction_radius: float = 8.0,
max_num_neighbors: int = 16,
rbf_size: int = None,
interacting_node_type = NodeType.Complex: NodeType,
) -> None:
super().__init__(hidden_channels, act, bias)
self.interaction_radius = interaction_radius
self.max_num_neighbors = max_num_neighbors
self.rbf_size = rbf_size if rbf_size else hidden_channels
self.distance_embedding = GaussianDistEmbedding(rbf_size, interaction_radius)
self.lin = Linear(rbf_size, hidden_channels, bias=False)
self.interacting_node_type = interacting_node_type

def interactions(self, data: HeteroData) -> Tuple[Tensor, OptTensor, OptTensor]:
pos = data[NodeType.Complex].pos
batch = data[NodeType.Complex].batch
pos = data[self.interacting_node_type].pos
batch = data[self.interacting_node_type].batch
edge_index = knn_graph(pos, self.max_num_neighbors + 1, batch, loop=True)
distances = (pos[edge_index[0]] - pos[edge_index[1]]).pow(2).sum(dim=1).sqrt()
mask = distances <= self.interaction_radius
Expand Down Expand Up @@ -161,7 +163,7 @@ def __init__(
) -> None:
super().__init__(config)
assert len(config["node_types"]) == 1
assert config["node_types"][0] == NodeType.Complex
self.node_type = config["node_types"]
self.act = resolve_act(act)
self.d_cut = interaction_radius
self.max_num_neighbors = max_num_neighbors
Expand All @@ -170,7 +172,7 @@ def __init__(
for mode in interaction_modes:
if mode == "covalent":
module = CovalentInteractions(
hidden_channels, act, intr_bias, config["node_types"][0]
hidden_channels, act, intr_bias, self.node_type,
)
elif mode == "structural":
module = StructuralInteractions(
Expand All @@ -180,6 +182,7 @@ def __init__(
interaction_radius,
max_num_neighbors,
hidden_channels,
interacting_node_type = self.node_type,
)
else:
raise ValueError(mode)
Expand Down Expand Up @@ -216,7 +219,7 @@ def __init__(
)

def forward(self, data: HeteroData) -> NodeEmbedding:
node_store = data[NodeType.Complex]
node_store = data[self.node_type]
node_repr = self.act(
self.atomic_num_embedding(node_store.z)
+ self.lin_atom_features(node_store.x)
Expand Down