def oppg_2_4(): N = 15 T = 10**(-6) d = 10000 # Number of protein plots calculations = 10 mean_energy = np.zeros(calculations) for i in range(len(mean_energy)): protein = Protein(N, T) energy = np.zeros(d) for j in range(d): protein.twist() energy[j] = protein.energy() mean_energy[i] = np.mean(energy) plt.figure('exercise-2-4') plt.title('Mean energy at $T = 0$') plt.grid() plt.xlabel('Calculation #') plt.ylabel('$<$E$>$') plt.xticks(np.arange(0, calculations, 1)) plt.plot(np.arange(calculations), mean_energy, color='#000000', markerfacecolor='#000000', linestyle='None', marker='o') plt.show()
def oppg_4_1(): 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)) * d count = 0 # Vector with energy energy = 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() energy[count] = protein.energy() count += 1 protein.change_temp(10**(-6)) for i in range(0, d): protein.twist() energy[count] = protein.energy() count += 1 # Create temp vector for plotting the energy x = np.arange(0, N_T) # Plot the energy plt.figure('exercise-4-1') plt.title('Protein energy') plt.grid() plt.xlabel('# twists') plt.ylabel('Energy') labels = [] for i in range(0, N_T, d): if (i % (N_T / 10)) == 0: labels.append(str(i)) else: labels.append("") plt.xticks(np.arange(0, N_T, d), labels) plt.plot(x, energy, color='#000000', linestyle='-', linewidth=0.3) plt.show()
def oppg_4_2(): T_step = -30 # increase the temp by this amount each iteration N = 30 T_max = 1500 d = 600 N_T = (T_max // abs(T_step)) count = 0 # Matrix with all energies for all twists and temp epsilon = np.zeros((N_T, d)) # Vector with mean energy for each temp e_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() epsilon[count][i] = protein.energy() e_mean[count] = np.mean(epsilon[count]) count += 1 protein.change_temp(10**(-6)) for i in range(0, d): protein.twist() epsilon[N_T - 1] = protein.energy() e_mean[N_T - 1] = np.mean(epsilon[N_T - 1]) e_mean = e_mean[::-1] # Create temp vector for plotting the mean energy x = np.arange(0, T_max, -T_step) # Plot the mean energy plt.figure('exercise-4-2') plt.title('Mean energy') plt.grid() plt.xlabel('T') plt.ylabel('$<$E$>$') plt.plot(x, e_mean, color='#000000', linestyle='-') plt.show()
def oppg_2_1(): 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 energies for all twists and temp epsilon = np.zeros((N_T, d_max)) # Vector with mean energy for each temp e_mean = np.zeros(N_T) # Calculate mean energy for temp close to zero protein = Protein(N, T) for i in range(0, d_max): protein.twist() epsilon[0][i] = protein.energy() e_mean[0] = np.mean(epsilon[0][:d_max]) # Calculate mean energy for all other temps up to T_max for j in range(1, N_T): 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() epsilon[j][i] = protein.energy() e_mean[j] = np.mean(epsilon[j][:d]) # Create temp vector for plotting the mean energy x = np.arange(0, T_max, T_step) # Plot the mean energy plt.figure('exercise-2-1') plt.title('Mean energy') plt.grid() plt.xlabel('T') plt.ylabel('$<E>$') plt.plot(x, e_mean, color='#000000', linestyle='-') plt.show()
def oppg_2_2(): N = 15 T_0 = 10**(-6) T_500 = 500 d = 5000 x = np.arange(0, d) protein1 = Protein(N, T_0) protein2 = Protein(N, T_500) energy1 = np.zeros(d) energy2 = np.zeros(d) for i in range(d): protein1.twist() protein2.twist() energy1[i] = protein1.energy() energy2[i] = protein2.energy() plt.figure('exercise-2-2') plt.suptitle('Binding energy') # Plot for T = 0 Kelvin plt.subplot(121) plt.title('$T = 0$') plt.grid() plt.xlabel('$\log$ # twists') plt.ylabel('E') plt.semilogx(x, energy1, color='#000000', linestyle='-') # Plot for T = 500 Kelvin plt.subplot(122) plt.title('$T = 500$') plt.xlabel('# twists') plt.ylabel('E') plt.grid() plt.plot(x, energy2, color='#000000', linestyle='-', linewidth=0.7) plt.show()