<commit_before>"""
Sile object for reading TBtrans binary files
"""
from __future__ import print_function

# Import sile objects
from sids.io.sile import *

# Import the geometry object
from sids import Geometry, Atom, SuperCell
from sids import Bohr

import numpy as np

__all__ = ['TBtransSile','PHtransSile']


class TBtransSile(NCSile):
    """ TBtrans file object """

    def _data(self,name):
        """ Local method for obtaining the data from the NCSile.
        
        This method checks how the file is access, i.e. whether 
        data is stored in the object or it should be read consequtively.
        """
        if self._access > 0:
            return self.__data[name]
        return self.variables[name]

    def _setup(self):
        """ Setup the special object for data containing """
        if self._access > 0:
            self.__data = dict()

            # Fake double calls
            access = self._access
            self._access = 0
            
            # Create elements
            for d in ['cell', 'xa', 'lasto',
                      'a_dev', 'pivot', 
                      'kpt', 'wkpt', 'E']:
                self.__data[d] = self._data(d)

            self._access = access
            
            # Create the geometry in the data file
            self.__data['_geom'] = self.read_geom()


    def read_sc(self):
        """ Returns `SuperCell` object from a .TBT.nc file """
        if not hasattr(self,'fh'):
            with self:
                return self.read_sc()

        cell = np.copy(self.cell,dtype=np.float64)
        cell.shape = (3,3)

        return SuperCell(cell)
    

    def read_geom(self):
        """ Returns Geometry object from a .TBT.nc file """
        # Quick access to the geometry object
        if self._access > 0:
            return self._data('_geom')
        
        if not hasattr(self,'fh'):
            with self:
                return self.read_geom()

        sc = self.read_sc()

        xyz = np.copy(self.xa, dtype=np.float64)
        xyz.shape = (-1,3)

        # Create list with correct number of orbitals
        lasto = np.copy(self.lasto, dtype=np.int32)
        nos = np.append([lasto[0]], np.diff(lasto))
        nos = np.array(nos,np.int32)

        # Default to Hydrogen atom with nos[ia] orbitals<commit_msg>bug: fixed reading variables from netcdf tbtrans<commit_after>"""
Sile object for reading TBtrans binary files
"""
from __future__ import print_function

# Import sile objects
from sids.io.sile import *

# Import the geometry object
from sids import Geometry, Atom, SuperCell
from sids import Bohr

import numpy as np

__all__ = ['TBtransSile','PHtransSile']


class TBtransSile(NCSile):
    """ TBtrans file object """

    def _data(self,name):
        """ Local method for obtaining the data from the NCSile.
        
        This method checks how the file is access, i.e. whether 
        data is stored in the object or it should be read consequtively.
        """
        if self._access > 0:
            return self.__data[name]
        return self.variables[name][:]

    def _setup(self):
        """ Setup the special object for data containing """
        if self._access > 0:
            self.__data = dict()

            # Fake double calls
            access = self._access
            self._access = 0
            
            # Create elements
            for d in ['cell', 'xa', 'lasto',
                      'a_dev', 'pivot', 
                      'kpt', 'wkpt', 'E']:
                self.__data[d] = self._data(d)

            self._access = access
            
            # Create the geometry in the data file
            self.__data['_geom'] = self.read_geom()


    def read_sc(self):
        """ Returns `SuperCell` object from a .TBT.nc file """
        if not hasattr(self,'fh'):
            with self:
                return self.read_sc()

        cell = np.array(np.copy(self.cell), dtype=np.float64)
        cell.shape = (3,3)

        return SuperCell(cell)
    

    def read_geom(self):
        """ Returns Geometry object from a .TBT.nc file """
        # Quick access to the geometry object
        if self._access > 0:
            return self._data('_geom')
        
        if not hasattr(self,'fh'):
            with self:
                return self.read_geom()

        sc = self.read_sc()

        xyz = np.array(np.copy(self.xa), dtype=np.float64)
        xyz.shape = (-1,3)

        # Create list with correct number of orbitals
        lasto = np.array(np.copy(self.lasto), dtype=np.int32)
        nos = np.append([lasto[0]], np.diff(lasto))
        nos = np.array(nos,np.int32)

        # Default to Hydrogen atom with nos[ia] orbitals
{'fraction_non_alphanumeric': 0.10487130397787704, 'fraction_numerical': 0.00723250372261221, 'mean_word_length': 1.8274203247143717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4289187', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1338, 'n_words': 422}