Python Modules for Transmission Electron Diffraction Simulations
Project description
Introducing pyemaps
Overview ↩
pyemaps package is a collection of python modules and libraries designed for transmission electron diffraction simulations and related crystallographic calculations. Main features include:
Kinematic and Dynamic Diffraction Simulations
Electron Powder Diffraction Simulations
Crystallographic Transformations and Calculations
Crystal Structure Factors Calculations
- X-Ray Structure Factors
- Electron Structure Factor in V (volts)
- Electron Structure Factor in 1/Å^2
- Electron Absorption Structure Factor in 1/Å^2
pyemaps comes with a set of helper classes with the intent of making accesses to above feature easy for users:
-
Crystal : crystal data module, classes and methods for loading crystal data from various data sources such pyemaps' own builtin data formatted files and (IUCr) Crystallographic Information Framework (CIF); for preparing microscope and sample control parameters for the above simulations.
-
EMC : electron microscope control module. Its class EMC makes it easy to handle simulation control parameters.
-
DP : kinematic diffraction python class. It encapsulates and models diffraction pattern generated from Crystal class instance.
-
BlochImgs : dynamic diffraction images list class. This class is design for handling multiple slices of bloch images with their associated controls.
-
Display: This python helper class provides a builtin visualisation of kinematic diffraction patterns with Kikuchi and HOLZ lines, and diffracted beams or disks and their Miller indices. Its methods also include rendering of dynamic diffraction (Bloch) images. Users can easily replace or extend these methods into their own application.
-
Errors: Error handling for pyemaps, capturing errors and making actionable and trackable error messages.
See sample code and latest release notes for details.
pyemaps is based on the proprietary Fortran applications released as backend of cloudEMAPS2.0.
Check EMlab Solution, Inc. for updates and releases. We welcome comments and suggestions from our user community. For reporting any issues and requesting pyemaps improvements, or sharing scripts using pyemaps, please go to our support page.
If you benefit from pyemaps in your microscopy and crystallography research and education and would like to donate, go to PayPal. Your generous donations are greatly appreciated and will keep us in the business of providing free software to the communities.
Requirements ↩
-
Python: Version >= 3.6
-
numpy: Version >= 1.21.2
-
matplotlib: Version >= 3.2.1
-
PyCifRW Version == 4.4.3
-
Operating Systems: Windows, 64-bit, >= 8GB RAM
Linux support planned in future releases, stay tuned.
Installation ↩
(.venv) $ pip install pyemaps
where .venv is the python virtual environment
PYEMAPS_CRYSTALS environment variable is optional. But setting it to a directory where all custom
crystal data files are located provides central location for organizing your own crystal data. pyemaps also searches this directory for your crystal data.
PYEMAPS_CRYSTALS=<local directory>
See FAQ for solutions to possible installation issues.
Basic Usage ↩
from pyemaps import Crystal
from pyemaps import DP
Getting Started ↩
Run the following on command line, after above successful installation:
python sample.py
where sample.py is as follows:
from pyemaps import Crystal as cr
from pyemaps import showDif, showBloch
from pyemaps import DPList
# create a crystal class instance and load it with builtin silicon data
c_name = 'Silicon'
si = cr.from_builtin(c_name)
# generate diffraction on the crystal instance with all default controls
# parameters, default controls returned as the first output ignored
dpl = DPList(c_name)
emc, si_dp = si.generateDP()
dpl.add(emc, si_dp)
#plot and show the diffraction pattern using pyemaps built-in plot function
showDif(dpl)
#hide Kikuchi lines
showDif(dpl, kshow=False)
#hide both Kukuchi line and Miller Indices
showDif(dpl, kshow=False, ishow=False)
#hide Miller Indices
showDif(dpl, ishow=False)
#Generate dynamic diffraction patterns using pyemaps' bloch module
bloch_imgs_list = []
emc, img = si.generateBloch() #with all default parameters
#create a dynamic diffraction pattern list /w assiated controls
bloch_imgs_list.append((emc, img))
showBloch(bloch_imgs_list, name = c_name) #grey color map
showBloch(bloch_imgs_list, bColor=True) #with predefined color map
The alternative to run the above without creating sample.py:
python -m pyemaps --sample (-s)
The diffraction plot is generated with silicon crystal data built in the package:
crystal Silicon: dw = iso
cell 5.4307 5.4307 5.4307 90 90 90
atom si 0.125 0.125 0.125 0.4668 1.00
spg 227 2
and default electron microscope and sample control parameters:
zone axis: (0,0,1)
microscope mode: normal
microscope camera length : 1000 mm
microscope voltage: 200 V
sample tilt: (0.0,0.0)
sample offset: (0.0,0.0)
spot size: 0.05 Å
The following is the dynamic diffraction pattern for Silicon builtin crystal with sampling set at 20. The left is the image in gray scale and the righ in a predefined color map
To see all crystal names with builtin data, call:
from pyemaps import Crystal as cr
cr.list_all_builtin_crystals()
To use a crystal data not in built-in database in above format (as xtl format), replace the code in sample.py:
from pyemaps import Crystal as cr
si = cr.from_builtin('Silicon')
with:
from pyemaps import Crystal as cr
si = cr.from_xtl(fn)
CIF format has recently been added to crystal data sources where pyemaps can import:
from pyemaps import Crystal as cr
si = cr.from_cif(fn)
where fn is a crystal data file name. See release notes for details how pyemaps imports .cif data
Note: pyemaps searches for fn if the full path is provided. Otherwise, it will look up the file in current working directory or in the directory set by PYEMAPS_CRYSTALS environment variable. In latter cases, fn is the file name without path.
Checking pyemaps version and displaying copyright information:
python -m pyemaps -c (--copyright)
python -m pyemaps -v (--version)
Visualisation ↩
Accessing diffraction patterns data is easy for pyemaps users to visualize the diffraction patterns in any programs other than pyemaps' builtin plot with python's matplotlib library:
- Raw kinematic diffraction data (DP) in python dictionary:
dp.__dict__ #dp is a pyemaps DP class object generated from calling generateDP by a crystal object
- Individual components (such as Kikuchi lines, Diffracted beams or HOLZ lines) as python lists:
dp.klines #Kikuchi lines list
dp.nklines #number of Kikuchi lines, same as len(dp.klines)
dp.disks #diffracted beams list
dp.ndisks #number of diffracted beams, same as len(dp.disks)
dp.hlines #HOLZ lines list
dp.nklines #number of HOLZ lines, same as len(dp.hlines)
dp.shift #deflection shifts of all of the above
...
- Raw dynamic diffraction data (Bloch) is an numpy array of floats with dimension of NxN where N is the detector size input for generateBloch(...) function. Each point in the array represent the image intensity. Pyemaps uses Python matplotlib in its builtin display function showBloch(). See its usage in sample code si_bloch.py
Sample scripts designed for you to explore pyemaps features are available in pyemaps' samples directory:
-
si_dif.py: spot diffraction patterns generated with silicon crystal data, plotted with matplotlib pyplot module. The code also shows how a list of diffraction patterns are generated and changed with one of electron microscope and sample controls - tilt in x direction.
-
si_bloch.py: demonstrates dynamic diffraction generation with similar control changes.
-
si_csf.py: structure factors generation and output by CSF pyemaps module.
-
powder.py: electron powder diffraction generation and intensity plot by ____ pyemaps module.
More samples code will be added as more features and releases are available.
To copy all of the samples from pyemaps package to the current working directory, following pyemaps installation. Run:
python -m pyemaps -cp (--copysamples)
all of the samples will be copied from pyemaps install directory to a folder named pyemaps_samples in your current working directory.
Licence ↩
pyemaps is distributed for electron diffraction and microscopy research, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more details.
-
pyemaps is for non-commercial use.
-
pyemaps is free software under the terms of the GNU General Public Licence as published by the Free Software Foundation, either version 3 of the Licence, or (at your option) any later version. You should have received a copy of the GNU General Public Licence along with pyemaps. If not, see https://www.gnu.org/licenses/.
Additional copyright notices and license terms applicable to portions of pyemaps are set forth in the COPYING file.
Contact supprort@emlabsoftware.com for any questions regarding the licence terms.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyemaps-0.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d8b8df670e3e03f480a1e3a7e0e63d70ecac2f8688002377afe48ac3e5e6f3d |
|
MD5 | d5909410e8860c09364b8e82c61f8d89 |
|
BLAKE2b-256 | f5759a65e4206133a5f8d6ebe5daad3036435ff955eabe23b02e6891f61b3e59 |