def visualize_substructures(native_contacts, substructures, max_res=None, ax=None, labelsize=30, fontsize=30):
    '\n    Visualizes substructures as follows\n    Everything that is a native contact but not part of any substructure will have value -1 on shown image\n    (Update 10/1/18, actually will only show contacts that are part of substructures)\n    Meanwhile, everything that is part of substructure i (i ranges from 0 to N_substructures-1) will have value i\n    Finally, all non-contacts will just be Nans and appear white\n    \n    Edited this on 2/4/19 so that substructures are labeled by letter rather than number\n    Also reinstated the feature that contacts unassigned to substructures are visualized\n    \n    On 2/10/2020, Changed a bit how the script work\n    Made it a bit simpler\n    Also made it so unassigned contacts are now shown in gray\n    '
    alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    substructure_image = np.zeros(np.shape(native_contacts))
    native_contacts = (native_contacts + np.transpose(native_contacts))
    unassigned_contacts = cp.deepcopy(native_contacts)
    for s in range(np.shape(substructures)[2]):
        substructure_image += ((s + 1) * (substructures[:, :, s] + substructures[:, :, s].transpose()))
        unassigned_contacts -= (substructures[:, :, s] + substructures[:, :, s].transpose())
    substructure_image[(substructure_image == 0)] = np.nan
    colors = cm.get_cmap('jet')
    if (ax == None):
        (fig, ax) = plt.subplots()
    ax.imshow(substructure_image, cmap='jet')
    ax.tick_params(labelsize=labelsize)
    for s in range(np.shape(substructures)[2]):
        y_pos = (np.where(substructures[:, :, s])[0][0] + 4)
        x_pos = (np.where(substructures[:, :, s])[1][0] + 5)
        curr_color = colors((s / (np.nanmax(substructure_image) - 1)))
        ax.annotate('{}'.format(alphabet[s]), (x_pos, y_pos), fontsize=fontsize, color=curr_color)
        ax.annotate('{}'.format(alphabet[s]), ((y_pos - 5), (x_pos - 8)), fontsize=fontsize, color=curr_color)
    nsubstructures = np.shape(substructures)[2]
    nbins = (nsubstructures + 1)
    unassigned_contacts[(unassigned_contacts == 0)] = np.nan
    ax.imshow(unassigned_contacts, cmap='gray', alpha=0.5)
    ax.plot(np.arange(0, len(native_contacts)), np.arange(0, len(native_contacts)), color='gray', linestyle=':')
    if (max_res != None):
        ax.set_xlim((max_res, 0))
        ax.set_ylim((0, max_res))
Visualizes substructures as follows
Everything that is a native contact but not part of any substructure will have value -1 on shown image
(Update 10/1/18, actually will only show contacts that are part of substructures)
Meanwhile, everything that is part of substructure i (i ranges from 0 to N_substructures-1) will have value i
Finally, all non-contacts will just be Nans and appear white

Edited this on 2/4/19 so that substructures are labeled by letter rather than number
Also reinstated the feature that contacts unassigned to substructures are visualized

On 2/10/2020, Changed a bit how the script work
Made it a bit simpler
Also made it so unassigned contacts are now shown in gray
def visualize_substructures(native_contacts, substructures, max_res=None, ax=None, labelsize=30, fontsize=30):
    '\n    Visualizes substructures as follows\n    Everything that is a native contact but not part of any substructure will have value -1 on shown image\n    (Update 10/1/18, actually will only show contacts that are part of substructures)\n    Meanwhile, everything that is part of substructure i (i ranges from 0 to N_substructures-1) will have value i\n    Finally, all non-contacts will just be Nans and appear white\n    \n    Edited this on 2/4/19 so that substructures are labeled by letter rather than number\n    Also reinstated the feature that contacts unassigned to substructures are visualized\n    \n    On 2/10/2020, Changed a bit how the script work\n    Made it a bit simpler\n    Also made it so unassigned contacts are now shown in gray\n    '
    alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    substructure_image = np.zeros(np.shape(native_contacts))
    native_contacts = (native_contacts + np.transpose(native_contacts))
    unassigned_contacts = cp.deepcopy(native_contacts)
    for s in range(np.shape(substructures)[2]):
        substructure_image += ((s + 1) * (substructures[:, :, s] + substructures[:, :, s].transpose()))
        unassigned_contacts -= (substructures[:, :, s] + substructures[:, :, s].transpose())
    substructure_image[(substructure_image == 0)] = np.nan
    colors = cm.get_cmap('jet')
    if (ax == None):
        (fig, ax) = plt.subplots()
    ax.imshow(substructure_image, cmap='jet')
    ax.tick_params(labelsize=labelsize)
    for s in range(np.shape(substructures)[2]):
        y_pos = (np.where(substructures[:, :, s])[0][0] + 4)
        x_pos = (np.where(substructures[:, :, s])[1][0] + 5)
        curr_color = colors((s / (np.nanmax(substructure_image) - 1)))
        ax.annotate('{}'.format(alphabet[s]), (x_pos, y_pos), fontsize=fontsize, color=curr_color)
        ax.annotate('{}'.format(alphabet[s]), ((y_pos - 5), (x_pos - 8)), fontsize=fontsize, color=curr_color)
    nsubstructures = np.shape(substructures)[2]
    nbins = (nsubstructures + 1)
    unassigned_contacts[(unassigned_contacts == 0)] = np.nan
    ax.imshow(unassigned_contacts, cmap='gray', alpha=0.5)
    ax.plot(np.arange(0, len(native_contacts)), np.arange(0, len(native_contacts)), color='gray', linestyle=':')
    if (max_res != None):
        ax.set_xlim((max_res, 0))
        ax.set_ylim((0, max_res))