Exemplo n.º 1
0
Arquivo: pdos.py Projeto: juijan/sisl
        def parse_atom_range(geom, value):
            if value.lower() in ("all", ":"):
                return np.arange(geom.no), "all"

            value = ",".join(  # ensure only single commas (no space between them)
                "".join(  # ensure no empty whitespaces
                    ",".join(  # join different lines with a comma
                        value.splitlines()).split()).split(","))

            # Sadly many shell interpreters does not
            # allow simple [] because they are expansion tokens
            # in the shell.
            # We bypass this by allowing *, [, {
            # * will "only" fail if files are named accordingly, else
            # it will be passed as-is.
            #       {    [    *
            sep = ['c', 'b', '*']
            failed = True
            while failed and len(sep) > 0:
                try:
                    ranges = lstranges(
                        strmap(int, value, 0, len(geom), sep.pop()))
                    failed = False
                except Exception:
                    pass
            if failed:
                print(value)
                raise ValueError("Could not parse the atomic/orbital ranges")

            # we have only a subset of the orbitals
            orbs = []
            no = 0
            for atoms in ranges:
                if isinstance(atoms, list):
                    # Get atoms and orbitals
                    ob = geom.a2o(atoms[0] - 1, True)
                    # We normalize for the total number of orbitals
                    # on the requested atoms.
                    # In this way the user can compare directly the DOS
                    # for same atoms with different sets of orbitals and the
                    # total will add up.
                    no += len(ob)
                    ob = ob[asarrayi(atoms[1]) - 1]
                else:
                    ob = geom.a2o(atoms - 1, True)
                    no += len(ob)
                orbs.append(ob)

            if len(orbs) == 0:
                print('Available atoms:')
                print(f'  1-{len(geometry)}')
                print('Input atoms:')
                print('  ', value)
                raise ValueError(
                    'Atomic/Orbital requests are not fully included in the device region.'
                )

            # Add one to make the c-index equivalent to the f-index
            return np.concatenate(orbs).flatten(), value
Exemplo n.º 2
0
Arquivo: basis.py Projeto: juijan/sisl
 def __call__(self, parser, ns, value, option_string=None):
     value = (value
              .replace("s", 0)
              .replace("p", 1)
              .replace("d", 2)
              .replace("f", 3)
              .replace("g", 4)
     )
     ns._l = strmap(int, value)[0]
Exemplo n.º 3
0
Arquivo: _kind.py Projeto: juijan/sisl
    def categorize(self, geometry, *args, **kwargs):
        # Now that we have the geometry, we know what is the end index
        # and we can finally safely convert the sequence to indices.
        indices_map = strmap(int, self._seq, start=0, end=geometry.na - 1)
        indices = lstranges(
            self._sanitize_negs(indices_map, end=geometry.na - 1))

        # Initialize the machinery of AtomIndex
        super().__init__(indices)
        self.set_name(self._seq)
        # Finally categorize
        return super().categorize(geometry, *args, **kwargs)
Exemplo n.º 4
0
            def __call__(self, parser, ns, value, option_string=None):
                E = ns._E
                Emap = strmap(float, value, E.min(), E.max())
                def Eindex(e):
                    return np.abs(E - e).argmin()

                # Convert to actual indices
                E = []
                for begin, end in Emap:
                    if begin is None and end is None:
                        ns._Erng = None
                        return
                    elif begin is None:
                        E.append(range(Eindex(end)+1))
                    elif end is None:
                        E.append(range(Eindex(begin), len(E)))
                    else:
                        E.append(range(Eindex(begin), Eindex(end)+1))
                # Issuing unique also sorts the entries
                ns._Erng = np.unique(arrayi(E).flatten())
Exemplo n.º 5
0
 def __call__(self, parser, ns, value, option_string=None):
     ns._Emap = strmap(float, value)[0]
Exemplo n.º 6
0
 def __call__(self, parser, ns, value, option_string=None):
     ns._Emap = strmap(float, value)[0]
Exemplo n.º 7
0
Arquivo: basis.py Projeto: juijan/sisl
 def __call__(self, parser, ns, value, option_string=None):
     ns._n = strmap(int, value)[0]