This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%javascript | |
//hack to fix export | |
require.config({ | |
paths: { | |
d3: 'https://cdnjs.cloudflare.com/ajax/libs/d3/5.9.2/d3', | |
jquery: 'https://code.jquery.com/jquery-3.4.1.min', | |
plotly: 'https://cdn.plot.ly/plotly-latest.min' | |
}, | |
shim: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%javascript | |
//remember to append <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> to head or top of body. | |
//output_subarea output_html rendered_html | |
let index = 0; //or whatever is the number of the graph. | |
//$('.plotly-graph-div').map((i,el) => element.append('<p>'+$(el).attr('id')+'</p>')) | |
let chart = $('.plotly-graph-div').eq(index).parent(); | |
/// optionally one could change the dimensions for the .plotly-graph-div and svg elements. | |
//chart.children('.plotly-graph-div').css('height','525px'); | |
//chart.children('.plotly-graph-div').css('width','100%'); | |
let codeEl = $('<pre id="plotText"><code></code></pre>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wikitextparser as wtp | |
import re | |
####### code to convert template to dictionary | |
def arg_to_val(arg): | |
val = arg.value | |
for t in arg.templates: | |
tval = t.arguments[0].value | |
if t.normal_name() in ('nowrap', 'val'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, re, csv, pickle | |
import wikitextparser as wtp | |
class WikicatParser(): | |
""" | |
Gets all the pages recursively within a category and parser the content (via a suplied function) and gets pageviews. | |
>>>pages = WikicatParser(cat_name, custom_page_parser=my_function, extra_fields=[], forbidden_categories_keywords=[...]).get_pages_recursively() | |
>>>print(pages.data) | |
>>>pandas.DataFrame.from_records(list(pages.data.values())) | |
custom_page_parser is for content mining. a function that given wiki text returns a dictionary of whatever it mined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import display, HTML | |
import uuid | |
class Progress: | |
""" | |
Add a progressbar. | |
Using https://getbootstrap.com/docs/4.3/components/progress/ not the HTML5 one. | |
Note that Jupyter uses an older version: 3.4 (https://getbootstrap.com/docs/3.4/components/), but I doubt this will be so for long hence the color via style. | |
Two uses different uses. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from dataclasses import dataclass | |
from typing import List | |
import pyrosetta | |
@dataclass | |
class GapData: | |
chain: str | |
start: int # PDB index of first missing residue | |
previous: int # PDB index of the preceeding present residue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A raspberry pi has a green and a blue LED connected to D23 and D24 | |
# ============== imports ========================================= | |
from apscheduler.schedulers.background import BackgroundScheduler | |
from functools import partial | |
from datetime import datetime | |
import digitalio | |
import board | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NGLView is a great way to see a set of rdkit.Chem molecules in 3D. | |
# Right clicking gives green spheres by default. Right clicking on a sphere removes it. So nice way to keep track | |
# the `ModNGL` object contains the dynamic property `picked_atoms` which lists the atoms that were clicked. | |
# Clicked twice is removed. However, there is no way to determine the button integer (left, middle, wheel, right). | |
# Before loading the mols from rdkit it would be nice to fill the PDB info. | |
# As seen in https://blog.matteoferla.com/2020/03/atom-names-purely-in-rdkit.html | |
# once one has the atom names one can delete the atoms off a ``rdkit.Chem.RWMol`` making it nice and clear for Fragmenstein. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rdkit import Chem | |
from rdkit.Chem import AllChem | |
class DummyMasker: | |
""" | |
A context manager that allows operations on a mol containing dummy atoms (R/*) that | |
otherwise would raise an RDKit error. | |
It simply masks and unmasks the dummy atoms. | |
>>> mol = Chem.MolFromSmiles('*CCC(C)C') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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): |