public void TestNewReactionScheme() { IChemObjectBuilder builder = RootObject.Builder; IReactionScheme scheme = builder.NewReactionScheme(); Assert.IsNotNull(scheme); }
/// <summary> /// Create a IReactionScheme give a IReactionSet object. /// </summary> /// <param name="reactionSet">The IReactionSet</param> /// <returns>The IReactionScheme</returns> public static IReactionScheme NewReactionScheme(IReactionSet reactionSet) { IReactionScheme reactionScheme = reactionSet.Builder.NewReactionScheme(); // Looking for those reactants which doesn't have any precursor. They are the top. List <IReaction> listTopR = new List <IReaction>(); foreach (var reaction in reactionSet) { if (ExtractPrecursorReaction(reaction, reactionSet).Count == 0) { listTopR.Add(reaction); } } foreach (var reaction in listTopR) { reactionScheme.Add(reaction); IReactionScheme newReactionScheme = SetScheme(reaction, reactionSet); if (newReactionScheme.Reactions.Count() != 0 || newReactionScheme.Schemes.Count != 0) { reactionScheme.Add(newReactionScheme); } } return(reactionScheme); }
private CMLReactionScheme CDKReactionSchemeToCMLReactionScheme(IReactionScheme cdkScheme, bool setIDs) { var reactionScheme = new CMLReactionScheme(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(cdkScheme); } if (!string.IsNullOrEmpty(cdkScheme.Id)) { reactionScheme.Id = cdkScheme.Id; } foreach (var reaction in cdkScheme.Reactions) { reactionScheme.Add(CDKReactionToCMLReaction(reaction)); } foreach (var intScheme in cdkScheme.Schemes) { reactionScheme.Add(CDKReactionSchemeToCMLReactionScheme(intScheme)); } return(reactionScheme); }
/// <summary> /// Extract a set of Reactions which are in top of a IReactionScheme. The top reactions are those /// which any of their reactants are participating in other reactions as a products. /// </summary> /// <param name="reactionScheme">The IReactionScheme</param> /// <returns>The set of top reactions</returns> public static IReactionSet ExtractTopReactions(IReactionScheme reactionScheme) { IReactionSet reactionSet = reactionScheme.Builder.NewReactionSet(); IReactionSet allSet = GetAllReactions(reactionScheme); foreach (var reaction in allSet) { IReactionSet precuSet = ExtractPrecursorReaction(reaction, allSet); if (precuSet.Count == 0) { bool found = false; foreach (var reactIn in reactionSet) { if (reactIn.Equals(reaction)) { found = true; } } if (!found) { reactionSet.Add(reaction); } } } return(reactionSet); }
public void TestGetAllMolecules_IReactionScheme3() { IReactionScheme scheme1 = builder.NewReactionScheme(); IReactionScheme scheme11 = builder.NewReactionScheme(); IReaction reaction1 = builder.NewReaction(); IAtomContainer molecule = builder.NewAtomContainer(); reaction1.Products.Add(molecule); reaction1.Reactants.Add(builder.NewAtomContainer()); scheme11.Add(reaction1); IReaction reaction2 = builder.NewReaction(); reaction2.Products.Add(builder.NewAtomContainer()); reaction2.Reactants.Add(molecule); scheme11.Add(reaction2); scheme1.Add(scheme11); IReactionScheme scheme12 = builder.NewReactionScheme(); IReaction reaction3 = builder.NewReaction(); reaction3.Products.Add(builder.NewAtomContainer()); reaction3.Reactants.Add(molecule); scheme12.Add(reaction3); scheme1.Add(scheme12); IReaction reaction11 = builder.NewReaction(); reaction11.Products.Add(builder.NewAtomContainer()); scheme1.Add(reaction11); Assert.AreEqual(5, ReactionSchemeManipulator.GetAllAtomContainers(scheme1).Count); }
public virtual void TestGetReactionSchemeCount() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); scheme.Add(scheme.Builder.NewReactionScheme()); Assert.AreEqual(1, scheme.Schemes.Count); }
public override void TestClone() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); object clone = scheme.Clone(); Assert.IsTrue(clone is IReactionScheme); Assert.AreNotSame(scheme, clone); }
public override void TestGetReactionCount() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); scheme.Add(scheme.Builder.NewReaction()); scheme.Add(scheme.Builder.NewReaction()); Assert.AreEqual(2, scheme.Count); }
public CMLCml CDKReactionSchemeToCMLReactionSchemeAndMoleculeList(IReactionScheme cdkScheme) { var cml = new CMLCml(); cml.Add(CDKAtomContainerSetToCMLList(ReactionSchemeManipulator.GetAllAtomContainers(cdkScheme))); cml.Add(CDKReactionSchemeToCMLReactionScheme(cdkScheme, true)); return(cml); }
public virtual void TestRemoveReactionScheme_IReactionScheme() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); IReactionScheme scheme1 = (IReactionScheme)NewChemObject(); IReactionScheme scheme2 = (IReactionScheme)NewChemObject(); scheme.Add(scheme1); scheme.Add(scheme2); scheme.Remove(scheme1); Assert.AreEqual(1, scheme.Schemes.Count); }
public void TestGetMoleculeSet_IAtomContainer_IAtomContainer_IReactionScheme() { IReactionScheme scheme1 = builder.NewReactionScheme(); IReactionScheme scheme11 = builder.NewReactionScheme(); IReaction reaction1 = builder.NewReaction(); reaction1.Id = "reaction1"; IAtomContainer startMol = builder.NewAtomContainer(); startMol.Id = "startMol"; reaction1.Reactants.Add(startMol); IAtomContainer mitMol = builder.NewAtomContainer(); mitMol.Id = "mitMol"; reaction1.Products.Add(mitMol); scheme11.Add(reaction1); IReaction reaction2 = builder.NewReaction(); reaction2.Products.Add(builder.NewAtomContainer()); reaction2.Reactants.Add(builder.NewAtomContainer()); reaction2.Id = "reaction2"; scheme11.Add(reaction2); scheme1.Add(scheme11); IReactionScheme scheme12 = builder.NewReactionScheme(); IReaction reaction3 = builder.NewReaction(); IAtomContainer finalMol = builder.NewAtomContainer(); finalMol.Id = "finalMol"; reaction3.Products.Add(finalMol); reaction3.Reactants.Add(mitMol); reaction3.Id = "reaction3"; scheme12.Add(reaction3); scheme1.Add(scheme12); IReaction reaction11 = builder.NewReaction(); reaction11.Products.Add(builder.NewAtomContainer()); reaction11.Id = "reaction11"; scheme1.Add(reaction11); var listSet = ReactionSchemeManipulator.GetAtomContainerSet(startMol, finalMol, scheme1); Assert.AreEqual(1, listSet.Count); var moleculeSet = listSet[0]; Assert.AreEqual("startMol", moleculeSet[0].Id); Assert.AreEqual("mitMol", moleculeSet[1].Id); Assert.AreEqual("finalMol", moleculeSet[2].Id); }
public virtual void TestRemoveAllReactionSchemes() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); IReactionScheme scheme1 = (IReactionScheme)NewChemObject(); IReactionScheme scheme2 = (IReactionScheme)NewChemObject(); scheme.Add(scheme1); scheme.Add(scheme2); Assert.AreEqual(2, scheme.Schemes.Count); scheme.Schemes.Clear(); Assert.AreEqual(0, scheme.Schemes.Count); }
public void TestGetAllMolecules_IReactionScheme() { IReactionScheme reactionScheme = builder.NewReactionScheme(); IReaction reaction1 = builder.NewReaction(); reaction1.Products.Add(builder.NewAtomContainer()); IReaction reaction2 = builder.NewReaction(); reaction2.Products.Add(builder.NewAtomContainer()); reactionScheme.Add(reaction1); // 1 reactionScheme.Add(reaction2); // 2 Assert.AreEqual(2, ReactionSchemeManipulator.GetAllAtomContainers(reactionScheme).Count); }
public virtual void TestAdd_IReactionScheme() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); scheme.Add(scheme.Builder.NewReactionScheme()); scheme.Add(scheme.Builder.NewReactionScheme()); scheme.Add(scheme.Builder.NewReactionScheme()); IReactionScheme tested = scheme.Builder.NewReactionScheme(); Assert.AreEqual(0, tested.Schemes.Count); tested.Add(scheme); Assert.AreEqual(1, tested.Schemes.Count); }
public override void TestReactions() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); scheme.Add(scheme.Builder.NewReaction()); scheme.Add(scheme.Builder.NewReaction()); scheme.Add(scheme.Builder.NewReaction()); Assert.AreEqual(3, scheme.Count); int count = 0; foreach (var reaction in scheme.Reactions) { ++count; } Assert.AreEqual(3, count); }
public void TestGetAllReactions_IReactionScheme() { IReactionScheme scheme1 = builder.NewReactionScheme(); IReactionScheme scheme11 = builder.NewReactionScheme(); IReaction reaction1 = builder.NewReaction(); IAtomContainer startMol = builder.NewAtomContainer(); startMol.Id = "startMol"; reaction1.Reactants.Add(startMol); IAtomContainer mitMol = builder.NewAtomContainer(); mitMol.Id = "mitMol"; reaction1.Products.Add(mitMol); scheme11.Add(reaction1); IReaction reaction2 = builder.NewReaction(); reaction2.Products.Add(builder.NewAtomContainer()); reaction2.Reactants.Add(builder.NewAtomContainer()); scheme11.Add(reaction2); scheme1.Add(scheme11); IReactionScheme scheme12 = builder.NewReactionScheme(); IReaction reaction3 = builder.NewReaction(); IAtomContainer finalMol = builder.NewAtomContainer(); finalMol.Id = "finalMol"; reaction3.Products.Add(finalMol); reaction3.Reactants.Add(startMol); scheme12.Add(reaction3); scheme1.Add(scheme12); IReaction reaction11 = builder.NewReaction(); reaction11.Products.Add(builder.NewAtomContainer()); scheme1.Add(reaction11); IReactionSet reactionSet = ReactionSchemeManipulator.GetAllReactions(scheme1); Assert.AreEqual(4, reactionSet.Count); Assert.AreEqual(reaction1, reactionSet[0]); Assert.AreEqual(reaction2, reactionSet[1]); Assert.AreEqual(reaction3, reactionSet[2]); Assert.AreEqual(reaction11, reactionSet[3]); }
/// <summary> /// Get all molecule objects from a set of Reactions given a <see cref="IAtomContainerSet"/> to add. /// </summary> /// <param name="scheme">The set of reaction to inspect</param> /// <param name="molSet">The set of molecules to be added</param> /// <returns>All molecules</returns> public static IChemObjectSet <IAtomContainer> GetAllAtomContainers(IReactionScheme scheme, IChemObjectSet <IAtomContainer> molSet) { // A ReactionScheme can contain other IRreactionSet objects foreach (var rm in scheme.Schemes) { foreach (var ac in GetAllAtomContainers(rm, molSet)) { bool contain = false; foreach (var atomContainer in molSet) { if (atomContainer.Equals(ac)) { contain = true; break; } } if (!contain) { molSet.Add((IAtomContainer)(ac)); } } } foreach (var reaction in scheme.Reactions) { var newAtomContainerSet = ReactionManipulator.GetAllAtomContainers(reaction); foreach (var ac in newAtomContainerSet) { bool contain = false; foreach (var atomContainer in molSet) { if (atomContainer.Equals(ac)) { contain = true; break; } } if (!contain) { molSet.Add(ac); } } } return(molSet); }
public void TestGetAllIDs_IReactionScheme() { IReactionScheme scheme1 = builder.NewReactionScheme(); scheme1.Id = "scheme1"; IReactionScheme scheme11 = builder.NewReactionScheme(); scheme11.Id = "scheme11"; IReaction reaction1 = builder.NewReaction(); reaction1.Id = "reaction1"; IAtomContainer molecule = builder.NewAtomContainer(); reaction1.Id = "molecule"; reaction1.Products.Add(molecule); reaction1.Reactants.Add(builder.NewAtomContainer()); scheme11.Add(reaction1); IReaction reaction2 = builder.NewReaction(); reaction1.Id = "reaction2"; reaction2.Products.Add(builder.NewAtomContainer()); reaction2.Reactants.Add(molecule); scheme11.Add(reaction2); scheme1.Add(scheme11); IReactionScheme scheme12 = builder.NewReactionScheme(); scheme12.Id = "scheme12"; IReaction reaction3 = builder.NewReaction(); reaction3.Id = "reaction3"; reaction3.Products.Add(builder.NewAtomContainer()); reaction3.Reactants.Add(molecule); scheme12.Add(reaction3); scheme1.Add(scheme12); IReaction reaction11 = builder.NewReaction(); reaction11.Id = "reaction11"; reaction11.Products.Add(builder.NewAtomContainer()); scheme1.Add(reaction11); Assert.AreEqual(6, ReactionSchemeManipulator.GetAllIDs(scheme1).Count()); }
public virtual void TestReactionSchemes() { IReactionScheme scheme = (IReactionScheme)NewChemObject(); scheme.Add(scheme.Builder.NewReactionScheme()); scheme.Add(scheme.Builder.NewReactionScheme()); scheme.Add(scheme.Builder.NewReactionScheme()); Assert.AreEqual(3, scheme.Schemes.Count); int count = 0; foreach (var sch in scheme.Schemes) { sch.GetType(); ++count; } Assert.AreEqual(3, count); }
public void TestExtractTopReactions_IReactionScheme() { IReactionScheme scheme1 = builder.NewReactionScheme(); IReaction reaction1 = builder.NewReaction(); IAtomContainer molA = builder.NewAtomContainer(); reaction1.Reactants.Add(molA); IAtomContainer molB = builder.NewAtomContainer(); reaction1.Products.Add(molB); scheme1.Add(reaction1); IReactionScheme scheme2 = builder.NewReactionScheme(); IReaction reaction2 = builder.NewReaction(); reaction2.Reactants.Add(molB); IAtomContainer molC = builder.NewAtomContainer(); reaction2.Products.Add(molC); scheme2.Add(reaction2); IReaction reaction3 = builder.NewReaction(); reaction3.Reactants.Add(molB); IAtomContainer molD = builder.NewAtomContainer(); reaction3.Products.Add(molD); scheme2.Add(reaction3); IReaction reaction4 = builder.NewReaction(); IAtomContainer molE = builder.NewAtomContainer(); reaction4.Reactants.Add(molE); IAtomContainer molF = builder.NewAtomContainer(); reaction4.Products.Add(molF); scheme1.Add(reaction4); IReactionSet reactionSet = ReactionSchemeManipulator.ExtractTopReactions(scheme1); Assert.AreEqual(2, reactionSet.Count); Assert.AreEqual(reaction1, reactionSet[0]); Assert.AreEqual(reaction4, reactionSet[1]); }
/// <summary> /// Create a IReactionScheme given as a top a IReaction. If it doesn't exist any subsequent reaction /// return null; /// </summary> /// <param name="reaction">The IReaction as a top</param> /// <param name="reactionSet">The IReactionSet to extract a IReactionScheme</param> /// <returns>The IReactionScheme</returns> private static IReactionScheme SetScheme(IReaction reaction, IReactionSet reactionSet) { IReactionScheme reactionScheme = reaction.Builder.NewReactionScheme(); IReactionSet reactConSet = ExtractSubsequentReaction(reaction, reactionSet); if (reactConSet.Count != 0) { foreach (var reactionInt in reactConSet) { reactionScheme.Add(reactionInt); IReactionScheme newRScheme = SetScheme(reactionInt, reactionSet); if (newRScheme.Count != 0 || newRScheme.Schemes.Count != 0) { reactionScheme.Add(newRScheme); } } } return(reactionScheme); }
/// <summary> /// Get all ID of this IReactionSet. /// </summary> /// <param name="scheme">The IReactionScheme to analyze</param> /// <returns>A List with all ID</returns> public static IEnumerable <string> GetAllIDs(IReactionScheme scheme) { var IDlist = new List <string>(); if (scheme.Id != null) { IDlist.Add(scheme.Id); } foreach (var reaction in scheme.Reactions) { IDlist.AddRange(ReactionManipulator.GetAllIDs(reaction)); } if (scheme.Schemes.Count != 0) { foreach (var rs in scheme.Schemes) { IDlist.AddRange(GetAllIDs(rs)); } } return(IDlist); }
/// <summary> /// Get all IReaction's object from a given IReactionScheme. /// </summary> /// <param name="scheme">The IReactionScheme to extract</param> /// <returns>The IReactionSet</returns> public static IReactionSet GetAllReactions(IReactionScheme scheme) { IReactionSet reactionSet = scheme.Builder.NewReactionSet(); // A ReactionScheme can contain other IRreactionSet objects if (scheme.Schemes.Count != 0) { foreach (var schemeInt in scheme.Schemes) { foreach (var reaction in GetAllReactions(schemeInt)) { reactionSet.Add(reaction); } } } foreach (var reaction in scheme.Reactions) { reactionSet.Add(reaction); } return(reactionSet); }
/// <summary> /// Extract the list of AtomContainers taking part in the IReactionScheme to originate a /// product given a reactant. /// </summary> /// <param name="origenMol">The start IAtomContainer</param> /// <param name="finalMol">The end IAtomContainer</param> /// <param name="reactionScheme">The IReactionScheme containing the AtomContainers</param> /// <returns>A List of IAtomContainerSet given the path</returns> public static IList <IChemObjectSet <IAtomContainer> > GetAtomContainerSet(IAtomContainer origenMol, IAtomContainer finalMol, IReactionScheme reactionScheme) { List <IChemObjectSet <IAtomContainer> > listPath = new List <IChemObjectSet <IAtomContainer> >(); IReactionSet reactionSet = GetAllReactions(reactionScheme); // down search // Looking for those reactants which are the origenMol bool found = false; foreach (var reaction in reactionSet) { if (found) { break; } foreach (var reactant in reaction.Reactants) { if (found) { break; } if (reactant.Equals(origenMol)) { var allSet = reactionSet.Builder.NewAtomContainerSet(); // START foreach (var product in reaction.Products) { if (found) { break; } if (!product.Equals(finalMol)) { var allSet2 = GetReactionPath(product, finalMol, reactionSet); if (allSet2.Count != 0) { allSet.Add(origenMol); allSet.Add(product); allSet.AddRange(allSet2); } } else { allSet.Add(origenMol); allSet.Add(product); } if (allSet.Count() != 0) { listPath.Add(allSet); found = true; } } break; } } } // TODO Looking for those products which are the origenMol // TODO: up search return(listPath); }
/// <inheritdoc/> public void Add(IReactionScheme scheme) { reactionScheme.Add(scheme); }
public void TestCreateReactionScheme_IReactionSet() { IAtomContainer molA = builder.NewAtomContainer(); molA.Id = "A"; IAtomContainer molB = builder.NewAtomContainer(); molB.Id = "B"; IAtomContainer molC = builder.NewAtomContainer(); molC.Id = "C"; IAtomContainer molD = builder.NewAtomContainer(); molD.Id = "D"; IAtomContainer molE = builder.NewAtomContainer(); molE.Id = "E"; IReactionSet reactionSet = builder.NewReactionSet(); IReaction reaction1 = builder.NewReaction(); reaction1.Id = "r1"; reaction1.Reactants.Add(molA); reaction1.Products.Add(molB); reactionSet.Add(reaction1); IReaction reaction2 = builder.NewReaction(); reaction2.Id = "r2"; reaction2.Reactants.Add(molB); reaction2.Products.Add(molC); reactionSet.Add(reaction2); IReaction reaction3 = builder.NewReaction(); reaction3.Id = "r3"; reaction3.Reactants.Add(molB); reaction3.Products.Add(molD); reactionSet.Add(reaction3); IReaction reaction4 = builder.NewReaction(); reaction4.Id = "r4"; reaction4.Reactants.Add(molC); reaction4.Products.Add(molE); reactionSet.Add(reaction4); IReactionScheme scheme1 = ReactionSchemeManipulator.NewReactionScheme(reactionSet); Assert.AreEqual(1, scheme1.Reactions.Count()); Assert.AreEqual("r1", scheme1.Reactions.ElementAt(0).Id); Assert.AreEqual(1, scheme1.Schemes.Count); IReactionScheme scheme2 = scheme1.Schemes.First(); Assert.AreEqual(2, scheme2.Reactions.Count()); Assert.AreEqual("r2", scheme2.Reactions.ElementAt(0).Id); Assert.AreEqual("r3", scheme2.Reactions.ElementAt(1).Id); Assert.AreEqual(1, scheme2.Schemes.Count); IReactionScheme scheme3 = scheme2.Schemes.First(); Assert.AreEqual(1, scheme3.Reactions.Count()); Assert.AreEqual("r4", scheme3.Reactions.ElementAt(0).Id); Assert.AreEqual(0, scheme3.Schemes.Count); }
public CMLReactionScheme CDKReactionSchemeToCMLReactionScheme(IReactionScheme cdkScheme) { return(CDKReactionSchemeToCMLReactionScheme(cdkScheme, true)); }
/// <inheritdoc/> public void Remove(IReactionScheme scheme) { reactionScheme.Remove(scheme); }
/// <summary> /// Get all AtomContainers object from a set of Reactions. /// </summary> /// <param name="scheme">The scheme of reaction to inspect</param> /// <returns>All molecules</returns> public static IChemObjectSet <IAtomContainer> GetAllAtomContainers(IReactionScheme scheme) { return(GetAllAtomContainers(scheme, scheme.Builder.NewAtomContainerSet())); }