General MacroMocelecular I/O, or GEMMI, is a C++ 11 header only library for low level crystalographic .
Because its header only it is certainly the easiest to access and use low level crystalographic C++ library, however GEMMI comes with python binding via Pybind11, making it arguably the easiest low level crystalographic library to access and use in python as well!
What follows is a cookbook of useful Python code that uses GEMMI to accomplish macromolecular crystalographic tasks.
Installation
pip install gemmi
Importing GEMMI
import gemmi
Loading models
structure: gemmmi.Structure = gemmi.read_pdb(pdb_path) # PDB file structure: gemmmi.Structure = gemmi.cif.read(cif_path) # mmCIF file
Loading reflection data
mtz = gemmi.read_mtz_file('../tests/5e5z.mtz')
Loading crystalographic maps
xmap = gemmi.read_ccp4_map(xmap_path)
Write models
structure.write_pdb(path) # Write to a pdb structure.make_mmcif_document().write_file(path) # Write to a mmCIF
Write reflections
mtz.write_to_file(path)
Write crystalographic maps
ccp4 = gemmi.Ccp4Map() ccp4.grid = xmap ccp4.update_ccp4_header(2, True) ccp4.write_ccp4_map(path)
Transforming reflection data to grids
xmap = mtz.transform_f_phi_to_map("FWT", "PHWT", sample_rate=4)
Subsampling grids (single point)
position = gemmi.Position((2, 3, 4)) grid.interpolate_value(position)
Subsampling grids (orhtogonal grid of points)
arr = numpy.zeros([32, 32, 32], dtype=numpy.float32) tr = gemmi.Transform() tr.mat.fromlist([[0.1, 0, 0], [0, 0.1, 0], [0, 0, 0.1]]) tr.vec.fromlist([1, 2, 3]) grid.interpolate_values(arr, tr)