Computational biophysics dihedral

From XuShuwenn/RedAct · View interactive version

Computational biophysics dihedral is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Calculate dihedral angles for protein backbone (N-CA-C-N) using torsion formula from atomic coordinates.

How to use this skill

Skill file

Protein Dihedral Angle Calculation

When to Use

New Section

Task-Protocol Override

Input Format

File /root/input.txt with one coordinate per line (x y z):

Calculation Method

Dihedral angle = angle between planes defined by (N, CA, C) and (CA, C, N')

Use torsion formula:

  1. Compute vectors
  2. Compute normals via cross products
  3. Calculate angle between normals using dot product
  4. Adjust sign based on direction

Prefer a standard-library implementation (math) for vector arithmetic, cross products, dot products, norms, and atan2-based signed torsion unless the environment clearly provides numpy.

Do not assume external packages are installed for this task. If basic arithmetic is sufficient, use built-in Python only.

Before writing the result, perform a quick sanity check:

Output Format

Write to /root/output.txt:

Dihedral angle: XXX.XX degrees

Round to 2 decimal places. Range: -180 to +180 degrees.

New Section

Execution Checklist

New Section

Finalization Checklist

Tips

New Section

Minimal Example

from pathlib import Path
from math import atan2, degrees, sqrt


def sub(a, b):
    return [a[i] - b[i] for i in range(3)]


def dot(a, b):
    return sum(a[i] * b[i] for i in range(3))


def cross(a, b):
    return [
        a[1] * b[2] - a[2] * b[1],
        a[2] * b[0] - a[0] * b[2],
        a[0] * b[1] - a[1] * b[0],
    ]


def norm(v):
    return sqrt(dot(v, v))


def scale(v, s):
    return [x * s for x in v]


lines = [line.strip() for line in Path('/root/input.txt').read_text().splitlines() if line.strip()]
if len(lines) != 4:
    raise ValueError('Expected exactly 4 coordinate lines')
pts = [[float(x) for x in line.split()] for line in lines]
p0, p1, p2, p3 = pts

b0 = sub(p1, p0)
b1 = sub(p2, p1)
b2 = sub(p3, p2)
n0 = cross(b0, b1)
n1 = cross(b1, b2)
b1_norm = norm(b1)
if norm(n0) == 0 or norm(n1) == 0 or b1_norm == 0:
    raise ValueError('Colinear or repeated atoms; dihedral undefined')

n0u = scale(n0, 1.0 / norm(n0))
n1u = scale(n1, 1.0 / norm(n1))
b1u = scale(b1, 1.0 / b1_norm)
m1 = cross(n0u, b1u)
angle = degrees(atan2(dot(m1, n1u), dot(n0u, n1u)))
Path('/root/output.txt').write_text(f'Dihedral angle: {angle:.2f} degrees\n')
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.