This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lewisk3's profile picture

Help making a periodic table in CC

Started by Lewisk3, 19 May 2016 - 01:09 AM
Lewisk3 #1
Posted 19 May 2016 - 03:09 AM
I am currently working on a atom structure calculator which only takes an atoms atomic number to generate its structure,
for the most part it works but there are some things it doesnt work on. the reason i want to calculate the atoms instead of have them pre-setup is because
i eventually want to make a molecule simulator.

now what i mean by doesnt work with some atoms is that some atoms have strange numbers of electrons in their shells like for instance,
22 or 16 or 14 or 30 or even 28. not sure if theres a pattern to these, so thats what i need help figuring out,
thanks.

heres the pastebin link - http://pastebin.com/gckNFraD

i made a smaller more refined and commented version for those of you that are confused:
Spoiler
electrons = 102
subs = {2,8,18,32}
-- Add more electron positions if our electrons fill the default ammount
if(electrons > 60)then
	for i = 1, math.ceil((electrons - 60) / 32) do
		subs[#subs+1] = 32
	end
end
-- do this while we have electrons still not placed.
while electrons > 0 do
	-- loop through the shells and try to fill them
for i = 1, #subs do
  if(electrons >= subs[i])then
				print(subs[i])
				electrons = electrons - subs[i]
  else -- if the electrons doesnt fill the shell then,
		   -- if we have less than or equal too 8 electrons left (max valence electrons)
		   -- then place them all down.
			if(electrons <= 8 and electrons > 0)then
				print(electrons)
				electrons= 0
			end
			-- look backwards through the table and search through previous shells
			-- so electrons that didnt get a chance to get placed are now placed.
	   for y = #subs, 1, -1  do
				if(electrons >= subs[y] and electrons > 0)then
					print(subs[y])
					electrons = electrons - subs[y]
				end
	   end
			 -- if the backwards loop couldnt find a place for some electrons then place the rest down.
			 -- the backwards loop cannot fail, if it does then there is less than 2 electrons left.
			 if(electrons > 0)then
				 print(electrons)
				 electrons = 0
			 end
		end
	end
end
Edited on 21 May 2016 - 12:11 PM
Konlab #2
Posted 22 May 2016 - 05:50 PM
I can help you with chemistry, just PM me, there is a large system behind electron configuration, i think i can explain it
Edit:
Here's a brief explanation:
There's not only orbitals like 1., 2. Etc. But each orbital has sub-orbitals: the first has only the s sub-orbital, it can hold 2 electrons, the second has one s sub-orbital, that can hold 2 electrons and one p sub orbital that can hold 6 electrons, s is filled first, because s sub orbitals have smaller energy. 3rd orbital has s, p and d, but 3d has greater energy than 4s, so 4s is filled first (in the 4th period) and then the 3d orbital (Sc->Zn), but it is even more complicated because for example Cu has its d orbital full and has 4s orbital with one electron because of simmetricity. So the best I think you can do is make a large database and not look for sense behind it (there is, but so many factors and calculations that make it useless for you)
Edited on 22 May 2016 - 03:56 PM
Lewisk3 #3
Posted 22 May 2016 - 11:50 PM
I can help you with chemistry, just PM me, there is a large system behind electron configuration, i think i can explain it
Edit:
Here's a brief explanation:
There's not only orbitals like 1., 2. Etc. But each orbital has sub-orbitals: the first has only the s sub-orbital, it can hold 2 electrons, the second has one s sub-orbital, that can hold 2 electrons and one p sub orbital that can hold 6 electrons, s is filled first, because s sub orbitals have smaller energy. 3rd orbital has s, p and d, but 3d has greater energy than 4s, so 4s is filled first (in the 4th period) and then the 3d orbital (Sc->Zn), but it is even more complicated because for example Cu has its d orbital full and has 4s orbital with one electron because of simmetricity. So the best I think you can do is make a large database and not look for sense behind it (there is, but so many factors and calculations that make it useless for you)
ok thanks for the explanation, but that still doesn't change the maximum number of electrons for KLMNOP so even if i where to make it fill subshells instead of shells i would be doing the same thing,
if you look at the formula for each shells sub orbitals the electron count is basically equal to, 2n^2. so, the issue i am having is where the previous shell is not completely filled in a atom but its next shell
has electrons in it. i understand the concept of energy orbitals being filled in other shells first because of the differance in energy, not sure if i can get my program to realize that though,
would i just fill all the S orbitals then move to the P orbitals than D orbitals ect?