Skip to content

Instantly share code, notes, and snippets.

View ISDementyev's full-sized avatar
💻
Computational Protein Design

Ilya S. Dementyev ISDementyev

💻
Computational Protein Design
View GitHub Profile
@ISDementyev
ISDementyev / decode_pdb.py
Last active August 31, 2023 17:09
Decodes and re-encodes PDBs to UTF-8
from glob import glob
def decode_encode_pdb(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as file:
lines = file.readlines()
decoded_lines = [line.encode('utf-8').decode('utf-8', 'replace') for line in lines]
with open(output_file, 'w', encoding='utf-8') as file:
file.writelines(decoded_lines)
@ISDementyev
ISDementyev / loadpdb.py
Created April 16, 2023 17:28
PyMOL script for loading all pdbs into one session
# Run using the terminal command: pymol loadpdb.py
from glob import glob
from pymol import cmd
files = glob("*.pdb")
for pdb in files:
cmd.load(pdb, object=pdb[:-4])
@ISDementyev
ISDementyev / delres.sh
Last active April 5, 2023 17:32
Crude way to remove various residues from pdb files, including waters
#!/bin/bash
pdbs=$(ls *.pdb)
for pdb in $pdbs
do
prefix=${pdb:0:4}
grep -vf residues.txt $pdb > $prefix-ensemble-nores.pdb
done
@ISDementyev
ISDementyev / CharToInt.cpp
Last active August 24, 2022 01:44
Allows conversion of chars to ints
int CharToInt(char Digit)
{
return (int)Digit - 48;
}
int main()
{
int Int6 = CharToInt('6');
printf("Int: %d", Int6);
return 0;
@ISDementyev
ISDementyev / weights.py
Created April 3, 2022 17:33
Creates proper probability distribution histogram
# Add this keyword into plt.hist: weights=np.ones(len(data)) / len(data)
# Also make sure that density=False
@ISDementyev
ISDementyev / pymol_com.py
Created March 8, 2022 20:11
Command line pseudocode for finding COM distance in PyMOL - not directly executable in its current format
# assuming you already have com coordinates, com1 and com2, which can be generated using centerofmass and appropriate input
pseudoatom com1_particle, pos=com1
pseudoatom com2_particle, pos=com2
dist distance_com, com1_particle, com2_particle
save file.pse
@ISDementyev
ISDementyev / create_c.sh
Last active August 25, 2021 15:10
Creates a number of c files (see comments)
#!/bin/bash
c=".c"
for i in {1..10} ; do echo "#include <stdio.h>" > file$i$c
# the loop takes the #include statement and appends it into the first line of each file; done to avoid writing it out every time.
@ISDementyev
ISDementyev / resdicts.py
Last active August 13, 2021 18:15
Residue dictionaries for one-letter and three-letter amino acid names
resdict = {"ALA": "A","CYS": "C","ASP": "D","GLU": "E","PHE": "F","GLY": "G","HIS": "H","ILE": "I","LYS": "K","LEU": "L","MET": "M","ASN": "N","PRO": "P","GLN": "Q","ARG": "R","SER": "S","THR": "T","VAL": "V","TRP": "W","TYR": "Y"}
resdict_inv = {one_let: three_let for three_let, one_let in resdict.items()}
@ISDementyev
ISDementyev / plot_latex.py
Last active March 29, 2023 11:41
Matplotlib plot with LaTeX (Computer Modern) font
import matplotlib.pyplot as plt
plt.style.use('seaborn') # I personally prefer seaborn for the graph style, but you may choose whichever you want.
params = {"ytick.color" : "black",
"xtick.color" : "black",
"axes.labelcolor" : "black",
"axes.edgecolor" : "black",
"text.usetex" : True,
"font.family" : "serif",
"font.serif" : ["Computer Modern Serif"]}
@ISDementyev
ISDementyev / build_dimer.py
Last active August 12, 2021 20:42
build_dimer public version (includes BioPython, PeptideBuilder dependencies)
# %%file build_dimer.py
import os
from PeptideBuilder import Geometry
import PeptideBuilder
import Bio.PDB
from simtk.unit import *
from simtk.openmm.app import *
import numpy as np
def buildPeptide(peptide, customAngles=False, phi=-40, psi=60, omega=180):