It is a header-only library. You need to ensure that
include directory is in your include path
when compiling your program. For example:
git clone https://github.com/project-gemmi/gemmi.git c++ -std=c++11 -Igemmi/include -O2 my_program.cpp
If you want Gemmi to uncompress gzipped files on the fly
(i.e. if you
you will also need to link your program with the zlib library.
If a file name is passed to Gemmi (through
it is assumed to be in ASCII or UTF-8.
Python 2.7/3.x module¶
To install the gemmi module you need pip, git and not too old C++ compiler (GCC 4.8+, Clang 3.4+, MSVC 2015+, ICC 17+):
pip install gemmi
(We have binary wheels for some Python versions on Windows, so the command above may actually download binaries).
Alternatively, to install the latest version directly from the repository:
pip install git+https://github.com/project-gemmi/gemmi.git
or clone the project (or download a zip file) and from the top-level directory do:
pip install .
If gemmi is already installed, uninstall the old version first
pip uninstall) or add option
On Windows Python 3.5+ should automatically find an appropriate compiler (MSVC 2015+) . If the compiler is not installed, pip shows a message with a download link. For Python 2.7 pip prefers MSVC 2008, which is too old to compile gemmi. You may still use MSVC 2015, 2017 or 2019, but before invoking pip you need to set the compiler environment with one of these commands:
"%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64 "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"
If you’d like to use PyPy instead of CPython – PyPy2.7 >= 5.7 is supported (although only occasionally tested – open an issue if it doesn’t work).
Fortran and C bindings¶
The Fortran bindings are in early stage and are not documented yet.
They use the ISO_C_BINDING module introduced in Fortran 2003.
You may see the
fortran/ directory to know what to expect.
The bindings and usage examples can be compiled with CMake:
cmake -D USE_FORTRAN=1 . make
The C bindings are used only for making Fortran bindings,
but they should be usable on their own.
If you use cmake to build the project
you get a static library
libcgemmi.a that can be used from C,
together with the
The library comes with a command-line program. To build it from source,
first make sure you have git, cmake and C++ compiler installed
sudo apt install git cmake make g++), then:
git clone https://github.com/project-gemmi/gemmi.git cd gemmi cmake . make
Binaries are distributed with the CCP4 suite and with Global Phasing software. They are also included in conda-forge packages. Additionally, the very latest Windows builds (as well as older ones) can be downloaded from AppVeyor CI: click the first (green) job, then in the Artifacts tab you should find gemmi.exe.
This project is using code from a number of third-party open-source projects.
Projects used in the C++ library and included under
- PEGTL – library for creating PEG parsers. License: MIT.
- sajson – high-performance JSON parser. License: MIT.
- PocketFFT – FFT library. License: 3-clause BSD.
- stb_sprintf – locale-independent snprintf() implementation. License: Public Domain.
- fast_float – locale-independent number parsing. License: Apache 2.0.
- tinydir – directory (filesystem) reader. License: 2-clause BSD.
Code derived from the following projects is used in the library:
- ksw2 – sequence alignment in
seqalign.hppis based on the ksw_gg function from ksw2. License: MIT.
- QCProt – superposition method
qcp.hppis taken from QCProt and adapted to our project. License: BSD.
- Larch – calculation of f’ and f”
fprime.hppis based on CromerLiberman code from Larch. License: 2-clause BSD.
Projects included under
third_party/, not used in the library itself,
but used in command-line utilities, python bindings or tests:
- The Lean Mean C++ Option Parser – command-line option parser. License: MIT.
- doctest – testing framework. License: MIT.
- linalg.h – linear algebra library. License: Public Domain.
- zlib – a subset of the zlib library for uncompressing gz files, used as a fallback when the zlib library is not found in the system. License: zlib.
Not distributed with Gemmi:
- pybind11 – used for creating Python bindings. License: 3-clause BSD.
- cctbx – used in tests and in scripts that generated space group data. License: 3-clause BSD.
Email me if I forgot about something.
List of C++ headers¶
Here is a list of C++ headers in
This list also gives an overview of the library.
- Addends to scattering form factors used in DensityCalculator and in StructureFactorCalculator.
- Sequence alignment, label_seq_id assignment, structure superposition.
- Generating biological assemblies by applying operations from struct Assembly to a Model. Includes chain (re)naming utilities.
- AsuData for storing reflection data.
- Functions that convert string to floating-point number ignoring locale. Simple wrappers around fastfloat::from_chars().
- Locale-independent functions that convert string to integer, equivalents of standard isspace and isdigit, and a few helper functions.
- Ratio of modified Bessel functions I1(x)/I0(x).
- Finding maxima or “blobs” in a Grid (map). Similar to CCP4 PEAKMAX and COOT’s “Unmodelled blobs”.
- Electron scattering factor coefficients from the International Tables.
- Calculate various properties of the model.
- CCP4 format for maps and masks.
- ChemComp - chemical component that represents a monomer from Refmac monomer library, or from PDB CCD.
- Reading coordinates from chemical component or Refmac monomer library files.
- CIF parser (based on PEGTL) with pluggable actions, and a set of actions that prepare Document.
- A class for converting SF-mmCIF to MTZ (merged or unmerged).
- struct Document that represents the CIF file (but can be also read from JSON file, such as CIF-JSON or mmJSON).
- Contact search, based on NeighborSearch from neighbor.hpp.
- Tools to prepare a grid with values of electron density of a model.
- Classes for iterating files in a directory tree, top-down, in an alphabetical order. It wraps the tinydir library (as we cannot depend on C++17 <filesystem> yet).
- Elements from the periodic table.
- Converts between enums (EntityType, PolymerType, Connection::Type, SoftwareItem::Classification) and mmCIF strings.
- fail() and unreachable()
- File-related utilities.
- The flood fill (scanline fill) algorithm for Grid. Assumes periodic boundary conditions in the grid and 6-way connectivity.
- Calculation of atomic form factors approximated by a sum of Gaussians. Tables with numeric coefficient are in it92.hpp and c4322.hpp.
- Fourier transform applied to map coefficients.
- C++ implementation of Cromer-Libermann calculation of anomalous scattering factors, with corrections from Kissel & Pratt, Acta Cryst. A46, 170 (1990). Single header. No dependencies.
- Ofstream and Ifstream: wrappers around std::ofstream and std::ifstream.
- 3d grids used by CCP4 maps, cell-method search and hkl data.
- Functions for transparent reading of gzipped files. Uses zlib.
- Input abstraction. Used to decouple file reading and uncompression.
- Interoperability between Model (MX) and SmallStructure (SX).
- X-ray scattering factor coefficients from International Tables for Crystallography Volume C, edition from 1992 or later.
- Iterators. Currently each of them is a BidirectionalIterator.
- Reading CIF-JSON (COMCIFS) and mmJSON (PDBj) formats into cif::Document.
- Least-squares fitting - Levenberg-Marquardt method.
- Searching for links based on the _chem_link table from monomer dictionary.
- Math utilities. 3D linear algebra.
- Class Intensities that reads multi-record data from MTZ, mmCIF or XDS_ASCII and merges it into mean or anomalous intensities. It can also read merged data.
- Metadata from coordinate files.
- Read mmcif (PDBx/mmCIF) file into a Structure from model.hpp.
- Function used in both mmcif.hpp and refln.hpp (for coordinate and reflection mmCIF files).
- Read any supported coordinate file.
- Data structures to keep macromolecular structure model.
- Monomer library - (Refmac) restraints dictionary, which is made of monomers (chemical components), links and modifications.
- MTZ reflection file format.
- A class for converting MTZ (merged or unmerged) to SF-mmCIF
- Cell-linked lists method for atom searching (a.k.a. grid search, binning, bucketing, cell technique for neighbor search, etc).
- Utilities for parsing CIF numbers (the CIF spec calls it ‘numb’).
- Read PDB file format and store it in Structure.
- Read sequence from PIR or FASTA format.
- Place hydrogens according to bond lengths and angles from monomer library.
- Heuristic methods for working with chains and polymers. Includes also a few well-defined functions, such as removal of hydrogens.
- Structural superposition, the QCP method.
- Functions for reading possibly gzipped CIF files. Trivial wrappers that can make compilation faster.
- Functions for reading possibly gzipped coordinate files. Trivial wrappers that can make compilation faster.
- Functions for reading possibly gzipped CCP4 map files. Trivial wrappers that can make compilation faster.
- ReciprocalGrid – grid for reciprocal space data.
- Reciprocal space utilities.
- Reads reflection data from the mmCIF format.
- Reindex merged or unmerged MTZ file.
- Function read_metadata_from_remarks() that interprets REMARK 3 and REMARK 200/230/240 filling in Metadata.
- List of common residues with basic data.
- Anisotropic scaling of data (includes scaling of bulk solvent parameters)
- Simple pairwise sequence alignment.
- SeqId – residue number and insertion code together.
- Direct calculation of structure factors.
- Representation of small molecule or inorganic crystal. Flat list of atom sites. Minimal functionality.
- Read small molecule CIF file into SmallStructure (from small.hpp).
- Flat bulk solvent mask. With helper tools that modify data on grid.
- Span - span of array or std::vector. MutableVectorSpan - span of std::vector with insert() and erase()
- to_str(float|double), gf_snprintf - wrappers around stb_sprintf.
- Crystallographic Symmetry. Space Groups. Coordinate Triplets.
- Writing cif::Document or its parts to std::ostream.
- Writing cif::Document or its parts as JSON (mmJSON, CIF-JSON, etc).
- Create cif::Document (for PDBx/mmCIF file) from Structure.
- copy_to_mmdb(): converts gemmi::Structure to mmdb::Manager.
- Writing PDB file format (Structure -> pdb file).
- Topo(logy) - restraints (from a monomer library) applied to a model.
- gemmi::tostr() - converts a list of arguments to string (uses ostringstream).
- Unit cell.
- Conversion between UTF-8 and wchar. Used only for file names on Windows.
- Utilities. Mostly for working with strings and vectors.
- Version number.
- Read XDS_ASCII.HKL. For now, only unmerged files are read.