danporter / dans_diffraction Goto Github PK
View Code? Open in Web Editor NEWReads crystallographic cif files and simulates diffraction
License: Apache License 2.0
Reads crystallographic cif files and simulates diffraction
License: Apache License 2.0
Hi,
I used your package and it worked fine for my use.
I may publish my work at the end of the process.
Do you have any idea about how I can cite your work ?
Thanks
Hi Dan,
Great code - thanks!
I was wondering if you have plans to add a voigt peak shape (see here).
I remember that realistically, line profiles usually have this lineshape. Gaussians are usually rare.
it can be something like:
t = np.arange(-1000, 1000, 0.1)
fwhmg = 2
fwhml = 2
v = sps.voigt_profile(t, fwhmg, fwhml)
I = np.convolve(I, v, 'same')
inside Scatter.generate_powder
. (I
is the pxrd profile with delta functions)
Question from Sirius Han, Princeton Uni
I had some questions about how intensities are calculated using the "print_all_reflections" method. To be precise, if I load in a .cif card and use the above method to calculate intensities, they vary somewhat considerably from the same .cif card loaded into, say, CrystalDiffract, or literature data from MinDat (I am a geoscientist, so my primary use case involves mineralogy data.)
For example, using the attached .cif card for Rutile, CrystalDiffract predicts
(hkl / I/Imax)
110 / 100
011 / 45.85
020 / 6.86
111 / 18.96
whereas using Dans-Diffraction, the following is calculated:
(hkl / I/Imax)
110 / 95.07
011 / 39.35
020 / 14.13
111 / 21.87
Another example: using the attached .cif card for Spinel, CrystalDiffract predicts
(hkl / I/Imax)
113 / 11.5
whereas Dans-Diffraction calculates:
(hkl / I/Imax)
113 / 0.00015
Hi Dan,
How about support python 3?
I did a simple migration with 2to3.py and some manual work. After running some examples, it seems that this project can be migrated to python 3 smoothly.
If you are going to support python 3, I can create a pull request.
Attachment is the log of migration. Most unsupported codes are 'print'.
Hepesu
Hi, I am going to use this great project to simulate X-ray diffraction result from cif. But when I , tried, I met an error in reading cif downloaded from CCDC, the entry id is 1000175. It gave this message.
Traceback (most recent call last):
File "D:/Workspace/ccdc/sims/test.py", line 3, in
xtl = Crystal('1000175.cif')
File "D:\Workspace\ccdc\sims\Dans_Diffraction\classes_crystal.py", line 99, in init
cifvals = fc.readcif(filename)
File "D:\Workspace\ccdc\sims\Dans_Diffraction\functions_crystallography.py", line 89, in readcif
while lines[n].split()[0][0] == '_':
IndexError: list index out of range
I tried to fix this by deleting lines that made the error, but it did not work.
I have a suggestion for this, how about using existing cif parser for cif parsing?
Thank you!
Hi
Is it possible to print the hkl, intensity and phase of each reflection? Or get the data in arrays?
Error Details:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[18], line 1
----> 1 import Dans_Diffraction as dif
2 xtl = dif.Crystal('2100636.cif')
3 xtl.info() # print Crystal structure parameters
File ~/opt/anaconda3/envs/Xerus/lib/python3.8/site-packages/Dans_Diffraction/__init__.py:105
1 """
2 Dans_Diffraction
3 Python package for loading crystal structures from cif files and calculating diffraction information.
(...)
97 Diamond Light Source, Chilton, Didcot, Oxon, OX11 0DE, U.K.
98 """
100 # Set TkAgg environment
101 #import matplotlib
102 #matplotlib.use('TkAgg')
103
104 # Dans Diffraction
--> 105 from . import functions_general as fg
106 from . import functions_plotting as fp
107 from . import functions_crystallography as fc
File ~/opt/anaconda3/envs/Xerus/lib/python3.8/site-packages/Dans_Diffraction/functions_general.py:647
643 B = np.dot(A, np.linalg.inv(CELL))
644 return B
--> 647 def isincell(A, cell_centre=[0, 0, 0], CELL=cell()):
648 """
649 Return boolean of whether vector xyx is inside a cell defined by position, size and rotation
650 A = [x,y,z] or [[x1,y1,z1]] array of positions
(...)
659 >>> [False,True,True]
660 """
662 A = np.asarray(A, dtype=np.float).reshape((-1, 3))
File ~/opt/anaconda3/envs/Xerus/lib/python3.8/site-packages/Dans_Diffraction/functions_general.py:631, in cell(lengths, rotation)
624 """
625 Returns a unit CELL with vectors defined by length and rotation (Deg)
626 :param lengths:
627 :param rotation:
628 :return:
629 """
630 CELL = np.eye(3) * lengths
--> 631 CELL = rot3D(CELL, *rotation)
632 return CELL
File ~/opt/anaconda3/envs/Xerus/lib/python3.8/site-packages/Dans_Diffraction/functions_general.py:200, in rot3D(A, alpha, beta, gamma)
183 def rot3D(A, alpha=0., beta=0., gamma=0.):
184 """Rotate 3D vector A by euler angles
185 A = rot3D(A,alpha=0.,beta=0.,gamma=0.)
186 where alpha = angle from X axis to Y axis (Yaw)
(...)
197 _\/X
198 """
--> 200 A = np.asarray(A, dtype=np.float).reshape((-1, 3))
202 # Convert to radians
203 alpha = alpha * np.pi / 180.
File ~/opt/anaconda3/envs/Xerus/lib/python3.8/site-packages/numpy/__init__.py:305, in __getattr__(attr)
300 warnings.warn(
301 f"In the future `np.{attr}` will be defined as the "
302 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
307 # Importing Tester requires importing all of UnitTest which is not a
308 # cheap import Since it is mainly used in test suits, we lazy import it
309 # here to save on the order of 10 ms of import time for most users
310 #
311 # The previous way Tester was imported also had a side effect of adding
312 # the full `numpy.testing` namespace
313 if attr == 'testing':
AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
When deal with CIF with large HKL range(or just large HKL list), calculate all intensities may use huge amount of mermory. This could be solved by splitting the HKL array into parts, calculating for each parts then merging back.
I use code below to solve the memory problem.
HKL = xtl.Cell.all_hkl(energy_kev, xtl.Scatter._scattering_max_twotheta)
intensity = []
HKL_split = np.array_split(HKL, len(HKL) // 1000)
for _HKL in HKL_split:
intensity += xtl.Scatter.intensity(_HKL).tolist()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.