# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# ALMOST_ZERO = 1.0e-6
# 
# CODON_NT_INDEX = numpy.full((3, N_CODON), -1, dtype='int')
# 
# STOP_CODON_TO_NT_INDICES = []
# 
# N_STOP = 0
# 
# N_NT = len(INDEX_TO_NT)
# 
# N_AA = len(INDEX_TO_AA)
# 
# INDEX_TO_NT = dict(enumerate('ACGT'))
# 
# CODON_NT_MUT = numpy.full((N_NT, N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')
# 
# CODON_TO_AA = []
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# CODON_NT = numpy.full((3, N_NT, N_CODON), False, dtype='bool')


import copy
import six
import abc
import warnings
import numpy
import scipy.misc
import scipy.optimize
import scipy.linalg
import scipy.stats
import scipy.special
    import doctest
from phydmslib.numutils import (broadcastMatrixMultiply,
                                broadcastMatrixVectorMultiply,
                                broadcastGetCols)
from phydmslib.constants import (N_CODON, CODON_NONSYN, CODON_TRANSITION,
                                 CODON_SINGLEMUT, ALMOST_ZERO, CODON_NT_INDEX,
                                 STOP_CODON_TO_NT_INDICES, N_STOP, N_NT, N_AA,
                                 INDEX_TO_NT, CODON_NT_MUT, CODON_NT_COUNT,
                                 CODON_TO_AA, INDEX_TO_AA, AA_TO_INDEX,
                                 CODON_NT)
                self.prx[r] /= self.prx[r].sum()

    def _update_dPrxy(self):
        """Update `dPrxy`."""
        if 'kappa' in self.freeparams:
            numpy.copyto(self.dPrxy['kappa'], self.Prxy / self.kappa,
                         where=CODON_TRANSITION)
            _fill_diagonals(self.dPrxy['kappa'], self._diag_indices)
        if 'omega' in self.freeparams:
            numpy.copyto(self.dPrxy['omega'], self.Frxy_no_omega * self.Qxy,
                         where=CODON_NONSYN)
            _fill_diagonals(self.dPrxy['omega'], self._diag_indices)
        if 'beta' in self.freeparams:
            self.dPrxy['beta'].fill(0)
            with numpy.errstate(divide='raise', under='raise', over='raise',
                                invalid='ignore'):
                numpy.copyto(self.dPrxy['beta'], self.Prxy *
                             (1 / self.beta + (self.piAx_piAy_beta *
                              (self.ln_piAx_piAy_beta / self.beta) /
                              (1 - self.piAx_piAy_beta))), where=CODON_NONSYN)
            numpy.copyto(self.dPrxy['beta'], self.Prxy/self.beta *
                         (1 - self.piAx_piAy_beta), where=numpy.logical_and(
                    CODON_NONSYN, numpy.fabs(1 - self.piAx_piAy_beta)
                    < ALMOST_ZERO))
            _fill_diagonals(self.dPrxy['beta'], self._diag_indices)
        if 'eta' in self.freeparams:
            for i in range(N_NT - 1):
                for w in range(i, N_NT):
                    numpy.copyto(self.dPrxy['eta'][i],
                                 self.Prxy / (self.eta[i] - int(i == w)),

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# ALMOST_ZERO = 1.0e-6
# 
# CODON_NT_INDEX = numpy.full((3, N_CODON), -1, dtype='int')
# 
# STOP_CODON_TO_NT_INDICES = []
# 
# N_STOP = 0
# 
# N_NT = len(INDEX_TO_NT)
# 
# N_AA = len(INDEX_TO_AA)
# 
# INDEX_TO_NT = dict(enumerate('ACGT'))
# 
# CODON_NT_MUT = numpy.full((N_NT, N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NT_COUNT = numpy.zeros((N_NT, N_CODON), dtype='int')
# 
# CODON_TO_AA = []
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# CODON_NT = numpy.full((3, N_NT, N_CODON), False, dtype='bool')


# Path: phydmslib/models.py
import copy
import six
import abc
import warnings
import numpy
import scipy.misc
import scipy.optimize
import scipy.linalg
import scipy.stats
import scipy.special
    import doctest
from phydmslib.numutils import (broadcastMatrixMultiply,
                                broadcastMatrixVectorMultiply,
                                broadcastGetCols)
from phydmslib.constants import (N_CODON, CODON_NONSYN, CODON_TRANSITION,
                                 CODON_SINGLEMUT, ALMOST_ZERO, CODON_NT_INDEX,
                                 STOP_CODON_TO_NT_INDICES, N_STOP, N_NT, N_AA,
                                 INDEX_TO_NT, CODON_NT_MUT, CODON_NT_COUNT,
                                 CODON_TO_AA, INDEX_TO_AA, AA_TO_INDEX,
                                 CODON_NT)

                self.prx[r] /= self.prx[r].sum()

    def _update_dPrxy(self):
        """Update `dPrxy`."""
        if 'kappa' in self.freeparams:
            numpy.copyto(self.dPrxy['kappa'], self.Prxy / self.kappa,
                         where=CODON_TRANSITION)
            _fill_diagonals(self.dPrxy['kappa'], self._diag_indices)
        if 'omega' in self.freeparams:
            numpy.copyto(self.dPrxy['omega'], self.Frxy_no_omega * self.Qxy,
                         where=CODON_NONSYN)
            _fill_diagonals(self.dPrxy['omega'], self._diag_indices)
        if 'beta' in self.freeparams:
            self.dPrxy['beta'].fill(0)
            with numpy.errstate(divide='raise', under='raise', over='raise',
                                invalid='ignore'):
                numpy.copyto(self.dPrxy['beta'], self.Prxy *
                             (1 / self.beta + (self.piAx_piAy_beta *
                              (self.ln_piAx_piAy_beta / self.beta) /
                              (1 - self.piAx_piAy_beta))), where=CODON_NONSYN)
            numpy.copyto(self.dPrxy['beta'], self.Prxy/self.beta *
                         (1 - self.piAx_piAy_beta), where=numpy.logical_and(
                    CODON_NONSYN, numpy.fabs(1 - self.piAx_piAy_beta)
                    < ALMOST_ZERO))
            _fill_diagonals(self.dPrxy['beta'], self._diag_indices)
        if 'eta' in self.freeparams:
            for i in range(N_NT - 1):
                for w in range(i, N_NT):
                    numpy.copyto(self.dPrxy['eta'][i],
                                 self.Prxy / (self.eta[i] - int(i == w)),

                                 where=CODON_NT_MUT[w])