private void TranslatePoints(int atmIdx, Vector3[][] points, int pointDensity, IAtom atom, Vector3 cp) { var totalRadius = PeriodicTable.GetVdwRadius(atom.Symbol).Value + solventRadius; var area = 4 * Math.PI * (totalRadius * totalRadius) * points.Length / pointDensity; double sumx = 0.0; double sumy = 0.0; double sumz = 0.0; foreach (var point in points) { var p = point[1]; sumx += p.X; sumy += p.Y; sumz += p.Z; } var vconst = 4.0 / 3.0 * Math.PI / (double)pointDensity; var dotp1 = (atom.Point3D.Value.X - cp.X) * sumx + (atom.Point3D.Value.Y - cp.Y) * sumy + (atom.Point3D.Value.Z - cp.Z) * sumz; var volume = vconst * (totalRadius * totalRadius) * dotp1 + (totalRadius * totalRadius * totalRadius) * points.Length; this.areas[atmIdx] = area; this.volumes[atmIdx] = volume; var tmp = new List <Vector3>(); foreach (var point in points) { tmp.Add(point[0]); } this.surfPoints[atmIdx] = tmp; }
public static void createEarth() { List <double> percentageList = new List <double>(); ChemicalElement element; List <ChemicalElement> chemicalElements = new List <ChemicalElement>(); element = PeriodicTable.findByName("Nitrogen"); chemicalElements.Add(element); percentageList.Add(78.08); element = PeriodicTable.findByName("Oxygen"); chemicalElements.Add(element); percentageList.Add(20.95); element = PeriodicTable.findByName("Argon"); chemicalElements.Add(element); percentageList.Add(0.93); element = PeriodicTable.findByName("Carbon"); chemicalElements.Add(element); percentageList.Add(0.04); ChemicalComposition chemicalComposition = new ChemicalComposition(chemicalElements, percentageList); Planet x = new Planet(chemicalComposition, ParametriUtente.Science.r_t, ParametriUtente.Science.AU); x.initPlanet(); Console.WriteLine("Earth created check debug values"); }
public static void ValidatePeriodicTable() { Assert.IsTrue(PeriodicTable.ValidateAverageMasses(1e-2)); Assert.IsFalse(PeriodicTable.ValidateAverageMasses(1e-3)); Assert.IsTrue(PeriodicTable.ValidateAbundances(1e-15)); Assert.IsFalse(PeriodicTable.ValidateAbundances(0)); }
/// <summary> /// <pre> /// -C#N /// -[N+]#[C-] /// -C=[N+]=N /// -N=[N+]=N /// </pre> /// </summary> internal static bool IsColinear(IAtom atom, IEnumerable <IBond> bonds) { if (PeriodicTable.IsMetal(atom.AtomicNumber)) { return(bonds.Count() == 2); } int numSgl = atom.ImplicitHydrogenCount ?? 0; int numDbl = 0; int numTpl = 0; int count = 0; foreach (var bond in bonds) { ++count; switch (bond.Order.Numeric()) { case 1: numSgl++; break; case 2: numDbl++; break; case 3: numTpl++; break; case 4: return(true); default: return(false); } } if (count != 2) { return(false); } switch (atom.AtomicNumber) { case 6: case 7: case 14: case 32: if (numTpl == 1 && numSgl == 1) { return(true); } if (numDbl == 2 && numSgl == 0) { return(true); } break; } return(false); }
public void TestNullArguments() { ChemicalFormula formulaA = new ChemicalFormula("CO"); IHasChemicalFormula ok = null; Assert.AreEqual("item", Assert.Throws <ArgumentNullException>(() => { formulaA.Add(ok); }).ParamName); ChemicalFormula ok2 = null; Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.Add(ok2); }).ParamName); Assert.AreEqual("other", Assert.Throws <ArgumentNullException>(() => { new ChemicalFormula(ok2); }).ParamName); Element ok3 = null; Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.AddPrincipalIsotopesOf(ok3, 0); }).ParamName); Assert.AreEqual("item", Assert.Throws <ArgumentNullException>(() => { formulaA.Remove(ok); }).ParamName); Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.Remove(ok2); }).ParamName); Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.IsSubsetOf(ok2); }).ParamName); Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.IsSupersetOf(ok2); }).ParamName); Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.CountWithIsotopes(ok3); }).ParamName); Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.CountSpecificIsotopes(ok3, 0); }).ParamName); Assert.IsFalse(formulaA.Equals(ok2)); IEnumerable <IHasChemicalFormula> ok4 = null; Assert.AreEqual("formulas", Assert.Throws <ArgumentNullException>(() => { ChemicalFormula.Combine(ok4); }).ParamName); Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { PeriodicTable.Add(ok3); }).ParamName); Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { new IsotopicDistribution(ok2); }).ParamName); IHasMass ok5 = null; Assert.AreEqual("objectWithMass", Assert.Throws <ArgumentNullException>(() => { ok5.ToMZ(0); }).ParamName); var ok7 = new PhysicalObjectWithChemicalFormula("C"); }
public void TestReplaceIsotopes() { ChemicalFormula formulaA = new ChemicalFormula("CC{13}2H3NO"); formulaA.Replace(PeriodicTable.GetElement("C")[13], PeriodicTable.GetElement("C")[12]); Assert.AreEqual("CC{12}2H3NO", formulaA.Formula); }
public void TestBug1245() { var ins = ResourceLoader.GetAsStream("NCDK.Data.CML.(1R)-1-aminoethan-1-ol.cml"); var reader = new CMLReader(ins); try { IChemFile cfile = reader.Read(ChemObjectBuilder.Instance.NewChemFile()); Assert.IsNotNull(cfile, "ChemFile was Null"); var containers = ChemFileManipulator.GetAllAtomContainers(cfile); Assert.AreEqual(1, containers.Count(), "Expected a single atom container"); IAtomContainer container = containers.First(); Assert.IsNotNull(container, "Null atom container read"); foreach (var atom in container.Atoms) { Assert.AreEqual( PeriodicTable.GetAtomicNumber(atom.Symbol), atom.AtomicNumber, "Incorrect atomic number"); } } finally { reader.Close(); } }
/// <summary> /// Create initial invariant labeling corresponds to step 1 /// </summary> /// <returns>List containing the</returns> private static List <InvPair> CreateInvarLabel(IAtomContainer atomContainer) { var atoms = atomContainer.Atoms; StringBuilder inv; var vect = new List <InvPair>(); foreach (var a in atoms) { inv = new StringBuilder(); var connectedAtoms = atomContainer.GetConnectedAtoms(a).ToReadOnlyList(); inv.Append(connectedAtoms.Count + (a.ImplicitHydrogenCount ?? 0)); //Num connections inv.Append(connectedAtoms.Count); //Num of non H bonds inv.Append(PeriodicTable.GetAtomicNumber(a.Symbol)); double charge = a.Charge ?? 0; if (charge < 0) //Sign of charge { inv.Append(1); } else { inv.Append(0); //Absolute charge } inv.Append((int)Math.Abs((a.FormalCharge ?? 0))); //Hydrogen count inv.Append((a.ImplicitHydrogenCount ?? 0)); vect.Add(new InvPair(long.Parse(inv.ToString(), NumberFormatInfo.InvariantInfo), a)); } return(vect); }
/// <summary> /// Mass number for a atom with a given atomic number and exact mass. /// </summary> /// <param name="atomicNumber">atomic number</param> /// <param name="exactMass">exact mass</param> /// <returns>the mass number (or <see langword="null"/>>) if no mass number was found</returns> /// <exception cref="IOException">isotope configuration could not be loaded</exception> private static int?MassNumber(int atomicNumber, double exactMass) { var symbol = PeriodicTable.GetSymbol(atomicNumber); var isotope = CDK.IsotopeFactory.GetIsotope(symbol, exactMass, 0.001); return(isotope?.MassNumber); }
private static void BenchmarkTimeGettingElementFromPeriodicTable() { Console.WriteLine("Starting benchmark BenchmarkTimeGettingElementFromPeriodicTable"); int numRepetitions = 100000000; Stopwatch stopWatch = new Stopwatch(); stopWatch.Restart(); for (int i = 0; i < numRepetitions; i++) { var a = PeriodicTable.GetElement(1); var b = a.Protons + a.AverageMass + 4; } stopWatch.Stop(); Console.WriteLine("Time for getting by atomic number: " + stopWatch.Elapsed); stopWatch.Restart(); for (int i = 0; i < numRepetitions; i++) { var a = PeriodicTable.GetElement("H"); var b = a.Protons + a.AverageMass + 4; } stopWatch.Stop(); Console.WriteLine("Time for getting by atomic symbol: " + stopWatch.Elapsed); Console.WriteLine("Benchmark BenchmarkTimeGettingElementFromPeriodicTable finished"); }
public override bool Matches(IAtom atom) { string symbol = atom.Symbol; int group = PeriodicTable.GetGroup(symbol); return(group == this.groupNumber); }
static void loop(PeriodicTable table) { while (true) { Console.Write("Enter an element symbol: "); string input = Console.ReadLine(); Element result = null; if (table.Elements.ContainsKey(input)) { result = table[input]; } else if (int.TryParse(input, out int index)) { if (index > 0 && index <= 118) { result = table[index]; } } if (result != null) { Console.WriteLine(result.ToString().Replace("; ", "\n> ").Insert(0, "> ")); } else { Console.WriteLine("Element not found."); } } }
private BODRIsotopeFactory() { string configFile = "NCDK.Config.Data.isotopes.dat"; var ins = ResourceLoader.GetAsStream(configFile); var buffer = new byte[8]; ins.Read(buffer, 0, 4); Array.Reverse(buffer, 0, 4); int isotopeCount = BitConverter.ToInt32(buffer, 0); for (int i = 0; i < isotopeCount; i++) { var atomicNum = ins.ReadByte(); ins.Read(buffer, 0, 2); Array.Reverse(buffer, 0, 2); var massNum = BitConverter.ToInt16(buffer, 0); ins.Read(buffer, 0, 8); Array.Reverse(buffer, 0, 8); var exactMass = BitConverter.ToDouble(buffer, 0); double natAbund; if (ins.ReadByte() == 1) { ins.Read(buffer, 0, 8); Array.Reverse(buffer, 0, 8); natAbund = BitConverter.ToDouble(buffer, 0); } else { natAbund = 0; } var isotope = new BODRIsotope(PeriodicTable.GetSymbol(atomicNum), atomicNum, massNum, exactMass, natAbund); Add(isotope); } }
public void ChemicalForulaMyTest() { ChemicalFormula formula = new ChemicalFormula(); formula.Add(new ChemicalFormula("C3H5NO")); Assert.AreEqual(PeriodicTable.GetElement("C").PrincipalIsotope.AtomicMass * 3 + PeriodicTable.GetElement("H").PrincipalIsotope.AtomicMass * 5 + PeriodicTable.GetElement("N").PrincipalIsotope.AtomicMass + PeriodicTable.GetElement("O").PrincipalIsotope.AtomicMass, formula.MonoisotopicMass); }
private void CreationKit_Load(object sender, EventArgs e) { Partita newGame = new Partita(); newGame = Partita.createPartita_form(); this.sessione = newGame; PeriodicTable.init(); this.StarSeedElements.DataSource = elementsComboBox_ds.periodicTable_UI; this.Element.DataSource = elementsComboBox_ds.periodicTable_UI; this.Element.DisplayMember = "completeName"; this.Element.ValueMember = "Self"; foreach (Object obj in Enum.GetValues(typeof(PlanetClassification))) { this.PlanetClassTxt.Items.Add(obj); } foreach (Object obj in Enum.GetValues(typeof(NucleusClassification))) { this.NucleusClassTxt.Items.Add(obj); } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { // TODO: Create an appropriate data model for your problem domain to replace the sample data /*var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter); * this.DefaultViewModel["Items"] = sampleDataGroups;*/ theTable = await PeriodicTable.LoadTable(); }
public void RemoveIsotopeCompletelyFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2NO"); formulaA.RemoveIsotopesOf(PeriodicTable.GetElement("H")); Assert.AreEqual(formulaA, formulaB); }
public void AddIsotopeWithExistingMassNumber() { Element al = PeriodicTable.GetElement("Al"); Assert.Throws <ArgumentException>(() => { al.AddIsotope(27, 28, 1); }, "Isotope with mass number " + 28 + " already exists"); }
public static void RemoveElementCompletelyFromFromula() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2NO"); formulaA.RemoveIsotopesOf(PeriodicTable.GetElement("H")); Assert.AreEqual(formulaB, formulaA); }
public void RemoveNegativeElementFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H5NO"); formulaA.Remove(PeriodicTable.GetElement("H"), -2); Assert.AreEqual(formulaA, formulaB); }
public ItemsPage() { theTable = new PeriodicTable(); LoadTable(); this.InitializeComponent(); DataContext = this; }
public void RemoveZeroIsotopeFromFromula() { ChemicalFormula formulaA = new ChemicalFormula("C2H3NO"); ChemicalFormula formulaB = new ChemicalFormula("C2H3NO"); formulaA.Remove(PeriodicTable.GetElement("H")[1], 0); Assert.AreEqual(formulaA, formulaB); }
public void RemoveElementCompletelyFromFromulaWithHeavyIsotope() { ChemicalFormula formulaA = new ChemicalFormula("C2C{13}H3NO"); ChemicalFormula formulaB = new ChemicalFormula("H3NO"); formulaA.Remove(PeriodicTable.GetElement("C")); Assert.AreEqual(formulaA, formulaB); }
public static void RemoveElementFromFromula() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO"); ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2HNO"); formulaA.Remove(PeriodicTable.GetElement("H"), 2); Assert.AreEqual(formulaA, formulaB); }
public void TestUpdateElements() { var elementLocation = Path.Combine(TestContext.CurrentContext.TestDirectory, "lal.dat"); Loaders.UpdateElements(elementLocation); Loaders.UpdateElements(elementLocation); Assert.IsTrue(PeriodicTable.ValidateAbundances(1e-15)); Assert.IsTrue(PeriodicTable.ValidateAverageMasses(1e-2)); }
public void ThresholdProbability() { ChemicalFormula formulaA = new ChemicalFormula("CO"); // Only the principal isotopes have joint probability of 0.5! So one result when calcuating isotopic distribution var a = new IsotopicDistribution(formulaA, 0.0001, 0.5); Assert.AreEqual(1, a.Masses.Count()); Assert.IsTrue((PeriodicTable.GetElement("C").PrincipalIsotope.AtomicMass + PeriodicTable.GetElement("O").PrincipalIsotope.AtomicMass).MassEquals(a.Masses[0])); }
public HumanPlayer(Color color) : base(color) { healthBar = new ProgressBar(new Zone(0, 0, 10, 2)); healthBar.BorderThickness = 0; resourceBar = new ResourceBar(new Zone(0, 0, 40, 6)); resourceBar.BorderThickness = 0; pt = new PeriodicTable(this); selectionCircle = new Animation("SelectionCircleSmall"); }
private static int GetAtomicNumber(ILigand ligand) { var atomNumber = ligand.LigandAtom.AtomicNumber; if (atomNumber != 0) { return(atomNumber); } return(PeriodicTable.GetAtomicNumber(ligand.LigandAtom.Symbol)); }
public static void ThresholdProbability() { ChemicalFormula formulaA = ChemicalFormula.ParseFormula("CO"); // Only the principal isotopes have joint probability of 0.5! So one result when calcuating isotopic distribution var a = IsotopicDistribution.GetDistribution(formulaA, 0.0001, 0.5); Assert.AreEqual(1, a.Masses.Count()); Assert.IsTrue(Math.Abs((PeriodicTable.GetElement("C").PrincipalIsotope.AtomicMass + PeriodicTable.GetElement("O").PrincipalIsotope.AtomicMass - a.Masses.First())) < 1e-9); }
private void RunCustomGenericCollection() { PeriodicTable < Element > elements = new PeriodicTable<Element>(); elements.AddElement( new Element( ElementType.Fluorine ) ); elements.AddElement( new Element( ElementType.Carbon ) ); elements.AddElement( new Element( ElementType.Lithium ) ); foreach( Element element in elements ) element.Display(); }
/// <summary> /// Initialize the surface, generating the points on the accessible surface /// area of each atom as well as calculating the surface area of each atom. /// </summary> private void Init() { // invariants foreach (var atom in atoms) { if (atom.Point3D == null) { throw new ArgumentException("One or more atoms had no 3D coordinate set"); } } // get r_f and geometric center var cp = new Vector3(0, 0, 0); double maxRadius = 0; foreach (var atom in atoms) { var vdwr = PeriodicTable.GetVdwRadius(atom.Symbol).Value; if (vdwr + solventRadius > maxRadius) { maxRadius = PeriodicTable.GetVdwRadius(atom.Symbol).Value + solventRadius; } cp.X = cp.X + atom.Point3D.Value.X; cp.Y = cp.Y + atom.Point3D.Value.Y; cp.Z = cp.Z + atom.Point3D.Value.Z; } cp.X = cp.X / atoms.Length; cp.Y = cp.Y / atoms.Length; cp.Z = cp.Z / atoms.Length; // do the tesselation var tess = new Tessellate("ico", tesslevel); tess.DoTessellate(); Trace.TraceInformation($"Got tesselation, number of triangles = {tess.GetNumberOfTriangles()}"); // get neighbor list var nbrlist = new NeighborList(atoms, maxRadius + solventRadius); Trace.TraceInformation("Got neighbor list"); // loop over atoms and get surface points this.surfPoints = new List <Vector3> [atoms.Length]; this.areas = new double[atoms.Length]; this.volumes = new double[atoms.Length]; for (int i = 0; i < atoms.Length; i++) { var pointDensity = tess.GetNumberOfTriangles() * 3; var points = AtomicSurfacePoints(nbrlist, i, atoms[i], tess); TranslatePoints(i, points, pointDensity, atoms[i], cp); } Trace.TraceInformation("Obtained points, areas and volumes"); }
public static void LoadElements() { // has the periodic table already been loaded? if (PeriodicTable.GetElement(1) != null) { return; } // periodic table has not been loaded yet - load it PeriodicTableLoader.Load(); }