A Python implementation to simulate single polymer chains using Brownian dynamics. The simulation models beads connected by springs under the influence of Brownian motion, excluded volume effects, and finitely extensible non-linear elastic (FENE) forces.
The simulation is based on the overdamped Langevin equation, which models the motion of particles in a fluid where inertial effects are negligible. The forces acting on each bead include:
- Brownian/random forces (thermal noise)
- FENE spring forces between consecutive beads
- Optional excluded volume forces between beads
The key equation governing the bead motion is:
dx/dt = ∑F/b
where:
x
is positionF
represents the sum of forcesb
is the drag coefficient
- Simulates both linear and circular polymer chains
- Configurable number of beads
- Configurable number of time steps, (
N = 2000001
by default but can be changed) - Adjustable simulation parameters (time step, spring constants, etc.)
- Calculates physical properties like:
- Radius of gyration
- End-to-end distance
- Mean square displacement
- Supports different chain configurations:
- Ideal chains (no excluded volume)
- Real chains (with excluded volume)
- Circular chains (polymer rings)
The Bead
class represents a 2D bead with a radius and an initial position in Cartesian coordinates. It includes methods to initialize the bead and calculate forces acting on it.
x
(float): The x-coordinate of the bead's center.y
(float): The y-coordinate of the bead's center.r
(float): The radius of the bead.
Initializes a new instance of the Bead
class with the specified position and radius.
Parameters:
x
(float): Initial x-coordinate of the bead's center. Default is0
.y
(float): Initial y-coordinate of the bead's center. Default is0
.r
(float): Radius of the bead. Default is0.04
.
Computes the forces acting on the bead.
Parameters:
j
(int): Index of the current bead.jj
(int, optional): Another index. Default isNone
.k
(float): Spring constant. Default is0
.k_ev
(float): Excluded volume interaction constant. Default is0
.Ls
(float, optional): Contour length. Default isNone
kBT
(float): Thermal energy. Default is1
.lk
(float): Kuhn length. Default is1
.conf
(str): Configuration type, either'linear'
or'circular'
. Default is'linear'
.- Please note that this parameter only affects a chain of beads and has no barring on an individual bead.
Advances the bead's position over time based on the sum of forces acting on it, following the overdamped Langevin equation.
Parameters:
Δt
(float): time step size.b
(float): Drag coefficient. Default is1
.κ
(float): Spring constant (replacesk
to avoid kernel confusion). Default is0
.
Returns: None, but updates:
positions_xy
: List of (x, y) coordinates over timeall_pos_xy
: Global list containing position histories of all beads- Updates the bead's position attributes (
self.x
,self.y
)
Algorithm:
- Initializes with current position
- For each time step:
- Calculates total force using
force_calculate
- Updates position using overdamped Langevin equation
- Stores new position
- Calculates total force using
- Converts position history to numpy array
# Create a new bead with initial position (0, 0)
bead = Bead(x=0, y=0)
# Calculate forces on the bead with index 1
bead.force_calculate(j=1)
# Advance the bead's position with time step 0.0001
bead.advance(Δt=0.0001, b=1)
The Simulation
class manages the simulation of a Brownian polymer chain consisting of multiple beads. It supports both linear and circular chain configurations.
nbeads
(int): Number of beads in the polymer chainconf
(str): Configuration type ('linear'
or'circular'
)ψ
(float): Initial angle between beads (circular configuration only)ρ
(float): Initial radius of circular configuration =(0.09*nbeads)/(2*π)
beads
(list): List of Bead objects comprising the polymer chain
Initializes a new polymer chain simulation.
Parameters:
nbeads
(int): Number of beads in the chainx
(float): Initial x-coordinate. Default is0
.y
(float): Initial y-coordinate. Default is0
.conf
(str): Configuration type ('linear'
or'circular'
). Default is'linear'
.
Initialization Process:
- Sets up chain configuration
- Creates global Brownian forces arrays (
Fx_sim
,Fy_sim
) - Initializes beads with appropriate spacing:
- Linear: Beads spaced
0.09
units apart horizontally - Circular: Beads arranged in a circle with radius
ρ
- Linear: Beads spaced
Creates a new bead instance.
Parameters:
x
(float): x-coordinate for the bead. Default is0
.y
(float): y-coordinate for the bead. Default is0
.
Returns:
Bead
: A new Bead instance
Advances the entire polymer chain simulation over time.
Parameters:
Δt
(float): time step sizeb
(float): Drag coefficient. Default is1
.κ_ev
(float): Excluded volume interaction constant. Default is0
.
Updates:
xs
,ys
: Lists of current bead positionsend_to_end
: End-to-end distance at each time stepRg2
: Radius of gyration squared at each time stepall_sim_pos
: Position history of all beads
Algorithm:
- Initializes position tracking arrays
- Records initial configuration
- For each time step:
- Updates positions of all beads simultaneously
- Calculates and stores chain properties (end-to-end distance, radius of gyration)
- Resets position trackers after simulation
# Create a linear polymer chain with 10 beads
sim = Simulation(nbeads=10, conf='linear')
# Run simulation with excluded volume interactions
sim.advance(Δt=0.0001, κ_ev=200)
# Create a circular polymer chain
circular_sim = Simulation(nbeads=10, conf='circular')
# Run simulation
circular_sim.advance(Δt=0.0001)
Fx_sim
,Fy_sim
: Arrays of random forcesxs
,ys
: Current positions of all beadsend_to_end
: Chain end-to-end distance historyRg2
: Radius of gyration squared historyall_sim_pos
: Complete position history of all beads
- Standard simulation parameters:
Ls = 1
(contour length)lk = 0.1
(Kuhn length)kBT = 1
(thermal energy)N
(number of time steps)Δt
(time step size)N
andΔt
determine the total simulation time and temporal resolution. The smallerΔt
is:- More accurate simulation (better resolution of the dynamics)
- But requires more steps (larger
N
) to simulate the same total time
- Optimal excluded volume constant (
κ_ev
) is typically around200
- Position updates are synchronized across all beads to maintain chain integrity
- The simulation uses the overdamped Langevin equation for bead motion
- 2D simulations only
- No hydrodynamic interactions
- Limited to single chain dynamics
Feel free to open issues or submit pull requests for:
- New features
- Documentation improvements
- Performance optimizations
This project is licensed under the MIT License. See the LICENSE file for details.