当前位置: 首页 > news >正文

AF3 FeaturePipeline类解读

AlphaFold3 feature_pipeline 模块 FeaturePipeline 类是一个封装类,通过调用函数np_example_to_features 实现整个数据处理流程

源代码:

def np_to_tensor_dict(
    np_example: Mapping[str, np.ndarray],
    features: Sequence[str],
) -> TensorDict:
    """Creates dict of tensors from a dict of NumPy arrays.

    Args:
        np_example: A dict of NumPy feature arrays.
        features: A list of strings of feature names to be returned in the dataset.

    Returns:
        A dictionary of features mapping feature names to features. Only the given
        features are returned, all other ones are filtered out.
    """
    # torch generates warnings if feature is already a torch Tensor
    to_tensor = lambda t: torch.tensor(t) if type(t) != torch.Tensor else t.clone().detach()
    tensor_dict = {
        k: to_tensor(v) for k, v in np_example.items() if k in features
    }

    return tensor_dict


def make_data_config(
    config: ml_collections.ConfigDict,
    mode: str,
    num_res: int,
) -> Tuple[ml_collections.ConfigDict, List[str]]:
    cfg = copy.deepcopy(config)
    mode_cfg = cfg[mode]
    # with cfg.unlocked():
    if mode_cfg.crop_size is None:
        mode_cfg.crop_size = num_res

    feature_names = cfg.common.unsupervised_features

    # Add seqemb related features if using seqemb mode.
    if cfg.seqemb_mode.enabled:
        feature_names += cfg.common.seqemb_features

    if cfg.common.use_templates:
        feature_names += cfg.common.template_features

    if cfg[mode].supervised:
        feature_names += cfg.supervised.supervised_features

    return cfg, feature_names


def np_example_to_features(
    np_example: FeatureDict,
    config: ml_collections.ConfigDict,
    mode: str,
    is_multimer: bool = False
):
    np_example = dict(np_example)

    seq_length = np_example["seq_length"]
    num_res = int(seq_length[0]) if seq_length.ndim != 0 else int(seq_length)
    cfg, feature_names = make_data_config(config, mode=mode, num_res=num_res)
 
    if "deletion_matrix_int" in np_example:
        np_example["deletion_matrix"] = np_example.pop(
            "deletion_matrix_int"
        ).astype(np.float32)

    tensor_dict = np_to_tensor_dict(
        np_example=np_example, features=feature_names
    )

    with torch.no_grad():
        if is_multimer:
            features = input_pipeline_multimer.process_tensors_from_config(
                tensor_dict,
                cfg.common,
                cfg[mode],
            )
        else:
            features = input_pipeline.process_tensors_from_config(
                tensor_dict,
                cfg.common,
                cfg[mode],
            )

    if mode == "train":
        p = torch.rand(1).item()
        use_clamped_fape_value 

相关文章:

  • 网站关键词设定百度推广创意范例
  • 怎样做校园网站推广在线培训网站次要关键词
  • 做商城网站产品怎么分布考证培训机构报名网站
  • vue做网站如何优化seo百度的网站网址
  • 网站示例关键词优化上海
  • 在线设计平台的概念如何优化网络延迟
  • 经典动态规划问题:爬楼梯的多种解法详解
  • 基于大模型的知识图谱搜索的五大核心优势
  • 每日c/c++题 备战蓝桥杯(二分答案模版)
  • 函数指针在C++遍历函数中的写法和应用(直接在函数中定义函数指针)。
  • Python调用手机摄像头检测火焰烟雾的三种方法
  • python定时调度升级
  • 使用 Ansys Discovery 可视化液体池中的水流
  • ES拼音分词自动补全实现
  • LLMs之PE:《Tracing the thoughts of a large language model》翻译与解读
  • 单例模式解析
  • 畅享电脑流畅运行:深度卸载、智能监视与空间释放
  • JS绘制叠加图片
  • 04_SQL概述及DDL
  • docker镜像拉取失败
  • Foldseek快速蛋白质结构比对
  • 计算机组成原理笔记(八)——2.4十进制和数串的表示
  • D4RL库的安装历程及成功经验
  • Golang并发编程:Data Race检测与解决方案
  • Qt非阻塞延时实现
  • 基于 GEE 的区域降水数据可视化:从数据处理到等值线绘制