MCPcopy Index your code
hub / github.com/DeepGraphLearning/DiffPack / step

Method step

diffpack/schedule.py:205–241  ·  view source on GitHub ↗

Denoise step for the input tensor (torsion angles). Args: x (Tensor): Torsion angles of shape :math:`(num_res, 4)` x_score (Tensor): Score of shape :math:`(num_res, 4)` t (Tensor): Timesteps of shape :math:`(num_res)` dt (float): Step size of

(self, x, x_score, t, dt, x_mask=None)

Source from the content-addressed store, hash-verified

203
204 @torch.no_grad()
205 def step(self, x, x_score, t, dt, x_mask=None):
206 """Denoise step for the input tensor (torsion angles).
207
208 Args:
209 x (Tensor): Torsion angles of shape :math:`(num_res, 4)`
210 x_score (Tensor): Score of shape :math:`(num_res, 4)`
211 t (Tensor): Timesteps of shape :math:`(num_res)`
212 dt (float): Step size of shape :math:`(num_res)`
213 x_mask (Tensor): Mask of shape :math:`(num_res, 4)`
214
215 Returns:
216 Tensor: Denoised torsion angles of shape :math:`(num_res, 4)`
217 """
218 sigma = self.t_to_sigma(t) # (num_res)
219 g = sigma * np.sqrt(2 * np.log(self.sigma_max / self.sigma_min)) # (num_res)
220
221 # Temperature Coefficient
222 alpha = 1 - (sigma / np.exp(self.sigma_max_log)) ** 2 if self.annealed_temp else None
223 annealed_weight = self.annealed_temp / (alpha + (1 - alpha) * self.annealed_temp) if self.annealed_temp else 1
224
225 # Noise
226 x_prev = x.clone()
227 if self.mode == "ode":
228 drift = (0.5 * g ** 2 * dt * (x_score * annealed_weight))
229 x_prev += drift
230 elif self.mode == "sde":
231 noise = torch.normal(mean=0, std=1, size=x_score.shape, device=x_score.device)
232 drift = g ** 2 * dt * (x_score * annealed_weight)
233 diffusion = g * torch.sqrt(dt) * noise
234 x_prev += (drift + diffusion)
235 else:
236 raise NotImplementedError
237
238 if x_mask is not None:
239 x_prev[~x_mask] = x[~x_mask]
240
241 return x_prev
242
243 @torch.no_grad()
244 def step_correct(self, x, x_score, x_batch, x_mask=None, snr=0.16):

Callers

nothing calls this directly

Calls 1

t_to_sigmaMethod · 0.95

Tested by

no test coverage detected