# Path: phydmslib/constants.py
# ALMOST_ZERO = 1.0e-6
# 
# CODON_TO_INDEX = {}
# 
# N_CODON = len(CODON_TO_INDEX)


import copy
import warnings
import numpy
import scipy.optimize
import Bio.Phylo
import phydmslib.models
    import doctest
from phydmslib.numutils import broadcastMatrixVectorMultiply
from phydmslib.constants import ALMOST_ZERO, CODON_TO_INDEX, N_CODON
                   ) == {clade.name for clade in tree.get_terminals()}
        self.alignment = copy.deepcopy(alignment)
        self.nseqs = len(alignment)
        alignment_d = dict(self.alignment)

        # For internal storage, branch lengths are in model units rather
        # than codon substitutions per site. So here adjust them from
        # codon substitutions per site to model units.
        assert isinstance(tree, Bio.Phylo.BaseTree.Tree), "invalid tree"
        self._tree = copy.deepcopy(tree)
        assert self._tree.count_terminals() == self.nseqs
        if branchScale is None:
            branchScale = self.model.branchScale
        else:
            assert isinstance(branchScale, float) and branchScale > 0
        for node in self._tree.find_clades():
            if node != self._tree.root:
                node.branch_length /= branchScale

        # index nodes
        self.name_to_nodeindex = {}
        self.ninternal = len(self._tree.get_nonterminals())
        self.ntips = self._tree.count_terminals()
        self.nnodes = self.ntips + self.ninternal
        self.rdescend = [-1] * self.ninternal
        self.ldescend = [-1] * self.ninternal
        self.underflowlogscale = numpy.zeros(self.nsites, dtype='float')
        if self._distributionmodel:
            self._Lshape = (self.model.ncats, self.nsites, N_CODON)
        else:

# Path: phydmslib/constants.py
# ALMOST_ZERO = 1.0e-6
# 
# CODON_TO_INDEX = {}
# 
# N_CODON = len(CODON_TO_INDEX)


# Path: phydmslib/treelikelihood.py
import copy
import warnings
import numpy
import scipy.optimize
import Bio.Phylo
import phydmslib.models
    import doctest
from phydmslib.numutils import broadcastMatrixVectorMultiply
from phydmslib.constants import ALMOST_ZERO, CODON_TO_INDEX, N_CODON

                   ) == {clade.name for clade in tree.get_terminals()}
        self.alignment = copy.deepcopy(alignment)
        self.nseqs = len(alignment)
        alignment_d = dict(self.alignment)

        # For internal storage, branch lengths are in model units rather
        # than codon substitutions per site. So here adjust them from
        # codon substitutions per site to model units.
        assert isinstance(tree, Bio.Phylo.BaseTree.Tree), "invalid tree"
        self._tree = copy.deepcopy(tree)
        assert self._tree.count_terminals() == self.nseqs
        if branchScale is None:
            branchScale = self.model.branchScale
        else:
            assert isinstance(branchScale, float) and branchScale > 0
        for node in self._tree.find_clades():
            if node != self._tree.root:
                node.branch_length /= branchScale

        # index nodes
        self.name_to_nodeindex = {}
        self.ninternal = len(self._tree.get_nonterminals())
        self.ntips = self._tree.count_terminals()
        self.nnodes = self.ntips + self.ninternal
        self.rdescend = [-1] * self.ninternal
        self.ldescend = [-1] * self.ninternal
        self.underflowlogscale = numpy.zeros(self.nsites, dtype='float')
        if self._distributionmodel:
            self._Lshape = (self.model.ncats, self.nsites, N_CODON)
        else:

            self._Lshape = (self.nsites, N_CODON)