Network#

class Network(ideal_bond_length, force_constants=None)#

Bases: object

Dynamic bead–spring network in 2D (complex plane).

The network stores:
  • positions: bead positions (complex).

  • connections: pairs of indices (bonds).

  • angled_triplets: dict mapping (i, j, k) → ideal angle at j.

  • stiff_triplets: list of (i, j, k) for chain stiffness.

  • forces: current force on each bead (complex).

  • names: mapping from external names (e.g., knotpy nodes/endpoints) to indices.

Forces:
  • Bond stretching to an ideal length.

  • Angular force toward an ideal angle.

  • Stiffness (prefers straight lines, i.e., ideal π).

  • Short-range repulsion with a cutoff.

  • Global damping.

Parameters:
  • ideal_bond_length (float) – Equilibrium length of a bond (spring).

  • force_constants (dict | None) –

    Optional override: {

    ”bond”: float, “angle”: float, “stiffness”: float, “repulsion”: float, “repulsion_cutoff”: float, “damping”: float,

    }

__init__(ideal_bond_length, force_constants=None)#

Methods

__init__(ideal_bond_length[, force_constants])

add_angled_triplet(triplet, angle)

Register an angular constraint.

add_connection(connection)

Add a single bond.

add_connections_from(connections)

Add multiple connections.

add_point(point, name)

Add a bead if name is new; otherwise reuse the index.

add_stiff_triplet(triplet)

Add a single stiffness triplet (i, j, k).

add_stiff_triplets_from(triplets)

Add multiple stiffness triplets (i, j, k).

average_connection_length()

Average bond length across all connections.

compute_forces()

Compute all forces for the current configuration.

compute_repulsive_ignore()

Precompute which bead pairs should be repelled.

distances()

List of bond lengths across all connections.

net_force_magnitude()

Mean magnitude of forces across beads (a stability indicator).

scale(factor)

Uniformly scale all bead positions by factor.

step(dt)

Advance the simulation by a single time step.

compute_repulsive_ignore()#

Precompute which bead pairs should be repelled.

Repulsion skips immediate neighbors along bonds, stiff triplets, and angled triplets to avoid fighting primary constraints.

add_point(point, name)#

Add a bead if name is new; otherwise reuse the index.

Parameters:
  • point (complex) – Position of the bead.

  • name (Any) – External identifier to map to this bead.

add_angled_triplet(triplet, angle)#

Register an angular constraint.

Parameters:
  • triplet (tuple) – Indices or external names (i, j, k) with angle at j.

  • angle (float) – Ideal angle in radians.

add_connections_from(connections)#

Add multiple connections.

Parameters:

connections (Iterable[tuple[(complex, name), (complex, name)]]) – Each connection includes (point, name) pairs for its endpoints.

add_connection(connection)#

Add a single bond.

Parameters:

connection (tuple) – ((point_a, name_a), (point_b, name_b)).

add_stiff_triplets_from(triplets)#

Add multiple stiffness triplets (i, j, k).

add_stiff_triplet(triplet)#

Add a single stiffness triplet (i, j, k).

average_connection_length()#

Average bond length across all connections.

distances()#

List of bond lengths across all connections.

scale(factor)#

Uniformly scale all bead positions by factor.

compute_forces()#

Compute all forces for the current configuration.

net_force_magnitude()#

Mean magnitude of forces across beads (a stability indicator).

step(dt)#

Advance the simulation by a single time step.

Parameters:

dt (float) – Time step multiplier applied to the velocity (force proxy).