realpython / realpython/python-guide
adding a new @classmethod to an existing class
還沒有人認領這個 Issue。
- 主要語言
- Batchfile
- 星號
- 29.8k
- 分支
- 5.9k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先確認此請求是否屬於 python-guide:payload 針對的是 opencadd.structure.core.Structure,而不是 guide 檔案。如果屬於範圍內,請閱讀 Structure.from_pdbid 和指定的 mmtf/MMCIFParser 入口點;只有在有一種已定義且經過測試的方式可以從本機 CIF 檔案建構 Structure 物件時,才算完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 15/100