gemmi

repository·master·Indexed 18 days ago

https://github.com/project-gemmi/gemmi

A high-performance C++ library and suite of tools for macromolecular crystallography. It supports file formats including mmCIF, PDB, MTZ, and MRC, and provides interfaces for C++, Python, command-line utilities, WebAssembly, and Fortran. Key features include the `gemmi align` CLI for pairwise sequence alignment, `NeighborSearch` for fixed-radius near neighbor searches, `ContactSearch` for finding atom pairs, and utilities for calculating Matthews coefficients and solvent content.

Tokens
101.7K
Snippets
325
Records
391
Agent score
62%

What's inside gemmi

  1. Overview of gemmi drg capabilities

    master

    The gemmi drg module generates monomer restraint dictionaries for crystallographic refinement. It combines chemical rules with statistical knowledge derived from AceDRG tables.

    Core Workflow:

    1. Read Monomer Definition: Typically a CCD-like CIF file.
    2. Build Molecular Graph: Analyzes atoms, bonds, and valence context.
    3. Consult AceDRG Tables: Looks up bond/angle targets and sigmas.
    4. Emit Restraints: Produces categories suitable for refinement workflows (bonds, angles, torsions, chirality, and planarity).

    Note that the produced values are empirical/statistical refinement targets (ideal values and sigmas/esds), not QM geometry optimizations.

  2. Overview of Gemmi capabilities

    master

    Gemmi is a library and set of programs designed for structural biology and macromolecular crystallography (MX). It provides tools for handling various crystallographic data formats and biological models.

    Core capabilities include:

    • Macromolecular Models: Working with PDB, PDBx/mmCIF, and mmJSON files.
    • Refinement & Small Molecules: Handling CIF files for refinement restraints and small molecule models.
    • Reflection Data: Processing MTZ and mmCIF formats.
    • Symmetry: Managing crystallographic symmetry and symmetry-aware analysis.
    • 3D Grids: Handling electron density maps, masks, and MRC/CCP4 formats with crystallographic symmetry.

    Supported Platforms & Languages:

    • Platforms: Linux, Windows, macOS, and WebAssembly (for web browsers).
    • Languages: C++14 (core), Python 3.8+ (bindings), and partial C and Fortran 2003 interfaces.
  3. Supported reflection file formats in Gemmi

    master

    Gemmi supports four primary formats for storing crystallographic reflection data (Miller indices and associated values):

    • MTZ files: The most common format used in macromolecular crystallography.
    • Structure factor mmCIF files: Used for data archiving in the Protein Data Bank (PDB).
    • XDS ASCII format: Data generated from processing diffraction images with XDS.
    • Small molecule structure factor CIF files: Typically identified by the .hkl file extension.
  4. Available Gemmi interfaces and tools

    master

    Gemmi is available through several interfaces depending on your workflow:

    • C++ Library: The core implementation (requires C++14).
    • Python Bindings: For integration into Python-based scientific workflows.
    • Command-line Tools: Standalone utilities for processing files.
    • WebAssembly: Partial bindings for web-based applications.
    • Fortran: A Fortran 2003+ interface (currently in progress).

    Additionally, Gemmi provides online tools such as GemmiMOL (a molecular viewer) and various data visualization projects.

  5. Access the Gemmi C++ API Reference

    master
    The Gemmi C++ library API is documented via Doxygen comments located in the include/gemmi/*.hpp headers. This documentation covers core data structures, structure I/O, chemistry, calculations, and more. For users working in Python, a separate Python API reference is available.
  6. Analyze 3D grids and maps

    master

    Gemmi provides extensive tools for 3D grid (map) manipulation:

    • grid.hpp: Core 3D grid structures used by CCP4 maps, cell-method search, and HKL data.
    • blob.hpp: Finds maxima or "blobs" in a Grid (map), similar to CCP4 PEAKMAX.
    • floodfill.hpp: Implements the flood fill (scanline fill) algorithm for a Grid, assuming periodic boundary conditions and 6-way connectivity.
    • isosurface.hpp: Extracts isosurfaces from 3D grids using the marching-cubes algorithm.
    • mc_tables.hpp: Contains lookup tables for the marching-cubes algorithm.
    • ccp4.hpp: Support for the CCP4 map and mask format.
  7. Understand CIF, STAR, and mmCIF formats

    master

    Gemmi's CIF parser works with several related formats used in molecular-structure sciences:

    • STAR: A human-readable data serialization format. It is the foundation for CIF.
    • CIF (Crystallographic Information File): A restricted derivative of STAR used in crystallography. It imposes certain limits (like line length) to simplify implementation.
    • mmCIF (PDBx/mmCIF): A specific application of the CIF syntax combined with a large dictionary (ontology/schema) in DDL2. It is used for macromolecular coordinates and reflection data.
    • DDL (Data Description Language): A schema language used for STAR and CIF.

    Key Syntax Features:

    • Key-value pairs: Formatted as _tag value (e.g., _year 2017).
    • Blocks: Sections starting with the data_ keyword followed by a name (e.g., data_tomato).
    • Loops: Used to represent tabular data concisely. A loop_ keyword is followed by column names, then the rows of values.
    • Null values: ? represents unknown and . represents not applicable. In mmCIF, . is used for mandatory items and ? for non-mandatory items.
  8. How bond and angle restraint matching works

    master

    Restraint assignment in gemmi drg uses a hierarchical matching strategy, attempting to find the most specific local environment before relaxing constraints.

    Bond Matching Levels

    Matching is keyed by progressively simpler context:

    • Level 0: Exact full COD-class match (most specific).
    • Levels 1-2: Type-relaxed matches/aggregates.
    • Levels 3-6: Neighborhood-relaxed matches/aggregates.
    • Levels 7-8: Broader nb2-level aggregation.
    • Levels 9-11: Hash/hybrid/ring summaries (HRS-style hierarchy).

    Angle Matching Levels

    Lookup follows a ladder based on the center atom hash and flank hashes:

    • 1D: Full key including types.
    • 2D: No type component.
    • 3D: No nb (neighbor) component.
    • 4D: Roots-only beyond hash/value key.
    • 5D: Hash + value key.
    • 6D: Hash-only summary.

    Fallbacks and Thresholds

    • Thresholding: Most paths require a minimum number of observations (defaulting to 3) to be accepted.
    • Bond Fallbacks: If specific matching fails, it falls back through HRS/element-hybrid routes, then to CCP4 ener_lib compatibility.
    • Angle Fallbacks: Falls back through HRS and then to geometry defaults based on center hybridization/coordination.
  9. Conformer Generation From Restraints

    master

    Gemmi aims to implement a route for generating a single, deterministic, idealized conformer for well-restrained small molecules from restraints. This process is more complex than hydrogen placement because it involves globally coupled constraints like torsions, chirality, ring closure, and nonbonded contacts.

    The proposed pragmatic workflow is:

    1. Build an internal-coordinate tree.
    2. Seed rigid fragments (small rings, aromatic systems, planar groups, peptide/nucleic templates).
    3. Place the remaining graph by walking bonds using bond/angle/torsion restraints.
    4. Enforce chirality during placement.
    5. Run restrained Cartesian minimization to clean up closure errors and clashes.
    6. Use a fallback embedding/minimization step for difficult rings/macrocycles.
  10. Understand Sohncke vs Enantiomorphic space groups

    master

    Gemmi follows the IUCr dictionary for chirality-related terminology:

    • Sohncke groups (non-enantiogenic): The 65 space groups containing only operations of the first kind (rotations, rototranslations, translations). Chiral structures crystallize in these groups.
    • Enantiomorphic space groups (chiral groups): The 22 groups that form 11 enantiomorphic pairs. Note that chiral structures can also crystallize in 43 of the achiral (non-enantiomorphic) space groups.
  11. Combine and manipulate symmetry operations

    master

    Symmetry operations can be combined using the multiplication operator *. When operations are combined, they are treated as symmetry operations and the result is automatically wrapped to the $[0, 1)$ range.

    Operations

    • Combination: op1 * op2 combines two operations.
    • Inversion: op.inverse() returns the inverse.
    • Wrapping: op.wrap() reduces the translation modulo 1.

    Note that op.wrap() is not automatically applied to individual operations upon creation (e.g., x,y+1,z is not automatically reduced to identity), but it is applied during combination to ensure results remain within the standard crystallographic range.

    import gemmi
    
    op = gemmi.Op('-y,x-y,z+1/3')
    
    # Combine operations
    combined = gemmi.Op('x-y,x,z+1/6') * '-x,-y,z+1/2'
    
    # Invert and wrap
    inverted = combined.inverse()
    wrapped = inverted.wrap()
  12. Apply deposition checks during CIF validation

    master

    The PDBx/mmCIF specification includes "alternate" versions of data types, ranges, and enumerations (e.g., _pdbx_item_type vs _item_type). These alternates are typically interpreted as stricter deposition constraints.

    To apply these stricter criteria during validation, use the use_deposition_checks option.

    • In Python: Set use_deposition_checks as a keyword argument in the cif.Ddl constructor.
    • In C++: Set the use_deposition_checks member variable directly.
    • In CLI: Use the --depo flag with the gemmi validate command.
    # Python example
    validator = cif.Ddl(use_deposition_checks=True)