Electronic distribution algorithm

Asked

Viewed 1,238 times

1

I’m trying to think of a different way to do electronic distribution. The way I did it was this: display the amount of electrons in each layer. However, in the distribution I want (1s² 2s² 2p6...) the order of the layers are not respected.

The distribution I want is done according to the diagram by Linus Pauling, that has this order here: 1s2, 2s2, 2p6, 3s2, 3p6, 4s2, 3d10, 4p6, 5s2, 4d10, 5p6, 6s2, 4f14, 5d10, 6p6, 7s2, 5f14, 6d10, 7p6. The number after the letter being the number of electrons of each sublevel (represented by the letters) and the number before the letter the layer/level.

I had also made one this way that I proposed, however, it was very badly written.

I put these diagram values as a string in an array and then used and abused str_replace(). I mean, I didn’t make an "algorithm itself".

For those who don’t understand electronic distribution and want to help, I’m going to distribute an atom of:

Atomic number 10 -> 1s² 2s² 2p6
Atomic number 11 -> 1s² 2s² 2p6 3s¹
Atomic number 14 -> 1s² 2s² 2p6 3s² 3p²

That is, just follow that order of the diagram from up there, not needing to fill all the vacancies for the electrons, but never exceeding the limit. So if anyone can help me find a way to distribute the way I mentioned, I’d appreciate it.

My code is as follows (I have now done the part that checks whether the distribution ends with 4 or 9 electrons in the "D" sublevel, and if so, remove an electron from the nearest "S" sublevel and send it to "D"):

<?php

if ($_GET['atomic_n']) {

$arr_1 = array("1s2", "2s2", "2p6", "3s2", "3p6", "4s2", "3d10", "4p6", "5s2", "4d10", "5p6", "6s2", "4f14", "5d10", "6p6", "7s2", "5f14", "6d10");
$arr_2 = substr_replace ($arr_1, "", 0, 2);
$arr_3 = substr_replace ($arr_1, "", 2);


 $eletrons = $_GET['atomic_n'];
 $contador = 0;

    for ($i = 0; $i<=17; $i++) {

        if ($contador < $eletrons) {

            $contador += $arr_2[$i];

            if ($contador < $eletrons) {

                $arr_4[] = "$arr_3[$i]<sup>".$arr_2[$i]."</sup>";

             } else {

               $arr_4[] = $arr_3[$i]."<sup>".($arr_2[$i]-$contador+$eletrons)."</sup>";

             }
   }
}

  $k = 0;
  while ($arr_4[$k]) {
  $ultimo_termo = $k;
  $k++;
  }

$arr_excl = substr_replace ($arr_4, "", 0, 1);

$eletrons_final_2 = substr_replace ($arr_4, "", 0, 2);
$eletrons_final = str_replace ("<sup>", "", $eletrons_final_2);

$subnivel_2 = preg_replace ("/[^a-z]/", "", $arr_4);
$subnivel = str_replace ("sup", "", $subnivel_2);
$nivel = substr_replace ($arr_4, "", 1);

if ( end($arr_excl) == "d<sup>4</sup>" || end($arr_excl) == "d<sup>9</sup>" ) {

 $r = $ultimo_termo;

        while ($r > 0) {


                if ($subnivel[$r] == "s") {

                    $eletrons_final[$r] -= 1;
                    $eletrons_final[$ultimo_termo] +=1;
                    break;

                }

        $r--;

        }

for ($w = 0; $w <= $ultimo_termo; $w++) {

    echo $nivel[$w].$subnivel[$w]."<sup>".$eletrons_final[$w]."</sup>"."<br>";

}



    } else {

      foreach ($arr_4 as $k => $v){
              echo "$v<br>";

      }

    }

}

?>
  • 1

    And what is the question?

  • How can I do Uai.. " The distribution I want is done according to Linus Pauling’s diagram, which has this order here:"

  • 1

    And what you’ve done?

  • Added, but I already tell you it won’t help no. It was all done based on string...

  • 2

    Look at the... I hate chemistry, but the only two things I see that you can do the most is rewrite the algorithm, using the right tools, for the right situations and maybe sort the arrays. Maybe because I don’t understand bulhufas of it, but based on in this table, Cobalt (27), for example, even distributed well, but was in a different order.

  • 1

    Friend, it is because there it is separated by layer. That is, everyone who starts with 1, with 2, with 3, etc... That is mere detail. Just take the last foreach and change. Display using the level parameter. The biggest problem you should not know is the following: Distributions that end up with 4 or 9 in the "D" sub-level become unstable, so they remove an electron from the last found S sub-level and pass to "D". Furthermore, there are still atoms that have distributions totally out of the rule, see Niobium... rsrs

  • Now I’ve implemented this last sub-level rule, who wants to take a look, and if you can comment on any mistakes, something like, I’d like to thank you.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.