Protein and RNA/DNA/XNA geometry analysis
Project description
Melodia_py
Protein & RNA Structure Analysis
Melodia_py is a Python library for computing Differential Geometry and Knot Theory descriptors of protein and RNA structures.
What's new in v0.1.8
MDAnalysis integration
- New entry point
geometry_from_mdanalysis()— compute per-residue backbone geometry directly from an MDAnalysisUniverse, supporting any topology/trajectory format MDAnalysis can read (GROMACS GRO+XTC, AMBER, CHARMM DCD, mmCIF, …). Each trajectory frame is treated as one model, so the output DataFrame has the same schema asgeometry_from_structure_fileand is immediately compatible with all downstream clustering and alignment functions:import MDAnalysis as mda import melodia_py as mel u = mda.Universe("ubiquitin.gro", "ubiquitin.xtc") df = mel.geometry_from_mdanalysis(u, n_jobs=-1) # model column = 0-based frame index; same columns as geometry_from_structure_file
- Sparse frame sampling — the
framesparameter accepts a list of 0-based frame indices, so long trajectories can be analysed at any stride without converting the file first:# Every 10th frame of a 1000-frame trajectory df = mel.geometry_from_mdanalysis(u, frames=list(range(0, 1000, 10)))
- MDAnalysis is an optional dependency — importing melodia_py is
unaffected if MDAnalysis is not installed; the
ImportErroris raised only whengeometry_from_mdanalysis()is actually called. Install with:pip install "melodia-py[mdanalysis]"
What's new in v0.1.7
Performance
- Parallel model processing —
geometry_from_structure_fileandgeometry_from_structurenow accept ann_jobsparameter. For multi-model files (NMR ensembles, MD trajectories) this parallelises across models using all available CPU cores. A 300-model NMR ensemble runs 6.5× faster withn_jobs=8:df = mel.geometry_from_structure_file("ensemble.pdb", n_jobs=8)
- Numba JIT writhing — the Gauss writhing number double loop is compiled
to native code via Numba
@njit, giving ~8× speedup on that calculation. - Adaptive arc-length integration — replaced the hand-rolled Euler loop
with
scipy.integrate.quadfor higher accuracy and fewer function evaluations.
RNA support
- Configurable backbone atom —
GeometryParsernow accepts anrna_atomparameter (default"C4'") to select the Cα equivalent for RNA chains.C4'is the community standard and is universally present in all nucleotides. Valid choices are exposed asGeometryParser.RNA_ATOMS:gp = GeometryParser(chain, rna_atom="C4'") # default, recommended gp = GeometryParser(chain, rna_atom="P") # phosphorus backbone
Correctness fixes
phiandpsiare now correctly typed asOptional[float]. Terminal residues (N-terminus and C-terminus) receiveNoneinstead of0.0.- RNA detection now uses set membership instead of substring matching, fixing a silent bug for multi-character residue names.
- Division-by-zero guard added in the writhing calculation for degenerate (colinear) atom geometries found in some PDB entries.
find_gapsis now O(n) instead of O(n²).
Build system
- Migrated from
setup.pytopyproject.toml(PEP 517/518). Install with standard pip — no--eggflags needed:pip install melodia-py pip install "melodia-py[fast,parallel]" # Numba + joblib extras pip install "melodia-py[all]" # everything
Installation
From PyPI
# To avoid problems with installing NGLView from pip, download the environment.yml file from:
https://github.com/rwmontalvao/Melodia_py.git
# Create and activate the environment
conda env create -f environment.yml
conda activate melodia_py
# Install melodia with pip
pip install melodia-py
With optional extras
| Extra | Installs | Enables |
|---|---|---|
fast |
numba, llvmlite | JIT-compiled writhing (~8× faster) |
parallel |
joblib | Multi-core model processing |
mdanalysis |
MDAnalysis | geometry_from_mdanalysis() for MD trajectories |
dev |
pytest, mypy, ruff, pre-commit | Development tools |
all |
all of the above | Everything |
pip install "melodia-py[fast,parallel]"
From source (recommended for development)
We recommend Miniforge for environment management.
# Clone the repository
git clone https://github.com/rwmontalvao/Melodia_py.git
cd Melodia_py
# Create and activate the environment
conda env create -f environment.yml
conda activate melodia_py
# Install in editable mode with all extras
pip install -e ".[all]"
Quick start
import melodia_py as mel
# Single-model structure
df = mel.geometry_from_structure_file("structure.pdb")
# Multi-model NMR ensemble — parallelise across models
df = mel.geometry_from_structure_file("ensemble.pdb", n_jobs=-1)
# RNA structure with C4' backbone atom (default)
df = mel.geometry_from_structure_file("rna.pdb", rna_atom="C4'")
# MD trajectory via MDAnalysis (requires melodia-py[mdanalysis])
import MDAnalysis as mda
u = mda.Universe("ubiquitin.tpr", "ubiquitin.xtc")
df = mel.geometry_from_mdanalysis(u, n_jobs=-1) # all frames
df = mel.geometry_from_mdanalysis(u, frames=[0, 50, 100]) # selected frames
# Inspect computed quantities
print(df.columns)
# id, model, code, chain, order, name,
# curvature, torsion, arc_length, writhing, phi, psi
Documentation
The examples folder contains Jupyter Notebooks with tutorials explaining Melodia_py's functionalities.
Authors
- Rinaldo W. Montalvão, PhD
- Antonio Marinho da Silva Neto, PhD
- William R. Pitt, PhD
Publication
Melodia: a Python library for protein structure analysis
Bioinformatics, 2024
References
- Montalvão R, Smith R, Lovell S, Blundell T: CHORAL: a differential geometry approach to the prediction of the cores of protein structures. Bioinformatics. 2005, 21: 3719–3725.
- Chang PL, Rinne AW, Dewey TG: Structure alignment based on coding of local geometric measures. BMC Bioinformatics. 2006, 7:346.
- Leung H, Montaño B, Blundell T, Vendruscolo M, Montalvão R: ARABESQUE: A tool for protein structural comparison using differential geometry and knot theory. World Res J Peptide Protein. 2012, 1: 33–40.
- Pitt WR, Montalvão R, Blundell T: Polyphony: superposition independent methods for ensemble-based drug discovery. BMC Bioinformatics. 2014, 15:324.
- Marinho da Silva Neto A, Reghim Silva S, Vendruscolo M, Camilloni C, Montalvão R: A superposition free method for protein conformational ensemble analyses and local clustering based on a differential geometry representation of backbone. Proteins. 2018, 87(4):302–312.
- Marinho da Silva Neto A, Montalvão R, Gondim Martins DB, Lima Filho JL, Madeiros Castelletti CH: A model of key residues interactions for HPVs E1 DNA binding domain–DNA interface based on HPVs residues conservation profiles and molecular dynamics simulations. Journal of Biomolecular Structure and Dynamics. 2019, 38(12):3720–3729.
Works using Melodia_py
Articles
- Arevalo SJ, Felice VVR, Acuña MB, Flores KO, Aguilar MQ, Balan A, Farah CS: The single-particle cryo-EM structures of a bacterial cyanide dihydratase and a fungal cyanide hydratase. Structure. 2026, 34: 599-610.
- Li WR, Cadet XF, Medina-Ortiz D, Davari MD, Sowdhamini R, Damour C, Li Y, Miranville A, Cadet F: From thermodynamics to protein design: Diffusion models for biomolecule generation towards autonomous protein engineering. arXiv. 2025: arXiv:2501.02680.
Thesis
- Rasul H: Evaluation of cell permeability in macrocyclic peptides: An exploratory computational chemistry approach. Lund University, 2025.
- Dimitriadis SA: Predicting protein-membrane interfaces of peripheral membrane proteins using machine learning. National and Kapodistian University of Athens, 2026.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file melodia_py-0.1.8.tar.gz.
File metadata
- Download URL: melodia_py-0.1.8.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb716123d959ce731b0f51dda2f2da08c3afabe30bbc12a0548719f6ddc3c518
|
|
| MD5 |
7ccdcf2fec4b7c7d1cfac92b0d957212
|
|
| BLAKE2b-256 |
78da312f29d22ffed954f38a73e985a46e71ee74abdc174d81971c06eb757baf
|
File details
Details for the file melodia_py-0.1.8-py3-none-any.whl.
File metadata
- Download URL: melodia_py-0.1.8-py3-none-any.whl
- Upload date:
- Size: 41.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dc6a5bc789c309112397d3d326b8fe76ab650059453a7f0c51d9249f497d50a
|
|
| MD5 |
d888fcb86fecadd723705eec27c42223
|
|
| BLAKE2b-256 |
ec523b42b993598e488cd9a13e731133d8b8a7ccf7b8cd57d497262f991d8f92
|