McCode icon indicating copy to clipboard operation
McCode copied to clipboard

cif2hkl produce file with wrong density

Open tkittel opened this issue 2 years ago • 6 comments

As noticed today with @willend, the commands:

cif2hkl --powder --mode NUC -o Al.hkl Al.cif 
cif2hkl --xtal --mode NUC -o Al.xhkl Al.cif

produce files with wrong density values (but correct unitcell "weight" and volume):

# density           1.64419 in [g/cm^3]
# weight          107.92616 in [g/mol]
# Vc               65.64102 volume of unit cell in [A^3]

The density of Al should be roughly 2.7g/cm3 which is indeed what is found from the weight and Vc values above.

tkittel avatar Mar 24 '22 16:03 tkittel

@farhi FYI

willend avatar Mar 24 '22 19:03 willend

We can see in the cif2hkl repo:

  • https://gitlab.com/soleil-data-treatment/soleil-software-projects/cif2hkl/-/blob/master/cif2hkl.F90#L549

that the density is indeed calculated from the mass and cell volume. In the example above we have

  • density = 107.92616 /65.64102 = 1.64

which is wrong. The cell volume seems OK, so it comes from the mass, defined at:

  • https://gitlab.com/soleil-data-treatment/soleil-software-projects/cif2hkl/-/blob/master/cif2hkl.F90#L369

and computed at:

  • https://gitlab.com/soleil-data-treatment/soleil-software-projects/cif2hkl/-/blob/master/cif2hkl.F90#L474

farhi avatar Mar 25 '22 13:03 farhi

I think the cell volume and masses are both OK (after all, 4 aluminium atoms should have a mass of about 4*27=108g/mole), but you are leaving out a factor of Avogadros constant and a factor of 1e24 (from Aa^3->cm^3):

density =  (107.92616g/(mole=6.0221409e+23) ) * 65.64102Aa^3 *  (1e-24cm^3/Aa^3))
            =  1.660539 * (107.92616 /65.64102 ) g/cm^3
            = 2.730 g/cm^3

tkittel avatar Mar 25 '22 13:03 tkittel

Great, I'll push it immediately.

farhi avatar Mar 25 '22 13:03 farhi

Great.

@farhi let me know once you did push to the SOLEIL repo - then I will update the copies cif2hkl that are in the McCode repo. (And plan for retrieving the newest version of the F90 at build time rather than today's situation which will easily be a game of apples and pears...)

willend avatar Mar 25 '22 13:03 willend

I am afraid something is still off, I just rebuilt and got the attached Al.hkl.txt which has a density of 0. :-)

willend avatar Mar 25 '22 17:03 willend

Upgrade cif2hkl to version 1.4.2 from:

  • https://gitlab.com/soleil-data-treatment/soleil-software-projects/cif2hkl

compile with:

  • gfortran -ffree-line-length-512 cif2hkl.F90 -lm

this issue is related to #899

farhi avatar Nov 08 '22 15:11 farhi

Close with commit 75b65de29de3fb509b70e12faaade39b5150174a

farhi avatar Nov 08 '22 15:11 farhi

Scanning dependencies of target cif2hkl
[ 25%] Building Fortran object CMakeFiles/cif2hkl.dir/libs/cif2hkl/cif2hkl.F90.o
/Users/pkwi/McCode/mcstas-comps/libs/cif2hkl/cif2hkl.F90:65097:16:

65012 |       do k = n, 1, -1
      |                     2
......
65097 |           y = w(k-1)
      |                1
Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at (2)
/Users/pkwi/McCode/mcstas-comps/libs/cif2hkl/cif2hkl.F90:65098:18:

65012 |       do k = n, 1, -1
      |                     2
......
65098 |           g = rv1(k-1)
      |                  1
Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at (2)
[ 50%] Linking Fortran executable cif2hkl
[ 50%] Built target cif2hkl
Scanning dependencies of target neutronics
[ 75%] Building Fortran object CMakeFiles/neutronics.dir/libs/neutronics/neutronics-subs.f.o
[100%] Linking Fortran static library libneutronics.a
[100%] Built target neutronics

willend avatar Nov 08 '22 15:11 willend