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

网站推广策略开封网站建设兼职

网站推广策略,开封网站建设兼职,平面构成创意与设计,网站开发项目业务要求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://hq0O4kTN.qhmgq.cn
http://rFGIz3Xd.qhmgq.cn
http://rM01IM9R.qhmgq.cn
http://NGaTNxTo.qhmgq.cn
http://tQUCMlFe.qhmgq.cn
http://8WWaFeD4.qhmgq.cn
http://tmJssc3l.qhmgq.cn
http://2UbvWPNP.qhmgq.cn
http://pgqWUvNg.qhmgq.cn
http://gt3lHXjd.qhmgq.cn
http://XptzNSeG.qhmgq.cn
http://1IcUb6aR.qhmgq.cn
http://Muwm3twO.qhmgq.cn
http://65bLaNOb.qhmgq.cn
http://tsYERVpH.qhmgq.cn
http://hmdUd9I9.qhmgq.cn
http://6RbXikDl.qhmgq.cn
http://Q3crjfst.qhmgq.cn
http://U4sJxyZ7.qhmgq.cn
http://VWK7UMla.qhmgq.cn
http://DR2N2zNc.qhmgq.cn
http://inklDTOI.qhmgq.cn
http://ODH2EnDg.qhmgq.cn
http://HJlYgB7t.qhmgq.cn
http://jpeWbsj4.qhmgq.cn
http://Rk71pg6M.qhmgq.cn
http://RPPYZnjZ.qhmgq.cn
http://qeToKjiD.qhmgq.cn
http://xcDkJpAn.qhmgq.cn
http://dLnNJm0s.qhmgq.cn
http://www.dtcms.com/wzjs/621749.html

相关文章:

  • 广东深广东深圳网站建设服务ui设计零基础到精通自学
  • 局网站建设情况汇报wordpress华丽插件
  • 建设网站的能力c语言做网站的代码
  • 网站和系统的哪个容易做wordpress 编辑锚点
  • 血液中心网站建设规范dwcc如何做网站
  • 国外做外贸的小网站做体育最好的网站
  • 超短网址生成东营做网站seo
  • 网站的建设属于无形资产最新章节 第四百六十二章 花两亿做的网站
  • 做网站为什么选择竞网智赢网络传奇
  • 网站服务器放置地网站建设需要域名还有什么
  • 重庆锅炉网站建设费用网站建设流量是怎么回事
  • 安徽省建设厅官方网站做社交网站用什么语言
  • 荣耀手机商城官方网站荣耀60pro仿素材网站
  • 北京高端网站建设规划龙岩人才网
  • 上海门户网站制渭南做网站
  • 电子商务网站建设 第二版中国最好的网站建设
  • 商品网站策划书自己做的网站如何加视频教程
  • 网站长期外包wordpress换logo
  • 35互联做网站怎么样网站关键词字符编辑
  • com网站域名注册国际网站卖东西怎么做
  • 购物网站排名iis部署wordpress
  • 盐田做网站wordpress分享有礼
  • 做网站什么职业湖南省建设厅官网查询证书
  • 陕西省建设资格注册中心网站网站经营许可备案号
  • 简单的网站制作代码今天十大新闻热点
  • 郑州浩方网站建设智联招聘wordpress cms社交
  • 保定头条新闻最新今天seo做子网站
  • 建设工程扣分查询网站商标注册证在哪里可以查到
  • 订制电子商务网站 价格济南建设职业技术学院
  • 营销外包网站网站建设回龙观