Open Miradin opened 5 years ago
Hey !
I wrote a small function to do those calculations a while back, see below (I'm not familiar with xraylib). Does your code not produce the right value?
import numpy as np
from periodic.table import element
def elDens(volDens,elements,ratios):
#Calculate electron density from the weight density in g/cm3
uScatt = 0
for i in range(len(elements)):
uScatt += element(elements[i]).mass * ratios[i]
rho = (volDens)/(1.66054 * uScatt)
return rho
density = 0.96
print("Electron density for C2H4 is: %.4f" % elDens(density ,['C','H'],[2,4])
Which outputs
Electron density for C2H4 is: 0.0206
Another option would be to use the 'fw' scattering length database, and use the density in g/cm3 in GenX and define your stack in weight percentages?
fw.C*0.856+fw.H*0.144
Hope it helps
Hello,
your code gives exactly the same value as mine. The problem is in correct composition notation. The code is giving different answers for 'C2H4', 'CH2' and 'C500H1000', which is the same composition, but describes different length of polymer (polymerization degree).
Thanks for your help.
Ok, I am at the point, where I am trying to understand the units here (from documentation):
Thus, the density (scatterers per unit volume (density in GenX)) becomes: dens=(ρ[kg/m3])/(1.66054×103×uscatt)
According to what is written, uscatt is the molecular mass of the atoms in composition, which has the units [g/mol] or [u] or [Da]. You have wrote this equation at the end:
dens=5.12×103/(1.66054×103×183.24=0.017
Now lets see what are the units of this '0.017' answer. We have expressed density in kg/A3, and got density of SrTiO3 like this: 5.12 [g/cm3] = 5.12 103 [kg/m3] = 5.12 103 *10-30 [kg/A3] this part is clear.
From this point this is what I am getting: [kg/A3] 103 10-30 / ([kg][g/mol]) = 5.12 10-27 / (1.66054 10-27 183.24) = = 0.0168 [mol/(g A3)] = 0.0168 [1/(u A3)]
I would say, the units looks strange for the density... Is it correct or I have made an en error somewhere?
@kibbi10 , could you, please, help me regarding " 'fw' scattering length database" ? If you are familiar with "periodictable" library, is this the correct value for, lets say, Carbon:
periodictable.C.xray.f0(0)
?
This code returns "Isotropic X-ray scattering factor' at q=0 and for Carbon it is 5.997.
Inside the file models/utils.py it is said that
fw Same thing as f but scaled ...
than, there is a lookup in fp, without any scaling at line 148:
sl.create_fw_lookup(__lookup_fp__, __w_dict__)
I have took a look at what is 'fp' and found that it is taken from henke tables and coincide with this code:
periodictable.C.xray.scattering_factors(wavelength=1.54)
This code returns (6.019160832578092, 0.009592242834992878)
So far I could not find the scaling rule. Can you help me here? Which value is correct, 6.019 or 5.997?
Moreover, I have found another interesting thing: Is it true, that in GenX for this calculation the wavelength is always fixed to 1.54 (from models/utils.py, line 152)?
Sorry, guys. Probably, I am asking a lot of questions in 1 post, but it is all related to the density values and units used. I am trying to figure out how "density" part works in the software. Please, help.
Hi,
I'll try to respond to your first post. GenX will expect that the density for C2000H4000 and C1000H2000 in units/AA^3 should differ. It all depends on what value you for f. If you use the fp table and define f=fp.C2000 + fp.H4000 then the density should be related to the number of C2000H4000 units per AA^3.
There is another model called soft_nx that works with scattering length densities instead of f and dens which is usually more favoured by the soft matter community. It might be easier...
Regarding the units - I believe they are correct, it seems that you have the wrong units in the constant.
The difference between the two tables for scattering lengths is rather small. They can be calculated with different codes so it is hard to say a "correct" answer.
The wavelength is changed in the script. What you have found is the default value.
Regarding the units - I believe they are correct, it seems that you have the wrong units in the constant.
Could you, please, write in details the units are used in this equation:
Hello,
I have a question related to density calculation. I'd like to mention @kibbi10, as he is involved in developing a port to python3. I have found a guide for recalculation here: http://genx.sourceforge.net/doc/faq.html#how-do-i-transform-from-g-cm3-to-formula-unit-a3 The problem is - I am trying to apply this method for polymers. Example: Polyethylene (C2H4)n, which is definitely equal to (CH2)2n. Basically the composition could be like this: C2000H4000 or C1000H2000 with the same density [g/cm^3]. In this case, how one should calculate density in [unit/Å^3] to obtain correct value?
I am using this code, which reflects the described situation:
Thank you.