Get all Reactions object containing a Molecule as a Reactant from a set
of Reactions.

@param reactSet The set of reaction to inspect
@param molecule The molecule to find as a reactant
@return         The IReactionSet
320512
public static IReactionSet getRelevantReactionsAsReactant(IReactionSet reactSet, IAtomContainer molecule) {
        IReactionSet newReactSet = reactSet.getBuilder().newInstance(IReactionSet.class);
        for (IReaction reaction : reactSet.reactions()) {
            for (IAtomContainer atomContainer : reaction.getReactants().atomContainers())
                if (atomContainer.equals(molecule)) newReactSet.addReaction(reaction);
        }
        return newReactSet;
    }
274044
public static Rectangle2D calculateBounds(IReactionSet reactionSet) {
        Rectangle2D totalBounds = new Rectangle2D.Double();
        for (IReaction reaction : reactionSet.reactions()) {
            Rectangle2D reactionBounds = calculateBounds(reaction);
            if (totalBounds.isEmpty()) {
                totalBounds = reactionBounds;
            } else {
                Rectangle2D.union(totalBounds, reactionBounds, totalBounds);
            }
        }
        return totalBounds;
    }
1299664
public static IAtomContainer checkAndCleanMolecule(IAtomContainer molecule) {
        boolean isMarkush = false;
        for (IAtom atom : molecule.atoms()) {
            if (atom.getSymbol().equals("R")) {
                isMarkush = true;
                break;
            }
        }

        if (isMarkush) {
            System.err.println("Skipping Markush structure for sanity check");
        }

        // Check for salts and such
        if (!ConnectivityChecker.isConnected(molecule)) {
            // lets see if we have just two parts if so, we assume its a salt and just work
            // on the larger part. Ideally we should have a check to ensure that the smaller
            //  part is a metal/halogen etc.
            IAtomContainerSet fragments = ConnectivityChecker.partitionIntoMolecules(molecule);
            if (fragments.getAtomContainerCount() > 2) {
                System.err.println("More than 2 components. Skipped");
            } else {
                IAtomContainer frag1 = fragments.getAtomContainer(0);
                IAtomContainer frag2 = fragments.getAtomContainer(1);
                if (frag1.getAtomCount() > frag2.getAtomCount()) {
                    molecule = frag1;
                } else {
                    molecule = frag2;
                }
            }
        }
        configure(molecule);
        return molecule;
    }
615144
def check_reaction(reactants, products):
    
    reactant_list = [reactant.split('@')[0].strip(
        'star').strip('gas') for reactant in reactants]
    product_list = [product.split('@')[0].strip(
        'star').strip('gas') for product in products]

    reactant_atoms = [extract_atoms(reactant) for reactant in reactant_list]
    product_atoms = [extract_atoms(product) for product in product_list]

    reactants = add_atoms(reactant_atoms)
    products = add_atoms(product_atoms)

    r_stars = 0
    p_stars = 0

    for i, a in enumerate(reactant_atoms):
        if a == '' or 'star' in reactant_list[i]:
            r_stars += 1
        elif isinstance(a, float):
            r_stars += a
    for a in product_atoms:
        if a == '':
            p_stars += 1
        elif isinstance(a, float):
            p_stars += a
    assert ''.join(sorted(reactants)) == ''.join(sorted(products))
462915
public static boolean hasGraphRepresentation(IAtomContainer molecule) {
        for (IBond bond : molecule.bonds())
            if (bond.getAtomCount() != 2) return false;
        return true;
    }
1314564
public static IReaction getReactionByAtomContainerID(IReactionSet reactionSet, String id) {
        for (IReaction reaction : reactionSet.reactions()) {
            if (AtomContainerSetManipulator.containsByID(reaction.getProducts(), id)) return reaction;
        }
        for (IReaction reaction : reactionSet.reactions()) {
            if (AtomContainerSetManipulator.containsByID(reaction.getReactants(), id)) return reaction;
        }
        return null;
    }
860696
@Override
    public int getConnectedAtomsCount(IAtom atom) {
        int count = 0;
        for (int i = 0; i < bondCount; i++) {
            if (bonds[i].contains(atom)) ++count;
        }
        return count;
    }
