Public API

PDBToolsBase.jl follows semantic versioning. This page defines the public API of the version of the package it belongs to: what is listed here is only changed in a breaking way in a new major version. Anything not listed here is internal, and may change in any release.

Note

The docstrings are written for users of PDBTools.jl, which re-exports the public names of this package. Thus, the examples use using PDBTools, and refer to PDBTools.name for names that are public but not exported.

What is public

  1. Public names: the names declared public in PDBToolsBase (Base.ispublic(PDBToolsBase, name) == true). The package exports nothing: public names are used qualified (PDBToolsBase.read_pdb) or imported explicitly (using PDBToolsBase: read_pdb). All of them are documented in this page (this is checked when the documentation is built), with the methods and keyword arguments described in their docstrings.

  2. Documented fields and properties:

  3. Documented behavior:

    • read_pdb and read_mmcif return a Structure, with the unit cell read from the file (CRYST1 or _cell fields), or nothing if the file does not define a unit cell or defines the 1Å unit cube (which indicates a non-crystallographic structure). The title is read from the TITLE (PDB) or _struct.title (mmCIF) fields, and the connectivity from the CONECT records of PDB files or the _geom_bond fields of mmCIF files.
    • read_xyz returns a Structure with the atoms of the xyz file, with the title read from the comment line.
    • Selections are functions that receive an Atom and return true or false (e.g. isprotein, or at -> name(at) == "CA"). Selections given as strings ("protein and name CA") are provided by PDBTools.jl.
    • Functions that support periodic boundary conditions accept the unitcell keyword argument as: false (no periodicity), true (use the unit cell of the Structure), or a unit cell (a UnitCell, a 3×3 matrix, or a vector of box sides).
    • A Structure behaves as a vector of atoms (AbstractVector{<:Atom}). Indexing with ranges, filter, copy, and other functions that create new vectors of atoms return new Structures with copies of the metadata, while view returns a Structure that shares the atoms and the metadata with the original one. When structures are concatenated, metadata that differs between them is set to nothing.
    • The files written by write_pdb and write_mmcif follow the PDB and PDBx/mmCIF formats, including the unit cell, title, and connectivity of Structures (CRYST1, TITLE and CONECT records in PDB files; _cell, _struct.title and _geom_bond fields in mmCIF files). write_xyz writes files in the xyz format.
    • The core API (reading, writing, and manipulating structures) can be compiled into executables with juliac --trim=safe (Julia ≥ 1.13).

What is not public

  • Names that are not declared public, even if accessible as PDBToolsBase.name (for example, the test files PDBToolsBase.test_file(name), or internal functions with names starting with _).
  • Methods and keyword arguments that are not described in the docstrings.
  • The printed output (show) of the types, and the exact formatting (column widths, number of digits, header lines) of the files written, as long as they remain valid PDB or mmCIF files.
  • The flag field of Atom.
  • The values of the properties of elements and residues, which may be corrected in any release.

Packages of the ecosystem developed together with PDBToolsBase.jl (in particular PDBTools.jl) may use internal names, and declare compatibility bounds accordingly. Other packages should use only the public API.

Data structures

PDBToolsBase.Atom — Type
Atom::DataType

Structure that contains the atom properties. It is mutable, so its fields can be modified.

Fields:

mutable struct Atom{CustomType}
    index::Int32 # The sequential index of the atoms in the file
    index_pdb::Int32 # The index as written in the PDB file (might be anything)
    name::InlineStrings.String15 # Atom name
    resname::InlineStrings.String15 # Residue name
    chain::InlineStrings.String15 # Chain identifier
    resnum::Int32 # Number of residue as written in PDB file
    residue::Int32 # Sequential residue (molecule) number in file
    x::Float32 # x coordinate
    y::Float32 # y coordinate
    z::Float32 # z coordinate
    beta::Float32 # temperature factor
    occup::Float32 # occupancy
    model::Int32 # model number
    segname::InlineStrings.String15 # Segment name (cols 73:76)
    pdb_element::InlineStrings.String15 # Element symbol string (cols 77:78)
    charge::Float32 # Charge (cols: 79:80)
    custom::CustomType # Custom fields
    flag::Int8 # Flag for internal use
end

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"))
   Structure{Atom{Nothing}} with 35 atoms
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     ALA     A        1        1   -9.229  -14.861   -5.481  0.00  0.00     1    PROT         1
       2 1HT1     ALA     A        1        1  -10.048  -15.427   -5.569  0.00  0.00     1    PROT         2
⋮
      34    C     ASP     A        3        3   -2.626  -10.480   -7.749  1.00  0.00     1    PROT        34
      35    O     ASP     A        3        3   -1.940  -10.014   -8.658  1.00  0.00     1    PROT        35

julia> resname(atoms[1])
"ALA"

julia> chain(atoms[1])
"A"

julia> element(atoms[1])
"N"

julia> mass(atoms[1])
14.0067f0

julia> position(atoms[1])
3-element StaticArraysCore.SVector{3, Float32} with indices SOneTo(3):
  -9.229
 -14.861
  -5.481

The pdb_element and charge fields, which are frequently left empty in PDB files, are not printed. The direct access to the fields is considered part of the interface.

Custom fields can be set on Atom construction with the custom keyword argument. The Atom structure will then be parameterized with the type of custom.

Example

julia> using PDBTools

julia> atom = Atom(index = 0; custom=Dict(:c => "c", :index => 1));

julia> typeof(atom)
Atom{Dict{Symbol, Any}}

julia> atom.custom
Dict{Symbol, Any} with 2 entries:
  :index => 1
  :c     => "c"

julia> atom.custom[:c]
"c"
source
PDBToolsBase.Structure — Type
Structure(atoms::AbstractVector{<:Atom}=Atom{Nothing}[]; unitcell=nothing)
Structure(atoms::AbstractVector{<:Atom}, metadata::MetaData)

A Structure is the main data structure in PDBTools.jl representing a molecular structure. It behaves as a vector of Atom objects, and carries metadata (see PDBTools.MetaData), such as the unit cell of the system, which is accessible as a property: s.unitcell. The underlying vector of atoms is s.atoms.

Indexing with ranges, filter, copy and other functions that create new vectors of atoms return new Structures, with copies of the metadata, while view returns a Structure sharing the metadata with the original one.

Example

julia> using PDBTools

julia> s = Structure(read_pdb(PDBTools.test_file("small.pdb")); unitcell=UnitCell(10.0, 10.0, 10.0));

julia> s.unitcell
UnitCell(a=10.000, b=10.000, c=10.000, α=90.00, β=90.00, γ=90.00)

julia> s.unitcell = UnitCell(a=10.0, b=20.0, c=30.0, γ=120.0)
UnitCell(a=10.000, b=20.000, c=30.000, α=90.00, β=90.00, γ=120.00)

julia> length(s[1:10])
10

julia> s[1:10].unitcell == s.unitcell
true
source
PDBToolsBase.MetaData — Type
MetaData

Metadata of a Structure. The fields of MetaData are accessible as properties of the structure (e.g. s.unitcell), and can be set in the Structure constructor.

Fields

  • unitcell::Union{Nothing,UnitCell}: The unit cell of the system (see UnitCell), or nothing if the structure is not periodic. When setting it (s.unitcell = ...), values that are not a UnitCell are converted with the UnitCell constructor.
  • connectivity::Union{Nothing,Vector{Vector{Int32}}}: The bonds of the atoms, as read from the CONECT records of PDB files or the _geom_bond fields of mmCIF files: connectivity[i] contains the indices of the atoms bonded to the atom with index i. The indices are the sequential indices of the atoms in the file (index(atom), which are not changed by selections or filtering). The bonds of PDB files are listed as in the file (they are not symmetrized), and repeated bonds, which indicate the bond order in PDB files (e.g. a double bond is listed twice), are kept. nothing if the connectivity is not available. When setting it, vectors of vectors of integers are converted to Vector{Vector{Int32}}.
  • title::Union{Nothing,String}: The title of the structure, as read from the TITLE records of PDB files, the _struct.title field of mmCIF files, or the comment line of xyz files. nothing if the file does not define a title.
Note

All fields of MetaData accept nothing, which means that the property is not defined. When structures with different metadata are concatenated, the conflicting properties are set to nothing.

