Runs SCWRL on input PDB strong or path to PDB and a sequence string.

    Parameters
    ----------
    pdb : str
        PDB string or a path to a PDB file.
    sequence : str
        Amino acid sequence for SCWRL to pack in single-letter code.
    path : bool, optional
        True if pdb is a path.

    Returns
    -------
    scwrl_std_out : str
        Std out from SCWRL.
    scwrl_pdb : str
        String of packed SCWRL PDB.

    Raises
    ------
    IOError
        Raised if SCWRL failed to run.

def run_scwrl(pdb, sequence, path=True):
    """Runs SCWRL on input PDB strong or path to PDB and a sequence string.

    Parameters
    ----------
    pdb : str
        PDB string or a path to a PDB file.
    sequence : str
        Amino acid sequence for SCWRL to pack in single-letter code.
    path : bool, optional
        True if pdb is a path.

    Returns
    -------
    scwrl_std_out : str
        Std out from SCWRL.
    scwrl_pdb : str
        String of packed SCWRL PDB.

    Raises
    ------
    IOError
        Raised if SCWRL failed to run.
    """
    if path:
        with open(pdb, 'r') as inf:
            pdb = inf.read()
    pdb = pdb.encode()
    sequence = sequence.encode()
    try:
        with tempfile.NamedTemporaryFile(delete=False) as scwrl_tmp,\
                tempfile.NamedTemporaryFile(delete=False) as scwrl_seq,\
                tempfile.NamedTemporaryFile(delete=False) as scwrl_out:
            scwrl_tmp.write(pdb)
            scwrl_tmp.seek(0)  # Resets the buffer back to the first line
            scwrl_seq.write(sequence)
            scwrl_seq.seek(0)
            if not global_settings['scwrl']['rigid_rotamer_model']:
                scwrl_std_out = subprocess.check_output(
                    [global_settings['scwrl']['path'],
                     '-i', scwrl_tmp.name,
                     '-o', scwrl_out.name,
                     '-s', scwrl_seq.name])
            else:
                scwrl_std_out = subprocess.check_output(
                    [global_settings['scwrl']['path'],
                     '-v',  # Rigid rotamer model
                     '-i', scwrl_tmp.name,
                     '-o', scwrl_out.name,
                     '-s', scwrl_seq.name])
            scwrl_out.seek(0)
            scwrl_pdb = scwrl_out.read()
    finally:
        os.remove(scwrl_tmp.name)
        os.remove(scwrl_out.name)
        os.remove(scwrl_seq.name)
    if not scwrl_pdb:
        raise IOError('SCWRL failed to run. SCWRL:\n{}'.format(scwrl_std_out))
    return scwrl_std_out.decode(), scwrl_pdb.decode()