Exemplo n.º 1
0
        /// <summary>
        /// <p>Converts a reaction to an 'inlined' reaction stored as a molecule. All
        /// reactants, agents, products are added to the molecule as disconnected
        /// components with atoms flagged as to their role <see cref="ReactionRole"/> and
        /// component group.</p>
        /// <p>
        /// The inlined reaction, stored in a molecule can be converted back to an explicit
        /// reaction with <see cref="ToReaction"/>. Data stored on the individual components (e.g.
        /// titles is lost in the conversion).
        /// </p>
        /// </summary>
        /// <param name="rxn">reaction to convert</param>
        /// <returns>inlined reaction stored in a molecule</returns>
        /// <seealso cref="ToReaction"/>
        public static IAtomContainer ToMolecule(IReaction rxn)
        {
            if (rxn == null)
            {
                throw new ArgumentNullException(nameof(rxn), "Null reaction provided");
            }
            IChemObjectBuilder bldr = rxn.Builder;
            IAtomContainer     mol  = bldr.NewAtomContainer();

            mol.SetProperties(rxn.GetProperties());
            mol.Id = rxn.Id;
            int grpId = 0;

            foreach (IAtomContainer comp in rxn.Reactants)
            {
                AssignRoleAndGrp(comp, ReactionRole.Reactant, ++grpId);
                mol.Add(comp);
            }
            foreach (IAtomContainer comp in rxn.Agents)
            {
                AssignRoleAndGrp(comp, ReactionRole.Agent, ++grpId);
                mol.Add(comp);
            }
            foreach (IAtomContainer comp in rxn.Products)
            {
                AssignRoleAndGrp(comp, ReactionRole.Product, ++grpId);
                mol.Add(comp);
            }
            return(mol);
        }