Giter Club home page Giter Club logo

xrd's Introduction

XRD

X-ray diffraction calculations.

NOTE

Much of this functionality has been merged into PyXtal (see this tutorial notebook for more information).

VXRD: Virtual X-Ray Diffraction

NOTE

The VXRD web app has also been merged into PyXtal (see this page for details).

In order to run and view VXRD locally, run the following shell commands:

$ cd XRD
$ pip install -r requirements.txt
$ cd ./flask
$ flask run

It's important to rerun pip install -r requirements.txt if this repository has been updated in case there are any new dependencies.

If everything is setup correctly, you should see the following output:

 * Serving Flask app "vxrd.py"
 * ...
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Then, open your web browser and enter the following URL: http://localhost:5000/

When finished, press CTRL+C in your terminal to shutdown the web-app.

VXRD: JSmol

In order to see the 3D structure visualized with JSmol, you'll need to unzip jsmol.zip into the following directory:

$ unzip jsmol.zip ./flask/app/static/

xrd's People

Contributors

dependabot[bot] avatar glading avatar qzhu2017 avatar sabaronett avatar sayred1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

xrd's Issues

Structure Factor + Additional Profiling

Deadline 2/19

Additional Profiling

  • Add original PV function.
  • Update the Profiling-Demo.ipynb
  • Assign reasonable default parameters for this choice.

Structure Factor

