update modify_residue_number and add batch_modify_residues
This commit is contained in:
@@ -146,7 +146,7 @@ class PDBAnalyzer:
|
|||||||
# Return a new instance of PDBAnalyzer pointing to the cleaned file
|
# Return a new instance of PDBAnalyzer pointing to the cleaned file
|
||||||
return cls(out_file)
|
return cls(out_file)
|
||||||
|
|
||||||
def modify_residue_number(self, chain_id: str, original_res_num: int, new_res_num: int) -> PandasPdb:
|
def modify_residue_number(self, chain_id: str, original_res_num: int, new_res_num: int) -> None:
|
||||||
"""
|
"""
|
||||||
Modify the residue number for a specific chain in a PDB file.
|
Modify the residue number for a specific chain in a PDB file.
|
||||||
|
|
||||||
@@ -154,9 +154,6 @@ class PDBAnalyzer:
|
|||||||
chain_id (str): The chain identifier in the PDB file.
|
chain_id (str): The chain identifier in the PDB file.
|
||||||
original_res_num (int): The original residue number to find.
|
original_res_num (int): The original residue number to find.
|
||||||
new_res_num (int): The new residue number to replace with.
|
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
|
# Check if the residue number to be replaced exists
|
||||||
mask = (self.biodata.df['ATOM']['chain_id'] == chain_id) & \
|
mask = (self.biodata.df['ATOM']['chain_id'] == chain_id) & \
|
||||||
@@ -167,6 +164,21 @@ class PDBAnalyzer:
|
|||||||
# Update the residue number
|
# Update the residue number
|
||||||
self.biodata.df['ATOM'].loc[mask, 'residue_number'] = new_res_num
|
self.biodata.df['ATOM'].loc[mask, 'residue_number'] = new_res_num
|
||||||
|
|
||||||
|
def batch_modify_residues(self, modifications: dict) -> PandasPdb:
|
||||||
|
"""
|
||||||
|
Batch modify multiple residues in a PDB file based on a dictionary of modifications.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
modifications (dict): A dictionary with chain identifiers as keys and a list of
|
||||||
|
tuples (original_res_num, new_res_num) as values.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
PandasPdb: The modified PDB structure as a PandasPdb object.
|
||||||
|
"""
|
||||||
|
for chain_id, changes in modifications.items():
|
||||||
|
for original_res_num, new_res_num in changes:
|
||||||
|
self.modify_residue_number(chain_id, original_res_num, new_res_num)
|
||||||
|
|
||||||
# Return the modified PandasPdb object
|
# Return the modified PandasPdb object
|
||||||
return self.biodata
|
return self.biodata
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user