public MoleculePane(Molecule moleculeT, MoleculePaneMode modeT = MoleculePaneMode.select) { InitializeComponent(); molecule = moleculeT; mode = modeT; InitializeStuff(); }
public MoleculePane(LiveElement[] liveElementsT, MoleculePaneMode modeT = MoleculePaneMode.select) { InitializeComponent(); mode = modeT; molecule = new Molecule(liveElementsT); InitializeStuff(); }
public static void SaveMolecule(Molecule molecule, string path) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(path)) { foreach (LiveElement lElement in molecule.elementList) { file.WriteLine(lElement.element.symbol+","+lElement.amount.ToString()); } } }
public static List<Molecule> FindEmpiricalCandidates(int passes =6, decimal thresholdConstant = 0.2M,params EmpiricalElement[] eles) { List<Molecule> candidates = new List<Molecule>(); decimal threshold = thresholdConstant * eles.Count(); decimal lowestMol = 99999999999; foreach(EmpiricalElement ele in eles) { ele.percentage /= ele.element.atomicMass.TotalAmount; if (ele.percentage < lowestMol) { lowestMol = ele.percentage;} } foreach(EmpiricalElement ele in eles) { ele.percentage /= lowestMol; } for (int i = 1; i < passes;i++ ) { Begin: if (i >= passes) { break; } decimal errorMargin = 0; EmpiricalElement[] elesCopy = new EmpiricalElement[eles.Count()]; for (int q = 0; q < elesCopy.Count(); q++ ) { elesCopy[q] = new EmpiricalElement(eles[q].percentage, eles[q].element); } foreach (EmpiricalElement ele in elesCopy) { ele.percentage *= (decimal)i; decimal errorAmmount = (decimal)Math.Abs((decimal)(Math.Round(ele.percentage,0)) - ele.percentage); if (errorMargin > thresholdConstant) { i++; goto Begin; } errorMargin += errorAmmount; } if (errorMargin > threshold) { i++; goto Begin; } Molecule moleculeCandidate = new Molecule(); foreach (EmpiricalElement ele in elesCopy) { moleculeCandidate.Add(new LiveElement(ele.element, Convert.ToInt32(Math.Round(ele.percentage,0)))); } candidates.Add(moleculeCandidate); } if (candidates.Count() <= 0) { MessageBox.Show("No empirical formula candidates were found."); } return candidates; }
public MoleculeInformation(Molecule moleculeT) { InitializeComponent(); molecule = moleculeT; lblFormula.Content = molecule.ToString(); lblMolecularMass.Content = molecule.GetMolecularMass().ToString(); grid.Children.Add(new MoleculePane(molecule.EmpiricalFormula())); grdMolecule.Children.Add(new MoleculePane(molecule,MoleculePane.MoleculePaneMode.display)); lblMolecularMass_Copy.Content = ""; timer.Interval += TimeSpan.FromMilliseconds(17); timer.Start(); timer.Tick += new EventHandler(tick); this.ResizeMode = System.Windows.ResizeMode.NoResize; }
public MolarConcentration(decimal concentrationValueT,Molecule moleculeT, UnitPrefix molPrefix, UnitPrefix litrePrefix) { molecule = moleculeT; concentration = new Unit(concentrationValueT, new SubUnit(molPrefix, BaseUnit.mol, 1), new SubUnit(litrePrefix, BaseUnit.L, -1)); }
public gramLitreConcentration(decimal concentrationValueT, Molecule moleculeT, UnitPrefix gramsPrefix, UnitPrefix litrePrefix) { molecule = moleculeT; concentration = new Unit(concentrationValueT, new SubUnit(gramsPrefix, BaseUnit.g, 1), new SubUnit(litrePrefix, BaseUnit.L, -1)); }
public Molecule EmpiricalFormula() { Molecule moleculeTemp = new Molecule(); int[] eleAmounts = new int[elementList.Count()]; for(int i = 0;i< eleAmounts.Count();i++) { eleAmounts[i] = elementList[i].amount; } if (eleAmounts.Count() > 1) { int temp = MyMath.GCD(eleAmounts); bool breakif = false; for (int i = 0; i < eleAmounts.Count(); i ++ ) if (eleAmounts[i] < temp) { breakif = true; } if (!breakif) { for (int i = 0; i < eleAmounts.Count(); i++) { eleAmounts[i] = eleAmounts[i] / temp; } } } for(int i = 0;i<eleAmounts.Count();i++) { moleculeTemp.Add(new LiveElement(elementList[i].element,eleAmounts[i])); } return new Molecule(moleculeTemp.elementList.ToArray()); }
public LiveMolecule(Molecule moleculeT, int amountT) { amount = amountT; molecule = moleculeT; }