| Title: | 'cry' and 'rgl' — Applications in Crystallography |
|---|---|
| Description: | Visualizing crystal structures and selected area electron diffraction (SAED) patterns. It provides functions cry_demo() and dp_demo() to load a file in 'CIF' (Crystallographic Information Framework) formats and display crystal structures and electron diffraction patterns. The function dp_demo() also performs simple simulation of powder X-ray diffraction (PXRD) patterns, and the results can be saved to a file in the working directory. The package has been tested on several platforms, including Linux on 'Crostini' with a Core™ m3-8100Y Chromebook, I found that even on this low-powered platform, the performance was acceptable. T. Hanashima (2001) <https://www2.kek.jp/imss/pf/tools/sasaki/sinram/sinram.html> Todd Helmenstine (2019) <https://sciencenotes.org/molecule-atom-colors-cpk-colors/> Wikipedia contributors (2023) <https://en.wikipedia.org/w/index.php?title=Atomic_radius&oldid=1179864711>. |
| Authors: | Toshihide Saitou [aut, cre, cph] |
| Maintainer: | Toshihide Saitou <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.1 |
| Built: | 2026-06-05 07:05:40 UTC |
| Source: | https://github.com/saitoutoshihide/rgl.cry |
Align crystal and diffraction pattern and displayed.
align(ax, dev = NULL, verbose = TRUE)align(ax, dev = NULL, verbose = TRUE)
ax |
An axis to align |
dev |
RGL device to apply. Defaults to current device. |
verbose |
logical: Should the report be suppressed? |
There is no z-axis alignment support because the visualization was created with the analogy of selected area electron diffraction (SAED) on transmission electron microscope (TEM) which typically have up to two axes. However you can rotate around the z-axis by the drag originates near the window edge.
No return value, called for side effects.
if (interactive()) { align("a") align("rb") align("1 1 0") align("60 -30") align(dev = 123, "a") }if (interactive()) { align("a") align("rb") align("1 1 0") align("60 -30") align(dev = 123, "a") }
Read a file in CIF formats, set the parameters, calculates them, and draws the crystal structure with an axis widget.
cry_demo( file = NULL, rf = 1, type = "b", zoom = 1, abc = c(0, 0, 0), clipplanes = rbind(c(0, 0, 0, 0)) )cry_demo( file = NULL, rf = 1, type = "b", zoom = 1, abc = c(0, 0, 0), clipplanes = rbind(c(0, 0, 0, 0)) )
file |
Optional file in CIF formats. The file can also be specified by URL. |
rf |
A positive value indicating the scale factor of atom radius. |
type |
A style of atom displaying such like ball, fill and ball-stick but ball-stick is not implemented. |
zoom |
A positive value indicating the current scene magnification. |
abc |
A length-3 integer vector of repetitions along the a, b, c axes. |
clipplanes |
A list of numeric vectors representing clip planes. Each vector should contain four elements (a, b, c, d). Round the values to one decimal places before making the final determination in the internal process. |
If no file argument is provided, and dp_demo() has been opened without
paired cry_demo(), the CIF parameters of already opened dp_demo() will be
used.
An integer the device number of the currently window.
cry_demo() cry_demo(system.file("orthorhombic_p.cif", package = "rgl.cry")) cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry"), abc = c(1,1,1), clipplanes = rbind(c(2.885490, 4.158112, -3.374928, -37.01), c(2.885490, -5.082574, 1.687449, -37.01), c(-5.7709802, 0.9244616, 1.6874797, -37.01), c(-2.885490, -4.158112, 3.374928, -37.01), c(-2.885490, 5.082574, -1.687449, -37.01), c(5.7709802, -0.9244616, -1.6874797, -37.01), c(5.771090, 8.316383, 15.180433, -332.92), c(-5.771090, -8.316383, -15.180433, 0.01))) if (interactive()) { cry_demo(file, type = "fill", zoom = 0.5) cry_demo("https://www.crystallography.net/cod/foo.cif") ## A rhombohedral crystal. cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry")) ## Extract crystal structure data from the internal processing of the package. library(pryr) lCIF <- rgl.cry:::pkg$inst[[nrow(rgl.cry:::pkg$inst), "lCIF"]] a <- lCIF$HEADER$CELL$A$VAL b <- lCIF$HEADER$CELL$B$VAL c <- lCIF$HEADER$CELL$C$VAL aa <- lCIF$HEADER$CELL$ALPHA$VAL # degree bb <- lCIF$HEADER$CELL$BETA$VAL cc <- lCIF$HEADER$CELL$GAMMA$VAL mat02 <- cry::xtal_mat02(a, b, c, aa, bb, cc) ea1 <- as.numeric(c(1, 0, 0) %*% mat02) # lattice vector ea2 <- as.numeric(c(0, 1, 0) %*% mat02) ea3 <- as.numeric(c(0, 0, 1) %*% mat02) ec3 <- ea1 + ea2 + ea3 # c-axis in a hexagonal crystal. ## a_hex is calculated as a - b, b_hex as b - c, and one of the clip planes is denoted as ## (a_hex + (a_hex + b_hex)) / 2 = a - b + a - b + b - c = 2a - b - c = a - (b + c) / 2. cp1 <- ea1 - (ea2 + ea3)/2 cp2 <- ea2 - (ea3 + ea1)/2 cp3 <- ea3 - (ea1 + ea2)/2 cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry"), abc = c(1,1,1), clipplanes = rbind( c(cp1, -crossprod(cp1)), c(cp2, -crossprod(cp2)), c(cp3, -crossprod(cp3)), c(-cp1, -crossprod(cp1)), c(-cp2, -crossprod(cp2)), c(-cp3, -crossprod(cp3)), c(ec3, -crossprod(ec3)), c(-ec3, 0))) }cry_demo() cry_demo(system.file("orthorhombic_p.cif", package = "rgl.cry")) cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry"), abc = c(1,1,1), clipplanes = rbind(c(2.885490, 4.158112, -3.374928, -37.01), c(2.885490, -5.082574, 1.687449, -37.01), c(-5.7709802, 0.9244616, 1.6874797, -37.01), c(-2.885490, -4.158112, 3.374928, -37.01), c(-2.885490, 5.082574, -1.687449, -37.01), c(5.7709802, -0.9244616, -1.6874797, -37.01), c(5.771090, 8.316383, 15.180433, -332.92), c(-5.771090, -8.316383, -15.180433, 0.01))) if (interactive()) { cry_demo(file, type = "fill", zoom = 0.5) cry_demo("https://www.crystallography.net/cod/foo.cif") ## A rhombohedral crystal. cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry")) ## Extract crystal structure data from the internal processing of the package. library(pryr) lCIF <- rgl.cry:::pkg$inst[[nrow(rgl.cry:::pkg$inst), "lCIF"]] a <- lCIF$HEADER$CELL$A$VAL b <- lCIF$HEADER$CELL$B$VAL c <- lCIF$HEADER$CELL$C$VAL aa <- lCIF$HEADER$CELL$ALPHA$VAL # degree bb <- lCIF$HEADER$CELL$BETA$VAL cc <- lCIF$HEADER$CELL$GAMMA$VAL mat02 <- cry::xtal_mat02(a, b, c, aa, bb, cc) ea1 <- as.numeric(c(1, 0, 0) %*% mat02) # lattice vector ea2 <- as.numeric(c(0, 1, 0) %*% mat02) ea3 <- as.numeric(c(0, 0, 1) %*% mat02) ec3 <- ea1 + ea2 + ea3 # c-axis in a hexagonal crystal. ## a_hex is calculated as a - b, b_hex as b - c, and one of the clip planes is denoted as ## (a_hex + (a_hex + b_hex)) / 2 = a - b + a - b + b - c = 2a - b - c = a - (b + c) / 2. cp1 <- ea1 - (ea2 + ea3)/2 cp2 <- ea2 - (ea3 + ea1)/2 cp3 <- ea3 - (ea1 + ea2)/2 cry_demo(system.file("rhombohedral_r.cif", package = "rgl.cry"), abc = c(1,1,1), clipplanes = rbind( c(cp1, -crossprod(cp1)), c(cp2, -crossprod(cp2)), c(cp3, -crossprod(cp3)), c(-cp1, -crossprod(cp1)), c(-cp2, -crossprod(cp2)), c(-cp3, -crossprod(cp3)), c(ec3, -crossprod(ec3)), c(-ec3, 0))) }
Read a file in CIF formats, set and the parameters, calculates them, draws the reciprocal lattice map with a cell widget.
dp_demo( file = NULL, reso = 1.2, ews.r = 40, zoom = 0.5, hkl_labels = TRUE, xrd = FALSE )dp_demo( file = NULL, reso = 1.2, ews.r = 40, zoom = 0.5, hkl_labels = TRUE, xrd = FALSE )
file |
Optional file in CIF formats. |
reso |
A real number. The highest data resolution, in angstroms. If the default value takes a long time to process displaying due to the large number of lattice points, you can expect to improve performance by increasing the value. |
ews.r |
Ewald sphere radius in angstrom^-1. |
zoom |
A positive value indicating the current scene magnification. |
hkl_labels |
A logical value indecating whether to show or hide the hkl
index labels. Defaults to |
xrd |
A logical value indicating whether to create an X-ray diffraction pattern simulation result file. |
If no file argument is provided, and cry_demo() has been opened without
paired dp_demo(), the CIF parameters of already opened cry_demo() will be
used.
Interactive rotation, zooming, and panning of structures are possible using
the 3D graphics library rgl. When the drag originates near the window
edge (within 5%), perform a Z-axis rotation.
This function also performs powder diffraction simulation and saves the results to a file in the working directory. Currently, it doesn't account for atomic ionization and uses standard atomic scattering factors.
An integer the device number of the currently window.
dp_demo() dp_demo(system.file("orthorhombic_p.cif", package = "rgl.cry")) dp_demo(system.file("orthorhombic_p.cif", package = "rgl.cry"), res = 2.0) if (interactive()) { dp_demo(file, zoom = 0.5) dp_demo("https://www.crystallography.net/cod/foo.cif") }dp_demo() dp_demo(system.file("orthorhombic_p.cif", package = "rgl.cry")) dp_demo(system.file("orthorhombic_p.cif", package = "rgl.cry"), res = 2.0) if (interactive()) { dp_demo(file, zoom = 0.5) dp_demo("https://www.crystallography.net/cod/foo.cif") }
Output a lCIF.
getCIF(dev = NULL)getCIF(dev = NULL)
dev |
The device that is used to extract the lCIF. The default is current device. |
A named list, the same as that of 'cry::readCIF.'
getCIF()getCIF()
Select one or more atoms or reciprocal lattice points in the window. The labels and Miller indices of the selected atoms or lattice points will be displayed.
select(dev = NULL, verbose = TRUE)select(dev = NULL, verbose = TRUE)
dev |
RGL device to apply. Defaults to current device. |
verbose |
logical: Should the report be suppressed? |
Selecting atoms or lattice points in the window will include all z-coordinates. If you do not want to include all z-coordinates, you will need to modify the code.
List of Miller indices or element labels.
if (interactive()) { select() select(dev = 123) }if (interactive()) { select() select(dev = 123) }