# Path: phydmslib/constants.py
# CODON_TO_AA = []
# 
# N_CODON = len(CODON_TO_INDEX)
# 
# N_AA = len(INDEX_TO_AA)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_NT = len(INDEX_TO_NT)


import random
import unittest
import copy
import numpy
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import CODON_TO_AA, N_CODON, N_AA, AA_TO_INDEX, N_NT
                (1 - (pirAx / pirAy)**beta))
        dFrxy_dpirAx = ((-omega * beta / pirAx) *
                        ((pirAx / pirAy)**beta *
                        (sympy.ln((pirAx / pirAy)**beta) - 1) + 1) /
                        ((1 - (pirAx / pirAy)**beta)**2))
        dFrxy_dpirAx_equal = -omega * beta / (2 * pirAx)
        dFrxy_dpirAy = ((omega * beta / pirAy) * ((pirAx / pirAy)**beta *
                        (sympy.ln((pirAx / pirAy)**beta) - 1) + 1) /
                        ((1 - (pirAx / pirAy)**beta)**2))
        dFrxy_dpirAy_equal = omega * beta / (2 * pirAy)
        diffpref = 1.0e-5
        for _itest in range(5):
            values = [[beta, 1], [pirAx, random.uniform(0.01, 0.5)],
                      [pirAy, random.uniform(0.01, 0.5)],
                      [omega, random.uniform(0.1, 2.0)]]
            self.assertTrue(abs(values[1][1] - values[2][1]) > diffpref,
                            "choose another random number seed as pirAx and "
                            "pirAy are too close.")
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAx.subs(values)),
                            float(sympy.diff(Frxy, pirAx).subs(values))))
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAy.subs(values)),
                            float(sympy.diff(Frxy, pirAy).subs(values))))
            values[2][1] = values[1][1] * (1 + diffpref)
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAx_equal.subs(
                    values)), float(sympy.diff(Frxy, pirAx).subs(values))))
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAy_equal.subs(
                    values)), float(sympy.diff(Frxy, pirAy).subs(values))))

        expcm_fitprefs = copy.deepcopy(self.expcm_fitprefs)
        for r in range(expcm_fitprefs.nsites):

# Path: phydmslib/constants.py
# CODON_TO_AA = []
# 
# N_CODON = len(CODON_TO_INDEX)
# 
# N_AA = len(INDEX_TO_AA)
# 
# AA_TO_INDEX = {aa: i for (i, aa) in INDEX_TO_AA.items()}
# 
# N_NT = len(INDEX_TO_NT)


# Path: tests/test_expcm_fitprefs.py
import random
import unittest
import copy
import numpy
import scipy.optimize
import sympy
import phydmslib.models
from phydmslib.constants import CODON_TO_AA, N_CODON, N_AA, AA_TO_INDEX, N_NT

                (1 - (pirAx / pirAy)**beta))
        dFrxy_dpirAx = ((-omega * beta / pirAx) *
                        ((pirAx / pirAy)**beta *
                        (sympy.ln((pirAx / pirAy)**beta) - 1) + 1) /
                        ((1 - (pirAx / pirAy)**beta)**2))
        dFrxy_dpirAx_equal = -omega * beta / (2 * pirAx)
        dFrxy_dpirAy = ((omega * beta / pirAy) * ((pirAx / pirAy)**beta *
                        (sympy.ln((pirAx / pirAy)**beta) - 1) + 1) /
                        ((1 - (pirAx / pirAy)**beta)**2))
        dFrxy_dpirAy_equal = omega * beta / (2 * pirAy)
        diffpref = 1.0e-5
        for _itest in range(5):
            values = [[beta, 1], [pirAx, random.uniform(0.01, 0.5)],
                      [pirAy, random.uniform(0.01, 0.5)],
                      [omega, random.uniform(0.1, 2.0)]]
            self.assertTrue(abs(values[1][1] - values[2][1]) > diffpref,
                            "choose another random number seed as pirAx and "
                            "pirAy are too close.")
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAx.subs(values)),
                            float(sympy.diff(Frxy, pirAx).subs(values))))
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAy.subs(values)),
                            float(sympy.diff(Frxy, pirAy).subs(values))))
            values[2][1] = values[1][1] * (1 + diffpref)
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAx_equal.subs(
                    values)), float(sympy.diff(Frxy, pirAx).subs(values))))
            self.assertTrue(numpy.allclose(float(dFrxy_dpirAy_equal.subs(
                    values)), float(sympy.diff(Frxy, pirAy).subs(values))))

        expcm_fitprefs = copy.deepcopy(self.expcm_fitprefs)
        for r in range(expcm_fitprefs.nsites):

            for x in range(N_CODON):