Takes a PDB filepath and constructs a FDProtein object. WARNING: All non-standard residue types will be converted into UNK. All non-standard atoms will be ignored. All water residues will be ignored. All hetero residues will be ignored if `filter_out_hetero_residues` is `True`.
(
pdb_filepath: str,
model_id: int = 0,
atom_occupancy_min_threshold: int = 0.5,
filter_out_hetero_residues: bool = True,
allow_insertion_code: bool = True,
accept_only_valid_backbone_residues: bool = True,
chain_id: Optional[Union[List[str], str]] = None,
bounding_box: Optional[np.ndarray] = None,
res_start: Optional[int] = None,
res_end: Optional[int] = None,
)
| 792 | |
| 793 | @beartype |
| 794 | def pdb_filepath_to_protein( |
| 795 | pdb_filepath: str, |
| 796 | model_id: int = 0, |
| 797 | atom_occupancy_min_threshold: int = 0.5, |
| 798 | filter_out_hetero_residues: bool = True, |
| 799 | allow_insertion_code: bool = True, |
| 800 | accept_only_valid_backbone_residues: bool = True, |
| 801 | chain_id: Optional[Union[List[str], str]] = None, |
| 802 | bounding_box: Optional[np.ndarray] = None, |
| 803 | res_start: Optional[int] = None, |
| 804 | res_end: Optional[int] = None, |
| 805 | ) -> FDProtein: |
| 806 | """Takes a PDB filepath and constructs a FDProtein object. |
| 807 | |
| 808 | WARNING: All non-standard residue types will be converted into UNK. All |
| 809 | non-standard atoms will be ignored. All water residues will be ignored. |
| 810 | All hetero residues will be ignored if `filter_out_hetero_residues` is `True`. |
| 811 | All residues without valid positions for their N, Ca, C, and O atoms will be ignored. |
| 812 | |
| 813 | Adapted from: https://github.com/aqlaboratory/openfold and https://github.com/zrqiao/NeuralPLexer |
| 814 | |
| 815 | :param pdb_filepath: The filepath to the PDB file to parse. |
| 816 | :param model_id: The model number to parse. |
| 817 | :param atom_occupancy_min_threshold: The minimum occupancy threshold for atoms. |
| 818 | :param filter_out_hetero_residues: If True, then hetero residues will be ignored. |
| 819 | :param allow_insertion_code: If True, residues with insertion codes are parsed. |
| 820 | :param accept_only_valid_backbone_residues: If True, only residues with valid N, Ca, C, and O atoms are parsed. |
| 821 | :param chain_id: If `chain_id` is specified (e.g., `[A, B]`), then only those chains |
| 822 | are parsed. Otherwise, all chains are parsed. |
| 823 | :param bounding_box: If provided, only chains with backbone intersecting with |
| 824 | the box are parsed. |
| 825 | :param res_start: If provided, only residues with index >= res_start are parsed. |
| 826 | :param res_end: If provided, only residues with index <= res_end are parsed. |
| 827 | :return: A new `FDProtein` parsed from the PDB contents. |
| 828 | """ |
| 829 | assert pdb_filepath.endswith(".pdb"), f"Invalid file extension: {pdb_filepath}" |
| 830 | assert os.path.exists(pdb_filepath), f"File not found: {pdb_filepath}" |
| 831 | |
| 832 | with open(pdb_filepath) as pdb_fh: |
| 833 | pdb_str = pdb_fh.read() |
| 834 | |
| 835 | pdb_fh = io.StringIO(pdb_str) |
| 836 | parser = PDBParser(QUIET=True) |
| 837 | structure = parser.get_structure("none", pdb_fh) |
| 838 | models = list(structure.get_models()) |
| 839 | if not (0 <= model_id < len(models)): |
| 840 | raise ValueError(f"Model ID {model_id} is out of range") |
| 841 | model = models[model_id] |
| 842 | if isinstance(chain_id, str): |
| 843 | chain_id = [chain_id] |
| 844 | |
| 845 | seq = [] |
| 846 | atom_positions = [] |
| 847 | aatype = [] |
| 848 | atomtypes = [] |
| 849 | atom_mask = [] |
| 850 | residue_index = [] |
| 851 | chain_ids = [] |
no test coverage detected