Atomic and molecular properties

Some simple atom properties can be retrieved using special functions, which operate on atoms of the type Atom. For example:

julia> atoms = readPDB("./file.pdb");

julia> printatom(atoms[1])
   index name resname chain   resnum  residue        x        y        z  beta occup model segname index_pdb
       1   OW     SOL     X        1        1   54.370   45.310   33.970  0.00  0.00     1       -         1

julia> mass(atoms[1])
14.0067

julia> atomic_number(atoms[1])
7

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

julia> element_name(atoms[1])
"Nitrogen"

The formula or stoichiometry of a selection can also be retrieved:

julia> atoms = wget("1LBD","protein and residue 1");

julia> f = formula(atoms)
C₃N₁O₂

julia> stoichiometry(select(atoms,"water"))
H₂O₁

AtomsBase compatibility

Compat

This interface requires at least PDBTools version 0.14.2.

The following functions are supported as part of the API, to conform the AtomsBase interface:

FunctionExampleOutput
atomic_number(::PDBTools.Atom)atomic_number(Atom(name="NE2"))7
atomic_symbol(::PDBTools.Atom)atomic_symbol(Atom(name="NE2")):N
atomic_mass(::PDBTools.Atom)atomic_mass(Atom(name="NE2"))14.0067
position(::PDBTools.Atom)position(Atom(name="NE2"))SVector{3,Float64}(0,0,0)

Custom Atom fields

Compat

Custom field support was introduced on PDBTools version 0.14.3.

Custom atom fields can be added to an Atom object by defining the custom dictionary. The fields can be accessed by the standard dot syntax if the field name does not clash with an existing Atom field, or by the custom_field getter function.

For example:

julia> atom = Atom(index = 0; custom=Dict(:c => "c", :index => 1))
       0    X     XXX     X        0        0    0.000    0.000    0.000  0.00  0.00     0    XXXX         0

julia> atom.c
"c"

julia> atom.index
0

julia> custom_field(atom, :index)
1

Setting new custom fields follow the standard Julia dictionary syntax:

julia> atom.custom[:new] = "NEW"
"NEW"

julia> atom.new
"NEW"

julia> custom_field(atom, :new)
"NEW"
Compat

The following feature was introduced in PDBTools version 0.14.4.

If a custom field with the :mass key is added to the atom, the mass function returns the mass set at that field:

julia> using PDBTools

julia> atom = Atom();

julia> atom.custom[:mass] = 10.0
10.0

julia> mass(atom)
10.0

Elements for custom atom types

Compat

The add_element! function was introduced in version 1.4.0.

The types of atoms that PDBTools recognizes is defined in the PDBTools.elements dictionary. If new atom types are defined, it is possible to add these types to the dictionary, such that other functions work for the new types. The function to be used is add_element!.

PDBTools.add_element!Function
add_element!(symbol::String, 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"])
PDBTools.Element(:C, "C", "Carbon", 6, 12.011, true)

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

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

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

julia> mass(atoms)
26.017699999999998

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
PDBTools.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"])
PDBTools.Element(:N, "N", "Nitrogen", 7, 14.0067, true)

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

julia> remove_custom_elements!();

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

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

source