Labels the reactants and products in the Reaction m1, m2, etc, and the atoms
accordingly, when no ID is given.
326795
private static void createIDsForReaction(IReaction reaction, List<String> tabuList) {
        if (tabuList == null) tabuList = ReactionManipulator.getAllIDs(reaction);

        if (null == reaction.getID()) {
            // generate new ID
            reactionCount  = setID(REACTION_PREFIX, reactionCount , reaction, tabuList);
        }

        if (policy == OBJECT_UNIQUE_POLICY) {
            // start atom and bond indices within a reaction set always from 1
            atomCount = 0;
            bondCount = 0;
        }

        for (IAtomContainer reactant : reaction.getReactants().atomContainers()) {
            createIDsForAtomContainer(reactant, tabuList);
        }
        for (IAtomContainer product : reaction.getReactants().atomContainers()) {
            createIDsForAtomContainer(product, tabuList);
        }
        Iterator<IAtomContainer> agents = reaction.getAgents().atomContainers().iterator();
        while (agents.hasNext()) {
            createIDsForAtomContainer((IAtomContainer) agents.next(), tabuList);
        }
    }
254200
private static void extractAtoms(String[] atomNames, List<Chain> chains,
			List<Atom> atoms) {

		for (Chain c : chains) {

			for (Group g : c.getAtomGroups()) {

				// a temp container for the atoms of this group
				List<Atom> thisGroupAtoms = new ArrayList<Atom>();
				// flag to check if this group contains all the requested atoms.
				boolean thisGroupAllAtoms = true;
				for (String atomName : atomNames) {
					Atom a = g.getAtom(atomName);

					if (a == null) {
						// this group does not have a required atom, skip it...
						thisGroupAllAtoms = false;
						break;
					}
					thisGroupAtoms.add(a);
				}
				if (thisGroupAllAtoms) {
					// add the atoms of this group to the array.
					for (Atom a : thisGroupAtoms) {
						atoms.add(a);
					}
				}

			}
		}
	}
824784
def stoichiometry( self ):
        
        return Counter( { label: number for label, number in zip( self.atoms, self.atom_numbers ) } )
914693
def p_formula_atom(self, p):
        """"""
        if p[1]==Symbols.TRUE.value:
            p[0] = PLTrue()
        elif p[1]==Symbols.FALSE.value:
            p[0] = PLFalse()
        else:
            p[0] = PLAtomic(Symbol(p[1]))
1282299
def validate_reaction(self):
        
        if self.reaction not in self._reaction_valid_values:
            raise ValueError("reaction should be one of: {valid}".format(
                valid=", ".join(self._reaction_valid_values)
            ))
932467
def check_reaction_on_surface(self, chemical_composition, reactants,
                                  products):
        
        con = self.connection or self._connect()
        self._initialize(con)
        cur = con.cursor()
        statement = """SELECT reaction.id FROM reaction WHERE
        reaction.chemical_composition='{}' and reaction.reactants='{}'
        and reaction.products='{}';""".format(chemical_composition,
                                              json.dumps(reactants),
                                              json.dumps(products))

        cur.execute(statement)
        rows = cur.fetchall()
        if len(rows) > 0:
            id = rows[0][0]
        else:
            id = None
        return id
217938
def decompose(self):
        
        mc = self._get_subclass('MoleculeContainer')
        reactants = mc()
        products = mc()

        for n, atom in self.atoms():
            reactants.add_atom(atom._reactant, n)
            products.add_atom(atom._product, n)

        for n, m, bond in self.bonds():
            if bond._reactant is not None:
                reactants.add_bond(n, m, bond._reactant)
            if bond._product is not None:
                products.add_bond(n, m, bond._product)
        return reactants, products
10416
public Set<LabelAtom> listAtoms() {
        Set<LabelAtom> r = new HashSet<>();
        accept(ATOM_COLLECTOR,r);
        return r;
    }
70614
def invariants(mol):
    """"""
    atom_ids = {}
    for a in mol.atoms:
        components = []
        components.append(a.number)
        components.append(len(a.oatoms))
        components.append(a.hcount)
        components.append(a.charge)
        components.append(a.mass)
        if len(a.rings) > 0:
            components.append(1)

        atom_ids[a.index] = gen_hash(components)

    return atom_ids
