Read and parse a pseudopotential file. Main entry point for client code.

        Returns:
            pseudopotential object or None if filename is not a valid pseudopotential file.
492492
def parse(self, filename):
        
        path = os.path.abspath(filename)

        # Only PAW supports XML at present.
        if filename.endswith(".xml"):
            return PawXmlSetup(path)

        ppdesc = self.read_ppdesc(path)

        if ppdesc is None:
            logger.critical("Cannot find ppdesc in %s" % path)
            return None

        psp_type = ppdesc.psp_type

        parsers = {
            "FHI": NcAbinitHeader.fhi_header,
            "GTH": NcAbinitHeader.gth_header,
            "TM": NcAbinitHeader.tm_header,
            "Teter": NcAbinitHeader.tm_header,
            "HGH": NcAbinitHeader.hgh_header,
            "HGHK": NcAbinitHeader.hgh_header,
            "ONCVPSP": NcAbinitHeader.oncvpsp_header,
            "PAW_abinit_text": PawAbinitHeader.paw_header,
        }

        try:
            header = parsers[ppdesc.name](path, ppdesc)
        except Exception:
            raise self.Error(path + ":\n" + straceback())

        if psp_type == "NC":
            pseudo = NcAbinitPseudo(path, header)
        elif psp_type == "PAW":
            pseudo = PawAbinitPseudo(path, header)
        else:
            raise NotImplementedError("psp_type not in [NC, PAW]")

        return pseudo
155621
def read_file(filename: PathLike = "experiment.yml") -> Dict[str, Any]:
    """"""
    logger.debug("Input file: %s", filename)

    with open(filename, "r") as stream:
        structure = yaml.safe_load(stream)
    return structure
10761
def parse(cls, filename, root=None):
    
    if root is not None:
      if os.path.isabs(filename):
        raise ValueError("filename must be a relative path if root is specified")
      full_filename = os.path.join(root, filename)
    else:
      full_filename = filename

    with io.open(full_filename, 'rb') as fp:
      blob = fp.read()

    tree = cls._parse(blob, filename)
    return cls(blob=blob, tree=tree, root=root, filename=filename)
581614
def read_local_file(filename):
    
    frm = inspect.currentframe().f_back
    if frm.f_code.co_name == 'run_code':
        frm = frm.f_back
    path = os.path.split(frm.f_code.co_filename)[0]
    return read_file(os.path.join(path, filename))
579202
def parse(string, is_file=False, obj=False):
        
        try:
            if obj is False:
                if is_file:
                    return system_json.load(string)
                return system_json.loads(string, encoding='utf8')
            else:
                if is_file:
                    return system_json.load(
                        string,
                        object_hook=lambda d: namedtuple('j', d.keys())
                        (*d.values()), ensure_ascii=False, encoding='utf8')
                return system_json.loads(
                    string,
                    object_hook=lambda d: namedtuple('j', d.keys())
                    (*d.values()), encoding='utf8')
        except (Exception, BaseException) as error:
            try:
                if current_app.config['DEBUG']:
                    raise error
            except RuntimeError as flask_error:
                raise error
            return None
413886
def _load(self, file_parser, section_name):
        
        # pylint: disable-msg=W0621
        log = logging.getLogger('argtoolbox')
        try:
            log.debug("looking for field (section=" + section_name
                      + ") : " + self._name)
            data = None
            try:
                if self.e_type == int:
                    data = file_parser.getint(section_name, self._name)
                elif self.e_type == float:
                    data = file_parser.getfloat(section_name, self._name)
                elif self.e_type == bool:
                    data = file_parser.getboolean(section_name, self._name)
                elif self.e_type == list:
                    data = file_parser.get(section_name, self._name)
                    data = data.strip()
                    data = data.decode(locale.getpreferredencoding())
                    data = data.split()
                    if not data:
                        msg = "The optional field '%(name)s' was present, \
type is list, but the current value is an empty \
list." % {"name": self._name}
                        log.error(msg)
                        raise ValueError(msg)
                elif self.e_type == str:
                    data = file_parser.get(section_name, self._name)
                    # happens only when the current field is present,
                    # type is string, but value is ''
                    if not data:
                        msg = "The optional field '%(name)s' was present, \
                        type is string, but the current value is an empty \
                        string." % {"name": self._name}
                        log.error(msg)
                        raise ValueError(msg)
                    data = data.decode(locale.getpreferredencoding())
                else:
                    msg = "Data type not supported : %(type)s " % {
                        "type": self.e_type}
                    log.error(msg)
                    raise TypeError(msg)

            except ValueError as ex:
                msg = "The current field '%(name)s' was present, but the \
required type is : %(e_type)s." %  {
                "name": self._name,
                "e_type": self.e_type
                }
                log.error(msg)
                log.error(str(ex))
                raise ValueError(str(ex))

            log_data = {"name": self._name, "data": data,
                        "e_type": self.e_type}
            if self.hidden:
                log_data['data'] = "xxxxxxxx"
            log.debug("field found : '%(name)s', value : '%(data)s', \
type : '%(e_type)s'", log_data)
            self.value = data

        except ConfigParser.NoOptionError:
            if self.conf_required:
                msg = "The required field '%(name)s' was missing from the \
config file." % {"name": self._name}
                log.error(msg)
                raise ValueError(msg)

            if self.default is not None:
                self.value = self.default
                log_data = {"name": self._name, "data": self.default,
                            "e_type": self.e_type}
                if self.hidden:
                    log_data['data'] = "xxxxxxxx"
                log.debug("Field not found : '%(name)s', default value : \
'%(data)s', type : '%(e_type)s'", log_data)
            else:
                log.debug("Field not found : '" + self._name + "'")
