Skip to content

adding a new @classmethod to an existing class #1173

@llevoc

Description

@llevoc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions