Пример #1
0
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
Пример #2
0
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()
Пример #3
0
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()