<commit_before># -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import numpy as np
from ctypes import c_double, c_bool, c_int, byref, POINTER
from enum import IntEnum

from .ffi import get_c_library, CHRP_CELL_TYPES
from .errors import _check_handle


class CellType(IntEnum):
    '''
    Possibles values for the cell type:
        - NONE: Do not log anything
        - ERROR: Only log errors
        - WARNING: Log errors and warnings
        - INFO: Log errors, warnings and informations
        - DEBUG: Log everything, from errors to debug informations
    '''

    Orthorombic = CHRP_CELL_TYPES.CHRP_CELL_ORTHOROMBIC
    Triclinic = CHRP_CELL_TYPES.CHRP_CELL_TRICLINIC
    Infinite = CHRP_CELL_TYPES.CHRP_CELL_INFINITE


class UnitCell(object):
    '''
    An ``UnitCell`` represent the box containing the atoms in the system, and
    its periodicity.

    A unit cell is fully represented by three lenghts (a, b, c); and three
    angles (alpha, beta, gamma). The angles are stored in degrees, and the
    lenghts in Angstroms. A cell also has a matricial representation, by
    projecting the three base vector into an orthonormal base. We choose to
    represent such matrix as an upper triangular matrix:

                | a_x   b_x   c_x |
                |  0    b_y   c_y |
                |  0     0    c_z |

    An unit cell also have a cell type, represented by the `CellType` class.
    '''

    def __init__(self, a, b, c, alpha=90.0, beta=90.0, gamma=90.0):
        '''
        Create a new ``UnitCell`` with cell lenghts of ``a``, ``b`` and ``c``,
        and cell angles ``alpha``, ``beta`` and ``gamma``.
        '''
        self.c_lib = get_c_library()
        if alpha == 90.0 and beta == 90.0 and gamma == 90.0:
            a, b, c = c_double(a), c_double(b), c_double(c)
            self._handle_ = self.c_lib.chrp_cell(a, b, c)
        else:
            self._handle_ = self.c_lib.chrp_cell_triclinic(
                c_double(a), c_double(b), c_double(c),
                c_double(alpha), c_double(beta), c_double(gamma)
            )
        _check_handle(self._handle_)

    def __del__(self):
        self.c_lib.chrp_cell_free(self._handle_)

    def lengths(self):
        '''Get the three lenghts of an ``UnitCell``, in Angstroms.'''
        a, b, c = c_double(), c_double(), c_double()
        self.c_lib.chrp_cell_lengths(
            self._handle_, byref(a), byref(b), byref(c)
        )
        return a.value, b.value, c.value

    def set_lengths(self, a, b, c):
        '''Set the three lenghts of an ``UnitCell``, in Angstroms.'''
        self.c_lib.chrp_cell_set_lengths(
            self._handle_, c_double(a), c_double(b), c_double(c)
        )

    def angles(self):
        '''Get the three angles of an ``UnitCell``, in degrees.'''
        alpha, beta, gamma = c_double(), c_double(), c_double()
        self.c_lib.chrp_cell_angles(
            self._handle_, byref(alpha), byref(beta), byref(gamma)<commit_msg>The c_lib attr seems not to be accessible in the __del__ function<commit_after># -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import numpy as np
from ctypes import c_double, c_bool, c_int, byref, POINTER
from enum import IntEnum

from .ffi import get_c_library, CHRP_CELL_TYPES
from .errors import _check_handle


class CellType(IntEnum):
    '''
    Possibles values for the cell type:
        - NONE: Do not log anything
        - ERROR: Only log errors
        - WARNING: Log errors and warnings
        - INFO: Log errors, warnings and informations
        - DEBUG: Log everything, from errors to debug informations
    '''

    Orthorombic = CHRP_CELL_TYPES.CHRP_CELL_ORTHOROMBIC
    Triclinic = CHRP_CELL_TYPES.CHRP_CELL_TRICLINIC
    Infinite = CHRP_CELL_TYPES.CHRP_CELL_INFINITE


class UnitCell(object):
    '''
    An ``UnitCell`` represent the box containing the atoms in the system, and
    its periodicity.

    A unit cell is fully represented by three lenghts (a, b, c); and three
    angles (alpha, beta, gamma). The angles are stored in degrees, and the
    lenghts in Angstroms. A cell also has a matricial representation, by
    projecting the three base vector into an orthonormal base. We choose to
    represent such matrix as an upper triangular matrix:

                | a_x   b_x   c_x |
                |  0    b_y   c_y |
                |  0     0    c_z |

    An unit cell also have a cell type, represented by the `CellType` class.
    '''

    def __init__(self, a, b, c, alpha=90.0, beta=90.0, gamma=90.0):
        '''
        Create a new ``UnitCell`` with cell lenghts of ``a``, ``b`` and ``c``,
        and cell angles ``alpha``, ``beta`` and ``gamma``.
        '''
        self.c_lib = get_c_library()
        if alpha == 90.0 and beta == 90.0 and gamma == 90.0:
            a, b, c = c_double(a), c_double(b), c_double(c)
            self._handle_ = self.c_lib.chrp_cell(a, b, c)
        else:
            self._handle_ = self.c_lib.chrp_cell_triclinic(
                c_double(a), c_double(b), c_double(c),
                c_double(alpha), c_double(beta), c_double(gamma)
            )
        _check_handle(self._handle_)

    def __del__(self):
        c_lib = get_c_library()
        c_lib.chrp_cell_free(self._handle_)

    def lengths(self):
        '''Get the three lenghts of an ``UnitCell``, in Angstroms.'''
        a, b, c = c_double(), c_double(), c_double()
        self.c_lib.chrp_cell_lengths(
            self._handle_, byref(a), byref(b), byref(c)
        )
        return a.value, b.value, c.value

    def set_lengths(self, a, b, c):
        '''Set the three lenghts of an ``UnitCell``, in Angstroms.'''
        self.c_lib.chrp_cell_set_lengths(
            self._handle_, c_double(a), c_double(b), c_double(c)
        )

    def angles(self):
        '''Get the three angles of an ``UnitCell``, in degrees.'''
        alpha, beta, gamma = c_double(), c_double(), c_double()
        self.c_lib.chrp_cell_angles(
            self._handle_, byref(alpha), byref(beta), byref(gamma)
{'fraction_non_alphanumeric': 0.10733628754308222, 'fraction_numerical': 0.007221401608403085, 'mean_word_length': 2.482285714285714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1598287', 'n_tokens_mistral': 2074, 'n_tokens_neox': 2002, 'n_words': 608}