Commit 30f2728a authored by Pieter van Velde's avatar Pieter van Velde

Created functions.py, contains add_bead, which creates a polymer

parent 39105191
import numpy as np
def add_bead(pos, n, T_dim):
phi = np.linspace(0, 2*np.pi - (2/n)*np.pi, n)
E = np.zeros(n)
for i in range(n):
pos_new = np.zeros(2)
pos_new[0] = pos[1,0] + np.cos(phi[i])
pos_new[1] = pos[1,1] + np.sin(phi[i])
rx = pos_new[0] - pos[:, 0]
ry = pos_new[1] - pos[:, 1]
r = np.sqrt(rx**2 + ry**2)
r[r==0] = np.nan
E[i] = np.sum(4*((1/r)**12 - (1/r)**6))
w = np.exp(-E/T_dim)
w[np.isnan(w)]=0
w_tot = np.sum(w)
P = w/w_tot
final_phi = np.random.choice(phi, p=P)
new = np.array([[pos[1,0] + np.cos(final_phi), pos[1,1] + np.sin(final_phi)]])
pos = np.r_[pos, new]
return pos
\ No newline at end of file
import numpy as np
\ No newline at end of file
import numpy as np
from matplotlib import pyplot as plt
from functions import add_bead
# Simultion constants
# Initialization
n = 6 # number of phis
T_dim = 0.001
pos = np.array([[0, 0], [1, 0]])
n_beads = 30
for j in range(n_beads):
pos = add_bead(pos, n, T_dim)
plt.plot(pos[:,0], pos[:,1], marker= ".", markersize=20, color="k" )
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment