MCPcopy Create free account
hub / github.com/InternScience/InternAgent / Distance

Class Distance

tasks/AutoMolecule3D/code/visnet/models/utils.py:213–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213class Distance(nn.Module):
214 def __init__(self, cutoff, max_num_neighbors=32, loop=True):
215 super(Distance, self).__init__()
216 self.cutoff = cutoff
217 self.max_num_neighbors = max_num_neighbors
218 self.loop = loop
219
220 def forward(self, pos, batch):
221 edge_index = radius_graph(pos, r=self.cutoff, batch=batch, loop=self.loop, max_num_neighbors=self.max_num_neighbors)
222 edge_vec = pos[edge_index[0]] - pos[edge_index[1]]
223
224 if self.loop:
225 mask = edge_index[0] != edge_index[1]
226 edge_weight = torch.zeros(edge_vec.size(0), device=edge_vec.device)
227 edge_weight[mask] = torch.norm(edge_vec[mask], dim=-1)
228 else:
229 edge_weight = torch.norm(edge_vec, dim=-1)
230
231 return edge_index, edge_weight, edge_vec
232
233
234class NeighborEmbedding(MessagePassing):

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected