Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

molecular weight #2

Closed
longemen3000 opened this issue Aug 3, 2020 · 3 comments
Closed

molecular weight #2

longemen3000 opened this issue Aug 3, 2020 · 3 comments

Comments

@longemen3000
Copy link

one way to obtain all the molecular weights in a programmatic way:

using PeriodicTables, Unitful
a = PeriodicTables._element_data
mw  = map(x->ustrip(x.atomic_mass),values(a))
names = map(x->x.symbol,values(a))
molecular_weights= Dict{String,Float64}(Iterators.zip(names,mw))

without depending on PeriodicTables or unitful, the data is the following:

H => 1.008,
He => 4.0026022,
Li => 6.94,
Be => 9.01218315,
B => 10.81,
C => 12.011,
N => 14.007,
O => 15.999,
F => 18.9984031636,
Ne => 20.17976,
Na => 22.989769282,
Mg => 24.305,
Al => 26.98153857,
Si => 28.085,
P => 30.9737619985,
S => 32.06,
Cl => 35.45,
Ar => 39.9481,
K => 39.09831,
Ca => 40.0784,
Sc => 44.9559085,
Ti => 47.8671,
V => 50.94151,
Cr => 51.99616,
Mn => 54.9380443,
Fe => 55.8452,
Co => 58.9331944,
Ni => 58.69344,
Cu => 63.5463,
Zn => 65.382,
Ga => 69.7231,
Ge => 72.6308,
As => 74.9215956,
Se => 78.9718,
Br => 79.904,
Kr => 83.7982,
Rb => 85.46783,
Sr => 87.621,
Y => 88.905842,
Zr => 91.2242,
Nb => 92.906372,
Mo => 95.951,
Tc => 98.0,
Ru => 101.072,
Rh => 102.905502,
Pd => 106.421,
Ag => 107.86822,
Cd => 112.4144,
In => 114.8181,
Sn => 118.7107,
Sb => 121.7601,
Te => 127.603,
I => 126.904473,
Xe => 131.2936,
Cs => 132.905451966,
Ba => 137.3277,
La => 138.905477,
Ce => 140.1161,
Pr => 140.907662,
Nd => 144.2423,
Pm => 145.0,
Sm => 150.362,
Eu => 151.9641,
Gd => 157.253,
Tb => 158.925352,
Dy => 162.5001,
Ho => 164.930332,
Er => 167.2593,
Tm => 168.934222,
Yb => 173.0451,
Lu => 174.96681,
Hf => 178.492,
Ta => 180.947882,
W => 183.841,
Re => 186.2071,
Os => 190.233,
Ir => 192.2173,
Pt => 195.0849,
Au => 196.9665695,
Hg => 200.5923,
Tl => 204.38,
Pb => 207.21,
Bi => 208.980401,
Po => 209.0,
At => 210.0,
Rn => 222.0,
Fr => 223.0,
Ra => 226.0,
Ac => 227.0,
Th => 232.03774,
Pa => 231.035882,
U => 238.028913,
Np => 237.0,
Pu => 244.0,
Am => 243.0,
Cm => 247.0,
Bk => 247.0,
Cf => 251.0,
Es => 252.0,
Fm => 257.0,
Md => 258.0,
No => 259.0,
Lr => 266.0,
Rf => 267.0,
Db => 268.0,
Sg => 269.0,
Bh => 270.0,
Hs => 269.0,
Mt => 278.0,
Ds => 281.0,
Rg => 282.0,
Cn => 285.0,
Nh => 286.0,
Fl => 289.0,
Mc => 289.0,
Lv => 293.0,
Ts => 294.0,
Og => 294.0,
Uue => 315.0,

the method of extraction was the following:

for (k,v) in Iterators.zip(nam,w)
print(k)
print(" => ")
print(v)
println(",")
end

to extract the molecular weight, it suffices to make a dict with this data and call it. but im not familiarized enough with the API to do a pull request

@zlatanvasovic
Copy link
Owner

zlatanvasovic commented Aug 3, 2020

Even though it's another dependency, I'd rather depend on PeriodicTable, so that I don't have to maintain a knowledge base here. Maybe just generate the list once and store as const? PeriodicTable can also be used for other things, like validating do all elements in a compound string exist in the periodic table.

The best way to add molecular weight into API is just to define a method, since by default compound string can be anything and may not be valid for periodic table.

function molecularweight(compound::Compound)
    weight = 0
    for (element, k) in elementtuples
       weight += k * getweight_fromtable(element)
    end
    return weight
end

There may be a nice way to do further calculations, i.e. check "The chemical composition matrix" at http://logical.ai/chemistry/html/chem-nullspace.html. To get a specific number of moles of some compound, you can use matrix multiplication. Then you just multiply that number by molecular weight, and voila!

@longemen3000
Copy link
Author

PeriodicTables.jl is basically a big Dict of elements haahah, but depends of unitful, and he molecular weights have units there.

@longemen3000
Copy link
Author

to add to the method (in case someone needs it)

function molecularweight(compound::Compound)
    weight = 0.0
    for (element, k) in compound.tuples
       weight += k * getweight_fromtable(element)
    end
    weight +=  0.000548597*compound.charge #electrons weight something
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants