adding a new @classmethod to an existing class

未关闭
#1,173 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
15/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
backend

调研方向

首先确认此请求是否属于 python-guide:payload 针对的是 opencadd.structure.core.Structure,而不是 guide 文件。如果属于范围内,请阅读 Structure.from_pdbid 和指定的 mmtf/MMCIFParser 入口点;只有在有一种已定义且经过测试的方式可以从本地 CIF 文件构造 Structure 对象时,才算完成。

由索引模型根据 Issue 内容生成。

描述

I have a python programming issue which I have not solved.

In python3, using 'from opencadd.structure.core import Structure'

defines the class Structure. The section of the Structure code that I need to modify is

@classmethod
@redo.retriable(attempts=10, sleeptime=2)
def from_pdbid(cls, pdbid):
    import mmtf

    return cls(mmtf.fetch(pdbid))

where I would like to include

# New method for CIF files
@classmethod
def from_cif(cls, filepath: str):
    """
    Create a Structure object from a local CIF file.
    """
    parser = MMCIFParser()
    structure_data = parser.get_structure("cif_file", filepath)
    # ... (processing to build Volkamer Structure object)
    return cls(atoms, residues, bonds)

This will skip trying to execute mmtf.fetch (which will timeout because pdb is no longer available for mmtf.fetch).
Instead using Structure.from_cif will avoid this issue and retrieve the file.

So far, I have not been able to do this successfully. Many blogs offer suggestions about adding a classmethod,
but I have failed and am asking for help from python exports.

Thanks in advance,
David
Fortran, R, Matlab, C, AWK, Perl, no Python

主要语言
Batchfile
星标
29.8k
派生
5.9k
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

realpython/python-guide 的其他 Issue

查看 realpython/python-guide 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。