MCPcopy Create free account
hub / github.com/DeepGraphLearning/S3F / atoms_to_points_normals

Function atoms_to_points_normals

s3f/surface.py:223–344  ·  view source on GitHub ↗

Turns a collection of atoms into an oriented point cloud. Sampling algorithm for protein surfaces, described in Fig. 3 of the paper. Args: atoms (Tensor): (N,3) coordinates of the atom centers `a_k`. batch (integer Tensor): (N,) batch vector, as in PyTorch_geometric.

(
    atoms,
    batch,
    distance=1.05,
    smoothness=0.5,
    resolution=1.0,
    nits=5,
    atomtypes=None,
    sup_sampling=20,
    variance=0.5,
)

Source from the content-addressed store, hash-verified

221
222
223def atoms_to_points_normals(
224 atoms,
225 batch,
226 distance=1.05,
227 smoothness=0.5,
228 resolution=1.0,
229 nits=5,
230 atomtypes=None,
231 sup_sampling=20,
232 variance=0.5,
233):
234 """Turns a collection of atoms into an oriented point cloud.
235
236 Sampling algorithm for protein surfaces, described in Fig. 3 of the paper.
237
238 Args:
239 atoms (Tensor): (N,3) coordinates of the atom centers `a_k`.
240 batch (integer Tensor): (N,) batch vector, as in PyTorch_geometric.
241 distance (float, optional): value of the level set to sample from
242 the smooth distance function. Defaults to 1.05.
243 smoothness (float, optional): radii of the atoms, if atom types are
244 not provided. Defaults to 0.5.
245 resolution (float, optional): side length of the cubic cells in
246 the final sub-sampling pass. Defaults to 1.0.
247 nits (int, optional): number of iterations . Defaults to 5.
248 atomtypes (Tensor, optional): (N,6) one-hot encoding of the atom
249 chemical types. Defaults to None.
250
251 Returns:
252 (Tensor): (M,3) coordinates for the surface points `x_i`.
253 (Tensor): (M,3) unit normals `n_i`.
254 (integer Tensor): (M,) batch vector, as in PyTorch_geometric.
255 """
256 # a) Parameters for the soft distance function and its level set:
257 T = distance
258
259 N, D = atoms.shape
260 B = sup_sampling # Sup-sampling ratio
261
262 # Batch vectors:
263 batch_atoms = batch
264 batch_z = batch[:, None].repeat(1, B).view(N * B)
265
266 # b) Draw N*B points at random in the neighborhood of our atoms
267 z = atoms[:, None, :] + 10 * T * torch.randn(N, B, D).type_as(atoms)
268 z = z.view(-1, D) # (N*B, D)
269
270 # We don't want to backprop through a full network here!
271 atoms = atoms.detach().contiguous()
272 z = z.detach().contiguous()
273
274 # N.B.: Test mode disables the autograd engine: we must switch it on explicitely.
275 with torch.enable_grad():
276 if z.is_leaf:
277 z.requires_grad = True
278
279 # c) Iterative loop: gradient descent along the potential
280 # ".5 * (dist - T)^2" with respect to the positions z of our samples

Callers

nothing calls this directly

Calls 2

soft_distancesFunction · 0.85
subsampleFunction · 0.85

Tested by

no test coverage detected