source
PDBToolsBase.UnitCell — Type
UnitCell(matrix::AbstractMatrix)
UnitCell(sides::AbstractVector)
UnitCell(a, b, c, α=90, β=90, γ=90)
UnitCell(; a, b, c, α=90, β=90, γ=90)
UnitCell(lattice::NamedTuple)

Unit cell of a periodic system. It can be defined by:

  • A 3×3 matrix, with the lattice vectors as columns.
  • A vector with the lengths of the sides of an orthorhombic box.
  • The lattice parameters: the lengths of the sides a, b, c (in Å), and the angles α, β, γ (in degrees), given as positional or keyword arguments, or as the named tuple returned by matrix_to_lattice.

A UnitCell behaves as the 3×3 unit cell matrix (with the lattice vectors as columns), and can be used wherever a unit cell matrix is accepted. The unit cell of a Structure is set with s.unitcell = UnitCell(...).

Example

julia> using PDBTools

julia> uc = UnitCell(10.0, 20.0, 30.0)
UnitCell(a=10.000, b=20.000, c=30.000, α=90.00, β=90.00, γ=90.00)

julia> UnitCell([10.0, 20.0, 30.0]) == uc
true

julia> UnitCell(a=10.0, b=20.0, c=30.0, γ=120.0)
UnitCell(a=10.000, b=20.000, c=30.000, α=90.00, β=90.00, γ=120.00)

julia> matrix_to_lattice(uc)
(a = 10.0f0, b = 20.0f0, c = 30.0f0, α = 90.0f0, β = 90.0f0, γ = 90.0f0)
source
PDBToolsBase.Residue — Type
Residue

Residue data structure.

The Residue structure carries the properties of the residue or molecule of the atoms it contains, but it does not copy the original vector of atoms, only the residue meta data for each residue. Thus, changes in the residue atoms will be reflected in the original vector of atoms.

Example

julia> using PDBTools

julia> pdb = wget("1LBD");

julia> residues = collect(eachresidue(pdb))
238-element Vector{Residue}[
    SER225A
    ALA226A
    ⋮
    MET461A
    THR462A
]

julia> resnum.(residues[1:3])
3-element Vector{Int32}:
 225
 226
 227

julia> residues[5].chain
"A"

julia> residues[8].range
52:58

julia> mass(residues[1])
82.0385f0
source
PDBToolsBase.Chain — Type
Chain

Creates a Chain data structure. Chains must be consecutive in the atoms vector, and are identified by having the same chain, segment, and model fields.

The Chain structure carries the properties of the atoms it contains, but it does not copy the original vector of atoms. This means that any changes made in the Chain structure atoms, will overwrite the original vector of atoms.

Examples

julia> using PDBTools

julia> ats = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(ats))
4-element Vector{Chain}[
    Chain(A-48 atoms)
    Chain(B-48 atoms)
    Chain(A-48 atoms)
    Chain(D-45 atoms)
]

julia> chains[1]
 Chain A with 48 atoms.
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     ASP     A        1        1  133.978  119.386  -23.646  1.00  0.00     1    ASYN         1
       2   CA     ASP     A        1        1  134.755  118.916  -22.497  1.00  0.00     1    ASYN         2
⋮
      47 HD23     LEU     A        3        3  130.568  111.868  -26.242  1.00  0.00     1    ASYN        47
      48    O     LEU     A        3        3  132.066  112.711  -21.739  1.00  0.00     1    ASYN        48

julia> mass(chains[1])
353.3787f0 

julia> model(chains[4])
2

julia> segname(chains[2])
"ASYN"
source
PDBToolsBase.Segment — Type
Segment

Segment data structure. Segments must be consecutive in the atoms vector, and are identified by having the same segname and model fields.

The Segment structure carries the properties of the segment it contains, but it does not copy the original vector of atoms, only the segment meta data and the reference to the original vector. Thus, changes in the segment atoms will be reflected in the original vector of atoms.

Example

julia> using PDBTools

julia> ats = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> segments = collect(eachsegment(ats))
2-element Vector{Segment}[
    A-(1905 atoms))
    B-(92 atoms))
]

julia> segname.(segments[1:2])
2-element Vector{InlineStrings.String15}:
 "A"
 "B"

julia> length(segments[2])
92
source
PDBToolsBase.Model — Type
Model

Model data structure. It carries the data of a model in a PDB file. Models must be consecutive in the atoms vector, and are identified by having the same model field.

The Model structure carries the properties of the model it contains, but it does not copy the original vector of atoms, only the model meta data and the reference to the original vector. Thus, changes in the model atoms will be reflected in the original vector of atoms.

Example

In the example below, 8S8N is PDB entry with 11 models.

julia> using PDBTools

julia> ats = wget("8S8N");

julia> models = collect(eachmodel(ats))
11-element Vector{Model}[
    1-(234 atoms))
    2-(234 atoms))
    ⋮
    10-(234 atoms))
    11-(234 atoms))
]

julia> models[1]
 Model 1 with 234 atoms.
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     DLE     A        2        1   -5.811   -0.380   -2.159  1.00  0.00     1                 1
       2   CA     DLE     A        2        1   -4.785   -0.493   -3.227  1.00  0.00     1                 2
⋮
     233  HT2   A1H5T     B      101       13   -5.695    5.959   -3.901  1.00  0.00     1               233
     234  HT1   A1H5T     B      101       13   -4.693    4.974   -2.743  1.00  0.00     1               234
source
PDBToolsBase.Sequence — Type
Sequence

Wrapper for strings, or vectors of chars, strings, or residue names, to dispatch on functions that operate on amino acid sequences.

Example

julia> seq = ["Alanine", "Glutamic acid", "Glycine"];

julia> mass(Sequence(seq))
257.2432

julia> seq = "AEG";

julia> mass(Sequence(seq))
257.2432
source

Reading and writing

PDBToolsBase.read_pdb — Function
read_pdb(pdbfile::AbstractString, selection::AbstractString)
read_pdb(pdbfile::AbstractString, selection_function::Function = all)

read_pdb(pdbdata::IOBuffer, selection::AbstractString)
read_pdb(pdbdata::IOBuffer, selection_function::Function = all)

Reads a PDB file (in legacy PDB or mmCIF/PDBx formats) and stores the data in a vector of type Atom.

If a selection is provided, only the atoms matching the selection will be read. For example, resname ALA will select all the atoms in the residue ALA.

If a selection function keyword is provided, only the atoms for which selection_function(atom) is true will be read.

The function automatically detects mmCIF format and switches to the mmCIF reader if the loop_ keyword is found in the file, or if an ATOM/HETATM line cannot be parsed in PDB format.

When reading an mmCIF file, the following keyword arguments are forwarded to the mmCIF reader:

  • field_assignment::Union{Nothing,Dict{String,Symbol}} = nothing: custom mapping from mmCIF _atom_site field names to Atom fields. See read_mmcif for details.
  • memory_available::Real = 0.8: fraction of available memory the reader is allowed to use.
  • stop_at = nothing: stop reading after this many atoms (useful for large files).

Examples

julia> using PDBTools

julia> protein = read_pdb(PDBTools.test_file("structure.pdb"))
   Structure{Atom{Nothing}} with 62026 atoms
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     ALA     A        1        1   -9.229  -14.861   -5.481  0.00  0.00     1    PROT         1
       2  HT1     ALA     A        1        1  -10.048  -15.427   -5.569  0.00  0.00     1    PROT         2
⋮
   62025   H1    TIP3     C     9339    19638   13.218   -3.647  -34.453  1.00  0.00     1    WAT2     62025
   62026   H2    TIP3     C     9339    19638   12.618   -4.977  -34.303  1.00  0.00     1    WAT2     62026

julia> ALA = read_pdb(PDBTools.test_file("structure.pdb"),"resname ALA")
   Structure{Atom{Nothing}} with 72 atoms
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     ALA     A        1        1   -9.229  -14.861   -5.481  0.00  0.00     1    PROT         1
       2  HT1     ALA     A        1        1  -10.048  -15.427   -5.569  0.00  0.00     1    PROT         2
