Skip to content

Instantly share code, notes, and snippets.

@JoaoRodrigues
JoaoRodrigues / frange.py
Last active October 6, 2020 23:13
Python 3.x range-like function with decimal step
import decimal
def frange(start, stop, step, include_stop=True):
"""Range-like function that accepts decimal step values."""
# To avoid rounding issues
# We cast the floats to string and then to decimals
# see: docs on Decimal(0.1) != Decimal('0.1')
dstep = decimal.Decimal(str(step))
@JoaoRodrigues
JoaoRodrigues / benchmark_PDBParser.py
Created August 22, 2020 22:40
Script to test PDBParser (biopython)
#!/usr/bin/env python
"""
Script to benchmark Bio.PDB PDBParser on a collection
of PDB files.
"""
import argparse
import gzip
import pathlib
@JoaoRodrigues
JoaoRodrigues / anton2_reimage.py
Last active October 25, 2019 01:45
Script to reimage Anton2 trajectories
#!/usr/bin/env python
"""
Python script to reimage/unwrap an MD simulation trajectory
ran on the Anton2 supercomputer.
Expects a topology file in .dms format and the trajectory
folder '.dtr'.
Requires:
@JoaoRodrigues
JoaoRodrigues / mdpretty.py
Created October 18, 2019 23:17
Assorted Python function for plotting molecular properties
# Copyright 2019 João Pedro Rodrigues
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@JoaoRodrigues
JoaoRodrigues / mda_PDBxParser.py
Last active October 16, 2019 06:41
PDBxParser to use with MDAnalysis to load PDBx/mmCIF files as Topologies
#!/usr/bin/env python
from __future__ import absolute_import, print_function
import collections
import re
import numpy as np
import warnings
@JoaoRodrigues
JoaoRodrigues / uniprot_rest_example.py
Created June 7, 2019 22:54
Example of Uniprot REST API (Python)
#!/usr/bin/env python
"""
Queries Uniprot database and retrieves (canonical) sequences.
"""
import argparse
import sys
import urllib.request
@JoaoRodrigues
JoaoRodrigues / fetch_sequences.py
Created June 5, 2019 19:43
Using Biopython (Bio.Entrez) to fetch sequences from NCBI
from Bio import Entrez
Entrez.email = None # change this!
assert Entrez.email is not None
# Read ids from file to a list
id_list = [ ... ]
results = {}
handle = Entrez.efetch(db="protein", id=id_list, retmode="xml")
REMARK 200 Generated with PyMOL and psico
ATOM 1 CY MET A 1 -57.588 1.993 21.439 1.00 0.00 C
ATOM 2 OY MET A 1 -58.412 1.073 21.529 1.00 0.00 O
ATOM 3 CAY MET A 1 -57.792 3.297 22.180 1.00 0.00 C
ATOM 4 N MET A 1 -56.540 1.838 20.704 1.00 0.00 N
ATOM 5 CA MET A 1 -56.332 0.585 19.985 1.00 0.00 C
ATOM 6 C MET A 1 -54.885 0.158 20.046 1.00 0.00 C
ATOM 7 O MET A 1 -54.053 0.864 20.614 1.00 0.00 O
ATOM 8 CB MET A 1 -56.802 0.738 18.512 1.00 0.00 C
ATOM 9 CG MET A 1 -58.316 0.961 18.308 1.00 0.00 C
PSF CMAP
7 !NTITLE
REMARKS original generated structure x-plor psf file
REMARKS 2 patches were applied to the molecule.
REMARKS topology C:/Users/joaor/Downloads/toppar/top_all36_prot.rtf
REMARKS topology C:/Users/joaor/Downloads/toppar/top_all22_prot.rtf
REMARKS segment A { first ACE; last CT3; auto angles dihedrals }
REMARKS patch CT3 A:27
REMARKS patch ACE A:1