Looks up a protein name in the RCSB PDB search API and downloads the best matching legacy PDB file. A 4-character PDB ID can also be supplied directly.

download_pdb(
  protein,
  out_dir = ".",
  filename = NULL,
  overwrite = FALSE,
  max_results = 10L,
  verbose = FALSE
)

Arguments

protein

Protein name or 4-character PDB ID.

out_dir

Default `"."`. Directory where the PDB file will be written.

filename

Default `NULL`. Optional output file name. If `NULL`, the downloaded file is named with the matched PDB ID.

overwrite

Default `FALSE`. Whether to overwrite an existing file.

max_results

Default `10L`. Maximum number of RCSB search matches to try when downloading a legacy PDB file.

verbose

Default `FALSE`. If `TRUE`, report the matched PDB ID and destination path.

Value

Path to the downloaded PDB file.

Examples

# Start with a direct PDB ID download. A temporary directory, custom
# filename, overwrite flag, and verbose output make the file handling clear.
pdb_file = download_pdb(
  "4fsp",
  out_dir = tempdir(),
  filename = "outer-membrane-barrel.pdb",
  overwrite = TRUE,
  verbose = TRUE
)
#> Downloaded RCSB PDB 4FSP for '4fsp' to /tmp/Rtmp0RXH6o/outer-membrane-barrel.pdb

read_pdb(pdb_file, verbose = TRUE) |>
  generate_ribbon_scene() |>
  render_model(
    pathtrace = FALSE,
    width = 800,
    height = 800,
    background = "grey12"
  )
#> Read CRYSTAL STRUCTURE OF PSEUDOMONAS AERUGINOSA OCCK11 (OPDR) PDB models [1]
#>   PDB ID: 4FSP
#>   Experiment: X-RAY DIFFRACTION
#>   Parsed: 3135 atoms, 364 residues, 1 chains, 192 bonds


# Protein-name lookup searches RCSB and tries up to three legacy PDB matches.
hemoglobin_file = download_pdb(
  "hemoglobin",
  out_dir = tempdir(),
  max_results = 3L
)
read_pdb(hemoglobin_file, verbose = TRUE) |>
  generate_ribbon_scene() |>
  render_model(
    pathtrace = FALSE,
    width = 800,
    height = 800,
    background = "grey12"
  )
#> Read CRYSTAL STRUCTURE OF DOG (CANIS FAMILIARIS) HEMOGLOBIN PDB models [1]
#>   PDB ID: 3GOU
#>   Experiment: X-RAY DIFFRACTION
#>   Parsed: 4618 atoms, 574 residues, 4 chains, 416 bonds