I used the “fold.py” script to calculate the NMR structure in Xplor-NIH (version 3.9). By default, the script doesn’t define the “chain ID” of the generated structures. It is often fine when visualizing in PyMOL or ChimeraX. However, chain ID is required for PDB deposition.
There are many ways to add chain ID to the NMR structures. Here are two examples.
===== Option #1 =========
I used chatGPT to generate a Python script to add chain ID in the ensemble file which was generated by another Python script. The default chain ID is “A”. Feel free to modify the script.
def add_chain_if_missing(input_pdb, output_pdb, default_chain='A'):
"""
Reads an ensemble PDB file, checks if chain information is missing,
and assigns a default chain if necessary.
made bye ChatGPT, 2025-02-01
Parameters:
input_pdb (str): Path to the input PDB file.
output_pdb (str): Path to save the modified PDB file.
default_chain (str): The chain identifier to assign if missing (default: 'A').
"""
with open(input_pdb, 'r') as infile, open(output_pdb, 'w') as outfile:
for line in infile:
if line.startswith(('ATOM', 'HETATM')):
if line[21].strip() == '': # Check if chain field is empty
line = line[:21] + default_chain + line[22:] # Insert default chain
outfile.write(line)
print(f"Modified PDB saved as {output_pdb}")
# Example usage
input_pdb = "aligned_ensemble.pdb" # Replace with your input PDB file
output_pdb = "aligned_ensemble_chainA.pdb" # Replace with your desired output file
add_chain_if_missing(input_pdb, output_pdb)
===== Option #2 =======
The second one is also an Python script, but it utilizes PyMOL to execute the same function.
from pymol import cmd
# Load your NMR ensemble file (PDB format)
cmd.load("ensemble.pdb", "nmr_ensemble")
# Loop through all models and change the chain ID
for i in range(1, cmd.count_states("nmr_ensemble") + 1):
cmd.alter(f"nmr_ensemble and state {i}", "chain='A'") # Change 'A' to desired chain
print(f"Modified chain ID in model {i}")
# Save all states into a new PDB file
cmd.save("modified_ensemble.pdb", "nmr_ensemble", state=0) # state=0 saves all states
# Quit PyMOL
cmd.quit()
Both scripts were tested and functioned well.
Note: the fold.py script can be found at: XPLOR-version-direcotry/eginput/gb1_rdc/