Skip to contents

Write reflections and experimental information to an MTZ file

Usage

writeMTZ(reflections, header, filename, title = NULL, batch_header = NULL)

Arguments

reflections

A data frame containing all reflection records in columns. This is usually derived from modifications of a previously existing data frame obtained using readMTZ.

header

A list whose components are other R objects. This is normally derived from the reading of another MTZ file using readMTZ. See further details at readMTZHeader.

filename

A character string. The path to a valid mtz file. If a file with the same name exists, it will be deleted.

title

A character string. The character string associated with the TITLE keyword in an MTZ file. This feature makes it easy to quickly identify the data file in CCP4 programs. Default (NULL) is for the output file to have the same title as the input file.

batch_header

A named list including information at data collection time. This component is present only for raw (unmerged) intensity data produce after the diffraction images integration. Merged MTZ reflection files have batch_header=NULL. Names and types depend on the type of experiment (more information on this can be found at CCP4.)

Value

This function does not return any R object. It outputs an MTZ reflection file to some target location.

Examples

# Read the 1dei_phases data included in the package
datadir <- system.file("extdata",package="cry")
filename <- file.path(datadir,"1dei_phases.mtz")
lMTZ <- readMTZ(filename)
#> Warning: truncating string with embedded nuls

# Change dataset name
print(lMTZ$header$DATASET)
#>   id    dname
#> 1  0 HKL_base
#> 2  1   data_1
lMTZ$header$DATASET[2,2] <- "New CRY dataset"

# Add one HISTORY line (string has to be 80-letters long)
addhist <- "From CRY 0.3.0 - run on Apr 2 20:12:00 2021"
n <- nchar(addhist)
nblanks <- 80-n
for (i in 1:nblanks) addhist <- paste0(addhist," ")
lMTZ$header$HISTORY <- c(lMTZ$header$HISTORY,addhist)

# Write to a new MTZ file
wd <- tempdir()
fname <- file.path(wd,"new.mtz")
writeMTZ(lMTZ$reflections,lMTZ$header,fname)