⋮
    1339    C     ALA     A       95       95   14.815   -3.057   -5.633  1.00  0.00     1    PROT      1339
    1340    O     ALA     A       95       95   14.862   -2.204   -6.518  1.00  0.00     1    PROT      1340

julia> ALA = read_pdb(PDBTools.test_file("structure.pdb"), atom -> atom.resname == "ALA")
   Structure{Atom{Nothing}} with 72 atoms
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     ALA     A        1        1   -9.229  -14.861   -5.481  0.00  0.00     1    PROT         1
       2  HT1     ALA     A        1        1  -10.048  -15.427   -5.569  0.00  0.00     1    PROT         2
⋮
    1339    C     ALA     A       95       95   14.815   -3.057   -5.633  1.00  0.00     1    PROT      1339
    1340    O     ALA     A       95       95   14.862   -2.204   -6.518  1.00  0.00     1    PROT      1340
source
PDBToolsBase.read_mmcif — Function
read_mmcif(mmCIF_file::AbstractString, selection::AbstractString; field_assignment)
read_mmcif(mmCIF_file::AbstractString, selection_function::Function = all, field_assignment)

read_mmcif(mmCIF_data::IOBuffer, selection::AbstractString; field_assignment)
read_mmcif(mmCIF_data::IOBuffer, selection_function::Function = all, field_assignment)

Reads a mmCIF file and stores the data in a vector of type Atom.

All fields except the file name are optional.

If a selection is provided, only the atoms matching the selection will be read. For example, resname ALA will select all the atoms in the residue ALA.

If a selection function is provided, only the atoms for which selection_function(atom) is true will be returned.

The field_assignment keyword is nothing (default) or a Dict{String,Symbol} and can be used to specify which fields in the mmCIF file should be read into the Atom type. For example field_assignment = Dict("type_symbol" => :name) will read the _atom_site.type_symbol field in the mmCIF file into the name field of the Atom type.

The default assignment is follows the standard mmCIF convention:

Dict{String,Symbol}(
    "id" => :index_pdb
    "Cartn_x" => :x
    "Cartn_y" => :y
    "Cartn_z" => :z
    "occupancy" => :occup
    "B_iso_or_equiv" => :beta
    "pdbx_formal_charge" => :charge
    "pdbx_PDB_model_num" => :model
    "label_atom_id" => :name
    "label_comp_id" => :resname
    "label_asym_id" => :chain
    "auth_seq_id" => :resnum
    "type_symbol" => :pdb_element
)

Source: https://mmcif.wwpdb.org/docs/tutorials/content/atomic-description.html

Examples

julia> using PDBTools

julia> ats = read_mmcif(PDBTools.test_file("small.cif"))
   Structure{Atom{Nothing}} with 76 atoms - with unit cell
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     GLY     A        1        1   -4.564   25.503   24.113  1.00 24.33     1                 1
       2   CA     GLY     A        1        1   -4.990   26.813   24.706  1.00 24.29     1                 2
⋮
      75    O     HOH     Q       63       15   -3.585   34.725   20.903  1.00 19.82     1              2980
      76    O     HOH     Q       64       16   -4.799   40.689   37.419  1.00 20.13     1              2981

julia> ats = read_mmcif(PDBTools.test_file("small.cif"), "index < 3")
   Structure{Atom{Nothing}} with 2 atoms - with unit cell
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    N     GLY     A        1        1   -4.564   25.503   24.113  1.00 24.33     1                 1
       2   CA     GLY     A        1        1   -4.990   26.813   24.706  1.00 24.29     1                 2

julia> ats = read_mmcif(PDBTools.test_file("small.cif"), at -> name(at) == "CA")
   Structure{Atom{Nothing}} with 11 atoms - with unit cell
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       2   CA     GLY     A        1        1   -4.990   26.813   24.706  1.00 24.29     1                 2
       6   CA     GLN     A        2        2   -4.738   30.402   23.484  1.00 23.74     1                 6
⋮
      70   CA      CA     G     1003       10  -24.170   27.201   64.364  1.00 27.40     1              2967
      71   CA      CA     H     1004       11  -10.624   32.854   69.292  1.00 29.53     1              2968
source
PDBToolsBase.read_xyz — Function
read_xyz(xyz_file::AbstractString, selection_function::Function = all)
read_xyz(xyz_data::IOBuffer, selection_function::Function = all)

Reads a file in the xyz format and returns a Structure.

The xyz format consists of one or more frames, each with:

  • a line with the number of atoms,
  • a comment line, which is stored as the title of the structure (from the first frame),
  • one line per atom, with the element symbol (or atom name, or atomic number) and the x, y, and z coordinates. Additional columns are ignored.

The first column is stored, as is, in the name field of the atoms (and is written back by write_xyz). The element symbol, if recognized from the first column, is stored in the pdb_element field (atomic numbers are converted to element symbols). Each frame is read as a different model (model field), and the atoms of each frame form a single residue.

If a selection function is provided, only the atoms for which selection_function(atom) is true will be read.

Example

julia> using PDBTools

julia> s = read_xyz(PDBTools.test_file("ethanol.xyz"))
   Structure{Atom{Nothing}} with 9 atoms
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
       1    C     XXX     X        1        1   -0.748   -0.015    0.024  0.00  0.00     1       X         1
       2    C     XXX     X        1        1    0.558    0.420   -0.619  0.00  0.00     1       X         2
⋮
       8    H     XXX     X        1        1    0.570    1.511   -0.745  0.00  0.00     1       X         8
       9    H     XXX     X        1        1    1.510    0.138   -2.348  0.00  0.00     1       X         9

julia> s.title
"Ethanol"
source
PDBToolsBase.write_pdb — Function
write_pdb(filename::AbstractString, atoms::AbstractVector{<:Atom}, [selection]; header=:auto, footer=:auto, append=false, connectivity=true)

Write a PDB file with the atoms in atoms to filename. The selection argument is a string or function that can be used to select a subset of the atoms in atoms. For example, write_pdb("test.pdb", atoms, "name CA").

Arguments

  • filename::AbstractString: The name of the file to write.
  • atoms::AbstractVector{<:Atom}: The atoms to write to the file.

Optional positional argument

  • selection::AbstractString: A selection string to select a subset of the atoms in atoms.

Keyword arguments

  • header::Union{String, Nothing}=:auto: The header to add to the PDB file. If :auto, a header will be added with the number of atoms in atoms.
  • footer::Union{String, Nothing}=:auto: The footer to add to the PDB file. If :auto, a footer will be added with the "END" keyword.
  • append::Bool=false: If true, the atoms will be appended to the file instead of overwriting it.
  • connectivity::Bool=true: If false, the connectivity of the structure (CONECT records) is not written.

The atoms are numbered sequentially in the file (serial numbers 1, 2, ..., in hexadecimal format above 99999), in the order in which they are written.

If atoms is a Structure, its metadata is written to the file: the unit cell in the CRYST1 field, the title in TITLE records, and the connectivity in CONECT records. The connectivity, which refers to the indices of the atoms (index(atom)), is converted to the serial numbers of the atoms in the file. Bonds to atoms that are not written (because of the selection) are not written. An error is thrown if two atoms to be written have the same index, because the bonds of these atoms would be ambiguous: in this case, use connectivity=false to write the file without the connectivity.

source
PDBToolsBase.write_mmcif — Function
write_mmcif(filename, atoms::AbstractVector{<:Atom}, [selection]; field_assignment=nothing, connectivity=true)

Write a mmCIF file with the atoms in atoms to filename. The optional selection argument is a string or function that can be used to select a subset of the atoms in atoms. For example, write_mmcif("test.cif", atoms, "name CA").

The optional field_assignment argument is a dictionary that can be used to assign custom fields to the mmCIF file.

If connectivity=false, the connectivity of the structure (_geom_bond fields) is not written.

If atoms is a Structure, its metadata is written to the file: the unit cell in the _cell fields, the title in the _struct.title field, and the connectivity in the _geom_bond fields, which list each bond once, by the _atom_site.id of the two atoms. The atoms are numbered sequentially in the file (_atom_site.id = 1, 2, ...), and the connectivity, which refers to the indices of the atoms (index(atom)), is converted to these numbers. Bonds to atoms that are not written (because of the selection) are not written. An error is thrown if two atoms to be written have the same index, because the bonds of these atoms would be ambiguous: in this case, use connectivity=false to write the file without the connectivity.

