Skip to content

Instantly share code, notes, and snippets.

@sjdv1982
sjdv1982 / AspectLayout.py
Created September 7, 2017 13:12
QLayout that keeps fixed aspect ratio of its only widget.
# Sjoerd de Vries, 2017
# partially based on code ported from https://gist.github.com/pavel-perina/1324ff064aedede0e01311aab315f83d, copyright (c) 2017 Pavel Perina
"""
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="kekule/release/kekule.js?modules=chemWidget,openbabel,indigo"></script>
<script>
Kekule.Indigo.enable();
1. Hex:
wget http://hex.loria.fr/dist800/hex-8.0.0-x64-mint14.run
chmod +x ./hex-8.0.0-x64-mint14.run
./hex-8.0.0-x64-mint14.run
Press Enter if there is any default value (in [...] )
Otherwise, type "y"
import numpy as np
from collections import namedtuple
### Convenience functions
variables = (
"rank", # 0 for no bid, 1 for 1 clubs, 2 for 1 diamonds, ..., 5 for 1 no-trump, ..., 35 for 7 no-trump
"passes", # 0 - 4 consecutive passes
"turn", # whose turn it is; 0 for the team who opens the bidding, 1 for the other
"contractor", # the team who did the last bidding; 0 for the team who opens the bidding, 1 for the other
"doubles" # the number of doubles (0,1,2)
"""
Recursive Bayesian approach to create optimal tournament schedules
Solution for The Riddler Classic, July 19: https://fivethirtyeight.com/features/can-you-construct-the-optimal-tournament/
Results:
4 players, 4 games:
Game 1. Player A vs player B, winner becomes the favorite.
Game 2. Favorite vs player C.
import numpy as np
fragments = np.load("fragments_clust.npy")
redun = np.load("redundancy-masks/1.0-seqclust-50.npy").astype(bool)
fragments = fragments[redun]
fragments_aa = np.array([f for f in fragments if f["motif"] == b"AAA"])
clus = [f for f in fragments_aa if f["clust1.0"] == 700]
print(clus)
@sjdv1982
sjdv1982 / cryoEM-galactosidase.ipynb
Last active January 28, 2020 13:07
MDFF-like (Wilson-regime) cross-correlation for simulated cryo-EM density maps of beta-galactosidase
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""fivethirtyeight.com Riddler Classic, Dec 11
https://fivethirtyeight.com/features/how-high-can-you-count-with-menorah-math/
'''
From Alex van den Brandhof comes a matter of life and death:
The Potentate of Puzzles decides to give five unlucky citizens a test. The potentate has countless red hats, green hats and blue hats. She says to the citizens, “Tomorrow, you will all be blindfolded as I place one of these hats on each of your heads. Once all the hats are placed, your blindfolds will be removed. At this point, there will be no communication between any of you! As soon as I give a signal, everyone must guess — at the same time — the color of the hat atop their own head. If at least one of you guesses correctly, all of you will survive! Otherwise …”
The potentate continues: “The good news is that there’s a little more information you’ll have. I will be arranging you into two rows facing each other, with two of you in one row and three of you in the other. Citizens in the same row cannot see each other,
"""
Parses the biological assemblies of a mmCIF file
For each assembly.
a list of 4x4 transformation matrices is computed, and returned together
with a list of chains
Each transformation matrix is to be applied to each chain in the list
Biological assemblies may contain non-protein or fantasy chains; it is possible
to pass in a list of interesting chains, and the returned chain lists will
then be filtered accordingly
"""
11 cards, 55 points in total
S = current score
K = cards remaining
score increase = (chance to draw a non-joker * average value of non-joker) - (chance to draw a joker * S)
= (K-1)/K * (55-S)/(K-1) - 1/K * S
= (55-S)/K - S/K
= (55 - 2S)/K