Learn R Programming

cry

cry is an R package to make it easier dealing with crystallographic data. The package includes functions to read/write data from/to some of the file mostly used in software for structural crystallography. Current entry include the readMTZ function to read MTZ files (see CCP4) and the corresponding writeMTZ. There are also readCIF, readpd_rtv and readSF_CIF to read files in CIF formats (Crystallographic Information Framework, see IUCr page). Users are welcome to suggest inclusions of different (not currently available) formats they might need for specific tasks and/or analysis.

cry includes also several functions to perform the most common and routine crystallographic calculations, many of them involving crystallographic symmetry. The main purpose of these functions is to enable users to investigate specific issues without having to resort to external packages and thus carrying the analysis through without having to abandon the R platform.

Installation

You can install the released version of crone from CRAN with:

install.packages("cry")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("jfoadi/cry")

Example

This is a simple example in which a CIF file containing structure factors is read and a part of its data used for statistical analysis. The file is included as example file in cry and is called 1dei-sf.cif. The first task is to import the data in R.

# Load cry package
library(cry)

# Save CIF data in a named list
datadir <- system.file("extdata",package="cry")
filename <- file.path(datadir,"1dei-sf.cif")
lCIF <- readSF_CIF(filename)

The newly-created R object, a list called lCIF, contains all that is included in the CIF file, but within a structure that can be used within R for various analyses. The components of this list can be readily explored using the common R functions names, class and str.

# What's containe in lCIF?
names(lCIF)
#> [1] "HEADER" "SYMM"   "REFL"

# What's the header?
class(lCIF$HEADER)   # It's a list
#> [1] "list"

# Is it a named list?
names(lCIF$HEADER)  # Yes
#> [1] "TITLE"      "CELL"       "SGN"        "HALL"       "HM"        
#> [6] "SHELX_CODE" "F_000"      "HIGH_RES"

# What's the space group name for this crystal structure?
print(lCIF$HEADER$HM)
#> [1] NA

# What's the space group number corresponding to P 21 21 21?
# Use one of cry's functions
xHM <- lCIF$HEADER$HM
translate_SG(xHM,SG_in="xHM",SG_out="number")$msg
#> [1] "Something wrong in your input:\n   1) the symbol or number input for this space group does not exist\n   2) if your inpur was a number, perhaps for this space group there are not that many settings"

# ... and the unit cell parameters?
cpars <- c(lCIF$HEADER$CELL$A$VAL,lCIF$HEADER$CELL$B$VAL,
           lCIF$HEADER$CELL$C$VAL,lCIF$HEADER$CELL$ALPHA$VAL,
           lCIF$HEADER$CELL$BETA$VAL,lCIF$HEADER$CELL$GAMMA$VAL)
print(cpars)
#> [1] NA NA NA NA NA NA

# The unit cell belongs to the orthorombic system,
# as it should be, due to symmetry (cry function)
print(crystal_system(gn=19))
#> [1] "ORTHOROMBIC"

The most important bit in the CIF file are the observed reflections (coming from x-ray diffraction of one or more crystals). They are contained in the named list REFL. All CIF files have a VAL field reporting the specific observed quantity and a field STD reporting the corresponding experimental error. Not always the last one is available. The VAL field is an R data frame that makes these data suitable to further analysis within R. The STD field mirrors VAL, but with the experimental errors counterparts, if available, otherwise it is NULL, as in the case here reported.

Copy Link

Version

Install

install.packages('cry')

Monthly Downloads

214

Version

0.5.2

License

GPL-2

Maintainer

James Foadi

Last Published

June 19th, 2025

Functions in cry (0.5.2)

check_rec_unit_cell_validity

Validity and compatibility of a cry object of class 'rec_unit_cell'
create_rec_unit_cell.cryst_symm

Reciprocal unit cell from a 'cryst_symm' object
check_unit_cell_validity

Validity and compatibility of a cry object of class 'unit_cell'
create_merged_reflections

S3 generic to create merged_reflections objects
create_rec_unit_cell.default

Default method for generic "create_rec_unit_cell"
deplete_systematic_absences

Deplete systematic absences
create_unit_cell.bravais