source
PDBToolsBase.write_xyz — Function
write_xyz(filename::AbstractString, atoms::AbstractVector{<:Atom}, [selection]; append=false)

Write a file in the xyz format with the atoms in atoms to filename. The selection argument is a string or function that can be used to select a subset of the atoms in atoms. For example, write_xyz("test.xyz", atoms, "name CA").

Each atom is written with its name (the name field), followed by its coordinates, such that files read with read_xyz are written back with the same first column. The comment line of each frame is the title of the structure, if atoms is a Structure with a title, and is empty otherwise. Atoms of different models are written as different frames.

Keyword arguments

  • append::Bool=false: If true, the atoms will be appended to the file instead of overwriting it.
source

Atom properties

PDBToolsBase.index — Function
index(atom::Atom)

Returns the sequential index of the atom in the structure.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Int32: The sequential index of the atom.

Example

julia> using PDBTools

julia> atom = Atom(index=42);

julia> index(atom)
42
source
PDBToolsBase.index_pdb — Function
index_pdb(atom::Atom)

Returns the atom index as written in the PDB file (may differ from sequential index).

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Int32: The PDB file index of the atom.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> index_pdb(atoms[1])
1
source
PDBToolsBase.name — Function
name(atom::Atom)

Returns the name of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • String: The atom name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> name(atoms[1])
"N"
source
name(residue::Residue)

Returns the name (residue name) of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • String: The residue name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> name(residues[1])
"ALA"
source
name(chain::Chain)

Returns the name (chain identifier) of the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • String: The chain identifier.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(atoms));

julia> name(chains[1])
"A"
source
name(segment::Segment)

Returns the name (segment name) of the segment.

Positional Arguments

  • segment::Segment: A Segment object.

Returns

  • String: The segment name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> segments = collect(eachsegment(atoms));

julia> name(segments[1])
"A"
source
PDBToolsBase.resname — Function
resname(residue::Union{AbstractString,Char}; residue_classes=nothing)

Returns the residue name, given the one-letter code or residue name. Differently from threeletter, this function will return the force-field name if available in the list of protein residues.

Note

When retrieving ambiguous codes, protein residue codes will be preferred. Use class=:nucleoside_residues to retrieve only nucleoside data, or data of any other specific class.

Examples

julia> resname("ALA")
"ALA"

julia> resname("GLUP")
"GLUP"
source
resname(atom::Atom)

Returns the residue name of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • String: The residue name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> resname(atoms[1])
"ALA"
source
resname(residue::Residue)

Returns the residue name of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • String: The residue name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> resname(residues[1])
"ALA"
source
PDBToolsBase.chain — Function
chain(atom::Atom)

Returns the chain identifier of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • String: The chain identifier.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> chain(atoms[1])
"A"
source
chain(residue::Residue)

Returns the chain identifier of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • String: The chain identifier.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> chain(residues[1])
"A"
source
chain(chain::Chain)

Returns the chain identifier of the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • String: The chain identifier.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(atoms));

julia> chain(chains[1])
"A"
source
PDBToolsBase.resnum — Function
resnum(atom::Atom)

Returns the residue number as written in the PDB file.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Int32: The residue number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> resnum(atoms[1])
1
source
resnum(residue::Residue)

Returns the residue number as written in the PDB file.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • Int32: The residue number from the PDB file.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> resnum(residues[1])
1
source
PDBToolsBase.residue — Function
residue(atom::Atom)

Returns the sequential residue (molecule) number in the structure.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Int32: The sequential residue number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residue(atoms[1])
1
source
residue(residue::Residue)

Returns the sequential residue (molecule) number of the residue in the structure.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • Int32: The sequential residue number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> residue(residues[1])
1
source
PDBToolsBase.segname — Function
segname(atom::Atom)

Returns the segment name of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • String: The segment name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> segname(atoms[1])
"PROT"
source
segname(residue::Residue)

Returns the segment name of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • String: The segment name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> segname(residues[1])
"PROT"
source
segname(chain::Chain)

Returns the segment name of the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • String: The segment name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("structure.pdb"), "protein");

julia> chains = collect(eachchain(atoms));

julia> segname(chains[1])
"PROT"
source
segname(segment::Segment)

Returns the segment name of the segment.

Positional Arguments

  • segment::Segment: A Segment object.

Returns

  • String: The segment name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> segments = collect(eachsegment(atoms));

julia> segname(segments[1])
"A"
source
PDBToolsBase.model — Function
model(atom::Atom)

Returns the model number of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Int32: The model number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> model(atoms[1])
1
source
model(residue::Residue)

Returns the model number of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • Int32: The model number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> model(residues[1])
1
source
model(chain::Chain)

Returns the model number of the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • Int32: The model number.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(atoms));

julia> model(chains[1])
1
source
model(model::Model)

Returns the model number.

Positional Arguments

  • model::Model: A Model object.

Returns

  • Int32: The model number.

Example

julia> using PDBTools

julia> atoms = wget("8S8N");

julia> models = collect(eachmodel(atoms));

julia> model(models[1])
1
source
PDBToolsBase.beta — Function
beta(atom::Atom)

Returns the temperature factor (B-factor) of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Float32: The B-factor value.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> beta(atoms[1])
0.0f0
source
PDBToolsBase.occup — Function
occup(atom::Atom)

Returns the occupancy of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Float32: The occupancy value (typically between 0 and 1).

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> occup(atoms[1])
0.0f0
source
PDBToolsBase.charge — Function
charge(atom::Atom)

Returns the formal charge of the atom.

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • Float32: The charge value.

Example

julia> using PDBTools

julia> atom = Atom(charge=1.0);

julia> charge(atom)
1.0f0
source
charge(residue::Residue)

Returns the formal charge of the residue. For protein residues, the charge is obtained from the standard protein residue database. For non-protein residues, a warning is issued and 0 is returned.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • Int: The formal charge of the residue.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("structure.pdb"), "protein and resname GLU");

julia> residues = collect(eachresidue(atoms));

julia> charge(residues[1])
-1
source
PDBToolsBase.pdb_element — Function
pdb_element(atom::Atom)

Returns the element symbol as written in the PDB file (columns 77-78).

Positional Arguments

  • atom::Atom: An Atom object.

Returns

  • String: The element symbol from the PDB file.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> pdb_element(atoms[1])
"N"
source
Base.position — Method
position(atom::Atom)

Returns the position of an atom given the Atom structure.

source
PDBToolsBase.set_position! — Function
set_position!(atom::Atom, x::Union{Tuple,AbstractVector})

Sets the position (x,y,z coordinates) of the atom, given a vector or tuple of coordinates.

source
PDBToolsBase.printatom — Function
printatom(atom::Atom)
printatom(io::IO, atom::Atom)

Prints an Atom structure in a human-readable format, with a title line. By default the output is printed to stdout, and the io argument can be used to specify a different output stream.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("structure.pdb"), "protein and residue 2");

julia> printatom(atoms[1])
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
      13    N     CYS     A        2        2   -6.351  -14.461   -5.695  1.00  0.00     1    PROT        13

julia> atoms[1] # default show method
   index name resname chain   resnum  residue        x        y        z occup  beta model segname index_pdb
      13    N     CYS     A        2        2   -6.351  -14.461   -5.695  1.00  0.00     1    PROT        13
source
PDBToolsBase.add_custom_field — Function
add_custom_field(atom::Atom, value)

Adds a custom field to an Atom structure, returning a new Atom structure with the custom field added. The returning Atom structure is parameterized with the type of value.

source
PDBToolsBase.get_atoms — Function
get_atoms(atom::Atom)
get_atoms(atoms::AbstractVector{<:Atom})

Returns the atom or vector of atoms. This function provides a consistent interface for extracting atoms from various structural elements (Atom, Residue, Chain, Model, etc.).

Positional Arguments

  • atom::Atom: A single Atom object.
  • atoms::AbstractVector{<:Atom}: A vector of Atom objects.

Returns

  • Atom or AbstractVector{<:Atom}: The input atom(s).

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> get_atoms(atoms[1]) == atoms[1]
true

julia> get_atoms(atoms) == atoms
true
source
get_atoms(residue::Residue)

