def pyvolvePartitions(model, divselection=None):
codons = pyvolve.genetics.Genetics().codons<EOL>codon_dict = pyvolve.genetics.Genetics().codon_dict<EOL>pyrims = pyvolve.genetics.Genetics().pyrims<EOL>purines = pyvolve.genetics.Genetics().purines<EOL>if divselection:<EOL><INDENT>(divomega, divsites) = divselection<EOL><DEDENT>else:<EOL><INDENT>divsites = []<EOL><DEDENT>assert all([<NUM_LIT:1> <= r <= model.nsites for r in divsites])<EOL>partitions = []<EOL>for r in range(model.nsites):<EOL><INDENT>matrix = scipy.zeros((len(codons), len(codons)), dtype='<STR_LIT:float>')<EOL>for (xi, x) in enumerate(codons):<EOL><INDENT>for (yi, y) in enumerate(codons):<EOL><INDENT>ntdiffs = [(x[j], y[j]) for j in range(<NUM_LIT:3>) if x[j] != y[j]]<EOL>if len(ntdiffs) == <NUM_LIT:1>:<EOL><INDENT>(xnt, ynt) = ntdiffs[<NUM_LIT:0>]<EOL>qxy = <NUM_LIT:1.0><EOL>if (xnt in purines) == (ynt in purines):<EOL><INDENT>qxy *= model.kappa<EOL><DEDENT>(xaa, yaa) = (codon_dict[x], codon_dict[y])<EOL>fxy = <NUM_LIT:1.0><EOL>if xaa != yaa:<EOL><INDENT>if type(model) == phydmslib.models.ExpCM_empirical_phi_divpressure:<EOL><INDENT>fxy *= model.omega * (<NUM_LIT:1> + model.omega2 * model.deltar[r])<EOL><DEDENT>elif r + <NUM_LIT:1> in divsites:<EOL><INDENT>fxy *= divomega<EOL><DEDENT>else:<EOL><INDENT>fxy *= model.omega<EOL><DEDENT><DEDENT>if type(model) in [phydmslib.models.ExpCM,<EOL>phydmslib.models.ExpCM_empirical_phi, phydmslib.models.ExpCM_empirical_phi_divpressure]:<EOL><INDENT>qxy *= model.phi[NT_TO_INDEX[ynt]]<EOL>pix = model.pi[r][AA_TO_INDEX[xaa]]**model.beta<EOL>piy = model.pi[r][AA_TO_INDEX[yaa]]**model.beta<EOL>if abs(pix - piy) > ALMOST_ZERO:<EOL><INDENT>fxy *= math.log(piy / pix) / (<NUM_LIT:1.0> - pix / piy)<EOL><DEDENT><DEDENT>elif type(model) == phydmslib.models.YNGKP_M0:<EOL><INDENT>for p in range(<NUM_LIT:3>):<EOL><INDENT>qxy *= model.phi[p][NT_TO_INDEX[y[p]]]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>type(model)))<EOL><DEDENT>matrix[xi][yi] = model.mu * qxy * fxy<EOL><DEDENT><DEDENT>matrix[xi][xi] = -matrix[xi].sum()<EOL><DEDENT>old_stdout = sys.stdout<EOL>sys.stdout = open(os.devnull, '<STR_LIT:w>')<EOL>try:<EOL><INDENT>m = pyvolve.Model("<STR_LIT>", {"<STR_LIT>":matrix})<EOL><DEDENT>finally:<EOL><INDENT>sys.stdout.close()<EOL>sys.stdout = old_stdout<EOL><DEDENT>partitions.append(pyvolve.Partition(models=m, size=<NUM_LIT:1>))<EOL><DEDENT>return partitions<EOL>
Get list of `pyvolve` partitions for `model`.

    Args:
        `model` (`phydmslib.models.Models` object)
            The model used for the simulations. Currently only
            certain `Models` are supported (e.g., `YNGKP`,
            `ExpCM`)
        `divselection` (`None` or 2-tuple `(divomega, divsites)`)
            Set this option if you want to simulate a subset of sites
            as under diversifying selection (e.g., an `omega` different
            than that used by `model`. In this case, `divomega` is
            the omega for this subset of sites, and `divsites` is a list
            of the sites in 1, 2, ... numbering.

    Returns:
        `partitions` (`list` of `pyvolve.Partition` objects)
            Can be fed into `pyvolve.Evolver` to simulate evolution.