Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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");
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 10
0
        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");
        }
Exemplo n.º 11
0
        public override bool Matches(IAtom atom)
        {
            string symbol = atom.Symbol;
            int    group  = PeriodicTable.GetGroup(symbol);

            return(group == this.groupNumber);
        }
Exemplo n.º 12
0
 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.");
         }
     }
 }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        /// <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();
        }
Exemplo n.º 17
0
        public void RemoveIsotopeCompletelyFromFromula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2NO");

            formulaA.RemoveIsotopesOf(PeriodicTable.GetElement("H"));

            Assert.AreEqual(formulaA, formulaB);
        }
Exemplo n.º 18
0
        public void AddIsotopeWithExistingMassNumber()
        {
            Element al = PeriodicTable.GetElement("Al");

            Assert.Throws <ArgumentException>(() =>
            {
                al.AddIsotope(27, 28, 1);
            }, "Isotope with mass number " + 28 + " already exists");
        }
Exemplo n.º 19
0
        public static void RemoveElementCompletelyFromFromula()
        {
            ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO");
            ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2NO");

            formulaA.RemoveIsotopesOf(PeriodicTable.GetElement("H"));

            Assert.AreEqual(formulaB, formulaA);
        }
Exemplo n.º 20
0
        public void RemoveNegativeElementFromFromula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H5NO");

            formulaA.Remove(PeriodicTable.GetElement("H"), -2);

            Assert.AreEqual(formulaA, formulaB);
        }
Exemplo n.º 21
0
        public ItemsPage()
        {
            theTable = new PeriodicTable();
            LoadTable();

            this.InitializeComponent();

            DataContext = this;
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 24
0
        public static void RemoveElementFromFromula()
        {
            ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO");
            ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2HNO");

            formulaA.Remove(PeriodicTable.GetElement("H"), 2);

            Assert.AreEqual(formulaA, formulaB);
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
0
        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]));
        }
Exemplo n.º 27
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");
 }
Exemplo n.º 28
0
        private static int GetAtomicNumber(ILigand ligand)
        {
            var atomNumber = ligand.LigandAtom.AtomicNumber;

            if (atomNumber != 0)
            {
                return(atomNumber);
            }
            return(PeriodicTable.GetAtomicNumber(ligand.LigandAtom.Symbol));
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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();
        }
Exemplo n.º 31
0
        /// <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");
        }
Exemplo n.º 32
0
        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();
        }