# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# CODON_TO_AA = []
# 
# INDEX_TO_CODON = {}
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import (N_CODON, NT_TO_INDEX, CODON_TO_AA,
                                 INDEX_TO_CODON, INDEX_TO_AA, CODON_SINGLEMUT,
                                 CODON_TRANSITION, CODON_NONSYN, N_NT,
                                 AA_TO_INDEX, N_AA)
        # prx is eigenvector or Prxy for the same r, but not different r
        for r in range(self.nsites):
            self.assertTrue(
                numpy.allclose(0, numpy.dot(self.expcm.prx[r],
                               self.expcm.Prxy[r])))
            if r > 0:
                self.assertFalse(
                    numpy.allclose(
                        0,
                        numpy.dot(self.expcm.prx[r], self.expcm.Prxy[r - 1])))

    def check_ExpCM_derivatives(self):
        """Use `sympy` to check values & derivatives of `ExpCM` attributes."""
        (Prxy, Qxy, phiw, beta, omega,
         eta0, eta1, eta2, kappa) = sympy.symbols("Prxy, Qxy, phiw, beta, "
                                                  "omega, eta0, eta1, eta2, "
                                                  "kappa")

        values = {"beta": self.params["beta"],
                  "omega": self.params["omega"],
                  "kappa": self.params["kappa"],
                  "eta0": self.params["eta"][0],
                  "eta1": self.params["eta"][1],
                  "eta2": self.params["eta"][2]}

        # check Prxy
        for r in range(self.nsites):
            for x in range(N_CODON):
                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                for y in [yy for yy in range(N_CODON) if yy != x]:

# Path: phydmslib/constants.py
# N_CODON = len(CODON_TO_INDEX)
# 
# NT_TO_INDEX = {nt: i for (i, nt) in INDEX_TO_NT.items()}
# 
# CODON_TO_AA = []
# 
# INDEX_TO_CODON = {}
# 
# INDEX_TO_AA = dict(enumerate('ACDEFGHIKLMNPQRSTVWY'))
# 
# CODON_SINGLEMUT = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_TRANSITION = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# CODON_NONSYN = numpy.full((N_CODON, N_CODON), False, dtype='bool')
# 
# N_NT = len(INDEX_TO_NT)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_AA = len(INDEX_TO_AA)


# Path: tests/test_expcm.py
import random
import unittest
import numpy
import scipy.linalg
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import (N_CODON, NT_TO_INDEX, CODON_TO_AA,
                                 INDEX_TO_CODON, INDEX_TO_AA, CODON_SINGLEMUT,
                                 CODON_TRANSITION, CODON_NONSYN, N_NT,
                                 AA_TO_INDEX, N_AA)

        # prx is eigenvector or Prxy for the same r, but not different r
        for r in range(self.nsites):
            self.assertTrue(
                numpy.allclose(0, numpy.dot(self.expcm.prx[r],
                               self.expcm.Prxy[r])))
            if r > 0:
                self.assertFalse(
                    numpy.allclose(
                        0,
                        numpy.dot(self.expcm.prx[r], self.expcm.Prxy[r - 1])))

    def check_ExpCM_derivatives(self):
        """Use `sympy` to check values & derivatives of `ExpCM` attributes."""
        (Prxy, Qxy, phiw, beta, omega,
         eta0, eta1, eta2, kappa) = sympy.symbols("Prxy, Qxy, phiw, beta, "
                                                  "omega, eta0, eta1, eta2, "
                                                  "kappa")

        values = {"beta": self.params["beta"],
                  "omega": self.params["omega"],
                  "kappa": self.params["kappa"],
                  "eta0": self.params["eta"][0],
                  "eta1": self.params["eta"][1],
                  "eta2": self.params["eta"][2]}

        # check Prxy
        for r in range(self.nsites):
            for x in range(N_CODON):
                pirAx = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[x]]]
                for y in [yy for yy in range(N_CODON) if yy != x]:

                    pirAy = self.prefs[r][INDEX_TO_AA[CODON_TO_AA[y]]]