I have a multi model pdb file and would like to extract the last frame or any other frame from it.


Do you have access to OpenBabel to run from the terminal?

For the purpose of demonstration, the example following is demonstrated on a file listing SMILES strings. However, the concept may be applied on a .pdb with multiple models (and equally works well enough on multi-model .sdf).

The input file input.smi is a small set of aromatics. SMILES strings and labels are tabulator separated:

c1ccccc1    Compound 1
c1(cc(cc(c1)C)C)C   Compound 2
c1(ccc(cc1)C)C  Compound 3
c1(ccccc1)C Compound 4
n1ccccc1    Compound 5
n1cnccc1    Compound 6
n1cncnc1    Compound 7

My interest is on the p-xylene only (i.e., Compound 3). With the instruction

obabel -ismi input.smi -f 3 -l 3 -osmi -O interest.smi

OpenBabel anticipates the input file to contain SMILES (-ismi), starts processing with the third model entry onward (-f 3, line/model counting index in the file starts by 1), accessing all entries up and including the third one (-l 3) in this file. The output, to contain SMILES and their labels (if present) is formatted (-osmi) and written permanently (-O) into file interest.smi which eventually contains

 c1(ccc(cc1)C)C  Compound 3

Since OpenBabel run from CLI is agnostic about file extensions, your processing of .pdb to be read, and to be written requires an adjustment of the input/output parameters e.g., in the pattern of

obabel -ipdb input.pdb -f 3 -l 3 -opdb -O interest.pdb

This approach equally allows to extract a contiguous set of entries, e.g.

obabel -ismi input.smi -f3 -l5 -osmi -O interest.smi

to process 3 molecules at once. The toggles -f and -l may be used independently of each other, and spaces between them and their then mandatory integer parameters may be omitted. The approach however is unable to pick a set molecules in the mixed pattern like (1, 3-5, 7).

Said selection may be achieve from obgui, too:

enter image description here

file=test.pdb #pdb file 
frame=10 # frame number to extract 
x_frame=$(egrep "MODEL.* $frame$" $file)
sed -n "/$x_frame/,/ENDMDL/p" $file > ${file::-4}_frame_$frame.pdb

output file will be written as filename_frame_10.pdb

The bash script below provides easier (repeated) access to the functionality described:


# Extract a specific .pdb from a multi model .pdb file

# Save this bash script as pick_pdb.sh and run
# bash pick_pdb.sh test.pdb 3
# to write test_frame_3.pdb as new file.  Relies on bash and sed.

if [[ -z "$1" ]] ; then
    printf "Check how to use this bash script with
        bash pick_pdb.sh -h  \n"

elif [[ "$1" == "-h" || "$1" == "--help" ]] ; then
    printf "Export a specific model from multi model .pdb file.

E.g., to extract the third model from intput.pdb,

    bash pick_pdb.sh input.pdb 3

writes file input_frame_2.pdb.  \n"


    filebase="$(basename "$file" .pdb)"

    x_frame=$(egrep "MODEL.* $frame$" "$file")
    sed -n "/$x_frame/,/ENDMDL/p" "$file" > "$output"
  • $\begingroup$ @Buttonwood could you please share the file? $\endgroup$
    – BND
    Oct 18 at 11:20
  • $\begingroup$ thank you for catching this. I was grepping only ATOM section while babel has HETATM there. Removed the grep ATOM section. $\endgroup$
    – BND
    Oct 18 at 11:38
  • $\begingroup$ Ok. Because I like your approach to call sed to extract the model of interest, a small re-usable bash script was written around your instructions. So autocomplete (of the file name) by the CLI and state the number of the model one is interested suffice. The repeated use as such (or, embedded into an other script past chmod u+x pick_pdb.sh) like ./pick_pdb.sh input.pdb 3 offer the results quickly with little typing only. $\endgroup$
    – Buttonwood
    Oct 18 at 15:13
  • $\begingroup$ @Buttonwood , Fantastic :), thank you $\endgroup$
    – BND
    Oct 18 at 15:17

You can use the Python script multiple_model_PDB_file_splitter:

# multiple_model_PDB_file_splitter.py by Wayne Decatur
# ver 0.2
## PURPOSE: Takes a formatted pdb file with multiple models and splits each model
# into individual files. Requires the PDB file include both MODEL and ENDMDL

# records for each of the models.

# Originally developed in Python 2.7, but confirmed to work in Python 3.6.

You can download it from here.

Other useful script from the same author can be download here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.