def create_substructure_PML(PDB_path, subs_to_plot, d_cutoff, min_clustersize, contact_sep_thresh, min_seq_separation=8, substructures=[], colours=[]):
    "\n    Identifies substructures, then creates a pymol .pml script that draws those substructures as colored contacts directly on the pymol\n    \n    Ex. Create_substructure_PML('MARR_umbrella3/marr_0.100_Emin.pdb', ['a','b','c','d','e','f'], 7.8, 7, 3)\n    You can also pre-enter the substructures as an optional argument\n    \n    Otherwise, it will compute the substrucutres using PDB_path and save the file as PDB_path but with .pml instead of .pdb\n    \n    You can optinally input the sequence of colors you want to use to paint the substructures (using the fancy British spelling colours)\n    Otherwise, it will color things automatically using the usual default sequence\n    That optional argument, if used, needs to have len equal to thhat of subs_to_plot: one color per substructure to plot\n    \n    \n    "
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    if (len(substructures) == 0):
        (native_contacts, substructures) = identify_native_substructures(PDB_path, d_cutoff, min_seq_separation, contact_sep_thresh, min_clustersize, plot=False)
    prefix = PDB_path.split('pdb')[0]
    PML_path = '{}pml'.format(prefix)
    Nsubs = np.shape(substructures)[2]
    file = open(PML_path, 'w')
    file.write('bg white \n color gray \n')
    if (len(colours) == 0):
        colors = cm.get_cmap('jet')
    counter = 0
    for s in range(Nsubs):
        if (alphabet[s] in subs_to_plot):
            if (len(colours) == 0):
                curr_color = colors((s / (Nsubs - 1)))
            else:
                curr_color = colours[counter]
            c_hex = cccc.to_hex(curr_color)
            c_hex = '0x{}'.format(c_hex.split('#')[1])
            sub = substructures[:, :, s]
            contacts = np.where(sub)
            substr = 'sub{}'.format(alphabet[s])
            for z in range(len(contacts[0])):
                i = (contacts[0][z] + 1)
                j = (contacts[1][z] + 1)
                lines = 'select aa, //resi {}/CA \n select bb, //resi {}/CA \n distance {}, aa, bb  \n hide labels, {}  \n set dash_color, {}, {} \n   '.format(i, j, substr, substr, c_hex, substr)
                file.write(lines)
            file.write('\n set dash_gap, 0.5 \n  set dash_radius, 0.2 \n')
            counter += 1
    file.close()
Identifies substructures, then creates a pymol .pml script that draws those substructures as colored contacts directly on the pymol

Ex. Create_substructure_PML('MARR_umbrella3/marr_0.100_Emin.pdb', ['a','b','c','d','e','f'], 7.8, 7, 3)
You can also pre-enter the substructures as an optional argument

Otherwise, it will compute the substrucutres using PDB_path and save the file as PDB_path but with .pml instead of .pdb

You can optinally input the sequence of colors you want to use to paint the substructures (using the fancy British spelling colours)
Otherwise, it will color things automatically using the usual default sequence
That optional argument, if used, needs to have len equal to thhat of subs_to_plot: one color per substructure to plot
def create_substructure_PML(PDB_path, subs_to_plot, d_cutoff, min_clustersize, contact_sep_thresh, min_seq_separation=8, substructures=[], colours=[]):
    "\n    Identifies substructures, then creates a pymol .pml script that draws those substructures as colored contacts directly on the pymol\n    \n    Ex. Create_substructure_PML('MARR_umbrella3/marr_0.100_Emin.pdb', ['a','b','c','d','e','f'], 7.8, 7, 3)\n    You can also pre-enter the substructures as an optional argument\n    \n    Otherwise, it will compute the substrucutres using PDB_path and save the file as PDB_path but with .pml instead of .pdb\n    \n    You can optinally input the sequence of colors you want to use to paint the substructures (using the fancy British spelling colours)\n    Otherwise, it will color things automatically using the usual default sequence\n    That optional argument, if used, needs to have len equal to thhat of subs_to_plot: one color per substructure to plot\n    \n    \n    "
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    if (len(substructures) == 0):
        (native_contacts, substructures) = identify_native_substructures(PDB_path, d_cutoff, min_seq_separation, contact_sep_thresh, min_clustersize, plot=False)
    prefix = PDB_path.split('pdb')[0]
    PML_path = '{}pml'.format(prefix)
    Nsubs = np.shape(substructures)[2]
    file = open(PML_path, 'w')
    file.write('bg white \n color gray \n')
    if (len(colours) == 0):
        colors = cm.get_cmap('jet')
    counter = 0
    for s in range(Nsubs):
        if (alphabet[s] in subs_to_plot):
            if (len(colours) == 0):
                curr_color = colors((s / (Nsubs - 1)))
            else:
                curr_color = colours[counter]
            c_hex = cccc.to_hex(curr_color)
            c_hex = '0x{}'.format(c_hex.split('#')[1])
            sub = substructures[:, :, s]
            contacts = np.where(sub)
            substr = 'sub{}'.format(alphabet[s])
            for z in range(len(contacts[0])):
                i = (contacts[0][z] + 1)
                j = (contacts[1][z] + 1)
                lines = 'select aa, //resi {}/CA \n select bb, //resi {}/CA \n distance {}, aa, bb  \n hide labels, {}  \n set dash_color, {}, {} \n   '.format(i, j, substr, substr, c_hex, substr)
                file.write(lines)
            file.write('\n set dash_gap, 0.5 \n  set dash_radius, 0.2 \n')
            counter += 1
    file.close()