public virtual void TestInitiate_IAtomContainerSet_IAtomContainerSet() { EntryReact entry = (EntryReact)dictionary[entryString.ToLowerInvariant()]; var xmlList = entry.ExampleReactions; Assert.IsTrue(xmlList.Count != 0, "The representation entry for [" + entryString + "] must contain at least one example of reaction."); Assert.IsTrue(xmlList.Count > 0, "The representation entry for [" + entryString + "] must contain at least one example of reaction."); foreach (var xml in xmlList) { CMLReader reader = new CMLReader(new MemoryStream(Encoding.UTF8.GetBytes(xml))); var chemFile = (IChemFile)reader.Read(builder.NewChemFile()); IReaction reactionDict = chemFile[0][0].ReactionSet[0]; var reactants = reactionDict.Reactants; var agents = reactionDict.Agents; var products = reactionDict.Products; if (agents.Count == 0) { agents = null; } IReactionSet reactions = reaction.Initiate(reactants, agents); Assert.IsTrue(reactions.Count > 0, "The products for [" + entryString + "] reaction is at least one reaction expected."); Assert.AreEqual(products[0].Atoms.Count, reactions[0].Products[0].Atoms.Count, "The products for [" + entryString + "] reaction is not the expected."); } }
/// <summary> /// Creates a map with the name and type of the parameters. /// </summary> private void InitiateParameterMap2(EntryReact entry) { var paramDic = entry.ParameterClass; this.ParameterList = new List <IParameterReaction>(); foreach (var param in paramDic) { string paramName = "NCDK.Reactions.Types.Parameters." + param[0]; try { var ipc = (IParameterReaction)this.GetType().Assembly.GetType(paramName).GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>()); ipc.IsSetParameter = bool.Parse(param[1]); ipc.Value = param[2]; Trace.TraceInformation("Loaded parameter class: ", paramName); ParameterList.Add(ipc); } catch (ArgumentException exception) { Trace.TraceError($"Could not find this IParameterReact: {paramName}"); Debug.WriteLine(exception); } catch (Exception exception) { Trace.TraceError($"Could not load this IParameterReact: {paramName}"); Debug.WriteLine(exception); } } }
public void TestGetEntryRepresentation() { EntryReact entry = (EntryReact)dictionary[entryString.ToLowerInvariant()]; Assert.AreNotSame(0, entry.Representations.Count, "The representation entry for [" + entryString + "] must contain at least one representation."); }
public void TestGetParameterList() { var paramObj = reaction.ParameterList; EntryReact entry = (EntryReact)dictionary[entryString.ToLowerInvariant()]; var paramDic = entry.ParameterClass; Assert.IsNotNull(paramObj, "The parameters entry for [" + entryString + "] must contain at least one parameter."); Assert.IsNotNull(paramDic, "The parameters entry for [" + entryString + "] must contain at least one parameter."); Assert.AreEqual(paramObj.Count, paramDic.Count, "The parameters entry for [" + entryString + "] must contain the same lenght as the reaction object."); }
/// <summary> /// Constructor of the ReactionEngine object. /// </summary> public ReactionEngine() { try { IReactionProcess reaction = (IReactionProcess)this; EntryReact entry = InitiateDictionary("reaction-processes", (IReactionProcess)reaction); InitiateParameterMap2(entry); reaction.ParameterList = ParameterList; // extract mechanism dependence, if there is one if (!string.IsNullOrEmpty(entry.Mechanism)) { ExtractMechanism(entry); } } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
/// <summary> /// Extract the mechanism necessary for this reaction. /// </summary> /// <param name="entry">The EntryReact object</param> private void ExtractMechanism(EntryReact entry) { string mechanismName = "NCDK.Reactions.Mechanisms." + entry.Mechanism; try { Mechanism = (IReactionMechanism)this.GetType().Assembly.GetType(mechanismName).GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>()); Trace.TraceInformation("Loaded mechanism: ", mechanismName); } catch (ArgumentException exception) { Trace.TraceError($"Could not find this IReactionMechanism: {mechanismName}"); Debug.WriteLine(exception); } catch (Exception exception) { Trace.TraceError($"Could not load this IReactionMechanism: {mechanismName}"); Debug.WriteLine(exception); } }
public void TestGetEntryDescription() { EntryReact entry = (EntryReact)dictionary[entryString.ToLowerInvariant()]; Assert.IsNotNull(entry.Description, "The description entry for [" + entryString + "] must not be null."); }
public void TestGetDictionaryEntry() { EntryReact entry = (EntryReact)dictionary[entryString.ToLowerInvariant()]; Assert.IsNotNull(entry, "The Entry [" + entryString + "] doesn't exist in OWL Dictionary."); }