Example #1
0
    def __init__(self, structure_file, file_type=None):
        PDBIO.__init__(self)

        dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
            structure_file)
        self.structure_file = structure_file

        # Unzip the file if it is zipped
        if file_type == '.gz':
            unzipped = ssbio.utils.gunzip_file(structure_file, outdir=dirname)
            dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
                unzipped)

        if not file_type:
            file_type = file_type2
        else:
            if '.' not in file_type:
                file_type = '.{}'.format(file_type)

        if file_type in ['.pdb', '.ent', '.mmcif', '.cif', '.mmtf']:
            # Load the structure
            if file_type.lower() == '.pdb' or file_type.lower() == '.ent':
                structure = pdbp.get_structure(id='ssbio_pdb',
                                               file=structure_file)
            if file_type.lower() == '.mmcif' or file_type.lower() == '.cif':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = cifp.get_structure(structure_id='ssbio_cif',
                                                   filename=structure_file)
            if file_type.lower() == '.mmtf':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = mmtfp.get_structure(file_path=structure_file)
            log.debug('{}: parsed 3D coordinates of structure'.format(
                op.basename(structure_file)))
        else:
            raise ValueError('{}: unsupported file type'.format(file_type))

        # If there are multiple models (NMR), use the first model as the representative structure
        # if len(structure) > 1:
        #     self.first_model = structure[0]
        #     structure = structure[0]
        #     self.set_structure(structure)
        #     log.debug('{}: using first model'.format(structure_file))
        # elif len(structure) == 0:
        #     log.error('{}: no models in structure!'.format(structure_file))
        # else:
        self.set_structure(structure)
        self.first_model = structure[0]
Example #2
0
    def __init__(self, structure_file, file_type=None):
        PDBIO.__init__(self)

        dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
            structure_file)
        self.structure_file = structure_file

        # Unzip the file if it is zipped
        if file_type == '.gz':
            unzipped = ssbio.utils.gunzip_file(structure_file, outdir=dirname)
            dirname, filename_without_extension, file_type2 = ssbio.utils.split_folder_and_path(
                unzipped)

        if not file_type:
            file_type = file_type2
        else:
            if '.' not in file_type:
                file_type = '.{}'.format(file_type)

        if file_type.lower() in ['.pdb', '.ent', '.mmcif', '.cif', '.mmtf']:
            # Load the structure
            if file_type.lower() == '.pdb' or file_type.lower() == '.ent':
                structure = pdbp.get_structure(id='ssbio_pdb',
                                               file=structure_file)
            if file_type.lower() == '.mmcif' or file_type.lower() == '.cif':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = cifp.get_structure(structure_id='ssbio_cif',
                                                   filename=structure_file)
            if file_type.lower() == '.mmtf':
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', PDBConstructionWarning)
                    structure = mmtfp.get_structure(file_path=structure_file)
            log.debug('{}: parsed 3D coordinates of structure'.format(
                op.basename(structure_file)))
        else:
            raise ValueError('{}: unsupported file type'.format(file_type))

        self.set_structure(structure)
        try:
            self.first_model = structure[0]
        except KeyError:
            raise KeyError(
                '{}: no models contained in structure! Please check structure file contents.'
                .format(structure_file))