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 corresponding paper (coming soon).

📫 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.1.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.1-py3-none-any.whl (22.9 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cgback-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b668b197fff789fd04e93b500a103a512ea9538d14ab59c9f6d8c5642acb80d7
MD5 f933b14b326826ed362e4dafb07add9b
BLAKE2b-256 751751cdc9b57dd4e6a6b87652936a5bfe8c2cffd928623bc2777968b1e4ebc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cgback-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6edfe748729487b2e3ad6b352b1df1b73c476f4ea492cf432631a760b475309d
MD5 b05b595b6881231d512339f2a9f4ca2f
BLAKE2b-256 234a156c14cdfe981eb0944c6c2ede0c9aaebaba49929fb5c1d8d706b0332654

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