Returns a view of the atoms that belong to the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • SubArray{Atom}: A view of the atoms in the residue.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> res_atoms = get_atoms(residues[1]);

julia> length(res_atoms)
12
source
get_atoms(chain::Chain)

Returns a view of the atoms that belong to the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • SubArray{Atom}: A view of the atoms in the chain.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(atoms));

julia> chain_atoms = get_atoms(chains[1]);

julia> length(chain_atoms)
48
source
get_atoms(segment::Segment)

Returns a view of the atoms that belong to the segment.

Positional Arguments

  • segment::Segment: A Segment object.

Returns

  • SubArray{Atom}: A view of the atoms in the segment.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> segments = collect(eachsegment(atoms));

julia> seg_atoms = get_atoms(segments[1]);

julia> length(seg_atoms)
1905
source
get_atoms(model::Model)

Returns a view of the atoms that belong to the model.

Positional Arguments

  • model::Model: A Model object.

Returns

  • SubArray{Atom}: A view of the atoms in the model.

Example

julia> using PDBTools

julia> atoms = wget("8S8N");

julia> models = collect(eachmodel(atoms));

julia> model_atoms = get_atoms(models[1]);

julia> length(model_atoms)
234
source

Iterators

PDBToolsBase.eachresidue — Function
eachresidue(atoms::AbstractVector{<:Atom})

Iterator for the residues (or molecules) of a selection.

Example

julia> using PDBTools

julia> atoms = wget("1LBD");

julia> eachresidue(atoms)
 Residue iterator with length = 238

julia> collect(eachresidue(atoms))
238-element Vector{Residue}[
    SER225A
    ALA226A
    ⋮
    MET461A
    THR462A
]
source
PDBToolsBase.eachchain — Function
eachchain(atoms::AbstractVector{<:Atom})

Iterator for the chains of a selection.

Example

julia> using PDBTools

julia> ats = read_pdb(PDBTools.test_file("chains.pdb"));

julia> eachchain(ats)
 Chain iterator with length = 4

julia> chains = collect(eachchain(ats))
4-element Vector{Chain}[
    Chain(A-48 atoms)
    Chain(B-48 atoms)
    Chain(A-48 atoms)
    Chain(D-45 atoms)
]
source
PDBToolsBase.eachsegment — Function
eachsegment(atoms::AbstractVector{<:Atom})

Iterator for the segments of a selection.

Example

julia> using PDBTools

julia> ats = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> sit = eachsegment(ats)
 Segment iterator with length = 2

julia> for seg in sit
           @show length(seg)
       end
length(seg) = 1905
length(seg) = 92

julia> collect(sit)
2-element Vector{Segment}[ 
    A-(1905 atoms))
    B-(92 atoms))
]
source
PDBToolsBase.eachmodel — Function
eachmodel(atoms::AbstractVector{<:Atom})

Iterator for the models of a selection.

Example

Here we show how to iterate over the models of a PDB file, annotate the index of the first atom of each model, and collect all models.

julia> using PDBTools

julia> ats = wget("8S8N");

julia> models = eachmodel(ats)
 Model iterator with length = 11

julia> first_atom = Atom[]
       for model in models
           push!(first_atom, model[1])
       end
       @show index.(first_atom);
index.(first_atom) = Int32[1, 235, 469, 703, 937, 1171, 1405, 1639, 1873, 2107, 2341]

julia> collect(models)
11-element Vector{Model}[
    1-(234 atoms))
    2-(234 atoms))
    ⋮
    10-(234 atoms))
    11-(234 atoms))
]
source

Elements and residues

PDBToolsBase.element — Function
element(atom::Atom)

Returns the element symbol, as a string, of an atom given the Atom structure. If the pdb_element is empty or "X", the element is inferred from the atom name. Otherwise, the pdb_element is returned.

Example

julia> using PDBTools

julia> at = Atom(name="NT3");

julia> element(at)
"N"
source
PDBToolsBase.element_name — Function
element_name(atom::Atom)

Returns the element name of an atom given its name, or Atom structure.

Example

julia> using PDBTools

julia> at = Atom(name="NT3");

julia> element_name(at)
"Nitrogen"
source
PDBToolsBase.element_symbol — Function
element_symbol(atom::Atom)

Returns a symbol for element name of an atom given its name, or Atom structure.

Example

julia> using PDBTools 

julia> at = Atom(name="NT3");

julia> element_symbol(at)
:N
source
PDBToolsBase.element_symbol_string — Function
element_symbol_string(atom::Atom)

Returns a string with the symbol of the element, given the Atom structure.

Example

julia> using PDBTools 

julia> at = Atom(name="NT3");

julia> element_symbol_string(at)
"N"
source
PDBToolsBase.element_vdw_radius — Function
element_vdw_radius(atom::Atom)

Returns the vdW radius of the element of the atom, in Å, or NaN if the data is not available.

Example

julia> using PDBTools 

julia> at = Atom(name="NT3");

julia> element_vdw_radius(at)
1.55f0
source
PDBToolsBase.atomic_number — Function
atomic_number(atom::Atom)

Returns the atomic number of an atom from its Atom structure.

Example

julia> using PDBTools

julia> at = Atom(name="NT3");

julia> atomic_number(at)
7
source
PDBToolsBase.mass — Function
mass(s::Sequence; residue_classes=nothing)

Returns the mass of a sequence of amino acids, given a Sequence struct type.

Note

When retrieving ambiguous codes, protein residue codes will be preferred. Use class=:nucleoside_residues to retrieve only nucleoside data, or data of any other specific class.

Examples

julia> seq = ["Alanine", "Glutamic acid", "Glycine"];

julia> mass(Sequence(seq))
257.2432

julia> seq = "AEG";

julia> mass(Sequence(seq))
257.2432

julia> seq = ["ALA", "GLU", "GLY"];

julia> mass(Sequence(seq))
257.2432

julia> mass(Sequence("AUT"))
755.2310170000001
source
mass(atom::Atom)
mass(atoms::AbstractVector{<:Atoms})

Returns the mass of an atom given its name, or Atom structure, or the total mass of a vector of Atoms.

If a mass is defined as a custom field in the the Atom structure, it is returned. Otherwise, the mass is retrieved from the element mass as inferred from the atom name.

Example

julia> using PDBTools

julia> atoms = [ Atom(name="NT3"), Atom(name="CA") ];

julia> mass(atoms[1])
14.0067f0

julia> mass(atoms)
26.0177f0
source
mass(residue::Residue)

Returns the total mass of all atoms in the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • Float32: The total mass in atomic mass units (amu).

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> mass(residues[1])
73.09489f0
source
mass(chain::Chain)

Returns the total mass of all atoms in the chain.

Positional Arguments

  • chain::Chain: A Chain object.

Returns

  • Float32: The total mass in atomic mass units (amu).

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("chains.pdb"));

julia> chains = collect(eachchain(atoms));

julia> mass(chains[1])
353.3787f0
source
mass(segment::Segment)

Returns the total mass of all atoms in the segment.

Positional Arguments

  • segment::Segment: A Segment object.

Returns

  • Float32: The total mass in atomic mass units (amu).

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> segments = collect(eachsegment(atoms));

julia> mass(segments[1])
25222.553f0
source
PDBToolsBase.oneletter — Function
oneletter(residue::Union{AbstractString,Char})

Function to return a one-letter residue code from the three letter code or residue name. The function is case-insensitive.

Examples

julia> oneletter("ALA")
"A"

julia> oneletter("Glutamic acid")
"E"
source
PDBToolsBase.threeletter — Function
threeletter(residue::AbstractString; residue_classes=nothing)

Function to return the three-letter natural-amino acid or nucleoside residue code from the one-letter code or residue name. The function is case-insensitive.

Note

When retrieving ambiguous codes, protein residue codes will be preferred. Use class=:nucleoside_residues to retrieve only nucleoside data, or data of any other specific class.

Examples

julia> using PDBTools

julia> threeletter("A")
"ALA"

julia> threeletter("Aspartic acid")
"ASP"

julia> threeletter("HSD")
"HIS"

julia> threeletter("G"; residue_classes=:nucleoside_residues)
"GUO"
source
PDBToolsBase.residuename — Function
residuename(residue::Union{AbstractString,Char})

