Exemple #1
0
        /// <summary>Returns a string that represents the current object.</summary>
        /// <returns>A string that represents the current object.</returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            for (var i = 0; i < Shells.Count; i++)
            {
                Shell current = Shells.ToArray()[i];

                if (i < Shells.Count - 1)
                {
                    sb.Append(current + " ");
                    continue;
                }

                sb.Append(current);
            }

            return(sb.ToString());
        }
Exemple #2
0
        /// <summary>
        /// Populates the current <see cref="ShellConfiguration"/> instance.
        /// </summary>
        public void Populate()
        {
            int left = Element.Electrons;

            for (var i = 0; i < ChemistryUtils.EnergyLevelConfiguration.Count; i++)
            {
                if (left == 0)
                {
                    break;
                }

                KeyValuePair <char, char[]> pair = ChemistryUtils.EnergyLevelConfiguration.ToList()[i];
                Shell shell = this[pair.Key];

                for (int x = 0; x < pair.Value.Length; x++)
                {
                    if (left == 0)
                    {
                        break;
                    }

                    Subshell subshell = shell[pair.Value[x]];

                    if (subshell.Electrons > 0)
                    {
                        continue;
                    }

                    if (left - subshell.Capacity < 0)
                    {
                        subshell.Populate(left);
                        left = 0;
                    }
                    else
                    {
                        subshell.Populate(subshell.Capacity);
                        left -= subshell.Capacity;
                    }

                    int stepsDown = x;
                    for (int z = 0; z < stepsDown; z++)
                    {
                        if (left == 0)
                        {
                            break;
                        }

                        Subshell diagonal = Shells.ToList()[i + z + 1].Subshells[x - (z + 1)];
                        if (left - diagonal.Capacity < 0)
                        {
                            diagonal.Populate(left);
                            left = 0;
                        }
                        else
                        {
                            diagonal.Populate(diagonal.Capacity);
                            left -= diagonal.Capacity;
                        }
                    }
                }
            }

            foreach (var shell in Shells.ToArray())
            {
                foreach (var subshell in shell.Subshells.ToArray())
                {
                    if (subshell.Electrons == 0)
                    {
                        shell.Subshells.Remove(subshell);
                    }
                }

                if (shell.Electrons == 0)
                {
                    Shells.Remove(shell);
                }
            }
        }