428986
def p_labelled_statement(self, p):
        """"""
        p[0] = ast.Label(identifier=p[1], statement=p[3])
7219
def _adjustment_reactions(self):
        """"""
        for reaction_id in self._model.reactions:
            if not self._model.is_exchange(reaction_id):
                yield reaction_id
1153748
def id_name(label, namespace=None):
        
        if not label.startswith(DOT):
            if namespace is None:
                namespace = NAMESPACE
            ex_label = namespace + label  # The mangled namespace.labelname label
        else:
            if namespace is None:
                namespace = GLOBAL_NAMESPACE  # Global namespace
            ex_label = label

        return ex_label, namespace
695818
def labels(self, mapping):
        
        # If any labels have been expressly removed, we need to track this
        # so that a future .patch() call can do the correct thing.
        existing = set([k for k in self.labels.keys()])
        incoming = set([k for k in mapping.keys()])
        self._label_removals = self._label_removals.union(existing.difference(incoming))

        # Actually update the labels on the object.
        self._patch_property("labels", copy.deepcopy(mapping))
328473
def convert_reaction_entry(self, reaction):
        """"""
        d = OrderedDict()
        d['id'] = reaction.id

        def is_equation_valid(equation):
            # If the equation is a Reaction object, it must have non-zero
            # number of compounds.
            return (equation is not None and (
                    not isinstance(equation, Reaction) or
                    len(equation.compounds) > 0))

        order = {
            key: i for i, key in enumerate(
                ['name', 'genes', 'equation', 'subsystem', 'ec'])}
        prop_keys = (set(reaction.properties) -
                     {'lower_flux', 'upper_flux', 'reversible'})
        for prop in sorted(prop_keys, key=lambda x: (order.get(x, 1000), x)):
            if reaction.properties[prop] is None:
                continue
            d[prop] = reaction.properties[prop]
            if prop == 'equation' and not is_equation_valid(d[prop]):
                del d[prop]

        return d
31140
private void identifyBonds() {
        IAtomContainer spt = getSpanningTree();
        IRing ring;
        int nBasicRings = 0;
        for (int i = 0; i < totalEdgeCount; i++) {
            if (!bondsInTree[i]) {
                ring = getRing(spt, molecule.getBond(i));
                for (int b = 0; b < ring.getBondCount(); b++) {
                    int m = molecule.indexOf(ring.getBond(b));
                    cb[nBasicRings][m] = 1;
                }
                nBasicRings++;
            }
        }
        bondsAcyclicCount = 0;
        bondsCyclicCount = 0;
        for (int i = 0; i < totalEdgeCount; i++) {
            int s = 0;
            for (int j = 0; j < nBasicRings; j++) {
                s += cb[j][i];
            }
            switch (s) {
                case (0): {
                    bondsAcyclicCount++;
                    break;
                }
                case (1): {
                    bondsCyclicCount++;
                    break;
                }
                default: {
                    bondsCyclicCount++;
                }
            }
        }
        identifiedBonds = true;
    }
578697
public void setAtoms(Atom[] atoms){
		Structure s = new StructureImpl();
		Chain c = new ChainImpl();
		c.setId("A");
		for (Atom a: atoms){
			c.addGroup(a.getGroup());
		}
		s.addChain(c);
		setStructure(s);
	}
900732
def translate_sbml_reaction(entry, new_id, compartment_map, compound_map):
    """"""
    new_entry = DictReactionEntry(entry, id=new_id)

    # Convert compound IDs in reaction equation
    if new_entry.equation is not None:
        compounds = []
        for compound, value in new_entry.equation.compounds:
            # Translate compartment to new ID, if available.
            compartment = compartment_map.get(
                compound.compartment, compound.compartment)
            new_compound = compound.translate(
                lambda name: compound_map.get(name, name)).in_compartment(
                    compartment)
            compounds.append((new_compound, value))

        new_entry.equation = Reaction(
            new_entry.equation.direction, compounds)

    # Get XHTML notes properties
    for key, value in iteritems(parse_xhtml_reaction_notes(entry)):
        if key not in new_entry.properties:
            new_entry.properties[key] = value

    return new_entry