Skip to content

Torsion angle loss #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Torsion angle loss #81

wants to merge 2 commits into from

Conversation

0x00b1
Copy link
Collaborator

@0x00b1 0x00b1 commented Apr 3, 2025

Closes #66

@0x00b1 0x00b1 requested a review from Copilot April 3, 2025 20:22
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/beignet/nn/functional/_torsion_angle_loss.py:7

  • [nitpick] The parameter name 'input' shadows the built-in Python function. Consider renaming it to 'input_tensor' for improved clarity.
def torsion_angle_loss(input, target: Tuple[Tensor, Tensor]) -> Tensor:

src/beignet/nn/functional/_torsion_angle_loss.py:19

  • Instead of using torch.unsqueeze, consider using torch.norm with keepdim=True (e.g. torch.norm(input, dim=-1, keepdim=True)) to improve code readability.
a = input / torch.unsqueeze(torch.norm(input, dim=-1), dim=-1)

@0x00b1 0x00b1 marked this pull request as draft April 3, 2025 20:23
@0x00b1 0x00b1 temporarily deployed to test.pypi.org April 3, 2025 20:25 — with GitHub Actions Inactive
@0x00b1 0x00b1 requested a review from Copilot April 3, 2025 20:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

tests/beignet/nn/functional/test__torsion_angle_loss.py:6

  • [nitpick] Consider renaming the variable 'input' as it shadows the built-in function 'input'.
input = torch.ones([1, 1, 7, 2])

src/beignet/nn/functional/_torsion_angle_loss.py:7

  • [nitpick] Consider renaming the parameter 'input' to avoid shadowing the built-in and to improve clarity.
def torsion_angle_loss(input, target: Tuple[Tensor, Tensor]) -> Tensor:

import torch


def test_torsion_angle_loss():
Copy link
Collaborator Author

@0x00b1 0x00b1 Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kleinhenz Just a smoke test.

I will revisit with improved unit tests after I implement the scaffolding for all the losses.

-------

"""
a = input / torch.norm(input, dim=-1, keepdim=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be clamped? 🤔

from torch import Tensor


def torsion_angle_loss(input, target: Tuple[Tensor, Tensor]) -> Tensor:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this something like alphafold2_torsion_angle_loss and add a reference to alphafold2 supplement algorithm 27 in the docstring?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. I will add a docstring!

As far as renaming, are there multiple torsion angle losses?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can imagine doing some different things. If you predict an angle instead of a 2d vector then the anglenorm part of this doesn't make sense and you would just do cosine of the difference. You could also do something like nll of wrapped normal.

@@ -0,0 +1,36 @@
from typing import Tuple
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use PEP 585 instead so the hint would be tuple[Tensor, Tensor]. I find it slightly cleaner but not a big deal either way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into this more it looks like those hints are actually being deprecated and removed once python 3.9 is EOL


b, c = target

x = torch.mean(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call x and y something slightly more descriptive like loss_torsion and loss_anglenorm to make it easier to compare with the description in the supplement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Torsion angle loss
2 participants