def calculate_accuracy(predictions, labels):
    num_proteins = predictions.shape[0]
    protein_accuracy = np.zeros(num_proteins, dtype=np.float32)
    label_accuracy = {1: {'total': 0, 'correct': 0}, 2: {'total': 0, 'correct': 0}, 3: {'total': 0, 'correct': 0}}
    for i in range(num_proteins):
        total_predictions = 0
        correct_predictions = 0
        for j in range(predictions.shape[1]):
            phi = math.degrees(labels[i][j][0])
            phi0 = math.degrees(predictions[i][j][0])
            psi = math.degrees(labels[i][j][1])
            psi0 = math.degrees(predictions[i][j][1])
            if ((phi != 0) or (psi != 0)):
                total_predictions += 1
                expected_state = get_backbone_distribution(labels[i][j])
                predicted_state = get_backbone_distribution(predictions[i][j])
                label_accuracy[predicted_state]['total'] += 1
                if (predicted_state == expected_state):
                    label_accuracy[predicted_state]['correct'] += 1
                diff = math.sqrt((math.pow((phi - phi0), 2) + math.pow((psi - psi0), 2)))
                diff_phi = (phi0 - phi0)
                diff_psi = (psi - psi0)
                criteria_1 = ((np.abs(diff_phi) < 60) & (np.abs(diff_psi) < 60))
                criteria_2 = (((np.abs((diff_phi + diff_psi)) < 60) & (np.abs(diff_psi) < 90)) & (np.abs(diff_phi) < 90))
                if (diff < 60):
                    correct_predictions += 1
            if (total_predictions > 0):
                protein_accuracy[i] = (correct_predictions / float(total_predictions))
    accuracy_dist = {}
    total = 0
    correct = 0
    for (label, val) in label_accuracy.iteritems():
        if (val['total'] > 0):
            accuracy_dist[label] = (val['correct'] / val['total'])
            total += val['total']
            correct += val['correct']
    if (total > 0):
        accuracy_dist['total'] = (correct / total)
    return (protein_accuracy, accuracy_dist)
def calculate_accuracy(predictions, labels):
    num_proteins = predictions.shape[0]
    protein_accuracy = np.zeros(num_proteins, dtype=np.float32)
    label_accuracy = {1: {'total': 0, 'correct': 0}, 2: {'total': 0, 'correct': 0}, 3: {'total': 0, 'correct': 0}}
    for i in range(num_proteins):
        total_predictions = 0
        correct_predictions = 0
        for j in range(predictions.shape[1]):
            phi = math.degrees(labels[i][j][0])
            phi0 = math.degrees(predictions[i][j][0])
            psi = math.degrees(labels[i][j][1])
            psi0 = math.degrees(predictions[i][j][1])
            if ((phi != 0) or (psi != 0)):
                total_predictions += 1
                expected_state = get_backbone_distribution(labels[i][j])
                predicted_state = get_backbone_distribution(predictions[i][j])
                label_accuracy[predicted_state]['total'] += 1
                if (predicted_state == expected_state):
                    label_accuracy[predicted_state]['correct'] += 1
                diff = math.sqrt((math.pow((phi - phi0), 2) + math.pow((psi - psi0), 2)))
                diff_phi = (phi0 - phi0)
                diff_psi = (psi - psi0)
                criteria_1 = ((np.abs(diff_phi) < 60) & (np.abs(diff_psi) < 60))
                criteria_2 = (((np.abs((diff_phi + diff_psi)) < 60) & (np.abs(diff_psi) < 90)) & (np.abs(diff_phi) < 90))
                if (diff < 60):
                    correct_predictions += 1
            if (total_predictions > 0):
                protein_accuracy[i] = (correct_predictions / float(total_predictions))
    accuracy_dist = {}
    total = 0
    correct = 0
    for (label, val) in label_accuracy.iteritems():
        if (val['total'] > 0):
            accuracy_dist[label] = (val['correct'] / val['total'])
            total += val['total']
            correct += val['correct']
    if (total > 0):
        accuracy_dist['total'] = (correct / total)
    return (protein_accuracy, accuracy_dist)