Returns the long residue name from other residue codes. The function is case-insensitive.

Note

When retrieving ambiguous codes, protein residue codes will be preferred. Use class=:nucleoside_residues to retrieve only nucleoside data, or data of any other specific class.

Examples

julia> residuename("A")
"Alanine"

julia> residuename("Glu")
"Glutamic Acid"

julia> residuename("A"; residue_classes=:nucleoside_residues)
"Adenosine"

""
source
residuename(r::Residue)

Returns the full residue name of the residue.

Positional Arguments

  • residue::Residue: A Residue object.

Returns

  • String: The full residue name.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> residues = collect(eachresidue(atoms));

julia> residuename(residues[1])
"Alanine"
source

Classification of atoms and residues

PDBToolsBase.isbackbone — Function
isbackbone(atom::Atom; backbone_atoms=["N", "CA", "C", "O"])

Returns true if the atom is a protein backbone atom, that is, if it is a protein atom with one of the names in backbone_atoms.

source
PDBToolsBase.issidechain — Function
issidechain(atom::Atom; not_side_chain_atoms=["N", "CA", "C", "O", "HN", "H", "HA", "HT1", "HT2", "HT3"])

Returns true if the atom is a protein side chain atom, that is, if it is a protein atom with a name that is not in not_side_chain_atoms.

source
PDBToolsBase.iswater — Function
iswater(atom::Atom; water_residues=["HOH", "OH2", "TIP3", "TIP3P", "TIP4P", "TIP5P", "TIP7P", "SPC", "SPCE"])
iswater(residue::Residue; water_residues=...)

Returns true if the atom belongs to, or the residue is, a water molecule, that is, if the residue name is one of water_residues.

source
PDBToolsBase.isacidic — Function
isacidic(atom::Atom)
isacidic(residue::Residue)

Returns true if the atom belongs to, or the residue is, an acidic protein residue.

source
PDBToolsBase.isaliphatic — Function
isaliphatic(atom::Atom)
isaliphatic(residue::Residue)

Returns true if the atom belongs to, or the residue is, an aliphatic protein residue.

source
PDBToolsBase.isaromatic — Function
isaromatic(atom::Atom)
isaromatic(residue::Residue)

Returns true if the atom belongs to, or the residue is, an aromatic protein residue.

source
PDBToolsBase.isbasic — Function
isbasic(atom::Atom)
isbasic(residue::Residue)

Returns true if the atom belongs to, or the residue is, a basic protein residue.

source
PDBToolsBase.ischarged — Function
ischarged(atom::Atom)
ischarged(residue::Residue)

Returns true if the atom belongs to, or the residue is, a charged protein residue.

source
PDBToolsBase.isneutral — Function
isneutral(atom::Atom)
isneutral(residue::Residue)

Returns true if the atom belongs to, or the residue is, a neutral protein residue.

source
PDBToolsBase.ishydrophobic — Function
ishydrophobic(atom::Atom)
ishydrophobic(residue::Residue)

Returns true if the atom belongs to, or the residue is, a hydrophobic protein residue.

source
PDBToolsBase.ispolar — Function
ispolar(atom::Atom)
ispolar(residue::Residue)

Returns true if the atom belongs to, or the residue is, a polar protein residue.

source
PDBToolsBase.isnonpolar — Function
isnonpolar(atom::Atom)
isnonpolar(residue::Residue)

Returns true if the atom belongs to, or the residue is, a non-polar protein residue.

source
PDBToolsBase.ispurine — Function
ispurine(atom::Atom)
ispurine(residue::Residue)

Returns true if the atom belongs to, or the residue is, a purine nucleoside.

source
PDBToolsBase.ispyrimidine — Function
ispyrimidine(atom::Atom)
ispyrimidine(residue::Residue)

Returns true if the atom belongs to, or the residue is, a pyrimidine nucleoside.

source

Custom elements and residues

PDBToolsBase.add_element! — Function
add_element!(symbol::AbstractString, reference_element::PDBTools.Element; elements=PDBTools.elements)

Add a new element to the elements dictionary. If the element already exists, overwrite it.

To remove all custom elements, use remove_custom_elements!().

Example

julia> using PDBTools

julia> remove_custom_elements!(); # if any

julia> atoms = [ Atom(name="A1"), Atom(name="A2") ];

julia> add_element!("A1", PDBTools.elements["C"])
PDBToolsBase.Element(:C, InlineStrings.String15("C"), "Carbon", 6, 12.011f0, true, 1.7f0)

julia> add_element!("A2", PDBTools.elements["N"])
PDBToolsBase.Element(:N, InlineStrings.String15("N"), "Nitrogen", 7, 14.0067f0, true, 1.55f0)

julia> element(atoms[1])
"C"

julia> element(atoms[2])
"N"

julia> mass(atoms)
26.0177f0

julia> remove_custom_elements!(); 

Here we repeteadly call remove_custom_elements!() to guarantee the proper execution of the test codes, without any custom elements predefined.

source
PDBToolsBase.remove_custom_elements! — Function
remove_custom_elements!()

Remove all custom elements from the elements dictionary.

Example

julia> using PDBTools

julia> remove_custom_elements!();

julia> add_element!("GN", PDBTools.elements["N"])
PDBToolsBase.Element(:N, InlineStrings.String15("N"), "Nitrogen", 7, 14.0067f0, true, 1.55f0)

julia> element(Atom(name="GN"))
"N"

julia> remove_custom_elements!();

julia> element(Atom(name="GN")) # returns `nothing`

Here we repeatedly call remove_custom_elements!() to guarantee the proper execution of the test codes, without any custom elements predefined.

source
PDBToolsBase.add_protein_residue! — Function
add_protein_residue!(resname::AbstractString, reference_residue::PDBTools.ProteinResidue)

Function to add a custom protein residue to the list of protein residues. The function will return the ProteinResidue object that was added. To remove all custom protein residues use remove_custom_protein_residues!().

Example

julia> using PDBTools

julia> remove_custom_protein_residues!();

julia> add_protein_residue!("sA", PDBTools.protein_residues["ALA"])
PDBToolsBase.ProteinResidue("sA", "ALA", "A", "Aliphatic", false, true, 71.037114, 71.0779, 0, true)

julia> isprotein(Atom(resname="sA"))
true

julia> remove_custom_protein_residues!(); # clean up

Here we repeatedly call remove_custom_residues!() to guarantee the proper execution of the test codes, without any custom residues in the list of protein residues.

source
PDBToolsBase.remove_custom_protein_residues! — Function
remove_custom_protein_residues!()

Function to remove all custom protein residues from the list of protein residues.

Example

julia> using PDBTools

julia> remove_custom_protein_residues!(); # clean up

julia> add_protein_residue!("sA", PDBTools.protein_residues["ALA"])
PDBToolsBase.ProteinResidue("sA", "ALA", "A", "Aliphatic", false, true, 71.037114, 71.0779, 0, true)

julia> isprotein(Atom(resname="sA"))
true

julia> remove_custom_protein_residues!();

julia> isprotein(Atom(resname="sA"))
false

Here we repeatedly call remove_custom_residues!() to guarantee the proper execution of the test codes, without any custom residues in the list of protein residues.

source
PDBToolsBase.add_nucleoside_residue! — Function
add_nucleoside_residue!(resname::AbstractString, reference_residue::PDBTools.NucleosideResidue)

Add a custom nucleoside residue to the list of nucleoside residues. Returns the added NucleosideResidue. Use remove_custom_nucleoside_residues!() to undo.

Example

julia> using PDBTools

julia> remove_custom_nucleoside_residues!();

julia> add_nucleoside_residue!("MYN", PDBTools.nucleoside_residues["ADO"])
PDBToolsBase.NucleosideResidue("MYN", "ADO", "A", "Purine", 267.094691, 267.094691, 0, true)

julia> isnucleoside(Atom(resname="MYN"))
true

julia> remove_custom_nucleoside_residues!(); # clean up
source
PDBToolsBase.remove_custom_nucleoside_residues! — Function
remove_custom_nucleoside_residues!()

Remove all custom nucleoside residues from the nucleoside residue list.

Example

julia> using PDBTools

julia> remove_custom_nucleoside_residues!();

