Make a sequence of applications from a list of tokens.

  atoms is a list of atoms, which will be handled left-associatively. E.g:

      ['foo', [], []] == foo()() ==> Application(Application('foo', []), [])
327445
def mkApplications(location, *atoms):
  
  atoms = list(atoms)
  while len(atoms) > 1:
    atoms[0:2] = [Application(location, atoms[0], atoms[1])]

  # Nothing left to apply
  return atoms[0]
1282418
def _prepare_atoms(topology, compute_cycles=False):
    """"""
    atom1 = next(topology.atoms())
    has_whitelists = hasattr(atom1, 'whitelist')
    has_cycles = hasattr(atom1, 'cycles')
    compute_cycles = compute_cycles and not has_cycles

    if compute_cycles or not has_whitelists:
        for atom in topology.atoms():
            if compute_cycles:
                atom.cycles = set()
            if not has_whitelists:
                atom.whitelist = OrderedSet()
                atom.blacklist = OrderedSet()

    if compute_cycles:
        bond_graph = nx.Graph()
        bond_graph.add_nodes_from(topology.atoms())
        bond_graph.add_edges_from(topology.bonds())
        all_cycles = _find_chordless_cycles(bond_graph, max_cycle_size=8)
        for atom, cycles in zip(bond_graph.nodes, all_cycles):
            for cycle in cycles:
                atom.cycles.add(tuple(cycle))
84442
public Collection<Application> list(String name)
    {
        List<Application> ret = new ArrayList<Application>();
        Collection<Application> applications = list();
        for(Application application : applications)
        {
            if(name == null || application.getName().equals(name))
                ret.add(application);
        }
        return ret;
    }
670236
Expr array() {
		if (peek().sym != Sym.LBRACK) {
			return atom();
		}
		
		move();
		if (peek().sym == Sym.RBRACK) {
			move();
			return new Array(ExprList.NULL_EXPR_ARRAY, location);
		}
		ExprList exprList = exprList();
		if (exprList.length() == 1 && peek().sym == Sym.RANGE) {
			move();
			Expr end = expr();
			match(Sym.RBRACK);
			return new RangeArray(exprList.getExprArray()[0], end, location);
		}
		
		match(Sym.RBRACK);
		return new Array(exprList.getExprArray(), location);
	}
42774
def write_atoms(fn, this, cycfn=None, conv=1.0, symbols=True):
    
    f = paropen(fn, "w")

    f.write("<--- Number of atoms\n")
    f.write("%i\n" % len(this))
    f.write("<--- Number of occupied orbitals\n")
    f.write("%f\n" % 0.0)
    f.write("<--- Atom positions\n")

    groups = None
    if this.has("groups"):
        groups = this.get_array("groups")

    gamma = None
    if this.has("gamma"):
        gamma = this.get_array("gamma")

    T = None
    if this.has("T"):
        T = this.get_array("T")

    for idx, i in enumerate(this):
        group_str = "1"
        if groups is not None:
            group_str = "%i" % groups[idx]
        gamma_str = "0.0"
        if gamma is not None:
            gamma_str = "%20.10e" % gamma[idx]
        T_str = "0.0"
        if T is not None:
            T_str = "%20.10e" % T[idx]

        sym = i.symbol

        r = i.position

        if symbols:
            f.write("%s   %f   %20.10e  %20.10e  %20.10e   %s %s %s\n" % (sym, ase.data.atomic_masses[ase.data.chemical_symbols.index(sym)], r[0]*conv, r[1]*conv, r[2]*conv, group_str, gamma_str, T_str))
        else:
            f.write("%i   %f   %20.10e  %20.10e  %20.10e   %s %s %s\n" % (ase.data.chemical_symbols.index(sym), ase.data.atomic_masses[ase.data.chemical_symbols.index(sym)], r[0]*conv, r[1]*conv, r[2]*conv, group_str, gamma_str, T_str))


    f.write("<--- Velocities\n")
    for i in this:
        m = i.mass
        if m is None:
            m = ase.data.atomic_masses[ase.data.chemical_symbols.index(i.symbol)]
        if i.momentum is not None:
            v = i.momentum/m
        else:
            v = [ 0.0, 0.0, 0.0 ]
        f.write("%20.10e %20.10e %20.10e\n" % ( v[0], v[1], v[2] ))

    f.write("<--- Forces\n")
    for i in this:
        f.write("0 0 0\n")

    f.write("<--- cell\n")
    cell = this.get_cell()
    f.write("%f %f %f\n" % tuple(cell[0, :]))
    f.write("%f %f %f\n" % tuple(cell[1, :]))
    f.write("%f %f %f\n" % tuple(cell[2, :]))

    for name, aux in this.arrays.items():
        if not name in atoms_default_fields:
            f.write("<--- %s\n" % name)
            if aux.dtype == int:
                if len(aux.shape) == 1:
                    for i in this:
                        f.write(" %i\n" % aux[i.index])
                else:
                    for i in this:
                        f.write(( aux.shape[1]*" %i" + "\n" ) % tuple(aux[i.index].tolist()))
            else:
                if len(aux.shape) == 1:
                    for i in this:
                        f.write(" %e\n" % aux[i.index])
                else:
                    for i in this:
                        f.write(( aux.shape[1]*" %e" + "\n" ) % tuple(aux[i.index].tolist()))

    f.close()

    if cycfn:
        write_cyc(cycfn, this, conv=conv)
