Skip to main content

Deep learning tool for backmapping coarse-grained to all-atom

Project description

CGBack

CGBack is a Python tool for backmapping coarse-grained structures into all-atom models using a diffusion-based generative model. It supports various model sizes, GPU acceleration, energy minimization with OpenMM, and reproducibility features.


📦 Installation

You can install CGBack using pip:

pip install cgback

or using uv:

uv tool install cgback

🧩 Dependencies

CGBack requires Python 3.10 or higher and the following Python packages:

Package Version Description
numpy ≥ 2.1.0 Numerical computations
scipy ≥ 1.15.0 Scientific computing utilities
torch ≥ 2.5.0 PyTorch deep learning framework
rich ≥ 13.9.4 Pretty terminal output

Additionally, to enable energy minimization, CGBack requires the following Python package:

Package Version Description
openmm ≥ 8.2.0 Molecular dynamics

🔧 Specific Sources (optional)

To install PyTorch for a specific CUDA version, please use the appropriate index:

For CUDA 11.8:

# using pip
pip install cgback --extra-index-url https://download.pytorch.org/whl/cu118

# using uv
uv tool install cgback --index pytorch=https://download.pytorch.org/whl/cu118

For CUDA 12.1:

# using pip
pip install cgback --extra-index-url https://download.pytorch.org/whl/cu121

# using uv
uv tool install cgback --index pytorch=https://download.pytorch.org/whl/cu121

For CUDA 12.4:

# using pip
pip install cgback --extra-index-url https://download.pytorch.org/whl/cu124

# using uv
uv tool install cgback --index pytorch=https://download.pytorch.org/whl/cu124

For CUDA 12.6:

# using pip
pip install cgback --extra-index-url https://download.pytorch.org/whl/cu126

# using uv
uv tool install cgback --index pytorch=https://download.pytorch.org/whl/cu126

For CUDA 12.8:

# using pip
pip install cgback --extra-index-url https://download.pytorch.org/whl/cu128

# using uv
uv tool install cgback --index pytorch=https://download.pytorch.org/whl/cu128

To enable energy minimization, please add OpenMM support.

For OpenMM with CPU and OpenCL support:

# using pip
pip install 'cgback[openmm]'

# using uv
uv tool install 'cgback[openmm]'

For OpenMM with CUDA 12 support:

# using pip
pip install 'cgback[openmm-cuda12]'

# using uv
uv tool install 'cgback[openmm-cuda12]'

Note: When running CGBack with OpenMM support enable for the first time, you may encounter several warnings. These messages are generated by the OpenMM package and do not indicate a problem with CGBack itself. The OpenMM team is expected to resolve them in a future update. You can safely ignore these warnings.The installation and functionality of CGBack remain unaffected.

⚙️ Installation examples

Example of an installation using PyTorch and OpenMM, both only with CPU support:

# using pip
pip install 'cgback[openmm]' --extra-index-url https://download.pytorch.org/whl/cpu

# using uv
uv tool install 'cgback[openmm]' --index pytorch=https://download.pytorch.org/whl/cpu

Example of an installation using PyTorch with CUDA 12.6 and OpenMM with CUDA 12:

# using pip
pip install 'cgback[openmm-cuda12]' --extra-index-url https://download.pytorch.org/whl/cu126

# using uv
uv tool install 'cgback[openmm-cuda12]' --index pytorch=https://download.pytorch.org/whl/cu126

🚀 Quick Start

The basic usage is very simple, just pass the coarse-grained structure to CGBack:

cgback input.pdb

The all-atom structure will be saved as out.pdb

📚 Examples

Basic backmapping:

cgback input.pdb # PDB format
cgback input.cif # PDBx/mmCIF format

Backmapping using different output formats:

cgback input.pdb -o out.pdb # Input in PDB format, output in PDB format
cgback input.cif -o out.cif # Input in PDBx/mmCIF format, output in PDBx/mmCIF format
cgback input.pdb -o out.cif # Input in PDB, output in PDBx/mmCIF format
cgback input.cif -o out.pdb # Input in PDBx/mmCIF format, output in PDB format

