Skip to content

Instantly share code, notes, and snippets.

import argparse
import json
import os
from datetime import datetime
import pathlib
import torch
import torch.multiprocessing as mp
from torch.optim import Adam
from torch.optim.lr_scheduler import LambdaLR
@yangkky
yangkky / alphafold2.ipynb
Created May 14, 2022 05:06
AlphaFold2.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yangkky
yangkky / masked_batch_norm.py
Last active December 10, 2022 20:24
Masked 1D batchnorm in PyTorch.
import torch
import torch.nn as nn
from torch.nn import init
class MaskedBatchNorm1d(nn.Module):
""" A masked version of nn.BatchNorm1d. Only tested for 3D inputs.
Args:
num_features: :math:`C` from an expected input of size
np.random.seed(9)
X1 = np.random.rand(3,4)*2
X1 = X1.astype(int)
X2 = np.random.rand(3,4)*2
X2 = X2.astype(int)
S = np.random.rand(9,2,2)
subs1 = [S[i][x1, x2] for i, (x1, x2) in enumerate(itertools.product(X1, X2))]
def test5(X1, X2, S):
i, n, n = S.shape
X_list = [[1, 0, 1, 0], [1, 1, 0, 0], [0, 1, 1, 1]]
X1 = torch.tensor(X_list)
X_list = [[1, 0, 1, 1], [1, 1, 1, 0], [1, 0, 1, 1], [1, 1, 1, 0]]
X2 = torch.tensor(X_list)
b1 = 3
b2 = 4
n = 2
d = 32
e1 = torch.randn(size=(b1, n, d))
e2 = torch.randn(size=(b2, n, d))
import numpy as np
from scipy import stats
n = 100
r = 10
x = np.linspace(-1.8, 1.8, n)
y = np.linspace(-1.8, 1.8, n)
X, Y = np.meshgrid(x, y)
from Bio.Seq import Seq
import Bio.PDB
import Bio.SeqUtils
pdb_filename = '../inputs/1qo7.pdb'
structure = Bio.PDB.PDBParser().get_structure(pdb_code, pdb_filename)
model = structure[0]
pdb_seq = [residue.resname for residue in model['B']]
pdb_seq = ''.join([Bio.SeqUtils.seq1(s) for s in pdb_seq])
ca_coord = np.array([residue['CA'].coord for residue in model['A'] if 'CA' in residue])
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-GB">
<info>
<title>Bioinformatics - Kevin Yang</title>
<id>http://csl.mendeley.com/styles/475547981/bioinformatics</id>
<link href="http://www.zotero.org/styles/bioinformatics" rel="self"/>
<link href="http://www.oxfordjournals.org/bioinformatics/for_authors/general.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>