Notes

  • The possible number of parameters will depend on the user. If the user wants, they may specify a FWHM that is different for the composite G and L functions, along with the eta parameter. Else, the user can specify a FWHM that is the same for G and L, along with eta.
  • The two PV functions must have different names.
  • Ignore Debye-Waller corrections.
  • The dispersion corrections ( f' and f'') are dependent on the radiation. (An example of Li is below)

Screen Shot 2020-02-20 at 2 05 48 PM

  • VESTA uses scattering factors that aren't tabulated in IUCr. Per a meeting with Keith, either gut GSAS (a more commonly used refinement software) and use their parameters, or look into literature for updated parameters with 11 scattering terms.

FWHM

@sayred1
Please implement the angle dependent FWHM to XRD calculation. Also please quickly compare the results with VESTA/Mercury for a few structures. See if you can get the good fit.

Weight function in similarity calculation

@sayred1
Right now, the triangle function is used.
image

l in the above equation should be consistent to r_range values. Why did you set 0.6 here?.

def __init__(self, f, g, N = None, x_range = None, r_range = None, weight = {'function': 'triangle', 'params': 0.6}):

However, triangle function is not smooth. I suggest you also add the cosine function used in our PyXtal_FF
image

This can ensure that the function smoothly goes to zero when r is approaching to r_cut.

VXRD: Enhancements

VXRD: Self-Gen. Structs

Tasks

  • Dynamic Energy vs. Similarity scatter plot (JS)
  • E vs. S points show corresponding plotly (on-click)
  • Historical jobs queued/listed w/ progress and cancelation.

Discrepancy between our XRD and vesta

For the same input

(base) qiangzhu@Qiangs-MacBook-Pro-2 XRD (master) $ python scripts/pxrd.py -c dataset/Acmm-POSCAR
  2theta     d_hkl     hkl       Intensity  Multi
  14.124     6.271   [ 0  0  2]    10.96        2
  15.486     5.722   [ 1  0  0]     4.73        2
  21.018     4.227   [ 1  0  2]     0.08        4
  23.089     3.852   [ 1  1  1]    50.54        8
  28.469     3.135   [ 0  0  4]    13.68        2
  30.747     2.908   [ 1  1  3]   100.00        8
  31.237     2.863   [ 0  2  0]    23.83        2
  31.264     2.861   [ 2  0  0]    20.41        2
  32.566     2.750   [ 1  0  4]     0.98        4

While the vesta output is
image

The intensity for [002] is very different.

@sayred1 please check what happened.

formula to determine hkl_max

    h1 = 2*int(np.linalg.norm(crystal.cell_para[0])/d_min)
    k1 = 2*int(np.linalg.norm(crystal.cell_para[1])/d_min)
    l1 = 2*int(np.linalg.norm(crystal.cell_para[2])/d_min)

The above formula is only correct for orthorhombic system

VXRD: Experimental Data

Tasks

  • Create new route for experimental comparison.
  • Copy new HTML template from existing comp.
  • Add new FileField to forms.py w/ diff. description (e.g., "Experimental data")
  • Update upload field (forms.py) description to "Structure File"
  • Update base.html w/ navbar link

@sabaronett
This webpage will be similar to #27 except that it does not takes the 2nd structure as the reference. It will take the experimental PXRD pattern with 2D array (2theta, peaks)

I will upload some experimental data file and script later.

XRD is not consistent with Mercury

@sayred1
I tried to use the same file (NaCl.cif) to compute the XRD, and compared it with Mercury. 8971765

The results are shown below. Clearly, we have a significant off for the 3rd peak. Could you just focus on that peak and recheck if the intensity is calculated correctly? I am thinking if this is because we missed some correction term or simply because we messed some expression in the current correction terms.

image

Please do this in time. If you are not clear about my concern, please talk to me. We have wasted a lot of time.

Discrepancy between XRD and .diff file

@sayred1 I looked into the problem again. So the reason why the diff file from on-line validation set generates different PXRD intensity is because they take into account of anisotropic displacement.

 47 loop_
 48 _atom_site_label
 49 _atom_site_fract_x
 50 _atom_site_fract_y
 51 _atom_site_fract_z
 52 _atom_site_U_iso_or_equiv
 53 Pb   0.22046   0.25000   0.14651 ?
 54 O   0.00000   0.00000   0.25000   0.01165
 55 F   0.50000   0.00000   0.25000   0.02115
 56 Cl   0.22270   0.25000   0.50000   0.02216
 57 loop_
 58 _atom_site_aniso_label
 59 _atom_site_aniso_U_11
 60 _atom_site_aniso_U_22
 61 _atom_site_aniso_U_33
 62 _atom_site_aniso_U_12
 63 _atom_site_aniso_U_13
 64 _atom_site_aniso_U_23
 65 Pb 1.47629 1.32923 1.24297 0.05810 0.12724 0.12735

https://www.iucr.org/__data/iucr/cifdic_html/1/cif_core.dic/Iatom_site_aniso_label.html

Scattering Factor

@qzhu2017

I've finished rewriting our scattering factor term to match pymatgen's code. I haven't compared it with pymatgen yet because I ran into something dealing with the pre-loaded scattering terms for each element.

Choosing SrF as the structure, pymatgen's scattering terms for Sr and F are 

[[  5.848 104.972]
  [  4.003  19.367]
  [  2.342   3.737]
  [  0.88    0.414]] 

[[  0.387  20.239]
 [  0.811   6.609]
 [  0.475   1.931]
 [  0.146   0.279]]

respectively.

Ours are

[[ 17.566   9.818   5.422   2.669   1.556  14.099   0.166 132.376   2.506]

 [  3.539   2.641   1.517   1.024  10.283   4.294   0.262  26.148   0.278]]

respectively.

I'm able to reshape ours to match their array shape, then proceed to calculating the scatter factor, but I'm not sure which subset of terms to use.

For now, I will just use their terms and ensure that our scattering terms match.

VXRD: Comparison

VXRD comparison

  • Build add'l page (route) for comparing the PXRD for two structures 720cc4e
  • Add another load menu for the 2nd structure 720cc4e
  • Add the additional shiftfield in this page (default=2.0) c6d3006
  • Debug "missing 2nd file" issue 8b92166
  • Verify comparison() route works 0aaa3bb
  • Final verification of plot w/ similarity #27 (comment)
  • Add vertically-stacked JSmol w/ 2x2 grid (plot in lower-left) a02536f
  • Create new branch "multicompare"
  • Multi-upload comparison, see #27 (comment)
    • Show dynamic list of structures from upload2, w/ 1st defaulted
    • Allow single selection of radio list to update JSmol2 and plotly comparison

Reference

Validation Dataset

@sayred1

After you implemented the similarity function,
I suggest you collect a database for systematic validation. Similar to what you have done for NaCl, select each representative structure from space group 1-230. Collect the experimental PXRD and compute the PXRD from Mercury and our own code. And then compute the similarity.

I will tell you more details on Friday.

VXRD: Profiling

@sabaronett

So far, we have four options of profiling functions in the pxrd code.

  • Gaussian: fwhm
  • Lorentzian: fwhm
  • Pseudo-Voigt: fwhm, eta,
  • Mod-pseudo-Voigt: fwhm, A, eta_h, eta_l, N
    @nb.njit(nb.f8[:](nb.f8[:], nb.f8, nb.f8, nb.f8, nb.f8, nb.i8), cache = True)
    def mod_pseudo_voigt(x, fwhm, A, eta_h, eta_l, N):
    """
    A modified split-type pseudo-Voigt function for profiling peaks
    - Izumi, F., & Ikeda, T. (2000).
    """
    tmp = np.zeros((N))
    for xi, dx in enumerate(x):
    if dx < 0:
    A = A
    eta_l = eta_l
    eta_h = eta_h
    else:
    A = 1/A
    eta_l = eta_h
    eta_h = eta_l
    tmp[xi] = ((1+A)*(eta_h + np.sqrt(np.pi*np.log(2))*(1-eta_h))) /\
    (eta_l + np.sqrt(np.pi*np.log(2)) * (1-eta_l) + A*(eta_h +\
    np.sqrt(np.pi*np.log(2))*(1-eta_h))) * (eta_l*2/(np.pi*fwhm) *\
    (1+((1+A)/A)**2 * (dx/fwhm)**2)**(-1) + (1-eta_l)*np.sqrt(np.log(2)/np.pi) *\
    2/fwhm *np.exp(-np.log(2) * ((1+A)/A)**2 * (dx/fwhm)**2))
    return tmp
    @nb.njit(nb.f8[:](nb.f8, nb.f8[:], nb.f8), cache = True)
    def gaussian(theta2, alpha, fwhm):
    """
    Gaussian function for profiling peaks
    """
    tmp = ((alpha - theta2)/fwhm)**2
    return np.exp(-4*np.log(2)*tmp)
    @nb.njit(nb.f8[:](nb.f8, nb.f8[:], nb.f8), cache = True)
    def lorentzian(theta2, alpha, fwhm):
    """
    Lorentzian function for profiling peaks
    """
    tmp = 1 + 4*((alpha - theta2)/fwhm)**2
    return 1/tmp
    def pseudo_voigt(theta2, alpha, fwhm, eta):
    """
    Original Pseudo-Voigt function for profiling peaks
    - Thompson, D. E. Cox & J. B. Hastings (1986).
    """
    L = lorentzian(theta2, alpha, fwhm)
    G = gaussian(theta2, alpha, fwhm)
    return eta * L + (1 - eta) * G

At the moment, we have three options in vxrd:

  • Gaussian: fwhm
  • Lorentzian: fwhm
  • Pseudo-Voigt: This is actually Mod-pseudo-Voigt

Can you try to fix this and make it be consistent with our pard code.

VXRD: Forms

Tasks

  • Turn on debug mode until app goes live 7163d67
  • 5 to 180 for 2θ 9ef33aa
  • 0.1 to 5 min/max for wavelength 9ef33aa
  • Add FloatField for min2theta 7f4efc7
  • Add FloatField for profiling resolution res (default=0.01) 24ff445
  • Add SelectField for profiling functions (default=gaussian) c5e8929
  • Link to ASE with acceptable upload formats 69ec34e
  • Flash "current file" message (normal alert) bea5aa2
  • Add FloatField for FWHM (min=1e-3, max=1.0, default=0.02) f279b04
  • Add FloatFields for pseudo-Voigt (similar ranges) f279b04
  • Implement multi-column form e40eb52
  • Dynamic sub-form for gaussian/lorentzian vs. pseudo_voigt params 7d966a2
  • Finalize form layout (sketch)
  • Put 2θ min/max fields on same line. 7d966a2
  • Implement final form layout 7d966a2
  • Fix pseudo-Voigt bug after submit c118a95
  • Add JSmol (moved to #21 (comment))
  • Set min/max for V (pseudo-Voigt) 28bba36
  • Update titles to "Virtual X-ray Diffraction" (VXRD) 0c578a0
  • Fix missing validation bug on profile param fields 7da4221
  • Investigate HTTP 500 on prod server for pseudo-Voigt profiling be0cbf9

Reference

  • Profiling demo: 671da96 for reference in advanced form logic.

VXRD: Uploads

Issues

  • Currently, after a successful submission, form requires user to re-upload CIF.
  • Since POSCAR doesn't have file ext., had to temp. disabled built-in file upload form validator
    • Bad files (CIF/POSCAR) or other file formats result in error

Tasks

  • Allow use of last upload for subsequent parameter changes/calculations by default. fb85cf4
  • Add POSCAR support 041bead
  • Finish custom validator using ase.io.read 85201a5

Import Errors

Steps to reproduce

  1. Create fresh conda venv w/ Python 3.8.1 (last known working version of VXRD);
  2. Followed README.md instructions to install requirements.txt;
  3. Ran Flask w/ flask run

Error

 * Serving Flask app "vxrd.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: While importing "vxrd", an ImportError was raised:

Traceback (most recent call last):
  File "/home/stanley/miniconda3/envs/xrd/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/home/stanley/github/sabaronett/XRD/flask/vxrd.py", line 1, in <module>
    from app import app
  File "/home/stanley/github/sabaronett/XRD/flask/app/__init__.py", line 16, in <module>
    from app import routes, errors
  File "/home/stanley/github/sabaronett/XRD/flask/app/routes.py", line 8, in <module>
    from pyxtal_xrd.XRD import XRD
ModuleNotFoundError: No module named 'pyxtal_xrd'

Similarity check for two structures

I just added the function to compute the XRDs for two structures and their similarity in 3a65f31

To run it you can go to scripts and do

$ python pxrd_comp.py -c [../dataset/NaCl.cif,../dataset/NaCl-POSCAR] -a [0,60]

This will generate a `1.html' file as follows
image

@sabaronett Can you try to enable this function in flask as well

@sayred1 The computed similarity is a bit funny. We can clearly find the two patterns are similar by eye. But the similarity is small. Need to check...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.