<commit_before>from math import radians, sin, cos, acos, sqrt, pi


class Cell(object):
    def __init__(self, parameters, symmetry):
        if parameters is None:
            self.cell = None
            return
        assert isinstance(parameters, tuple)
        assert len(parameters) == 6
        self.a, self.b, self.c = parameters[:3]
        self.alpha, self.beta, self.gamma = parameters[3:]
        self.cell = parameters
        self.symmetry = symmetry  # international SG symbol w/ spaces

    def get_volume(self):
        ca = cos(radians(self.alpha))
        cb = cos(radians(self.beta))
        cg = cos(radians(self.gamma))
        return self.a * self.b * self.c * sqrt((1 - ca*ca - cb*cb - cg*cg) +
                                               2 * ca*cb*cg)

    def asu_volume(self, z=None):
        if z is None:
            z = calculate_z_order(self.symmetry)
        return self.get_volume() / z

    def __str__(self):
        return str(self.cell)

    # The orthogonalization matrix we use is described in ITfC B p.262:
    # "An alternative mode of orthogonalization, used by the Protein
    # Data Bank and most programs, is to align the a1 axis of the unit
    # cell with the Cartesian X1 axis, and to align the a*3 aixs with the
    # Cartesian X3 axis."
    def get_orth_matrix(self):
        a, b, c = self.a, self.b, self.c
        alpha = radians(self.alpha)
        beta = radians(self.beta)
        gamma = radians(self.gamma)
        alpha_star = acos((cos(gamma)*cos(beta) - cos(alpha)) /
                          (sin(beta)*sin(gamma)))
        return Mat3(a, b*cos(gamma),  c*cos(beta),
                    0, b*sin(gamma), -c*sin(beta)*cos(alpha_star),
                    0, 0,             c*sin(beta)*sin(alpha_star))

    def get_frac_matrix(self):
        return self.get_orth_matrix().inverse()

    def max_shift_in_mapping(self, other):
        trans = self.get_frac_matrix().dot(other.get_orth_matrix())
        return (trans - Mat3.identity()).euclidean_norm()

    # This affects only primitive orthorhombic (P 2x 2x 2x).
    # Convert the "reference" (symmetry-based) settings to the "standard"
    # (cell-based) settings. See the SETTING keyword in POINTLESS.
    def to_standard(self):
        if self.alpha == self.beta == self.gamma == 90 and (
                self.a > self.b or self.b > self.c):
            sym_splitted = self.symmetry.split()
            # i'm not sure if the condition below is redundant
            if len(sym_splitted) == 4 and sym_splitted[0] == 'P':
                reordered = sorted(zip(self.cell[:3], sym_splitted[1:]))
                new_cell, new_symm = zip(*reordered)
                return Cell(new_cell + (90., 90., 90.),
                            symmetry=' '.join(['P'] + new_symm))
        return self


class Mat3(object):
    "Matrix 3x3"
    def __init__(self, *args):
        if len(args) == 1:
            self.m = tuple(args[0])
        else:
            self.m = args
        assert len(self.m) == 9

    def __getitem__(self, index):
        return self.m[index]
    def __str__(self):
        return "[%g %g %g; %g %g %g; %g %g %g]" % self.m
    def __repr__(self):
        return "Mat3" + str(self.m)

    def __add__(self, other):
        assert isinstance(other, Mat3)
        return Mat3(a+b for a,b in zip(self.m, other.m))
    def __sub__(self, other):
        assert isinstance(other, Mat3)
        return Mat3(a-b for a,b in zip(self.m, other.m))
    # scalar must be float<commit_msg>fix the previous commit<commit_after>from math import radians, sin, cos, acos, sqrt, pi


class Cell(object):
    def __init__(self, parameters, symmetry):
        if parameters is None:
            self.cell = None
            return
        assert isinstance(parameters, tuple)
        assert len(parameters) == 6
        self.a, self.b, self.c = parameters[:3]
        self.alpha, self.beta, self.gamma = parameters[3:]
        self.cell = parameters
        self.symmetry = symmetry  # international SG symbol w/ spaces

    def get_volume(self):
        ca = cos(radians(self.alpha))
        cb = cos(radians(self.beta))
        cg = cos(radians(self.gamma))
        return self.a * self.b * self.c * sqrt((1 - ca*ca - cb*cb - cg*cg) +
                                               2 * ca*cb*cg)

    def asu_volume(self, z=None):
        if z is None:
            z = calculate_z_order(self.symmetry)
        return self.get_volume() / z

    def __str__(self):
        return str(self.cell)

    # The orthogonalization matrix we use is described in ITfC B p.262:
    # "An alternative mode of orthogonalization, used by the Protein
    # Data Bank and most programs, is to align the a1 axis of the unit
    # cell with the Cartesian X1 axis, and to align the a*3 aixs with the
    # Cartesian X3 axis."
    def get_orth_matrix(self):
        a, b, c = self.a, self.b, self.c
        alpha = radians(self.alpha)
        beta = radians(self.beta)
        gamma = radians(self.gamma)
        alpha_star = acos((cos(gamma)*cos(beta) - cos(alpha)) /
                          (sin(beta)*sin(gamma)))
        return Mat3(a, b*cos(gamma),  c*cos(beta),
                    0, b*sin(gamma), -c*sin(beta)*cos(alpha_star),
                    0, 0,             c*sin(beta)*sin(alpha_star))

    def get_frac_matrix(self):
        return self.get_orth_matrix().inverse()

    def max_shift_in_mapping(self, other):
        trans = self.get_frac_matrix().dot(other.get_orth_matrix())
        return (trans - Mat3.identity()).euclidean_norm()

    # This affects only primitive orthorhombic (P 2x 2x 2x).
    # Convert the "reference" (symmetry-based) settings to the "standard"
    # (cell-based) settings. See the SETTING keyword in POINTLESS.
    def to_standard(self):
        if self.alpha == self.beta == self.gamma == 90 and (
                self.a > self.b or self.b > self.c):
            sym_splitted = self.symmetry.split()
            # i'm not sure if the condition below is redundant
            if len(sym_splitted) == 4 and sym_splitted[0] == 'P':
                reordered = sorted(zip(self.cell[:3], sym_splitted[1:]))
                new_cell, new_symm = zip(*reordered)
                return Cell(new_cell + (90., 90., 90.),
                            symmetry=' '.join(('P',) + new_symm))
        return self


class Mat3(object):
    "Matrix 3x3"
    def __init__(self, *args):
        if len(args) == 1:
            self.m = tuple(args[0])
        else:
            self.m = args
        assert len(self.m) == 9

    def __getitem__(self, index):
        return self.m[index]
    def __str__(self):
        return "[%g %g %g; %g %g %g; %g %g %g]" % self.m
    def __repr__(self):
        return "Mat3" + str(self.m)

    def __add__(self, other):
        assert isinstance(other, Mat3)
        return Mat3(a+b for a,b in zip(self.m, other.m))
    def __sub__(self, other):
        assert isinstance(other, Mat3)
        return Mat3(a-b for a,b in zip(self.m, other.m))
    # scalar must be float
{'fraction_non_alphanumeric': 0.1220276235227111, 'fraction_numerical': 0.012245479139968674, 'mean_word_length': 2.061900610287707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '427116', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2197, 'n_words': 626}