507308
def parse(self, file_name):
        
        root = ET.parse(file_name).getroot()
        return self._parse(root)
905890
def readFromFile(self, filename):
        '''
        
        '''
        s = dict(np.load(filename))
        try:
            self.coeffs = s['coeffs'][()]
        except KeyError:
            #LEGENCY - remove
            self.coeffs = s
        try:
            self.opts = s['opts'][()]
        except KeyError:
            pass
        return self.coeffs
412124
def parse(self, file_name):
        
        self.object = self.parsed_class()
        with open(file_name, encoding='utf-8') as f:
            self.parse_str(f.read())
        return self.object
1258097
def get_file_contents(filename):
    
    data = None
    try:
        with open(filename) as pf:
            data = pf.read()
    except IOError:
        # File not found, return None
        pass
    return data
1020567
def read(filename='cache'):
	
	cache_path = get_cache_path(filename)
	if not os.path.exists(cache_path) or os.stat(cache_path).st_size == 0:
		return None
	with open(cache_path, 'r') as file:
		return json.load(file)
1238278
def parsefile(self, filename):
        
        with open(filename, 'rb') as fd:
            return self.parse(fd.read())
999010
def read_file(self, file_path):
        
        try:
            with open(self.cont_path(file_path)) as fd:
                return fd.read()
        except IOError as ex:
            logger.error("error while accessing file %s: %r", file_path, ex)
            raise ColinException(
                "There was an error while accessing file %s: %r" % (file_path, ex))
686455
def read(self, src):
        
        geojson = None
        if not self.is_valid_src(src):
            error = "File < {0} > does not exists or does start with 'http'."
            raise ValueError(error.format(src))
        if not self.is_url(src):
            return open(src, 'r').read().decode('latin-1').encode('utf-8')
        tmp = self.get_location(src)
        # if src poits to url that was already downloaded
        # read from local file instead
        if os.path.isfile(tmp):
            with open(tmp, 'r') as f:
                return f.read()
        # download file and write to local filesystem before returning
        response = urllib2.urlopen(src)
        data = response.read().decode('latin-1').encode('utf-8')
        with open(tmp, 'w') as f:
            f.write(data)
            return data
871938
def parseFile( self, file_or_filename, parseAll=False ):
        
        try:
            file_contents = file_or_filename.read()
        except AttributeError:
            with open(file_or_filename, "r") as f:
                file_contents = f.read()
        try:
            return self.parseString(file_contents, parseAll)
        except ParseBaseException as exc:
            if ParserElement.verbose_stacktrace:
                raise
            else:
                # catch and re-raise exception from here, clears out pyparsing internal stack trace
                raise exc
565752
def _read_object(self, path):
    ''''''
    if not os.path.exists(path):
      return None

    if os.path.isdir(path):
      raise RuntimeError('%s is a directory, not a file.' % path)

    with open(path) as f:
      file_contents = f.read()

    return file_contents
916646
def read_file(self):
        
        with open(self.filename, mode='r+', encoding='utf8') as text_file:
            self.raw_file = text_file.read()  # pylint: disable= attribute-defined-outside-init
        self.file_lines = [x.rstrip() for x in self.raw_file.splitlines()]