# Path: phydmslib/constants.py
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# ALMOST_ZERO = 1.0e-6


import os
import sys
import math
import phydmslib.models
import pyvolve
import numpy
import random
import Bio.Phylo
    import doctest
from phydmslib.constants import (NT_TO_INDEX, AA_TO_INDEX, ALMOST_ZERO)
from tempfile import mkstemp
    assert all((1 <= r <= model.nsites for r in divsites))

    partitions = []
    for r in range(model.nsites):
        matrix = numpy.zeros((len(codons), len(codons)), dtype='float')
        for (xi, x) in enumerate(codons):
            for (yi, y) in enumerate(codons):
                ntdiffs = [(x[j], y[j]) for j in range(3) if x[j] != y[j]]
                if len(ntdiffs) == 1:
                    (xnt, ynt) = ntdiffs[0]
                    qxy = 1.0
                    if (xnt in purines) == (ynt in purines):
                        qxy *= model.kappa
                    (xaa, yaa) = (codon_dict[x], codon_dict[y])
                    fxy = 1.0
                    if xaa != yaa:
                        if type(model) ==\
                         phydmslib.models.ExpCM_empirical_phi_divpressure:
                            fxy *= (model.omega *
                                    (1 + model.omega2 * model.deltar[r]))
                        elif r + 1 in divsites:
                            fxy *= divomega
                        else:
                            fxy *= model.omega
                    if type(model) in [phydmslib.models.ExpCM,
                                       phydmslib.models.ExpCM_empirical_phi,
                                       (phydmslib.models
                                        .ExpCM_empirical_phi_divpressure)]:
                        qxy *= model.phi[NT_TO_INDEX[ynt]]
                        pix = model.pi[r][AA_TO_INDEX[xaa]]**model.beta

# Path: phydmslib/constants.py
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# ALMOST_ZERO = 1.0e-6


# Path: phydmslib/simulate.py
import os
import sys
import math
import phydmslib.models
import pyvolve
import numpy
import random
import Bio.Phylo
    import doctest
from phydmslib.constants import (NT_TO_INDEX, AA_TO_INDEX, ALMOST_ZERO)
from tempfile import mkstemp

    assert all((1 <= r <= model.nsites for r in divsites))

    partitions = []
    for r in range(model.nsites):
        matrix = numpy.zeros((len(codons), len(codons)), dtype='float')
        for (xi, x) in enumerate(codons):
            for (yi, y) in enumerate(codons):
                ntdiffs = [(x[j], y[j]) for j in range(3) if x[j] != y[j]]
                if len(ntdiffs) == 1:
                    (xnt, ynt) = ntdiffs[0]
                    qxy = 1.0
                    if (xnt in purines) == (ynt in purines):
                        qxy *= model.kappa
                    (xaa, yaa) = (codon_dict[x], codon_dict[y])
                    fxy = 1.0
                    if xaa != yaa:
                        if type(model) ==\
                         phydmslib.models.ExpCM_empirical_phi_divpressure:
                            fxy *= (model.omega *
                                    (1 + model.omega2 * model.deltar[r]))
                        elif r + 1 in divsites:
                            fxy *= divomega
                        else:
                            fxy *= model.omega
                    if type(model) in [phydmslib.models.ExpCM,
                                       phydmslib.models.ExpCM_empirical_phi,
                                       (phydmslib.models
                                        .ExpCM_empirical_phi_divpressure)]:
                        qxy *= model.phi[NT_TO_INDEX[ynt]]
                        pix = model.pi[r][AA_TO_INDEX[xaa]]**model.beta

                        piy = model.pi[r][AA_TO_INDEX[yaa]]**model.beta