Skip to content

Commit

Permalink
Use handwritten cosine similarity (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
zasdfgbnm authored Nov 2, 2020
1 parent ca6e325 commit d0ab8a8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions torchani/aev.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def angular_terms(Rca: float, ShfZ: Tensor, EtaA: Tensor, Zeta: Tensor,
vectors12 = vectors12.unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).unsqueeze(-1)
distances12 = vectors12.norm(2, dim=-5)

# 0.95 is multiplied to the cos values to prevent acos from
# returning NaN.
cos_angles = 0.95 * torch.nn.functional.cosine_similarity(vectors12[0], vectors12[1], dim=-5)
angles = torch.acos(cos_angles)
cos_angles = vectors12.prod(0).sum(1) / distances12.prod(0)
# 0.95 is multiplied to the cos values to prevent acos from returning NaN.
angles = torch.acos(0.95 * cos_angles)

fcj12 = cutoff_cosine(distances12, Rca)
factor1 = ((1 + torch.cos(angles - ShfZ)) / 2) ** Zeta
Expand Down

0 comments on commit d0ab8a8

Please sign in to comment.