def oppg_4_3(return_protein): T_step = -30 # increase the temp by this amount each iteration N = 15 T_max = 1500 d = 600 N_T = (T_max // abs(T_step)) count = 0 # Matrix with all diameters for all twists and temp length = np.zeros((N_T, d)) # Vector with mean energy for each temp L_mean = np.zeros(N_T) # Calculate energy protein = Protein(N, T_max) for j in range(T_max, -T_step, T_step): print(j) protein.change_temp(j) for i in range(0, d): protein.twist() length[count][i] = protein.diameter() L_mean[count] = np.mean(length[count]) count += 1 protein.change_temp(10**(-6)) for i in range(0, d): protein.twist() length[N_T - 1] = protein.diameter() L_mean[N_T - 1] = np.mean(length[N_T - 1]) L_mean = L_mean[::-1] # Create temp vector for plotting the mean diameter x = np.arange(0, T_max, -T_step) # Plot the mean diameter plt.figure('exercise-4-3') plt.title('Mean diameter') plt.grid() plt.xlabel('T') plt.ylabel('$<$L$>$') plt.plot(x, L_mean, color='#000000', linestyle='-') plt.show() if return_protein: return protein, N
def oppg_3(): T_step = 5 # Increase the temp by this amount each iteration N = 15 T = 10**(-6) # Define temperature CLOSE to zero to avoid division by zero s = 0.003 d_max = 10000 T_max = 1500 N_T = T_max // T_step # Matrix with all diameters for all twists and temps length = np.zeros((N_T, d_max)) # Vector with mean energy for each temp L_mean = np.zeros(N_T) # Calculate mean diameter for temp close to zero protein = Protein(N, T) for i in range(0, d_max): protein.twist() length[0][i] = protein.diameter() L_mean[0] = np.mean(length[0][:d_max]) # Calculate mean diameter for all other temps up to T_max for j in range(1, N_T): print(j) protein = Protein(N, j * T_step) d = int(np.ceil(d_max * np.exp(-s * (j * T_step)))) for i in range(0, d): protein.twist() length[j][i] = protein.diameter() L_mean[j] = np.mean(length[j][:d]) # Create temp vector for plotting the mean diameter x = np.arange(0, T_max, T_step) # Plot the mean diameter plt.figure('exercise-3') plt.title('Mean diameter') plt.grid(color='#ffffff', linestyle='-') plt.xlabel('T') plt.ylabel('$<L>$') plt.plot(x, L_mean, color='#000000', linestyle='-') plt.show()