realpython / realpython/python-guide
adding a new @classmethod to an existing class
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Batchfile
- Estrelas
- 29.8k
- Forks
- 5.9k
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Primeiro, verifique se esta solicitação pertence ao python-guide: o payload tem como alvo opencadd.structure.core.Structure, e não um arquivo do guia. Se estiver no escopo, leia Structure.from_pdbid e os entry points nomeados de mmtf/MMCIFParser; o trabalho estará concluído quando houver uma forma definida e testada de construir objetos Structure a partir de arquivos CIF locais.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 15/100