proteindf_bridge.position module

class proteindf_bridge.position.Position(*args)

Bases: object

Represents a 3D Cartesian position vector (x, y, z).

Supports basic vector arithmetic (addition, subtraction, scalar multiplication, dot product, cross product, and normalization).

Parameters:

*args – 0, 1, or 3 positional arguments. - If 0 arguments: Initializes to origin (0.0, 0.0, 0.0). - If 1 argument: Another Position, a sequence of 3 numbers, or a coordinate string. - If 3 arguments: Three numbers (x, y, z).

Raises:
  • TypeError – If the arguments are invalid in count or type.

  • BrInputError – If parsing from a string or slice fails.

cross(other)

Computes the cross product with another position vector.

Parameters:

other – The other position as a Position, sequence of 3 floats, or coordinate string.

Returns:

A new Position instance representing the cross product vector.

Raises:
dihedral(p2, p3, p4)

Calculates the dihedral (torsion) angle in degrees formed by four points.

The angle is measured around the axis formed by p2 and p3 for the sequence (self, p2, p3, p4).

Parameters:
  • p2 – The second position.

  • p3 – The third position.

  • p4 – The fourth position.

Returns:

The dihedral angle in degrees (-180.0 to 180.0).

Raises:
  • TypeError – If any point cannot be parsed as a position.

  • BrInputError – If parsing any point fails.

distance_from(other=None)

Calculates the Euclidean distance to another position.

Parameters:

other – The target position as a Position, a sequence of 3 floats, or a coordinate string. Defaults to None (the origin).

Returns:

The Euclidean distance as a float.

Raises:
  • TypeError – If other is not a valid coordinate specification.

  • BrInputError – If parsing other fails.

dot(other)

Computes the dot product with another position vector.

Parameters:

other – The other position as a Position, sequence of 3 floats, or coordinate string.

Returns:

The dot product as a float.

Raises:
epsilon

Distance tolerance threshold used for equality comparisons.

get_raw_data()

Returns the coordinates as a list of three floats [x, y, z].

Returns:

A list containing the x, y, and z coordinates.

move_to(arg)

Sets the position to new coordinates in-place.

Parameters:

arg – Target coordinates as a Position, a sequence of 3 floats, or a coordinate string.

Raises:
  • TypeError – If arg is not a valid coordinate specification.

  • BrInputError – If parsing from a string or slice fails.

norm()

Normalizes the position vector in-place to unit length.

Returns:

The normalized Position object (self).

Raises:

BrValueError – If the vector has zero length.

position

Alias for xyz. The coordinates as a list of three floats [x, y, z].

rotate(mat)

Rotates the position vector in-place by a 3x3 rotation matrix.

Parameters:

mat – A 3x3 rotation matrix (Matrix or an object with rows, cols, and get(row, col)).

Raises:
  • TypeError – If mat is not a Matrix or an object with rows, cols, and get(row, col).

  • ValueError – If matrix dimensions are not 3x3.

square_distance_from(other=None)

Calculates the squared Euclidean distance to another position.

Parameters:

other – The target position as a Position, a sequence of 3 floats, or a coordinate string. Defaults to None (the origin).

Returns:

The squared Euclidean distance as a float.

Raises:
  • TypeError – If other is not a valid coordinate specification.

  • BrInputError – If parsing other fails.

x

The x-coordinate value.

xyz

The coordinates as a list of three floats [x, y, z].

y

The y-coordinate value.

z

The z-coordinate value.