1290878
private AstExec parseFunctionApplication() {
    eatChar('(');
    ArrayList<AstRoot> asts = new ArrayList<>();
    while (skipWS() != ')')
      asts.add(parseNext());
    eatChar(')');
    AstExec res = new AstExec(asts);
    if (peek(0) == '-') {
      eatChar('-');
      eatChar('>');
      AstId tmpid = new AstId(token());
      res = new AstExec(new AstRoot[]{new AstId("tmp="), tmpid, res});
    }
    return res;
  }
712769
def center_atoms(self):
        
        nodes = set()
        for n, atom in self.atoms():
            if atom._reactant != atom._product:
                nodes.add(n)

        for n, m, bond in self.bonds():
            if bond._reactant != bond._product:
                nodes.add(n)
                nodes.add(m)

        return list(nodes)
429962
public List<String> lemmatize(String[] tokens, String[] posTags) {
    String[] annotatedLemmas = lemmatizer.lemmatize(tokens, posTags);
    String[] decodedLemmas = lemmatizer.decodeLemmas(tokens, annotatedLemmas);
    final List<String> lemmas = new ArrayList<String>(Arrays.asList(decodedLemmas));
    return lemmas;
  }
1042621
def parse_atoms(self, pdb):
    """"""
    
    atomre = re.compile("ATOM")
    
    atomlines = [line for line in pdb.lines if atomre.match(line)]
    
    chainresnums = {}
    
    for line in atomlines:
      chain = line[21]
      resname = line[17:20]
      resnum = line[22:27]
      #print resnum
      chainresnums.setdefault(chain, [])
      
      if resnum in chainresnums[chain]:
        assert self[chain][chainresnums[chain].index(resnum)] == resname
      else:
        if resnum[-1] == ' ':
          self.setdefault(chain, [])
          self[chain] += [resname]
          chainresnums[chain] += [resnum]
    
    return chainresnums
527297
@Override
    public List<IAtom> getConnectedAtomsList(IAtom atom) {
        List<IAtom> atomsList = new ArrayList<IAtom>();
        for (int i = 0; i < bondCount; i++) {
            if (bonds[i].contains(atom)) atomsList.add(bonds[i].getOther(atom));
        }
        return atomsList;
    }
848306
protected TokenList.Token createOp( TokenList.Token left , TokenList.Token op , TokenList.Token right ,
                                      TokenList tokens , Sequence sequence )
    {
        Operation.Info info = functions.create(op.symbol, left.getVariable(), right.getVariable());

        sequence.addOperation(info.op);

        // replace the symbols with their output
        TokenList.Token t = new TokenList.Token(info.output);
        tokens.remove(left);
        tokens.remove(right);
        tokens.replace(op,t);
        return t;

    }
525667
def select_atoms(indices):
    '''

    '''
    rep = current_representation()
    rep.select({'atoms': Selection(indices, current_system().n_atoms)})
    return rep.selection_state
737635
def application(tokens):
    """"""
    tokens = iter(tokens)
    func = next(tokens)
    paren = next(tokens)

    if func and func.name == "symbol" and paren.name == "lparen":
        # We would be able to unambiguously parse function application with
        # whitespace between the function name and the lparen, but let's not
        # do that because it's unexpected in most languages.
        if func.end != paren.start:
            raise errors.EfilterParseError(
                start=func.start, end=paren.end,
                message="No whitespace allowed between function and paren.")

        return common.TokenMatch(None, func.value, (func, paren))
738118
private void parseMacro( TokenList tokens , Sequence sequence ) {
        Macro macro = new Macro();

        TokenList.Token t = tokens.getFirst().next;

        if( t.word == null ) {
            throw new ParseError("Expected the macro's name after "+tokens.getFirst().word);
        }
        List<TokenList.Token> variableTokens = new ArrayList<TokenList.Token>();

        macro.name = t.word;
        t = t.next;
        t = parseMacroInput(variableTokens, t);
        for( TokenList.Token a : variableTokens ) {
            if( a.word == null) throw new ParseError("expected word in macro header");
            macro.inputs.add(a.word);
        }
        t = t.next;
        if( t == null || t.getSymbol() != Symbol.ASSIGN)
            throw new ParseError("Expected assignment");
        t = t.next;
        macro.tokens = new TokenList(t,tokens.last);

        sequence.addOperation(macro.createOperation(macros));
    }
464289
def process_tokens(
    tokens: Sequence[Token], *, end: str = "\n", sep: str = " "
) -> Tuple[str, str]:
    
    # Flatten the list of tokens in case some of them are of
    # class UnicodeSequence:
    flat_tokens = list()  # type: List[Token]
    for token in tokens:
        if isinstance(token, UnicodeSequence):
            flat_tokens.extend(token.tuple())
        else:
            flat_tokens.append(token)

    with_color = _process_tokens(flat_tokens, end=end, sep=sep, color=True)
    without_color = _process_tokens(flat_tokens, end=end, sep=sep, color=False)
    return (with_color, without_color)
1214031
function symbol(lexer, text) {
  var token = lexer.next_token(text);
  return sl.atom(text, {token: token});
}
293284
def build_sequence(self, xs, masks, init, is_left_to_right):
        '''
        
        '''
        states = []
        last = init
        if is_left_to_right:
            for i, xs_i in enumerate(xs):
                h = self.build(xs_i, last, masks[i])
                states.append(h)
                last = h
        else:
            for i in range(len(xs) - 1, -1, -1):
                h = self.build(xs[i], last, masks[i])
                states.insert(0, h)
                last = h
        return states