public void TestReactionSet2() { SpeciesDescription info1; Species reactant1; CreateSpeciesInfoAndSpecies("reactant1", 10, out info1, out reactant1); SpeciesDescription info2; Species reactant2; CreateSpeciesInfoAndSpecies("reactant2", 40, out info2, out reactant2); SpeciesDescription info3; Species product1; CreateSpeciesInfoAndSpecies("product1", 90, out info3, out product1); SpeciesDescription info4; Species reactant3; CreateSpeciesInfoAndSpecies("reactant3", 1, out info4, out reactant3); SpeciesDescription info5; Species reactant4; CreateSpeciesInfoAndSpecies("reactant4", 2, out info5, out reactant4); SpeciesDescription info6; Species product2; CreateSpeciesInfoAndSpecies("product2", 3, out info6, out product2); const double rate1 = 2.0; const double rate2 = 3.0; Reaction reaction1 = CreateReaction(info1, reactant1, info2, reactant2, info3, product1, rate1); Reaction reaction2 = CreateReaction(info4, reactant3, info5, reactant4, info6, product2, rate2); var reactions = new List <Reaction> { reaction1, reaction2 }; var reactionSet = new ReactionSet(reactions); double[] gamma = { 1.5, 2 }; Assert.AreEqual(9.0, reactionSet.UpdateRates(gamma)); Assert.AreEqual(3.0, reactionSet.CurrentRates[1]); Assert.AreEqual(3.0, reactionSet.PredilectionRates[0]); Assert.AreEqual(2, reactionSet.NumReactions); reactionSet.FireReaction(0); Assert.AreEqual(9, reactant1.Value); Assert.AreEqual(39, reactant2.Value); Assert.AreEqual(91, product1.Value); reactionSet.FireReaction(1); Assert.AreEqual(0, reactant3.Value); Assert.AreEqual(1, reactant4.Value); Assert.AreEqual(4, product2.Value); int mu = reactionSet.SelectReaction(reactionSet.CurrentRates.Sum()); Assert.AreEqual(1, mu); mu = reactionSet.SelectReaction(0.0); Assert.AreEqual(0, mu); }
/*! * \brief Initialize the Medium * \param reactionsSets The list of all the reactions sets * \param moleculesSets The list of all the molecules sets */ public void Init(LinkedList <ReactionSet> reactionsSets, LinkedList <MoleculeSet> moleculesSets) { //Receive a linkedlist of Sets _reactions = new LinkedList <IReaction>(); _numberGenerator = new NumberGenerator(NumberGenerator.normale, -10f, 10f, 0.01f); //Try to find the good set in the LinkedList ReactionSet reactSet = ReactionEngine.getReactionSetFromId(_reactionsSet, reactionsSets); MoleculeSet molSet = ReactionEngine.getMoleculeSetFromId(_moleculesSet, moleculesSets); //Put all the different molecules from the linkedList in an arrayList ArrayList allMolecules = ReactionEngine.getAllMoleculesFromMoleculeSets(moleculesSets); if (reactSet == null) { Logger.Log("Medium::Init Cannot find group of reactions named " + _reactionsSet, Logger.Level.WARN); } if (molSet == null) { Logger.Log("Medium::Init Cannot find group of molecules named" + _moleculesSet, Logger.Level.WARN); } initATPProduction(); initReactionsFromReactionSet(reactSet); initMoleculesFromMoleculeSets(molSet, allMolecules); initDegradationReactions(allMolecules); foreach (IReaction r in _reactions) { r.enableSequential = _enableSequential; } }
public async Task addReactionToPost(int userId, int postId, int reactionId) { if (await this._db.reactions.AnyAsync(x => x.id == reactionId)) { if (await this._db.posts.AnyAsync(x => x.id == postId)) { if (await this._db.users.AnyAsync(x => x.id == userId)) { ReactionSet reactionSet = new ReactionSet(); Reaction reaction = new Reaction(); reactionSet.postId = postId; reactionSet.reactionId = reactionId; reactionSet.userId = userId; reactionSet.date = DateTime.Now; if (!this._db.reactionSets.Any(x => ((x.postId == postId) && (x.userId == userId)))) { reactionSet.reaction = await this._db.reactions.FirstOrDefaultAsync(x => x.id == reactionId); this._db.Add(reactionSet); } } } } }
public void SetUp() { string filename1 = "NCDK.Data.MDL.reaction-1.rxn"; var ins1 = ResourceLoader.GetAsStream(filename1); MDLRXNReader reader1 = new MDLRXNReader(ins1); ReactionSet set = (ReactionSet)reader1.Read(new ReactionSet()); reaction = set[0]; reader1.Close(); }
public void SetUp() { builder = ChemObjectBuilder.Instance; string filename1 = "NCDK.Data.MDL.reaction-1.rxn"; var ins1 = ResourceLoader.GetAsStream(filename1); MDLRXNReader reader1 = new MDLRXNReader(ins1); set = (ReactionSet)reader1.Read(new ReactionSet()); reader1.Close(); }
/*! * \brief Load reactions from a ReactionSet * \param reactionsSet The set to load */ public void initReactionsFromReactionSet(ReactionSet reactionsSet) { if (reactionsSet == null) { return; } foreach (IReaction reaction in reactionsSet.reactions) { addReaction(IReaction.copyReaction(reaction)); } // _reactions.AddLast(reaction); }
public void TestRemoveAtomAndConnectedElectronContainers_IChemModel_IAtom() { IAtomContainer mol1 = new AtomContainer(); IAtom atom1 = new Atom("Cl"); mol1.Atoms.Add(atom1); mol1.Atoms.Add(new Atom("Cl")); IBond bond1 = new Bond(mol1.Atoms[0], mol1.Atoms[1]); mol1.Bonds.Add(bond1); IAtomContainer mol2 = new AtomContainer(); IAtom atom2 = new Atom("I"); mol2.Atoms.Add(atom2); mol2.Atoms.Add(new Atom("I")); IBond bond2 = new Bond(mol2.Atoms[0], mol2.Atoms[1]); mol2.Bonds.Add(bond2); var molSet = ChemObjectBuilder.Instance.NewAtomContainerSet(); molSet.Add(mol1); IReaction r = new Reaction(); r.Products.Add(mol2); IReactionSet rSet = new ReactionSet { r }; var model = new ChemModel { MoleculeSet = molSet, ReactionSet = rSet }; IAtom otherAtom = new Atom("Cl"); Assert.AreEqual(2, ChemModelManipulator.GetBondCount(model)); Assert.AreEqual(4, ChemModelManipulator.GetAtomCount(model)); ChemModelManipulator.RemoveAtomAndConnectedElectronContainers(model, otherAtom); Assert.AreEqual(2, ChemModelManipulator.GetBondCount(model)); Assert.AreEqual(4, ChemModelManipulator.GetAtomCount(model)); ChemModelManipulator.RemoveAtomAndConnectedElectronContainers(model, atom1); Assert.AreEqual(1, ChemModelManipulator.GetBondCount(model)); Assert.AreEqual(3, ChemModelManipulator.GetAtomCount(model)); ChemModelManipulator.RemoveAtomAndConnectedElectronContainers(model, atom2); Assert.AreEqual(0, ChemModelManipulator.GetBondCount(model)); Assert.AreEqual(2, ChemModelManipulator.GetAtomCount(model)); }
public void TestReactionSet_1() { IReaction reaction11 = builder.NewReaction(); IAtomContainer hydroxide = builder.NewAtomContainer(); hydroxide.Atoms.Add(builder.NewAtom("O")); reaction11.Reactants.Add(hydroxide); IAtomContainer proton = builder.NewAtomContainer(); proton.Atoms.Add(builder.NewAtom("H")); reaction11.Reactants.Add(proton); IAtomContainer water = builder.NewAtomContainer(); water.Atoms.Add(builder.NewAtom("O")); reaction11.Products.Add(water); IReactionSet reactionSet = new ReactionSet(); reactionSet.Add(reaction11); // now serialize to MDL RXN StringWriter writer = new StringWriter(); string file = ""; MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.Write(reactionSet); mdlWriter.Close(); file = writer.ToString(); Assert.IsTrue(file.Length > 0); // now deserialize the MDL RXN output IReaction reaction2 = builder.NewReaction(); MDLRXNReader reader = new MDLRXNReader(new StringReader(file)); reaction2 = (IReaction)reader.Read(reaction2); reader.Close(); Assert.AreEqual(2, reaction2.Reactants.Count); Assert.AreEqual(1, reaction2.Reactants[0].Atoms.Count); Assert.AreEqual(1, reaction2.Reactants[1].Atoms.Count); Assert.AreEqual(1, reaction2.Products.Count); Assert.AreEqual(1, reaction2.Products[0].Atoms.Count); }
public void TestReactionSet1() { SpeciesDescription info1; Species reactant1; CreateSpeciesInfoAndSpecies("reactant1", 10, out info1, out reactant1); SpeciesDescription info2; Species reactant2; CreateSpeciesInfoAndSpecies("reactant2", 40, out info2, out reactant2); SpeciesDescription info3; Species product1; CreateSpeciesInfoAndSpecies("product1", 90, out info3, out product1); const double rate1 = 2.0; Reaction reaction1 = CreateReaction(info1, reactant1, info2, reactant2, info3, product1, rate1); Assert.AreEqual(reaction1.Reactants[0], reactant1); Assert.AreEqual(reaction1.Reactants[1], reactant2); Assert.AreEqual(reaction1.Products[0], product1); var reactions = new List <Reaction> { reaction1 }; var reactionSet1 = new ReactionSet(reactions); Assert.AreEqual(reactionSet1.Reactions[0].Name, reactions[0].Name); double[] gamma = { 2.0 }; Assert.AreEqual(4.0, reactionSet1.UpdateRates(gamma)); Assert.AreEqual(4.0, reactionSet1.PredilectionRates[0]); Assert.AreEqual(2.0, reactionSet1.CurrentRates[0]); Assert.AreEqual(1, reactionSet1.NumReactions); reactionSet1.FireReaction(0); Assert.AreEqual(9, reactant1.Value); Assert.AreEqual(39, reactant2.Value); Assert.AreEqual(91, product1.Value); reactionSet1.FireReaction(0); Assert.AreEqual(8, reactant1.Value); Assert.AreEqual(38, reactant2.Value); Assert.AreEqual(92, product1.Value); }
public async Task <bool> deleteUserReactionsOnPost(int userId, int postId) { if (!await this._db.posts.AnyAsync(x => x.id == postId)) { if (!await this._db.users.AnyAsync(x => x.id == userId)) { return(false); } } ReactionSet reactionSet = await _db.reactionSets.FirstOrDefaultAsync(x => ((x.userId == userId) && (x.postId == postId))); if (reactionSet == null) { return(false); } _db.Remove(reactionSet); return(true); }
public async Task addReactionByNameToPost(int userId, int postId, string reactionName) { if (await this._db.reactions.AnyAsync(x => x.name == reactionName)) { if (await this._db.posts.AnyAsync(x => x.id == postId)) { if (await this._db.users.AnyAsync(x => x.id == userId)) { ReactionSet reactionSet = new ReactionSet(); Reaction reaction = new Reaction(); Reaction reactionToGetId = await this._db.reactions.FirstOrDefaultAsync(x => x.name == reactionName); reactionSet.postId = postId; reactionSet.reactionId = reactionToGetId.id; reactionSet.userId = userId; reactionSet.date = DateTime.Now; if (!this._db.reactionSets.Any(x => ((x.postId == postId) && (x.userId == userId) && (x.reaction.name == reactionName)))) { reactionSet.reaction = await this._db.reactions.FirstOrDefaultAsync(x => x.id == reactionToGetId.id); this._db.Add(reactionSet); } if (this._db.reactionSets.Any(x => ((x.postId == postId) && (x.userId == userId) && (x.reaction.name == reactionName)))) { await this.deleteUserReactionsOnPost(userId, postId); reactionSet.reaction = await this._db.reactions.FirstOrDefaultAsync(x => x.id == reactionToGetId.id); } else if (this._db.reactionSets.Any(x => ((x.postId == postId) && (x.userId == userId)))) { await this.deleteUserReactionsOnPost(userId, postId); reactionSet.reaction = await this._db.reactions.FirstOrDefaultAsync(x => x.id == reactionToGetId.id); this._db.Add(reactionSet); } } } } }
public async Task <Reaction> getUserReactionToPost(int userId, int postId) { if (!await this._db.users.AnyAsync(x => x.id == userId)) { if (!await this._db.posts.AnyAsync(x => x.id == postId)) { return(null); } } ReactionSet reactionSet = new ReactionSet(); reactionSet = await this._db.reactionSets.Include(x => x.reaction).FirstOrDefaultAsync(x => ((x.postId == postId) && (x.userId == userId))); Reaction reaction = new Reaction(); if (reactionSet == null) { return(null); } reaction = reactionSet.reaction; return(reaction); }
/*! \brief Load reactions from a ReactionSet \param reactionsSet The set to load */ public void initReactionsFromReactionSet(ReactionSet reactionsSet) { if (reactionsSet == null) return; foreach (IReaction reaction in reactionsSet.reactions) addReaction(IReaction.copyReaction(reaction)); // _reactions.AddLast(reaction); }