Skip to content

Instantly share code, notes, and snippets.

View pengzhangzhi's full-sized avatar
:bowtie:
thinking

Fred pengzhangzhi

:bowtie:
thinking
View GitHub Profile
@pengzhangzhi
pengzhangzhi / discrete_flow_matching.py
Created March 11, 2025 22:37
standard alone discrete diffusion model example on 2D data.
import torch
import matplotlib.pyplot as plt
from torch import nn, Tensor
from sklearn.datasets import make_moons
# Set device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class DiscreteFlow(nn.Module):
def __init__(self, dim: int = 2, h: int = 128, v: int = 128):
@pengzhangzhi
pengzhangzhi / esmfold.py
Created February 5, 2025 16:36
using esmfold to fold a dir of fasta or just a fasta file.
# Copyright (c) 2023 Meta Platforms, Inc. and affiliates
# Copyright (c) 2024 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: Apache-2.0
#
# This file has been modified by Xinyou Wang on Jul 21, 2024
#
# Original file was released under MIT, with the full license text
# available at https://github.com/facebookresearch/esm/blob/main/LICENSE
#
# This modified file is released under the same license.
def renum_pdb_str(pdb_str, Ls=None, renum=True, offset=1):
from string import ascii_uppercase, ascii_lowercase
assert len(Ls) == 2
Ls = [int(i) for i in Ls]
alphabet_list = list(ascii_uppercase+ascii_lowercase)
if Ls is not None:
L_init = 0
new_chain = {}
for L,c in zip(Ls, alphabet_list):
new_chain.update({i:c for i in range(L_init,L_init+L)})