def polynomialcutofffn(self, r, rcut, p): epsilon = 1e-8 # Prevent division by zero or…
- User
def polynomial_cutoff_fn(self, r, r_cut, p): epsilon = 1e-8 # Prevent division by zero or negative distances pol_fn = lambda x: 1 - (1/2) * (p+1)(p+2) * (x / (r_cut + epsilon))p + p(p+2)(x / (r_cut + epsilon))**(p+1) - (1/2)p(p+1)(x / (r_cut + epsilon))**(p+2) return self.safe_mask(r < r_cut, pol_fn, r, 0) def basis(self, r): offsets = torch.linspace(math.exp(-self.r_cut), 1, self.n_rbf) # shape: (n_rbf) coefficient = ((2 / self.n_rbf) * (1 - math.exp(-self.r_cut))) ** (-2) return torch.exp(-abs(coefficient) * (torch.exp(-r) - offsets) ** 2) def filter(self, ri, rj, Xi, Xj): # Compute the distance and normalized difference between ri and rj r_ij = torch.norm(ri - rj, dim=-1, keepdim=True) r_hat_ij = (ri - rj) / (r_ij + 1e-8) # Normalize to unit vectors
code# Start calculating X_ij as a vector of distances for each degree X_ij = [] start_idx = 0 # Iterate over the degrees from l_min to l_max (but handle indexing directly) for l in range(self.l_max - self.l_min + 1): num_m = 2 * (self.l_min + l) + 1 # Compute the number of components for this degree # Extract the relevant slice for this degree Xi_l = Xi[..., start_idx : start_idx + num_m] Xj_l = Xj[..., start_idx : start_idx + num_m] # Compute the norm of the difference for this degree X_ij_l = torch.norm(Xi_l - Xj_l, dim=-1, keepdim=True) # Append to the list of distance norms X_ij.append(X_ij_l) # Move the start index forward by the number of components start_idx += num_m # Concatenate all X_ij_l for each degree X_ij = torch.cat(X_ij, dim=-1) # Apply MLP0 to the radial part radial_part = self.MLP0(self.polynomial_cutoff_fn(self.basis(r_ij), self.r_cut, self.p)) # Apply MLP1 to the spherical part spherical_part = self.MLP1(X_ij) # Concatenate the radial part with the X_ij return radial_part+spherical_part Assistant
python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.