Pymol script for viewing classic coiled-coil Socket output.

    Notes
    -----
    For examples of these views, browse the CC+ database here: http://coiledcoils.chm.bris.ac.uk/ccplus/search/.

    Parameters
    ----------
    pdb_file: str
        Path to a pdb_file.
    cutoff: float
        Socket cutoff in Angstroms.
    min_kihs: int
        Mininmum number of KnobIntoHole interactions between pairs of helices needed to define a coiled coil.
    outfile: None or str
        Path to a output file to save the pml script.

    Returns
    -------
    script_string: str
        Pymol commands for classic coiled-coil view.

def make_pymol(pdb_file, cutoff=7.0, min_kihs=2, outfile=None):
    """ Pymol script for viewing classic coiled-coil Socket output.

    Notes
    -----
    For examples of these views, browse the CC+ database here: http://coiledcoils.chm.bris.ac.uk/ccplus/search/.

    Parameters
    ----------
    pdb_file: str
        Path to a pdb_file.
    cutoff: float
        Socket cutoff in Angstroms.
    min_kihs: int
        Mininmum number of KnobIntoHole interactions between pairs of helices needed to define a coiled coil.
    outfile: None or str
        Path to a output file to save the pml script.

    Returns
    -------
    script_string: str
        Pymol commands for classic coiled-coil view.

    """
    a = convert_pdb_to_ampal(pdb=pdb_file, path=True)
    kg = KnobGroup.from_helices(a, cutoff=cutoff)
    g = kg.filter_graph(kg.graph, cutoff=cutoff, min_kihs=min_kihs)
    ccs = sorted_connected_components(g)
    # Opens pymol script, initial set up of screen
    script_lines = ['load {0}'.format(pdb_file)]
    script_lines.append("hide all")
    script_lines.append("bg_color white")
    script_lines.append("set antialias, 1")
    script_lines.append("set cartoon_dumbbell_length, 0.35")
    script_lines.append("set_color lightgrey, [240,240,240]")
    script_lines.append("set depth_cue, 0")
    script_lines.append("color lightgrey, all")
    script_lines.append("cartoon dumbbell")
    script_lines.append("show cartoon")
    for cc_number, cc in enumerate(ccs):
        helices = [x for x in g.nodes() if x.number in cc.nodes()]
        #helices = cc.nodes()
        cc_region = kg.get_coiledcoil_region(cc_number=cc_number, cutoff=cutoff, min_kihs=min_kihs)
        tag_residues_with_heptad_register(cc_region)
        assigned_regions = kg.get_assigned_regions(include_alt_states=False, complementary_only=False, helices=helices)
        helix_starts = [int(h[0].id) for h in helices]
        helix_ends = [int(h[-1].id) for h in helices]
        chains = [h.ampal_parent.id for h in helices]
        assigned_starts = [assigned_regions[h.number][0] for h in helices]
        assigned_ends = [assigned_regions[h.number][1] for h in helices]
        assigned_selections = ['{0}/{1}-{2}/'.format(chain, assigned_start, assigned_end)
                               for chain, assigned_start, assigned_end in zip(chains, assigned_starts, assigned_ends)]
        script_lines.append("select cc{0}, {1}".format(cc_number, ' '.join(assigned_selections)))
        script_lines.append("cartoon automatic, cc{0}".format(cc_number))
        for h_number, h in enumerate(helices):
            chain = chains[h_number]
            helix_start = helix_starts[h_number]
            helix_end = helix_ends[h_number]
            assigned_start = assigned_starts[h_number]
            assigned_end = assigned_ends[h_number]
            selection = '{0}/{1}-{2}/'.format(chain, helix_start, helix_end)
            script_lines.append("select cc{0}eh{1}, {2}".format(cc_number, h_number, selection))
            selection = '{0}/{1}-{2}/'.format(chain, assigned_start, assigned_end)
            script_lines.append("select cc{0}ah{1}, {2}".format(cc_number, h_number, selection))
            kihs = [x for x in kg if x.knob_helix == h]
            for x in kihs:
                knob_selection_name = 'cc{0}ah{1}k{2}'.format(cc_number, h_number, x.knob_residue.id)
                hole_selection_name = knob_selection_name + 'hole'
                knob_selection = '{0}/{1}/'.format(chain, x.knob_residue.id)
                script_lines.append('select {0}, {1}'.format(knob_selection_name, knob_selection))
                hole_selection = ' '.join(['{0}/{1}/'.format(x.hole_chain, y.id) for y in x.hole_residues])
                script_lines.append('select {0}, {1}'.format(hole_selection_name, hole_selection))
                script_lines.append('show sticks, {0}'.format(knob_selection_name))
                script_lines.append('show sticks, {0}'.format(hole_selection_name))
            for r in h.get_monomers():
                if 'register' in r.tags:
                    color = _heptad_colours[r.tags['register']]
                    script_lines.append('color {0}, {1}/{2}/'.format(color, chain, r.id))
    script_lines.append('deselect')
    script_lines.append('orient')
    script_lines.append('rotate z, 90')
    script_lines.append('zoom complete=1')
    script_string = '\n'.join(script_lines)
    if outfile is not None:
        if isinstance(outfile, str) and outfile[-3:] == 'pml':
            with open(outfile, 'w') as foo:
                foo.write(script_string)
    return script_string