add modify_residue_number

This commit is contained in:
2024-02-02 11:16:21 +08:00
parent 155153581f
commit cacef78dfc

View File

@@ -145,6 +145,30 @@ class PDBAnalyzer:
# Return a new instance of PDBAnalyzer pointing to the cleaned file
return cls(out_file)
def modify_residue_number(self, chain_id: str, original_res_num: int, new_res_num: int) -> PandasPdb:
"""
Modify the residue number for a specific chain in a PDB file.
Args:
chain_id (str): The chain identifier in the PDB file.
original_res_num (int): The original residue number to find.
new_res_num (int): The new residue number to replace with.
Returns:
PandasPdb: The modified PDB structure as a PandasPdb object.
"""
# Check if the residue number to be replaced exists
mask = (self.biodata.df['ATOM']['chain_id'] == chain_id) & \
(self.biodata.df['ATOM']['residue_number'] == original_res_num)
if not mask.any():
raise ValueError(f"Residue number {original_res_num} in chain {chain_id} does not exist in the PDB file.")
# Update the residue number
self.biodata.df['ATOM'].loc[mask, 'residue_number'] = new_res_num
# Return the modified PandasPdb object
return self.biodata
def extract_chains_to_new_pdb(self, chains: List[str]) -> PandasPdb:
"""