Skip to content

Instantly share code, notes, and snippets.

Avatar

Matteo Ferla matteoferla

View GitHub Profile
@matteoferla
matteoferla / set_to_neutral_pH
Last active Sep 17, 2021
A small function to fix the pH protonation/deprotonation of RDKit Chem objects —fixes the charge of simple, i.e. biological cases. So amino acid is fine, but complex artificial drug won't be.
View set_to_neutral_pH
from rdkit import mol
def set_to_neutral_pH(mol: Chem):
"""
Not great, but does the job.
* Protonates amines, but not aromatic bound amines.
* Deprotonates carboxylic acid, phosphoric acid and sulfuric acid, without ruining esters.
"""
protons_added = 0
@matteoferla
matteoferla / colabs_mike.ipynb
Created Sep 13, 2021
Colabs cell to upload a given structure within `output_dir` to Michelanglo
View colabs_mike.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matteoferla
matteoferla / notebook_clipboard.py
Created Sep 6, 2021
Copy the browser's system's clipboard into a variable in the Python kernel of a notebook potentially hosted remotely (i.e. on a different system)
View notebook_clipboard.py
def get_notebook_clipboard(variable_name:str) -> None:
"""Called on its own cell,
assigns the value of the browser's clipboard to the Python `variable`,
available after the cell has run.
This is due to the issue that the system clipboard of the notebook may differ (remote)"""
from IPython.display import HTML
HTML(f"""<script>
console.log('Reading clipboard...');
navigator.clipboard.readText().then(text => IPython.notebook.kernel.execute(`{variable_name} = "${'text'}"`));
console.log('...Clipboard read.');
@matteoferla
matteoferla / msa_maker.py
Created Jul 16, 2021
A simple class to make a MSA picture using Plotly or simply convert a residue position from seq A to seq B.
View msa_maker.py
from typing import *
import requests
import plotly.graph_objects as go
import numpy as np
from collections import Counter
# biopython imported within the method.
class MSAMaker(MSAOps):
"""
@matteoferla
matteoferla / distances.py
Last active Jul 2, 2021
Get a table of distances from a set of residues
View distances.py
# this is not the quickest way, but gets the job done.
code = 'XXXX'
targets = dict(gate = [2517, 2513],
filter = [2472, 2478],
calcium = [3003, 3004],
zinc = [3001],
i3p = [3002]
)
@matteoferla
matteoferla / consurfer.py
Last active Apr 30, 2021
An unofficial Python API to the Consurf DB that allows pandas output, chain changes, offset correction, conservation mapping to bfactors of a PyRosetta pose or PyMOL object etc. Can get offset from aligning or Swissmodel
View consurfer.py
from typing import *
import re
import requests
# not std lib imports in methods --> bad typehinting
class Consurfer:
"""
@matteoferla
matteoferla / blanker.js
Last active Oct 15, 2021
Given a webpage requiring a low res screenshot, replace words with ■. Handy for making screenshots where words do not matter (see below for details)
View blanker.js
function blanker(node) {
//vanilla JS. Change the following as desired:
const blankBlock = '■'; //'▬'
const unblankableTags = ['H1', 'H2', 'H3', 'H4', 'H5'];
const unblankableClasses = ['font-weight-bold'];
// cases:
if (unblankableTags.includes(node.tagName)) {
//pass
} else if (node.classList && unblankableClasses.some(c => node.classList.contains(c))) {
@matteoferla
matteoferla / print_score_weight_table.py
Created Apr 1, 2021
Making a table of Pyrosetta scorefunctions
View print_score_weight_table.py
# this was run in a Jupyter notebook.
import pyrosetta
import os
import pandas as pd
from typing import *
pyrosetta.distributed.maybe_init(extra_options='-mute all')
# ------------------------------------------------------------------------------------
@matteoferla
matteoferla / ss_parser.py
Last active Mar 5, 2021
In NGL a problem is that sheets don't look right when there are no `SHEET` or `HELIX` records. This Python class return to as a string output the SS of the PDB. Currently uses PyMOL, but in future I'll add Pyrosetta.
View ss_parser.py
from collections import namedtuple
class SSParser:
"""
Create a SS block from PDB data.
Written to be agnostic of PDB parser, but for now only has PyMOL.
.. code-block:: python
@matteoferla
matteoferla / sphinxify_vars.py
Created Feb 6, 2021
Print out what the attributes are for copy pasting for Sphinx documentation
View sphinxify_vars.py
"""
In the docstring for a class the variables can be defined with ``:var xxx:``, ``:ivar xxx:`` and ``:cvar xxx:``.
This prints a block for a given class instance to make it easier.
Dynamic attributes will be marked as class variables.
Private attributes will not show.
NB. Writing ``#:`` is probably easier and saner, but has to be done during coding...
"""
def sphinxify_vars(obj):