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.9
Results change. Curvature and torsion change for every residue past the first ~10 of each chain, and values near chain ends and breaks are now NaN. Results from v0.1.8 and earlier are not comparable with results from this version.
Correctness fixes
-
Curvature and torsion no longer depend on the residue's position in the chain. The local Chebyshev fit in
calc_curvature_torsionwas done on the raw curve parameter (the residue index). Past ~10 residues the fit lost rank without warning, so values depended on where a residue sat in the chain, not only on its local geometry: on an ideal α-helix, interior curvature ranged 0.35–0.51 instead of a constant 0.514. Each fitting window is now mapped to [−1, 1], and the fit has full rank for any chain length. -
Chains are split at breaks. A break is two consecutive Cα atoms more than 4.2 Å apart (missing residues, or residues dropped for a missing Cα). Each segment gets its own spline, so no geometry is computed over a connection that does not exist, and φ/ψ are
Noneacross the break. A singleChainBreakWarninglists the breaks found:import warnings from melodia_py.geometryparser import ChainBreakWarning with warnings.catch_warnings(): warnings.simplefilter("ignore", ChainBreakWarning) # or "error" df = mel.geometry_from_structure_file("structure.pdb")
Breaks are detected from distances, not residue numbering, so a numbering jump between bonded residues is not a break. RNA chains are not split yet.
-
No more copied values at chain ends. The first and last residue used to repeat their neighbour's curvature and torsion, and the first and last three residues shared one writhing value. A value is now computed only where its whole window lies inside the chain or segment, and is
NaNelsewhere:Quantity Window NaNatcurvature, torsion, arc_length residues i−1 to i+1 first and last residue writhing residues i−2 to i+2 first two and last two residues The residue next to each end is computed, but is biased by the spline's end condition (33% high on an ideal helix); from two residues in, the end has no effect. Drop the
NaNrows where a complete table is needed:df = df.dropna(subset=["curvature", "torsion"])
-
bfactor_from_geo,cluster_alignmentandclustering.superimposeracceptNaNvalues: residues without a value keep the default B-factor, are left out of the clustering and get the cluster label-1, so they never form or join a conserved block.
Packaging
pip install melodia-pynow gives a working package.nglview,ipywidgets,numbaandjoblibwere imported byimport melodia_pybut not declared as dependencies, so the import failed in a clean environment.numba(≥ 0.61, the first release supporting Python 3.13) andjoblibare now core dependencies.nglviewandipywidgetsare only needed by the structure viewers, which now import them when called; install them with the newvizextra (or from conda-forge):pip install "melodia-py[viz]"
Tests
- A
tests/suite covers these fixes (constant values along an ideal helix, independence from residue numbering, chain breaks, chain ends,NaNhandling). Run it from a source install (see From source below):pytest
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 |
|---|---|---|
viz |
nglview, ipywidgets | view_putty(), view_cartoon(), view_tube() in notebooks |
mdanalysis |
MDAnalysis | geometry_from_mdanalysis() for MD trajectories |
dev |
pytest, mypy, ruff, pre-commit | Development tools |
all |
all of the above | Everything |
Numba (JIT-compiled writhing) and joblib (multi-core model processing) are
installed with the core package. The former fast and parallel extras still
work but add nothing.
pip install "melodia-py[viz]"
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.
Metadata
Release files for melodia-py 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| melodia_py-0.1.9.tar.gz | 54.4 kB | Without provenance | Details for melodia_py-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| melodia_py-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for melodia_py-0.1.9-py3-none-any.whl |
Total release size: 99.9 kB
Release files / melodia_py-0.1.9.tar.gz
| Download URL | melodia_py-0.1.9.tar.gz |
|---|---|
| Size | 54.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ecd722c36c761c9702ae13e7a126c03a8354529dee14ebd588b0ef54b3f0d106
|
|
BLAKE2b-256 checksum How to use checksums |
dc2e297373d77abdcb1e0ffdcbe6f9fecedf114ba19552aa1bb8d320b89a4592
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / melodia_py-0.1.9-py3-none-any.whl
| Download URL | melodia_py-0.1.9-py3-none-any.whl |
|---|---|
| Size | 45.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97da6891d5478e743eff671a03c8ce72a581792ec373f77d1443433919a4fd16
|
|
BLAKE2b-256 checksum How to use checksums |
5d22664cdf39317bce389afc78ebeccccc587b376f865b37a3d2ce9944880400
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for melodia-py 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.