# How to extract part of protein complex separated with HEADER with two molecules from one PDB file

I have a PDB file which contain two molecules (receptor and ligand). Each molecule will have its own header. All in ONE PDB file.

‌The header of receptor section looks like this (line 1-6 of the PDB file):

HEADER rec.pdb
REMARK original generated coordinate pdb file
ATOM      1  N   GLY A   1     -51.221 -13.970  37.091  1.00  0.00      RA0  N
ATOM      2  H   GLY A   1     -50.383 -13.584  37.482  1.00  0.00      RA0  H
ATOM      3  CA  GLY A   1     -50.902 -15.071  36.197  1.00  0.00      RA0  C
ATOM      4  C   GLY A   1     -49.525 -15.659  36.443  1.00  0.00      RA0  C


and this ligand section (line 11435 to 11440) of the PDB file

HEADER lig.000.00.pdb
ATOM      1  N   MET A   1      27.318 -26.957  12.663  1.00  0.00      LA0  N
ATOM      2  H   MET A   1      27.313 -27.570  11.870  1.00  0.00      LA0  H
ATOM      3  CA  MET A   1      28.374 -27.102  13.668  1.00  0.00      LA0  C
ATOM      4  CB  MET A   1      28.531 -28.564  14.090  1.00  0.00      LA0  C
ATOM      5  CG  MET A   1      27.224 -29.154  14.628  1.00  0.00      LA0  C


Note that the receptor and ligand section also contain the string RA0 and LA0 at the 11th column of PDB file.

What I want to do is to rename the chain of receptor as chain A and ligand as chain B. In order to do that I intended to extract both part into two different objects first, then rename the chain and finally put them together again.

I tried this code with Bio3D. But doesn't work:

library(bio3d)
pdb_infile <- "myfile.pdb"

receptor_segment.sele <- atom.select(pdb, segid = "RA0",  verbose = TRUE)
receptor_pdb <- trim.pdb(pdb, receptor_segment.sele)
ligand_segment.sele <- atom.select(pdb, segid = "LA0",  verbose = TRUE)
ligand_pdb <- trim.pdb(pdb, ligand_segment.sele) # showed no entry


What's the way to do it? I'm open to solution with R or Python.

Since this is not a correct PDB file, it can be interpreted differently by different PDB reading libraries. The most reliable way to change it would be to read it as plain text and change the chain ID to B in the lines that have segment ID LA0.