Unit cell starting from a Bravais symbol
print.unit_cell

Print method for an object of class "unit_cell".
cryst_symm

Constructor for an S3 object of class "cryst_symm".
create_rec_unit_cell.bravais

Reciprocal unit cell starting from a Bravais symbol
crystal_family

Crystal family corresponding to given space group.
frac_to_orth

From fractional to orthogonal coordinates
find_symm_setting

Find specific space group setting
print.rec_unit_cell

Print method for an object of class "rec_unit_cell".
lattice_stuff

Calculation of useful lattice parameters
create_unit_cell.rec_unit_cell

Unit cell starting from a reciprocal unit cell
create_unit_cell.default

Default method for generic "create_unit_cell"
hkl_to_reso

Calculates resolution, given the Miller indices
extract_symmetry_info

Information on a specific space group
full_symm_strings

Symmetry operations in human readable form
op_xyz_to_matrix

Human-readable symmetry operator into matrix and vector
readMTZ

Load an MTZ file
create_unit_cell.cryst_symm

Unit cell from a 'cryst_symm' object
generate_miller

Generate Miller indices
plot_SHELX

Plot SHELXC log files
findHM

Correct spelling for Herman-Mauguin space groups symbols
readMTZHeader

Reads and output an MTZ header
read_SHELX_log

Reads and SHELXD log files
readmm_CIF

Reads and output an mmCIF file
writeMTZ

Write data to an MTZ file
orth_to_frac

From orthogonal to fractional coordinates
syminfo_to_matrix_list

Operators of a specific space group in matrix form
check_validity

Validity and compatibility of cry objects
num_symm_settings

Number of space group settings
readCIF

Reads and output a CIF file
create_rec_unit_cell.unit_cell

Reciprocal unit cell starting from a unit cell
rec_unit_cell

Constructor for an S3 object of class "rec_unit_cell.
translate_SG

Translation of space group symbols, numbers, etc.
unit_cell

Constructor for an S3 object of class "unit_cell.
print.angle

Print method for an object of class "angle".
writeXDS_ASCII

Write data to an XDS_ASCII file.
print.bravais

Print method for an object of class "bravais".
print.cryst_symm

Print method for an object of class "cryst_symm".
merged_reflections

Constructor for an S3 object of class "merged_reflections".
create_unit_cell

S3 generic to create unit_cell objects
lowest_uc_compatible_SG

Space group compatible with given cell
readXDS_ASCII

Load an XDS_ASCII file.
readSF_CIF

Reads and output an CIF file
sysabs

Locate systematic absences
theme_cry

cry theme for ggplot2
readXDS_ASCIIHeader

Load an XDS_ASCII file's header.
xtal_mat02

Matrix for cell orthogonalisation (second choice)
xtal_mat01

Matrix for cell orthogonalisation (first choice)
readpd_rtv

Reads and output a CIF file for powder diffraction
op_xyz_list_to_matrix_list

List of matrices and vectors of a specific space group
symm_to_cell_const

Cell parameter constrains from symmetry
readsm_REFL

Reads and output an CIF file
syminfo_to_op_xyz_list

Operators of a specific space group
change_COLSRC

Change COLSRC date and time stamp
bravais

Constructor for an S3 object of class "bravais"
calculate_cell_volume

S3 generic to compute cell volume
angle

Constructor for an S3 object of class "angle"
calculate_cell_volume.unit_cell

Volume of a unit cell (in cubic angstroms)
calculate_cell_volume.rec_unit_cell

Volume of a reciprocal unit cell (in \(angstroms^(-3)\))
avei_vs_res

Mean and standard deviation in resolution shells.
check_bravais_validity

Validity and compatibility of a cry object of class 'bravais'
check_angle_validity

Validity and compatibility of a cry object of class 'angle'
create_rec_unit_cell

S3 generic to create rec_unit_cell objects
create_merged_reflections.default

Default method for generic "create_merged_reflections"
check_cryst_symm_validity

Validity and compatibility of a cry object of class 'cryst_symm'
check_merged_reflections_validity

Validity and compatibility of a cry object of class 'merged_reflections'
crystal_system

Crystal system corresponding to given space group.