Backmapping using GPU:

cgback input.pdb -d cuda # on CUDA systems
cgback input.pdb -d mps  # on Apple systems

Backmapping using different models:

cgback input.pdb -m S  # Small model
cgback input.pdb -m M  # Medium model (default)
cgback input.pdb -m L  # Large model

Verbose output and logging:

cgback input.pdb -v

Save intermediate files:

cgback input.pdb -k

Energy Minimization with OpenMM (requires enabling support for OpenMM):

cgback input.pdb -e

🧪 Advanced Usage

Generate different outputs with controlled random seeds:

cgback input.pdb -s 1
cgback input.pdb -s 2

Specify the number of diffusion steps manually:

cgback input.pdb -n 150

Change batch size for larger or smaller memory usage:

cgback input.pdb -b 128

Customize energy minimization tolerance and iterations (in this case with a tolerance of 5.0 kJ/mol and 1000 minimization iterations):

cgback input.pdb -e --energy-minimization-tolerance 5.0 --energy-minimization-max-iterations 1000

Skip fixing atomic clashes during refinement:

cgback input.pdb --skip-fix-structure-clashes

Perform only backmapping, skipping adding hydrogen atoms, and skipping the whole refinement step:

cgback input.pdb --skip-add-hydrogen --skip-fix-structure

✨ Extra Usage

CGBack can act as a lightweight structure‑repair tool, no coarse‑grained input required. Here are four handy one‑liners you can drop into your workflow:

  1. Add missing hydrogen atoms:
# input.pdb is a heavy‑atom model that lacks H-atoms
cgback input.pdb # out.pdb with idealised H‑atoms added

Hydrogen atoms are placed according to standard protonation states at pH7±0.5. Combine with -e (energy minimization) if you want a quick local relaxation.

  1. Mutate a residue in‑place:
# Prepare input.pdb so the target residue:
#  • is renamed to the desired three‑letter code (e.g. ALA → LYS)
#  • keeps only its CA atom
cgback input.pdb # out.pdb with the rebuilt target residue

CGBack reconstructs the full side‑chain, stitches it into the existing backbone, and removes clashes.

  1. Fix structural artifacts:
# input.pdb has atoms poking through aromatic rings
cgback input.pdb # out.pdb with penetrations resolved and stereochemistry repaired

CGBack detects atoms that intrude an aromatic ring plane and re‑positions them to a clash‑free site. It also scans all chiral centers and regenerates one in the canonical form. Combine with -e (energy minimization) if you want a quick local relaxation.

🧬 Citation

If you use CGBack in your research, please cite the following paper:

Ugarte La Torre, D., Sugita, Y.; CGBack: Diffusion Model for Backmapping Large-Scale and Complex Coarse-Grained Molecular Systems, bioRxiv 2025.06.04.657965; doi: https://doi.org/10.1101/2025.06.04.657965

📫 Contact

For bug reports or feature requests, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cgback-1.0.3.tar.gz (23.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cgback-1.0.3-py3-none-any.whl (22.9 MB view details)

Uploaded Python 3

File details

Details for the file cgback-1.0.3.tar.gz.

File metadata

  • Download URL: cgback-1.0.3.tar.gz
  • Upload date:
  • Size: 23.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cgback-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0b1840283b2b8e836ea23774905e49a5605578905d0bf40df7726bda2c6d98d3
MD5 11dafaeb60e26a51f59e2786a5bc8068
BLAKE2b-256 036b6e5bcfdc1778aff29ad03799ae4e4a4d7988d9579d9f152ba790e1f263db

See more details on using hashes here.

File details

Details for the file cgback-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: cgback-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cgback-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d2a3837a71b478bcaccb8cb1a952f1eafa9abbfbbd08eb0a9d0be1d76add63
MD5 f452831884a3b570a1f86c09c6e55035
BLAKE2b-256 ab94e86e2e353730364e1ade76e201daca4d3a86e36301157b4364ec321d9d9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page