realpython / realpython/python-guide
adding a new @classmethod to an existing class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Batchfile
- Sterne
- 29.8k
- Forks
- 5.9k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Prüfe zunächst, ob diese Anfrage in python-guide gehört: Der Payload zielt auf opencadd.structure.core.Structure statt auf eine Guide-Datei. Falls sie in den Umfang fällt, lies Structure.from_pdbid und die benannten mmtf/MMCIFParser-Einstiegspunkte; abgeschlossen ist die Aufgabe erst, wenn es eine definierte, getestete Möglichkeit gibt, Structure-Objekte aus lokalen CIF-Dateien zu erstellen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 15/100