325099
public static IAtomContainerSet getAllMolecules(IReactionSet set) {
        IAtomContainerSet moleculeSet = set.getBuilder().newInstance(IAtomContainerSet.class);
        for (IReaction reaction : set.reactions()) {
            IAtomContainerSet molecules = ReactionManipulator.getAllMolecules(reaction);
            for (IAtomContainer ac : molecules.atomContainers()) {
                boolean contain = false;
                for (IAtomContainer atomContainer : moleculeSet.atomContainers()) {
                    if (atomContainer.equals(ac)) {
                        contain = true;
                        break;
                    }
                }
                if (!contain) moleculeSet.addAtomContainer(ac);

            }
        }
        return moleculeSet;
    }
322141
private IAtomContainer getUnplacedAtoms(IAtom atom) {
        IAtomContainer unplacedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
        List bonds = molecule.getConnectedBondsList(atom);
        IAtom connectedAtom;
        for (int f = 0; f < bonds.size(); f++) {
            connectedAtom = ((IBond) bonds.get(f)).getOther(atom);
            if (!connectedAtom.getFlag(CDKConstants.ISPLACED)) {
                unplacedAtoms.addAtom(connectedAtom);
            }
        }
        return unplacedAtoms;
    }
30396
public static final Atom[] centerAtoms(Atom[] atomSet)
			throws StructureException {

		Atom centroid = getCentroid(atomSet);
		return centerAtoms(atomSet, centroid);
	}
990812
@Override
    public void paint(IChemModel chemModel, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter) {
        // check for an empty model
        IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
        IReactionSet reactionSet = chemModel.getReactionSet();

        // nasty, but it seems that reactions can be read in as ChemModels
        // with BOTH a ReactionSet AND a MoleculeSet...
        if (moleculeSet == null || reactionSet != null) {
            if (reactionSet != null) {
                reactionSetRenderer.paint(reactionSet, drawVisitor, bounds, resetCenter);
            }
            return;
        }

        // calculate the total bounding box
        Rectangle2D modelBounds = BoundsCalculator.calculateBounds(moleculeSet);

        this.setupTransformToFit(bounds, modelBounds,
                AverageBondLengthCalculator.calculateAverageBondLength(chemModel), resetCenter);

        // generate the elements
        IRenderingElement diagram = moleculeSetRenderer.generateDiagram(moleculeSet);

        // paint it
        this.paint(drawVisitor, diagram);
    }
471539
public static IReactionSet getAllReactions(IReactionScheme scheme) {
        IReactionSet reactionSet = scheme.getBuilder().newInstance(IReactionSet.class);

        // A ReactionScheme can contain other IRreactionSet objects
        if (scheme.getReactionSchemeCount() != 0) for (IReactionScheme schemeInt : scheme.reactionSchemes()) {
            for (IReaction reaction : getAllReactions(schemeInt).reactions())
                reactionSet.addReaction(reaction);
        }
        for (IReaction reaction : scheme.reactions())
            reactionSet.addReaction(reaction);

        return reactionSet;
    }
625504
public static boolean has2DCoordinates(IReaction reaction) {
        for (IAtomContainer mol : reaction.getReactants().atomContainers())
            if (!has2DCoordinates(mol))
                return false;
        for (IAtomContainer mol : reaction.getProducts().atomContainers())
            if (!has2DCoordinates(mol))
                return false;
        for (IAtomContainer mol : reaction.getAgents().atomContainers())
            if (!has2DCoordinates(mol))
                return false;
        return true;
    }
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);
        }
    }
465302
public Point3d geometricCenterAllPlacedAtoms(IAtomContainer molecule) {
        IAtomContainer allPlacedAtoms = getAllPlacedAtoms(molecule);
        return GeometryUtil.get3DCenter(allPlacedAtoms);
    }
343477
@Override
    public void paint(IReactionSet reactionSet, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter) {

        // total up the bounding boxes
        Rectangle2D totalBounds = BoundsCalculator.calculateBounds(reactionSet);

        this.setupTransformToFit(bounds, totalBounds,
                AverageBondLengthCalculator.calculateAverageBondLength(reactionSet), resetCenter);

        ElementGroup diagram = new ElementGroup();
        for (IReaction reaction : reactionSet.reactions()) {
            diagram.add(reactionRenderer.generateDiagram(reaction));
        }

        // paint them all
        this.paint(drawVisitor, diagram);
    }
836084
public static List<IAtomContainer> getAllAtomContainers(IRingSet set) {
        List<IAtomContainer> atomContainerList = new ArrayList<IAtomContainer>();
        for (IAtomContainer atomContainer : set.atomContainers()) {
            atomContainerList.add(atomContainer);
        }
        return atomContainerList;
    }