Get metadata for a single basis set

    If the basis doesn't exist, an exception is raised
480052
def _get_basis_metadata(name, data_dir):
    '''
    '''

    # Transform the name into an internal representation
    tr_name = misc.transform_basis_name(name)

    # Get the metadata for all basis sets
    metadata = get_metadata(data_dir)

    if not tr_name in metadata:
        raise KeyError("Basis set {} does not exist".format(name))

    return metadata[tr_name]
425952
def _bse_cli_list_basis_sets(args):
    ''''''
    metadata = api.filter_basis_sets(args.substr, args.family, args.role, args.data_dir)

    if args.no_description:
        liststr = metadata.keys()
    else:
        liststr = format_columns([(k, v['description']) for k, v in metadata.items()])

    return '\n'.join(liststr)
700524
def _get_metadata_model(name=None):
    """"""
    if name is not None:
        try:
            return registry[name]
        except KeyError:
            if len(registry) == 1:
                valid_names = 'Try using the name "%s" or simply leaving it '\
                              'out altogether.' % list(registry)[0]
            else:
                valid_names = "Valid names are " + ", ".join(
                    '"%s"' % k for k in list(registry))
            raise Exception(
                "Metadata definition with name \"%s\" does not exist.\n%s" % (
                    name, valid_names))
    else:
        assert len(registry) == 1, \
            "You must have exactly one Metadata class, if using " \
            "get_metadata() without a 'name' parameter."
        return list(registry.values())[0]
1003465
def infos_on_basis_set(self):
        
        o = []
        o.append("=========================================")
        o.append("Reading basis set:")
        o.append("")
        o.append(" Basis set for {} atom ".format(str(self.filename)))
        o.append(" Maximum angular momentum = {}".format(self.data['lmax']))
        o.append(" Number of atomics orbitals = {}".format(self.data['n_nlo']))
        o.append(" Number of nlm orbitals = {}".format(self.data['n_nlmo']))
        o.append("=========================================")

        return str(0)
491544
def _cli_check_family(family, data_dir):
    ''''''

    if family is None:
        return None

    family = family.lower()
    if not family in api.get_families(data_dir):
        errstr = "Basis set family '" + family + "' does not exist.\n"
        errstr += "For a complete list of families, use the 'bse list-families' command"
        raise RuntimeError(errstr)

    return family
1374238
def getMetadataId(self, metadata):
        
        return str(datamodel.VariantSetMetadataCompoundId(
            self.getCompoundId(), 'metadata:' + metadata.key))
541438
def get_set(self, fieldname):
        """"""
        set_items = set()
        for ntdata in self.nts:
            set_items |= getattr(ntdata, fieldname)
        return set_items
993786
def GetArtifact(self, name):
    
    self._CheckDirty()
    result = self._artifacts.get(name)
    if not result:
      raise rdf_artifacts.ArtifactNotRegisteredError(
          "Artifact %s missing from registry. You may need to sync the "
          "artifact repo by running make in the artifact directory." % name)
    return result
289221
def _GetMetadataForClients(self, client_urns):
    """"""

    result = {}
    metadata_to_fetch = set()

    for urn in client_urns:
      try:
        result[urn] = self._cached_metadata[urn]
      except KeyError:
        metadata_to_fetch.add(urn)

    if metadata_to_fetch:
      if data_store.RelationalDBEnabled():
        client_ids = set(urn.Basename() for urn in metadata_to_fetch)
        infos = data_store.REL_DB.MultiReadClientFullInfo(client_ids)

        fetched_metadata = [
            export.GetMetadata(client_id, info)
            for client_id, info in infos.items()
        ]
      else:
        client_fds = aff4.FACTORY.MultiOpen(
            metadata_to_fetch, mode="r", token=self.token)

        fetched_metadata = [
            export.GetMetadataLegacy(client_fd, token=self.token)
            for client_fd in client_fds
        ]

      for metadata in fetched_metadata:
        metadata.source_urn = self.source_urn

        self._cached_metadata[metadata.client_urn] = metadata
        result[metadata.client_urn] = metadata
        metadata_to_fetch.remove(metadata.client_urn)

      for urn in metadata_to_fetch:
        default_mdata = export.ExportedMetadata(source_urn=self.source_urn)
        result[urn] = default_mdata
        self._cached_metadata[urn] = default_mdata

    return [result[urn] for urn in client_urns]
