public void AddCompound(Compound compound) { switch (compound.Type) { case COMPOUND_TYPES.Reactant: currentSynthesis.Reactants.Add(compound); break; case COMPOUND_TYPES.Reagent: currentSynthesis.Reagents.Add(compound); break; case COMPOUND_TYPES.Product: currentSynthesis.Products.Add(compound); break; } currentSynthesis.UpdateSynthesis(); Console.WriteLine("AddCompound reac {0}, reag {1}, prod {2}", currentSynthesis.Reactants.Count, currentSynthesis.Reagents.Count, currentSynthesis.Products.Count); }
//-------------------Other Methods------------------------------------------ public void AddCompound(Compound compound) { switch (compound.Type) { case COMPOUND_TYPES.Reactant: currentSynthesis.Reactants.Add(compound); break; case COMPOUND_TYPES.Reagent: currentSynthesis.Reagents.Add(compound); break; case COMPOUND_TYPES.Product: currentSynthesis.Products.Add(compound); break; } currentSynthesis.UpdateSynthesis(); gridView.DataSource = currentSynthesis.AllCompounds; reactionViewer1.Synth = currentSynthesis; reactionViewer1.UpdateControl(); Console.WriteLine("AddCompound reac {0}, reag {1}, prod {2}", currentSynthesis.Reactants.Count, currentSynthesis.Reagents.Count, currentSynthesis.Products.Count); }
private void DrawCompoundText(Compound comp, RectangleF region, Graphics g, bool displayRefName) { //Find the center of the region PointF center = new PointF(region.Location.X + region.Width * 0.5f, region.Location.Y + region.Height * 0.5f); string name = string.Empty; //if we display refname the name is that otherwise we just write the formula if (displayRefName) name = comp.RefName; else name = comp.Formula; SizeF stringSize = g.MeasureString(name, font); PointF drawPos = new PointF(center.X - stringSize.Width * 0.5f, center.Y); g.DrawString(name, font, Brushes.Black, drawPos); }
public CompoundRegion(Compound comp, Molecule visualComp, RectangleF rect) { this.compound = comp; this.rect = rect; this.visualMol = visualComp; }
private void addCompoundButton_Click(object sender, EventArgs e) { //Before anything else we check that the molecule is initialized either by formula or structure if (molecule == null) { MessageBox.Show("There is no molecular data, please enter a formula or paste a structure.", "Error"); return; } //First we get all of the values in the text boxes double density = 0, massVal = 0, molsVal = 0, volVal = 0, concVal = 0; string refname = string.Empty; try { massVal = double.Parse(massTextBox.Text); molsVal = double.Parse(molsTextBox.Text); if(densityTextBox.Enabled) density = double.Parse(densityTextBox.Text); if(volumeTextBox.Enabled) volVal = double.Parse(volumeTextBox.Text); if(concentrationTextBox.Enabled) concVal = double.Parse(concentrationTextBox.Text); } catch (FormatException) { MessageBox.Show("Some input was not a number, please check your input and add the compound again"); return; } if (!string.IsNullOrEmpty(nameTextBox.Text)) refname = nameTextBox.Text; //Build the new compound bool isLimiting = false; bool isTarget = false; if (typeSelection.SelectedIndex == (int)COMPOUND_TYPES.Product) { //if it is the product we get the checkbox value and set limiting to false isLimiting = false; isTarget = isLimitingCheckBox.Checked; } else { isLimiting = isLimitingCheckBox.Checked; isTarget = false; } //Finally build the dictionaries Unit mols, mass, volume; mols = new Unit(molsVal, "mol", molUnitSelection.SelectedIndex); mass = new Unit(massVal, "g", massUnitSelection.SelectedIndex); volume = new Unit(volVal, "l", volumeUnitSelection.SelectedIndex); Solution solution = new Solution(solventTextBox.Text, new Unit(concVal, "mol/l",(int)UNIT_POWERS.none)); Compound comp = new Compound(molecule, refname, typeSelection.SelectedIndex, stateSelection.SelectedIndex, isLimiting, isTarget, density, mols, mass, volume, solution); if (comp.State == PHASE_STATE.Liquid) Console.WriteLine("Liquid, my mass is " + comp.Mass.ToString()); parent.AddCompound(comp); this.Close(); }
private static ObservableCollection<Compound> ReadBlock(XmlNodeList compoundList, COMPOUND_TYPES type) { ObservableCollection<Compound> returnList = new ObservableCollection<Compound>(); foreach (XmlNode node in compoundList) { string localid = string.Empty; string name = string.Empty; string refid = string.Empty; int fileid = 0; //In the files each compound is recognized by a five digit number, so we can attach mol data int state = 0; string formula = string.Empty; float density = 0.0f; Unit mols = new Unit(0, "mol", (int)UNIT_POWERS.none); Unit mass = new Unit(0, "g", (int)UNIT_POWERS.none); Unit volume = new Unit(0, "l", (int)UNIT_POWERS.none); Solution solvent = new Solution("null", new Unit(0, "mol/l", (int)UNIT_POWERS.none)); bool isLimiting = false; bool isTarget = false; foreach (XmlNode inner in node.ChildNodes) { switch (inner.Name) { case "fileid": fileid = int.Parse(inner.InnerText); break; case "localid": localid = inner.InnerText; break; case "name": name = inner.InnerText; break; case "refid": refid = inner.InnerText; break; case "formula": formula = inner.InnerText; break; case "state": string text = inner.InnerText; if (text == "solid") state = 0; if (text == "liquid") state = 1; if (text == "gas") state = 2; if (text == "solvated") state = 3; break; case "islimiting": isLimiting = bool.Parse(inner.InnerText); break; case "istarget": isTarget = bool.Parse(inner.InnerText); break; case "density": if (inner.InnerText == "null") break; density = float.Parse(inner.InnerText); break; case "mols": if(inner.InnerText == "null") break; mols = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value)); break; case "mass": if (inner.InnerText == "null") break; mass = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value)); break; case "volume": if (inner.InnerText == "null") break; volume = new Unit(double.Parse(inner.InnerText), inner.Attributes["unit"].Value, int.Parse(inner.Attributes["unit_power"].Value)); break; case "solvent": if (inner.InnerText == "null") break; solvent = new Solution(inner.InnerText, new Unit(float.Parse(inner.Attributes["conc"].Value), inner.Attributes["conc_unit"].Value, int.Parse(inner.Attributes["unit_power"].Value))); break; } } Compound c = new Compound(name, refid, localid, fileid, (int)type, state, isLimiting, isTarget, formula, density, mols, mass, volume, solvent); Console.WriteLine(c.ToString()); returnList.Add(c); } return returnList; }
private void SetEquivalency(Compound comp) { if (LimitingReactant != null) comp.Equivalency = comp.Mols.BaseValue / LimitingReactant.Mols.BaseValue; else comp.Equivalency = 1; }
/// <summary> /// Balances the other reactants and reagents from their equivalency to the sender which is the limiting reactant /// </summary> /// <param name="_sender">The limiting reactant</param> private void BalanceFromEquivalency(Compound _sender) { if (reactants.Count >= 2) { foreach (Compound reactant in reactants) { //continue on if the reactant is this one if (reactant == _sender) continue; reactant.Mols = new Unit(_sender.Mols.BaseValue * reactant.Equivalency, _sender.Mols.UnitType, _sender.Mols.Power); reactant.Mass = new Unit(reactant.Mols.BaseValue * reactant.MolWeight, "g", (int)UNIT_POWERS.none); //Volume is density / mass and we multiply by 10^-3 to get it in liters (this is expecting density as g/ml reactant.Volume = new Unit(reactant.Mass.BaseValue / reactant.Density, "l", (int)UNIT_POWERS.none); } } foreach (Compound reagent in reagents) { if (reagent == _sender) continue; reagent.Mols = new Unit(_sender.Mols.BaseValue * reagent.Equivalency, _sender.Mols.UnitType, _sender.Mols.Power); reagent.Mass = new Unit(reagent.Mols.BaseValue * reagent.MolWeight, "g", (int)UNIT_POWERS.none); //Volume is density / mass and we multiply by 10^-3 to get it in liters (this is expecting density as g/ml reagent.Volume = new Unit(reagent.Mass.BaseValue / reagent.Density, "l", (int)UNIT_POWERS.none); } OnSynthesisChanged(EventArgs.Empty); }
public void RemoveCompound(Compound comp) { if (reactants.Contains(comp)) reactants.Remove(comp); if (reagents.Contains(comp)) reagents.Remove(comp); if (products.Contains(comp)) products.Remove(comp); OnSynthesisChanged(EventArgs.Empty); }