julia> add_nucleoside_residue!("MYN", PDBTools.nucleoside_residues["ADO"])
PDBToolsBase.NucleosideResidue("MYN", "ADO", "A", "Purine", 267.094691, 267.094691, 0, true)

julia> isnucleoside(Atom(resname="MYN"))
true

julia> remove_custom_nucleoside_residues!();

julia> isnucleoside(Atom(resname="MYN"))
false
source
PDBToolsBase.Element — Type
PDBTools.Element

Properties of a chemical element: symbol, symbol_string, name, atomic_number, mass (in atomic mass units), custom (whether it was added with add_element!), and vdw_radius (van der Waals radius, in Å).

source
PDBToolsBase.elements — Constant
PDBTools.elements

Dictionary mapping element names, as found in structure files, to their properties (of type PDBTools.Element). Custom elements are added with add_element!.

source
PDBToolsBase.ProteinResidue — Type
PDBTools.ProteinResidue

Properties of a protein residue: name, three_letter_code, one_letter_code, type ("Acidic", "Aliphatic", "Aromatic", ...), polar, hydrophobic, mono_isotopic_mass, mass, charge, and custom (whether it was added with add_protein_residue!).

source

Coordinates

PDBToolsBase.positions — Function
positions(atoms::AbstractVector{<:Atom}; selection)

Returns the coordinates of the atoms. The input may be one atom (type Atom), a vector of atoms, or a Residue. The coordinates are returned as a vector of static vectors (from StaticArrays), more specifically as a Vector{SVector{3,Float64}}.

Examples

julia> using PDBTools, StaticArrays 

julia> protein = wget("1LBD");

julia> positions(protein[1])
3-element SVector{3, Float64} with indices SOneTo(3):
 45.228
 84.358
 70.638

julia> positions(protein[1], as=SVector{3,Float32})
3-element SVector{3, Float32} with indices SOneTo(3):
 45.228
 84.358
 70.638

julia> positions(protein, "index <= 2")
2-element Vector{SVector{3, Float64}}:
 [45.228, 84.358, 70.638]
 [46.08, 83.165, 70.327]

julia> positions(protein, at -> at.resname == "ALA")
110-element Vector{SVector{3, Float64}}:
 [43.94, 81.982, 70.474]
 [43.02, 80.825, 70.455]
 [41.996, 80.878, 69.34]
 ⋮
 [-17.866, 84.088, 51.741]
 [-18.496, 83.942, 52.777]
 [-15.888, 82.583, 51.706]
  
julia> residues = collect(eachresidue(protein));

julia> positions(residues[1])
6-element Vector{SVector{3, Float64}}:
 [45.228, 84.358, 70.638]
 [46.08, 83.165, 70.327]
 [45.257, 81.872, 70.236]
 [45.823, 80.796, 69.974]
 [47.147, 82.98, 71.413]
 [46.541, 82.639, 72.662]
source
PDBToolsBase.distance — Function
distance(x,y)

Computes the minimum distance between two sets of atoms, between an atom and a set of atoms, or simply the distance between two atoms, or from the coordinates or sets of coordinates.

The input may be an Atom vector of Atoms, or a 3D vector, or a vector of 3D vector of coordinates, for examples as output by the positions function.

Examples

julia> model = wget("1BSX");

julia> protein = select(model,"protein");

julia> ligand = select(model,"resname T3");

julia> distance(protein,ligand)
2.7775834820937417

julia> distance(protein[1],ligand[3])
36.453551075306784

julia> distance(positions(ligand),protein)
2.7775834820937417
source
PDBToolsBase.closest — Function
closest(x,y)

Computes the minimum distance between two sets of atoms and returns the indices of the atoms and their distance. Both vector of atoms or vectors of coordinates can be used as input.

Examples

julia> model = wget("1BSX");

julia> protein = select(model,"protein");

julia> ligand = select(model,"resname T3");

julia> closest(ligand,protein)
(43, 3684, 2.7775834820937417)

julia> ligand[43]
    4037   O1      T3     B        2      512  -22.568   81.625    3.159 36.59  1.00     1       -      4041

julia> closest(ligand[43],protein)
(1, 3684, 2.7775834820937417)

julia> x = positions(protein)
3994-element Vector{SVector{3, Float64}}:
 [52.884, 24.022, 35.587]
 [52.916, 24.598, 36.993]
 ⋮
 [-46.887, 86.925, 13.235]
 [-47.164, 83.593, 15.25]

julia> closest(ligand,x)
(43, 3684, 2.7775834820937417)
source
PDBToolsBase.residue_residue_distance — Function
residue_residue_distance(
    r1::PDBTools.Residue, 
    r2::PDBTools.Residue; 
    positions::AbstractVector{AbstractVector{T}}=nothing; 
    unitcell=false
)

Calculate the minimum distance between two residues in a protein structure. If the positions argument is not provided, the function calculates the distance using the coordinates of the atoms in the residues. If positions is provided, the function uses the coordinates in the positions array.

Arguments

  • r1::PDBTools.Residue: Residue 1
  • r2::PDBTools.Residue: Residue 2
  • positions::AbstractVector{AbstractVector{T}}: Optional alternate positions of the atoms in the structure.
  • unitcell=false: Periodic boundary conditions. false: no periodicity; true: use the unit cell of the Structure the residues belong to; a matrix or vector: the unit cell to be used.
Note

The index of the atoms in the residues must match the index of the atoms in the positions array.

Example

julia> using PDBTools

julia> ats = read_pdb(PDBTools.test_file("dimer.pdb"));

julia> residues = collect(eachresidue(ats));

julia> r1 = residues[1]; r10 = residues[10];

julia> println(name(r1), resnum(r1), " and ", name(r10), resnum(r10))
LYS211 and GLU220

julia> d = residue_residue_distance(r1, r10)
16.16511f0
source
PDBToolsBase.maxmin — Function
maxmin(atoms::AbstractVector{<:Atom}; selection)

Returns the maximum and minimum coordinates of an atom vector, and the length (maximum minus minimum) in each direction.

Example

julia> protein = wget("1LBD");

julia> maxmin(protein)
 
 Minimum atom coordinates: xmin = [-29.301, 57.178, 45.668]
 Maximum atom coordinates: xmax = [47.147, 99.383, 86.886]
 Length in each direction: xlength = [76.448, 42.205, 41.217999999999996]
source
PDBToolsBase.center_of_mass — Function
center_of_mass(x::AbstractVector{<:AbstractVector}[, mass::AbstractVector=nothing])

Calculate the center of mass of a set of points.

Arguments

  • x::AbstractVector{<:AbstractVector}: A vector of coordinates.
  • mass::AbstractVector: A vector of masses. If not provided, all masses are assumed to be equal.

Example

julia> import PDBTools: center_of_mass

julia> x = [ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0] ];

julia> center_of_mass(x)
3-element Vector{Float64}:
 4.0
 5.0
 6.0

julia> center_of_mass(x, [1.0, 2.0, 3.0]) # providing masses
3-element Vector{Float64}:
 5.0
 6.0
 7.0
source
center_of_mass(atoms::AbstractVector{<:Atom})

Calculate the center of mass of the atoms.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> center_of_mass(atoms)
3-element StaticArraysCore.SVector{3, Float32} with indices SOneTo(3):
  -5.5844226
 -13.1104145
  -7.1399713
source
PDBToolsBase.moveto! — Function
moveto!(atoms::AbstractVector{<:Atom}; center::AbstractVector{<:Real}=SVector(0.0, 0.0, 0.0))

Move the center of mass of the atoms to the specified center position, which defaults to the origin.

Example

julia> using PDBTools

julia> atoms = read_pdb(PDBTools.test_file("small.pdb"));

julia> center_of_mass(atoms)
3-element StaticArraysCore.SVector{3, Float32} with indices SOneTo(3):
  -5.5844226
 -13.1104145
  -7.1399713

julia> moveto!(atoms; center = [1.0, 2.0, 3.0]);

julia> center_of_mass(atoms)
3-element StaticArraysCore.SVector{3, Float32} with indices SOneTo(3):
 1.0
 2.0000014
 3.0
source

Dihedral angles