1331760
def metadata_from_fname(self, fname):
        
        MetaData = namedtuple('MetaData', self.split_order)
        base_name = os.path.basename(fname)              # e.g. 'test_S1_C2_Z3_T4.tif'
        name, suffix = base_name.split('.')              # e.g. 'test_S1_C2_Z3_T4', 'tif'
        data = name.split('_')[-len(self.split_order):]  # e.g. ['S1', 'C2', 'Z3', 'T4']
        args = [ int(x[1:]) for x in data ]               # e.g. [1, 2, 3, 4]
        return MetaData(*args)
715297
def _get_exceptions_db(self):
        """"""
        template = "{extype} ({exmsg}){raised}"
        if not self._full_cname:
            # When full callable name is not used the calling path is
            # irrelevant and there is no function associated with an
            # exception
            ret = []
            for _, fdict in self._ex_dict.items():
                for key in fdict.keys():
                    ret.append(
                        {
                            "name": fdict[key]["name"],
                            "data": template.format(
                                extype=_ex_type_str(key[0]),
                                exmsg=key[1],
                                raised="*" if fdict[key]["raised"][0] else "",
                            ),
                        }
                    )
            return ret
        # When full callable name is used, all calling paths are saved
        ret = []
        for fdict in self._ex_dict.values():
            for key in fdict.keys():
                for func_name in fdict[key]["function"]:
                    rindex = fdict[key]["function"].index(func_name)
                    raised = fdict[key]["raised"][rindex]
                    ret.append(
                        {
                            "name": self.decode_call(func_name),
                            "data": template.format(
                                extype=_ex_type_str(key[0]),
                                exmsg=key[1],
                                raised="*" if raised else "",
                            ),
                        }
                    )
        return ret
683079
def _get_metadap_dap(name, version=''):
    ''''''
    m = metadap(name)
    if not m:
        raise DapiCommError('DAP {dap} not found.'.format(dap=name))
    if not version:
        d = m['latest_stable'] or m['latest']
        if d:
            d = data(d)
    else:
        d = dap(name, version)
        if not d:
            raise DapiCommError(
                'DAP {dap} doesn\'t have version {version}.'.format(dap=name, version=version))
    return m, d
484199
def _get_metadata(self):
        """"""
        self.metadata = self.fetch_header()
        self.variables = {g.name for g in self.metadata.grids}
301233
def getDatasetByName(self, name):
        
        if name not in self._datasetNameMap:
            raise exceptions.DatasetNameNotFoundException(name)
        return self._datasetNameMap[name]
1296298
def get_metadata(self, obj, prefix=None):
        
        uri = "/%s/%s" % (self.uri_base, utils.get_name(obj))
        resp, resp_body = self.api.method_head(uri)
        ret = {}
        # Add the metadata prefix, if needed.
        if prefix is None:
            prefix = OBJECT_META_PREFIX
        low_prefix = prefix.lower()
        for hkey, hval in list(resp.headers.items()):
            lowkey = hkey.lower()
            if lowkey.startswith(low_prefix):
                cleaned = hkey.replace(low_prefix, "").replace("-", "_")
                ret[cleaned] = hval
        return ret
792756
def metadata(self, key=None, database=None, table=None, fallback=True):
        
        assert not (database is None and table is not None), \
            "Cannot call metadata() with table= specified but not database="
        databases = self._metadata.get("databases") or {}
        search_list = []
        if database is not None:
            search_list.append(databases.get(database) or {})
        if table is not None:
            table_metadata = (
                (databases.get(database) or {}).get("tables") or {}
            ).get(table) or {}
            search_list.insert(0, table_metadata)
        search_list.append(self._metadata)
        if not fallback:
            # No fallback allowed, so just use the first one in the list
            search_list = search_list[:1]
        if key is not None:
            for item in search_list:
                if key in item:
                    return item[key]
            return None
        else:
            # Return the merged list
            m = {}
            for item in search_list:
                m.update(item)
            return m
734911
def table_metadata(self, database, table):
        ""
        return (self.metadata("databases") or {}).get(database, {}).get(
            "tables", {}
        ).get(
            table, {}
        )