Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""
Example to align two equivalent protein structures.
"""
from Bio.PDB import PDBParser, Superimposer
parser = PDBParser(QUIET=1)
@JoaoRodrigues
JoaoRodrigues / top_to_pdb.py
Created February 21, 2014 17:13
CNS Topology to PDB file - loads charges into b-factor column and parses bonds to CONECT statements
#!/usr/bin/env python
"""
Replaces the bfactor column of a PDB file
with the charge information present in a
CNS topology file.
Atoms missing from the topology are automatically
assigned a set charge (default 0.0)
@JoaoRodrigues
JoaoRodrigues / sort_pdb.py
Created March 21, 2014 15:59
Sort the ATOM/HETATM lines of a PDB file
#!/usr/bin/env python
import sys
if len(sys.argv[1:]) != 1:
print "usage: sort_pdb.py <pdb file>"
sys.exit(1)
try:
with open(sys.argv[1]) as handle:
#!/usr/bin/env python
from Bio.PDB import PDBParser, PDBIO,
class PREFilter(Select):
def accept_atom(self, atom):
forbidden_atoms = set(['N', 'C', '...'])
if atom.parent.resname == 'CYS' and atom.name in forbidden_atoms:
if atom - atom.parent['CA'] > 3.0:
continue
@JoaoRodrigues
JoaoRodrigues / sampling_analysis.py
Created October 29, 2014 00:27
Sampling Analysis in BioPython
#!/usr/bin/env python
# -*- coding: utf-8 -*
"""
Utility script to analyze several docking poses of a protein complex.
Produces PDB file with color-coded ligand center-of-mass positions
that reflect the population density (i.e. number of neighbor models).
Works with multiple chain models by considering as "ligand" all chains
defined as NOT part of the receptor. Default, chain A is the only receptor.
@JoaoRodrigues
JoaoRodrigues / ensemble-rmsd.py
Created March 19, 2015 17:10
Calculates per residue displacement in an ensemble of structures (based on CA atoms)
#!/usr/bin/env python
"""
Analyzes the RMSD on a residue basis for an ensemble
of protein structures.
"""
from __future__ import print_function, division
import argparse
@JoaoRodrigues
JoaoRodrigues / struct_compare.py
Last active September 26, 2023 04:15
Very long script to match the chains of PDB files to a reference. Produces a lot of output per match: which chains match which, the seq. id, the RMS after iterative fitting, and the alignment with markers of seq and structural mismatch.
#!/usr/bin/env python
"""
Utility to match (and compare) PDB files.
On homo-multimers, will match chains sequentially.
Uses global sequence alignment to find equivalent positions
between the sequences. Also superimposes the structures based
on the alignments and outputs per-chain RMSDs.
@JoaoRodrigues
JoaoRodrigues / seq_align.py
Last active October 3, 2024 12:04
Pairwise Sequence Alignment with Biopython
#!/usr/bin/env python
from __future__ import print_function, division
from operator import itemgetter
import os
import sys
import tempfile
import warnings
@JoaoRodrigues
JoaoRodrigues / bio_align.py
Last active January 6, 2023 22:10
Sequence-based structure alignment of protein structures with Biopython
#!/usr/bin/env python
"""Sequence-based structural alignment of two proteins."""
import argparse
import pathlib
from Bio.PDB import FastMMCIFParser, MMCIFIO, PDBParser, PDBIO, Superimposer
from Bio.PDB.Polypeptide import is_aa
@JoaoRodrigues
JoaoRodrigues / md_smooth.py
Last active October 24, 2016 23:42
Smooths a trajectory using mdtraj and an weighted adaptive window algorithm.
#!/usr/bin/env python
"""
Smooths a trajectory using mdtraj and an weighted adaptive window algorithm.
"""
from __future__ import print_function, division
import argparse
import os