Computational XRD: Difference between revisions
| (14 intermediate revisions by the same user not shown) | |||
| Line 9: | Line 9: | ||
Here we give an example of how to generate nanoparticles with different dislocations. One may have to play around a bit with the directories to make sure that the files get opened and written to the correct places. A python version of the MD++ code is necessary. The relevant python files are: |
Here we give an example of how to generate nanoparticles with different dislocations. One may have to play around a bit with the directories to make sure that the files get opened and written to the correct places. A python version of the MD++ code is necessary. The relevant python files are: |
||
generate_particles.py |
generate_particles.py |
||
XRDsetup.py |
XRDsetup.py |
||
and these can be run with the command: |
and these can be run with the command: |
||
| ⚫ | |||
bin/eam generate_particles.py |
bin/eam generate_particles.py |
||
</pre> |
|||
'''Notable Parameters''' |
'''Notable Parameters''' |
||
| Line 27: | Line 27: | ||
</pre> |
</pre> |
||
This generates a series of .cn, .cfg, and a file of atomic positions which will be read by the C++ code to calculate the Intensity. |
This generates a series of .cn, .cfg, and a file of atomic positions which will be read by the C++ code to calculate the Intensity. |
||
===Intensity Calculation in C++=== |
===Intensity Calculation in C++=== |
||
First, make sure the required libraries are installed. The GSL |
First, make sure the required libraries are installed. The GSL and C++11 packages are required (the GSL library is for easily making histograms). The required files are the previous file of atomic positions written by generate_particles.py and the following C++ file which can be run as: |
||
Now we are ready to run |
|||
| ⚫ | |||
| ⚫ | |||
<pre> |
<pre> |
||
| ⚫ | |||
</pre> |
|||
followed simply by |
followed simply by |
||
<pre> |
<pre> |
||
./XRD.exe |
./XRD.exe |
||
<pre> |
</pre> |
||
'''Parameters''' |
'''Parameters''' |
||
| Line 49: | Line 46: | ||
<pre> |
<pre> |
||
flag = 0 |
flag = 0 |
||
Radius = 40 |
Radius = 40 |
||
| ⚫ | |||
wavelength = 0.67 # the wavelength of the incident monochromatic X-ray beam |
|||
# this needs to be adjusted to larger values for large runs |
|||
# because of memory issues. If not set properly, the code will |
|||
| ⚫ | |||
# exit with a memory error. |
|||
# the background noise is quite dependent on this |
|||
| ⚫ | |||
# parameter so don't make it too small |
|||
| ⚫ | |||
</pre> |
</pre> |
||
I plan to run several different sizes and compare the time taken for this calculation for a fixed num_bins, divs, and N to access the scalability. Currently the code is highly un-optimized |
I plan to run several different sizes and compare the time taken for this calculation for a fixed num_bins, divs, and N to access the scalability. Currently the code is highly un-optimized (completely serial) and still runs very fast. A 4 nm nanoparticle calculation takes ~30 seconds with this code. |
||
===Plotting and Interpolating=== |
===Plotting and Interpolating=== |
||
The next step is to read the file of Intensities and Q values into the python script attached. The Intensity and Q values that are either background before the first real Bragg peak or are small values past Q~20 are gotten rid of. The interpolation is only done on the largest 5-10 peaks. The number of peaks that can be reasonably interpolated decreases with increasing number of dislocations as the peaks broaden. |
The next step is to read the file of Intensities and Q values into the python script attached. The Intensity and Q values that are either background before the first real Bragg peak or are small values past Q~20 are gotten rid of. The interpolation is only done on the largest 5-10 peaks. The number of peaks that can be reasonably interpolated decreases with increasing number of dislocations as the peaks broaden. The following file plots and interpolates the intensity and it should be run as: |
||
<pre> |
|||
python MD++_plot.py Radius flag cutoff |
|||
</pre> |
|||
where Radius, flag, and cutoff are parameters. These are some important parameters to consider, especially in the interpolation. |
|||
'''Parameters''' |
'''Parameters''' |
||
| Line 70: | Line 73: | ||
Radius = int(sys.argv[1]) |
Radius = int(sys.argv[1]) |
||
flag = int(sys.argv[2]) |
flag = int(sys.argv[2]) |
||
cutoff = |
cutoff = float(sys.argv[3]) # Bragg peaks with maximum below this cutoff will be ignored |
||
tol = 0.1 # The Q range around which the program searches for a half-maximum |
tol = 0.1 # The Q range around which the program searches for a half-maximum. |
||
# This really doesn't need to be changed |
|||
</pre> |
</pre> |
||
Thus the cutoff must be chosen carefully if one wants to get the most number of peaks that have resolved half-widths. This gets more important with increased peak broadening. |
|||
===CUDA Code=== |
===CUDA Code=== |
||
The code is obviously parallel. The next step is to re-write the code in CUDA to improve speed. The vast majority of time is spent in the distances calculation so for now, only this section will be made into a CUDA kernel. As the particles get bigger and more heavily deformed, the number of bins may need to be increased, leading to a notable increase in the XRD time. Unless the number of bins necessary is outrageously large (even at the huge overkill of 100,000 bins for a 4 nm nanoparticle, the entire calculation of distances + XRD takes 75 seconds), the XRD time should not get too large from this contribution. One important note is that the cluster of GPUs need to have the GSL libraries available. |
|||
The code is obviously parallel. The next step is to re-write the code in CUDA to improve speed. |
|||
Latest revision as of 21:57, 23 August 2015
Computational XRD
Making Nanoparticles
Here we give an example of how to generate nanoparticles with different dislocations. One may have to play around a bit with the directories to make sure that the files get opened and written to the correct places. A python version of the MD++ code is necessary. The relevant python files are: generate_particles.py XRDsetup.py
and these can be run with the command:
bin/eam generate_particles.py
Notable Parameters
# flag = 0 is no dislocations # flag = 1 is only one dislocation # flag = 2 is multiple randomly generated dislocations flag = 0 start = 40 # Radius of the nanoparticle numDisls = 6 # if flag == 2, the number of dislocations
This generates a series of .cn, .cfg, and a file of atomic positions which will be read by the C++ code to calculate the Intensity.
Intensity Calculation in C++
First, make sure the required libraries are installed. The GSL and C++11 packages are required (the GSL library is for easily making histograms). The required files are the previous file of atomic positions written by generate_particles.py and the following C++ file which can be run as:
g++ -o XRD.exe XRD.cpp -lgsl -lgslcblas -lm -std=c++11
followed simply by
./XRD.exe
Parameters
flag = 0
Radius = 40
wavelength = 0.67 # the wavelength of the incident monochromatic X-ray beam
num_bins = 25000 # the number of bins in the histogram per division
# the background noise is quite dependent on this
# parameter so don't make it too small
N = 10000 # the number of Intensity points to calculate
I plan to run several different sizes and compare the time taken for this calculation for a fixed num_bins, divs, and N to access the scalability. Currently the code is highly un-optimized (completely serial) and still runs very fast. A 4 nm nanoparticle calculation takes ~30 seconds with this code.
Plotting and Interpolating
The next step is to read the file of Intensities and Q values into the python script attached. The Intensity and Q values that are either background before the first real Bragg peak or are small values past Q~20 are gotten rid of. The interpolation is only done on the largest 5-10 peaks. The number of peaks that can be reasonably interpolated decreases with increasing number of dislocations as the peaks broaden. The following file plots and interpolates the intensity and it should be run as:
python MD++_plot.py Radius flag cutoff
where Radius, flag, and cutoff are parameters. These are some important parameters to consider, especially in the interpolation.
Parameters
wavelength = 0.67
Radius = int(sys.argv[1])
flag = int(sys.argv[2])
cutoff = float(sys.argv[3]) # Bragg peaks with maximum below this cutoff will be ignored
tol = 0.1 # The Q range around which the program searches for a half-maximum.
# This really doesn't need to be changed
Thus the cutoff must be chosen carefully if one wants to get the most number of peaks that have resolved half-widths. This gets more important with increased peak broadening.
CUDA Code
The code is obviously parallel. The next step is to re-write the code in CUDA to improve speed. The vast majority of time is spent in the distances calculation so for now, only this section will be made into a CUDA kernel. As the particles get bigger and more heavily deformed, the number of bins may need to be increased, leading to a notable increase in the XRD time. Unless the number of bins necessary is outrageously large (even at the huge overkill of 100,000 bins for a 4 nm nanoparticle, the entire calculation of distances + XRD takes 75 seconds), the XRD time should not get too large from this contribution. One important note is that the cluster of GPUs need to have the GSL libraries available.