Advanced mol2 atom correspondence tool with cross-type-system Support
BackBonus is a Python tool for determining atom-wise correspondence between molecular structures in mol2 format. It attempts to match molecules even when they use different atom type systems (currently: SYBYL, AMBER, GAFF, GAFF2).
- Cross-type-system matching: Maps between SYBYL, AMBER, GAFF, and GAFF2 atom types
- Automatic bond detection: Intelligently detects bonds based on atomic distances when not present in input files
- Multiple matching strategies: From exact matching to flexible element-based correspondence
- Rich reporting: Multiple output formats (Console, JSON, HTML, CSV) with detailed statistics
- Molecular validation: Validates bond lengths, valences, and molecular structure integrity
- Atom renaming: Automatically rename atoms in target molecules based on template correspondence
pip install backbonusgit clone https://github.com/MicheleBonus/backbonus.git
cd backbonus
pip install -e .git clone https://github.com/MicheleBonus/backbonus.git
cd backbonus
pip install -e ".[dev]"# Simple correspondence finding
backbonus -t template.mol2 -T target.mol2
# With atom renaming
backbonus -t template.mol2 -T target.mol2 --rename -o renamed.mol2
# Cross-system matching (GAFF to SYBYL)
backbonus -t template_gaff.mol2 -T target_sybyl.mol2 --rename# Multiple output formats with bond detection
backbonus -t ref.mol2 -T query.mol2 -f console -f html -f json -b
# Using specific matching strategies
backbonus -t ref.mol2 -T query.mol2 -s cross -s relaxed -s element
# Specify atom type systems explicitly
backbonus -t template.mol2 -T target.mol2 --template-type sybyl --target-type gaff2
# Verbose output for debugging
backbonus -t ref.mol2 -T query.mol2 -vvfrom backbonus import Mol2Parser, AtomCorrespondence, AtomTypeMapper
# Parse molecules
template_parser = Mol2Parser("template.mol2", detect_bonds=True)
template = template_parser.parse()
target_parser = Mol2Parser("target.mol2", detect_bonds=True)
target = target_parser.parse()
# Find correspondence
type_mapper = AtomTypeMapper()
correspondence = AtomCorrespondence(template, target, type_mapper)
result = correspondence.find_correspondence()
# Access results
print(f"Match: {result.match_percentage:.1f}%")
print(f"Strategy: {result.strategy_used.value}")
for target_id, template_id in result.mapping.items():
print(f"Atom {target_id} -> {template_id}")BackBonus uses a graph-based approach to find atom correspondence:
- Molecular graph construction: Converts mol2 structures into NetworkX graphs
- Type system detection: Automatically identifies the atom type system used
- Multi-strategy matching: Attempts various matching strategies in order:
- Exact: Perfect match of atom types and bond orders
- Cross-system: Maps between different type systems using comprehensive conversion tables
- Relaxed: Matches based on element and connectivity
- Element-only: Matches based solely on element types
- Subgraph: Finds partial matches for incomplete correspondences
BackBonus includes comprehensive atom type mapping data derived from AmberTools/Antechamber:
- SYBYL: Tripos Sybyl atom types (e.g., C.3, N.pl3, O.2)
- AMBER: Amber force field types (e.g., CT, CA, N3)
- GAFF: General Amber Force Field types (e.g., c3, ca, n3)
- GAFF2: Updated GAFF types with improved parameters
The mapping system handles:
- Direct type conversions (e.g., C.3 → c3)
- Aromatic type recognition (e.g., C.ar → ca)
- Special atom types (e.g., N.pl3 → n)
- Halogen and metal atom types
When bonds are not present or need verification:
- Distance Calculation: Computes distances between all atom pairs
- Covalent Radii Check: Uses elemental covalent radii with tolerance
- Bond Order Assignment: Determines single/double/triple/aromatic bonds
- Validation: Checks valences and bond lengths for chemical validity
# config.yaml
matching:
strategies: [cross, relaxed, element]
timeout: 60
bond_detection:
tolerance: 0.45
max_bond_length: 3.0
output:
formats: [console, json]
include_charges: trueUse with: backbonus -t template.mol2 -T target.mol2 -c config.yaml
Rich formatted output with colored tables and progress indicators
Structured data with complete mapping information:
{
"summary": {
"template_file": "template.mol2",
"target_file": "target.mol2",
"match_percentage": 95.2,
"strategy": "cross"
},
"correspondence": [...]
}Interactive web page with visualizations and statistics
Tabular format for analysis in spreadsheet applications
Run the test suite:
# Basic tests
pytest
# With coverage
pytest --cov=backbonus
# Specific test file
pytest tests/test_correspondence.py -vWe welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
If you use BackBonus in your research, please cite:
@software{backbonus2025,
author = {Bonus, Michele},
title = {BackBonus: Advanced Mol2 Atom Correspondence Tool},
year = {2025},
url = {https://github.com/MicheleBonus/backbonus}
}This project is licensed under the MIT License - see the LICENSE file for details.
- Atom type definitions and mapping data derived from AmberTools/Antechamber
- Graph algorithms powered by NetworkX
- Beautiful terminal output via Rich
Michele Bonus - Michele.Bonus@hhu.de
Project Link: https://github.com/MicheleBonus/backbonus
- GUI interface for visual correspondence inspection
- Support for other molecular file formats
- Machine learning-based matching for difficult cases
- Integration with popular molecular visualization tools
- Batch processing capabilities