PDBToolsBase.dihedral — Function
dihedral(v1, v2, v3, v4; degrees=true)
dihedral(v::AbstractVector; degrees=true)

Computes the dihedral angle between the planes formed by the vectors v1-v2 and v2-v3, and v2-v3 and v3-v4. The input vectors must have 3 elements. The function returns the dihedral angle in radians or degrees.

If the input is a vector with 4 vectors, the function computes the dihedral angle between the planes formed by the vectors v[1]-v[2] and v[2]-v[3], and v[2]-v[3] and v[3]-v[4].

The optional argument degrees specifies whether the output is in degrees (default) or radians.

source
dihedral(at1::Atom, at2::Atom, at3::Atom, at4::Atom)

Computes the dihedral angle given four atoms of type PDBTools.Atom.

Example

julia> using PDBTools

julia> pdb = read_pdb(PDBTools.test_file("structure.pdb"));

julia> C1 = pdb[11]; N2 = pdb[13]; CA2 = pdb[15]; C2 = pdb[22];

julia> phi = dihedral(C1, N2, CA2, C2) 
-36.70359f0
source
PDBToolsBase.dihedrals — Function
dihedrals(v::AbstractVector{<:AbstractVector}; degrees=true)

Computes the dihedral angles for many sets of 4 vectors. The input is a vector of vectors, where each element is a vector with 4 vectors. The function returns a vector with the dihedral angles in radians or degrees.

Example

julia> using PDBTools: dihedrals

julia> v1 = [[-8.483, -14.912, -6.726], [-5.113, -13.737, -5.466], [-3.903, -11.262, -8.062], [-1.162, -9.64, -6.015]];

julia> v2 = [[-9.229, -14.861, -5.481], [-8.483, -14.912, -6.726], [-7.227, -14.047, -6.599], [-7.083, -13.048, -7.303]];

julia> dihedrals([v1,v2])
2-element Vector{Float64}:
  164.43481280739516
 -115.82544005374316
source

Periodic systems

PDBToolsBase.lattice_to_matrix — Function
lattice_to_matrix(a, b, c, α, β, γ)

Converts unit cell lattice parameters and convert them to a 3x3 unit cell matrix (orthogonalization matrix), where the lattice vectors are the columns of the matrix.

The resulting matrix has the lattice vectors as its columns, with vector 'a' aligned along the x-axis and vector 'b' in the xy-plane. This matrix can be used to transform fractional coordinates to Cartesian coordinates.

Arguments

  • a::Real: Length of side a in Ångströms.
  • b::Real: Length of side b in Ångströms.
  • c::Real: Length of side c in Ångströms.
  • α::Real: Angle alpha in degrees.
  • β::Real: Angle beta in degrees.
  • γ::Real: Angle gamma in degrees.

Returns

  • A 3x3 static matrix representing the unit cell vectors.
source
PDBToolsBase.matrix_to_lattice — Function
matrix_to_lattice(M::AbstractMatrix)

Converts a 3x3 unit cell matrix where the lattice vectors are the columns, back into the six lattice parameters (sides a, b, c and angles α, β, γ).

Arguments

  • M::AbstractMatrix: A 3x3 matrix where columns are the lattice vectors.

Returns

  • NamedTuple: A named tuple containing the six parameters: (a, b, c, α, β, γ). Lengths are in the matrix's original units (typically Ångströms), and angles are in degrees.
source
PDBToolsBase.read_unitcell — Function
read_unitcell(file::AbstractString)

Reads the lattice parameters of unitcell from a PDB (CRYST1 field) or mmCIF file, and converts it to a unitcell matrix with the lattice_to_matrix function. The unitcell matrix contains the lattice vectors as the columns of the matrix.

Example

julia> using PDBTools

julia> m = read_unitcell(PDBTools.test_file("pbc.pdb"))
3×3 StaticArraysCore.SMatrix{3, 3, Float32, 9} with indices SOneTo(3)×SOneTo(3):
 85.0   0.0   0.0
  0.0  85.0   0.0
  0.0   0.0  85.0

julia> matrix_to_lattice(m)
(a = 85.0f0, b = 85.0f0, c = 85.0f0, α = 90.0f0, β = 90.0f0, γ = 90.0f0)
source
PDBToolsBase.wrap — Function
wrap(x, xref, unit_cell_matrix::SMatrix{N,N,T}) where {N,T}
wrap(x, xref, sides::AbstractVector)

Wraps the coordinates of point x such that it is the minimum image relative to xref. The unit cell may be given a a static matrix of size (N,N) or as a vector of length N.

source
PDBToolsBase.wrap_to_first — Function
wrap_to_first(x, unit_cell_matrix)

Wraps the coordinates of point x such that the returning coordinates are in the first unit cell with all-positive coordinates. The unit cell has to be a matrix of size (N,N).

Example

julia> using PDBTools: wrap_to_first

julia> uc = [10.0 0.0 0.0; 0.0 10.0 0.0; 0.0 0.0 10.0]
3×3 Matrix{Float64}:
 10.0   0.0   0.0
  0.0  10.0   0.0
  0.0   0.0  10.0

julia> wrap_to_first([15.0, 13.0, 2.0], uc)
3-element Vector{Float64}:
 5.0
 3.0000000000000004
 2.0
source

Structural alignment

PDBToolsBase.align — Function
align(x, y; mass=nothing)
align!(x, y; mass=nothing)

Aligns two structures (sets of points in 3D space). Solves the "Procrustes" problem, which is to find the best translation, and rotation, that aligns the two structures, minimizing the RMSD between them.

Structures are expected to be of the same size, and the correspondence is assumed from the vector indices.

align returns a new vector containing the coordinates of x aligned to y. align! modifies the input vector x in place.

source
PDBToolsBase.align! — Function
align(x, y; mass=nothing)
align!(x, y; mass=nothing)

Aligns two structures (sets of points in 3D space). Solves the "Procrustes" problem, which is to find the best translation, and rotation, that aligns the two structures, minimizing the RMSD between them.

Structures are expected to be of the same size, and the correspondence is assumed from the vector indices.

align returns a new vector containing the coordinates of x aligned to y. align! modifies the input vector x in place.

source
PDBToolsBase.rmsd — Function
rmsd(x::AbstractVector,y::AbstractVector)

Calculate the root mean square deviation between two vectors of coordinates.

Arguments

  • x::AbstractVector: A vector of coordinates.
  • y::AbstractVector: A vector of coordinates.

Returns

  • rmsd::Real: The root mean square deviation between the two vectors.
julia> import PDBTools: rmsd

julia> x = [ [1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0] ];

julia> y = [ [2.0, 3.0, 4.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0] ];

julia> rmsd(x, y)
1.0
source
PDBToolsBase.alignment_movements — Function
alignment_movements(
    x::AbstractVector{<:AbstractVector},
    y::AbstractVector{<:AbstractVector};
    mass=nothing,
    xm=zeros(3, length(x)),
    xp=zeros(3, length(x)),
)

Returns cmx, cmy, and rotation_matrix, necessary to translate and rotate y to minimize the RMSD relative to x.

Can be used to obtain the movement that aligns two sets of points, of the same size, and apply these movements to another set of points.

source
PDBToolsBase.apply_alignment_transformation! — Function
apply_alignment_transformation!(x, cmx, cmy, rotation_matrix)

Translates and rotates x such that the coordinates cmx are moved to cmy, and such apply the rotation defined in rotation_matrix.

source

Shared function names

These functions have methods defined in other packages of the ecosystem, which extend the functions defined here.

PDBToolsBase.distances — Function
distances

Shared function name: methods are defined by packages of the ecosystem (e.g. MolSimToolkit.jl), and documented there.

source
PDBToolsBase.coordination_number — Function
coordination_number

Shared function name: methods are defined by packages of the ecosystem (e.g. MolSimToolkit.jl, ComplexMixtures.jl), and documented there. Calling it with arguments not supported by any method throws an ArgumentError.

source
PDBToolsBase.save — Function
save

Shared function name: methods are defined by packages of the ecosystem (e.g. PDBTools.jl, ComplexMixtures.jl), and documented there.

source
PDBToolsBase.load — Function
load

Shared function name: methods are defined by packages of the ecosystem (e.g. PDBTools.jl, ComplexMixtures.jl), and documented there.

source