Exemplo n.º 1
0
        //public static AtomWithOrbitals FromStableIsotope(ElementName element)
        //{
        //    var isotope = IsotopeTable.GetStableIsotopeOf(element).FirstOrDefault();
        //    if (isotope == null)
        //        throw new ChemistryException($"No stable isotope known for {element}");
        //    return new AtomWithOrbitals(isotope.Protons, isotope.Neutrons);
        //}

        private void PopulateOrbitalsInGroundState()
        {
            if (Orbitals.Any(o => !o.IsEmpty))
            {
                throw new InvalidOperationException("Population of orbits only implemented for all orbits being empty");
            }
            var energySortedOrbitals = Orbitals.ToLookup(OrbitalComparer.CalculateOrbitalOrder);
            var energyGroups         = energySortedOrbitals.Select(x => x.Key).Distinct().OrderBy(x => x);
            var electronCount        = 0;

            foreach (var energyGroup in energyGroups)
            {
                var energyEqualOrbitals = energySortedOrbitals[energyGroup].ToList();
                // Add first electron
                foreach (var energyEqualOrbital in energyEqualOrbitals)
                {
                    var electron = new Electron();
                    energyEqualOrbital.AddElectron(electron);
                    electronCount++;
                    if (electronCount == Protons)
                    {
                        break;
                    }
                }
                if (electronCount == Protons)
                {
                    break;
                }
                // Add second electron
                foreach (var energyEqualOrbital in energyEqualOrbitals)
                {
                    var electron = new Electron();
                    energyEqualOrbital.AddElectron(electron);
                    electronCount++;
                    if (electronCount == Protons)
                    {
                        break;
                    }
                }
                if (electronCount == Protons)
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void AddBondElectron(Electron electron)
        {
            if (IsFull)
            {
                throw new ChemistryException("Adding a third electron to an orbital is forbidden");
            }
            if (IsEmpty)
            {
                throw new ChemistryException("Adding a bond electron to an empty orbital sounds like an error...");
            }
            var existingElectron = Electrons[0];

            if (existingElectron.Spin == electron.Spin)
            {
                electron.Spin = existingElectron.Spin.Invert();
            }
            Electrons.Add(electron);
        }
Exemplo n.º 3
0
 public void AddElectron(Electron electron)
 {
     if (IsFull)
     {
         throw new ChemistryException("Adding a third electron to an orbital is forbidden");
     }
     if (electron.AssociatedOrbital != null)
     {
         throw new ChemistryException("Cannot add electron to orbital which is already associated to another orbital");
     }
     if (!IsEmpty)
     {
         var existingElectron = Electrons[0];
         if (existingElectron.Spin == electron.Spin)
         {
             electron.Spin = existingElectron.Spin.Invert();
         }
     }
     Electrons.Add(electron);
     electron.AssociatedOrbital = this;
 }