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

动态网站开发j手机如何制作自己的网站

动态网站开发j,手机如何制作自己的网站,个人博客系统wordpress,网站研发公司AlphaFold3 create_alignment_db_sharded 脚本在源代码的scripts/alignment_db_scripts文件夹下。 该脚本中的 create_shard 函数的功能是将一部分链(shard_files)中的所有对齐文件写入一个 .db 文件,并返回这些链的索引信息(字节…

AlphaFold3 create_alignment_db_sharded 脚本在源代码的scripts/alignment_db_scripts文件夹下。 该脚本中的 create_shard 函数的功能是将一部分链(shard_files)中的所有对齐文件写入一个 .db 文件,并返回这些链的索引信息(字节偏移+长度+文件名)供上层构建 super index。

源代码:

def create_shard(shard_files: list[Path], output_dir: Path, output_name: str, shard_num: int
) -> dict:"""Creates a single shard of the alignment database, and returns thecorresponding indices for the super index."""CHUNK_SIZE = 200shard_index = defaultdict(create_index_default_dict)  # e.g. {chain_name: {db: str, files: [(file_name, db_offset, file_length)]}, ...}chunk_iter = chunked_iterator(shard_files, CHUNK_SIZE)pbar_desc = f"Shard {shard_num}"output_path = output_dir / f"{output_name}_{shard_num}.db"db_offset = 0db_file = open(output_path, "wb")for files_chunk in tqdm(chunk_iter,total=ceil(len(shard_files) / CHUNK_SIZE),desc=pbar_desc,position=shard_num,leave=False,):# get processed files for one chunkchunk_data = process_chunk(files_chunk)# write to db and store info in indexfor chain_name, file_data in chunk_data.items():shard_index[chain_name]["db"] = output_path.namefor file_name, file_bytes in file_data:file_length = len(file_bytes)shard_index[chain_name]["files"].append((file_name, db_offset, file_length))db_file.write(file_bytes)db_offset += file_lengthdb_file.close()return shard_index

代码解读:

函数签名
def create_shard(shard_files: list[Path],         # 当前 shard 负责处理的链目录列表output_dir: Path,                # 输出 .db 文件的目录output_name: str,                # .db 文件名前缀(如 "alignment")shard_num: int                   # 当前 shard 的编号(用于命名)
) -> dict:                           # 返回:当前 shard 的 index 字典
初始化
CHUNK_SIZE = 200
shard_index = defaultdict(create_index_default_dict)
chunk_iter = chunked_iterator(shard_files, CHUNK_SIZE)
output_path = output_dir / f"{output_name}_{shard_num}.db"
db_offset = 0
db_file = open(output_path, "wb")
  • CHUNK_SIZE = 200:每次并发处理 200 个链目录,避免线程开销过大

  • shard_index:保存当前 shard 中的所有链名对应的索引信息

  • output_path:构造 .db 文件的路径,如 alignment_0.db

  • db_offset:记录当前 .db 文件的写入偏移位置(以字节为单位)

shard_index = defaultdict(create_index_default_dict)

这里你传入的是一个函数名 create_index_default_dict而不是函数调用结果(也就是不加 ())!

意图:

让 defaultdict 在访问一个不存在的 key 时,调用该函数来生成默认值。

说明
defaultdict(<function>)不是调用函数,而是传入一个函数对象
每次访问不存在的 key会自动执行 function(),作为该 key 的默认值
适合嵌套结构如 dict[str → dict[str, list]]
主循环:分批读取 + 写入
for files_chunk in tqdm(chunk_iter, ...):chunk_data = process_chunk(files_chunk)

调用 process_chunk():多线程读取这 200 个链目录下的所有文件,得到结构:

chunk_data = {"1abc_A": [("file1.a3m", b"..."), ("file2.sto", b"...")],"2xyz_B": [("file1.a3m", b"...")]
}
写入 .db 文件 + 更新索引
for chain_name, file_data in chunk_data.items():shard_index[chain_name]["db"] = output_path.namefor file_name, file_bytes in file_data:file_length = len(file_bytes)shard_index[chain_name]["files"].append((file_name, db_offset, file_length))db_file.write(file_bytes)db_offset += file_length

对于每个链:

  • shard_index[chain_name]["db"] 记录它在哪个 .db 文件中

  • 每个对齐文件都写入 .db 文件,顺序写入

  • 记录每个文件的 (file_name, 起始字节位置, 文件长度)

  • 更新 db_offset 以便下一个文件写入时知道正确的起点

完成处理后关闭文件并返回索引
db_file.close()
return shard_index

这个 shard_index 是供上层 super_index.update(shard_index) 使用的,格式类似:

{"1abc_A": {"db": "alignment_0.db","files": [["file1.a3m", 0, 1024],["file2.sto", 1024, 512]]}
}
总结:函数作用图解
[shard_files: list of chain dirs]↓
[chunked (200 chains at a time)]↓
[每个 chunk -> 并发读取 (ThreadPoolExecutor)]↓
[每个文件的字节数据 -> 顺序写入到 .db 文件]↓
[记录 offset 和长度 → shard_index 字典]↓
[返回 shard_index 字典]

函数特点与优势

特点优势
Chunk 处理降低内存和线程并发压力
多线程读取加快文件加载速度
顺序写入.db 文件结构简单,适合大规模读取
索引记录精确每个链的每个文件都有 offset,方便快速查找
与 ProcessPoolExecutor 配合使用多个 shard 并行构建,CPU 利用率高
http://www.dtcms.com/wzjs/38177.html

相关文章:

  • 抖音 运营关键词点击优化工具
  • 宁波网站建设是哪家便宜怎么制作一个简单的网页
  • 服装企业北京网站建设百度第三季度财报2022
  • webydo生成的网站能下载代码吗seo排名软件怎么做
  • 网站开发编辑器能翻到国外的浏览器
  • 做化学合成的网站有哪些百度推广平台登录网址
  • 无锡网站制作高端丹东网站seo
  • 做网站需要注册商标多少类当日网站收录查询统计
  • 那里做直播网站优化网络
  • 大型移动网站开发中国新冠一共死去的人数
  • 自己做网站需要学什么软件网站开发需要的技术
  • 校园网站短视频代运营费用明细
  • b2b商城网站建设关键词优化收费标准
  • 网站建设技术人员招聘百度热榜排行
  • 嘉兴商城网站开发设计营销型网站有哪些
  • 平度做网站广州seo关键词优化费用
  • 海外seo网站推广google官网注册账号入口
  • 比wordpress更好的网站程序什么是网站外链
  • 网站推广公司就去柚米产品互联网推广
  • 建设网站要服务器吗微信公众号怎么创建
  • 做药品网站有哪些内容近一周新闻热点事件
  • 怎么用本机做服务器发布网站电商网站建设步骤
  • 用网站做平台网站建设图片
  • 英文网站设计哪家好网站搭建教程
  • 石家庄专业建站公司百度指数名词解释
  • 网站后台不能粘贴企业seo
  • 无锡滨湖住房与城乡建设局网站公司网站推广方法
  • 免费独立站建站平台有哪些中国免费网站服务器下载
  • 承德市隆化城乡建设局网站seo搜索引擎优化心得体会
  • 企业网站建设的目的和意义微信引流推广