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 = read_pdb("./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₁
PDBTools.mass — Functionmass(s::Sequence)Returns the mass of a sequence of amino acids, given a Sequence struct type.
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.2432mass(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.0177f0PDBTools.element — Functionelement(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.  Othwerwise, the pdb_element is returned.
Example
julia> using PDBTools
julia> at = Atom(name="NT3");
julia> element(at)
"N"PDBTools.element_name — Functionelement_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"PDBTools.element_symbol — Functionelement_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)
:NPDBTools.element_symbol_string — Functionelement_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"PDBTools.element_vdw_radius — Functionelement_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.55f0PDBTools.formula — Functionformula(atoms::AbstractVector{<:Atom})Returns the molecular formula of the current selection. The output is an indexable "Formula" structure, where each element is a tuple with the element name and the number of atoms.
Example
julia> using PDBTools
julia> pdb  = read_pdb(PDBTools.TESTPDB, "residue 1"); # testing PDB file
julia> resname(pdb[1])
"ALA"
julia> f = formula(pdb)
H₇C₃N₁O₁
julia> f[1]
("H", 7)
PDBTools.stoichiometry — Functionstoichiometry(atoms::AbstractVector{<:Atom})Returns the stoichiometry of atom selection in a Formula structure. 
Example
julia> using PDBTools
julia> pdb  = read_pdb(PDBTools.TESTPDB, "water"); # testing PDB file
julia> stoichiometry(pdb)
H₂O₁PDBTools.printatom — Functionprintatom(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.TESTPDB, "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        13Custom Atom fields
Custom atom fields can be created in Atom objects by defining the custom keyword. By default, custom == nothing. The custom fields can be added on construction, or  with the add_custom_field function, which creates a new instance of an Atom  with the added value in the custom field:
For example:
julia> using PDBTools
julia> atom = Atom(custom="TEST");
julia> atom.custom
"TEST"
julia> atom = Atom(;name = "CA", resname="ALA"); # no custom field
julia> atom.resname
"ALA"
julia> new_atom = add_custom_field(atom, Dict(:charge => 2.0));
julia> new_atom.resname
"ALA"
julia> new_atom.custom[:charge]
2.0
PDBTools.add_custom_field — Functionadd_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.
Elements for custom atom types
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! — Functionadd_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, InlineStrings.String3("C"), "Carbon", 6, 12.011f0, true, 1.7f0)
julia> add_element!("A2", PDBTools.elements["N"])
PDBTools.Element(:N, InlineStrings.String3("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.
PDBTools.remove_custom_elements! — Functionremove_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, InlineStrings.String3("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 repeteadly call remove_custom_elements!() to guarantee the proper execution of the test codes, without any custom elements predefined.
Additional property-retrieving and set functions
The following functions are supported as part of the API, as a intending to interface with AtomsBase. Nevertheless, currently these functions do not overload the exported ones from AtomsBase, because that package is in a unstable state.
| Function | Example | Output | 
|---|---|---|
| atomic_number(::Atom) | atomic_number(Atom(name="NE2")) | 7 | 
| atomic_symbol(::Atom) | atomic_symbol(Atom(name="NE2")) | :N | 
| atomic_mass(::Atom) | atomic_mass(Atom(name="NE2")) | 14.0067 | 
| position(::Atom) | position(Atom(name="NE2")) | SVector{3,Float64}(0,0,0) | 
| set_position!(::Atom, x::Union{Tuple,AbstractVector}) | set_position!(at, (1,2,3)) | Atom | 
PDBTools.atomic_number — Functionatomic_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)
7PDBTools.atomic_symbol — Functionatomic_symbol(atom::Atom)Returns the atomic symbol of an atom given the Atom structure.
PDBTools.atomic_mass — Functionatomic_mass(atom::Atom)Returns the atomic mass of an atom given the Atom structure.
Base.position — Functionposition(atom::Atom)Returns the position of an atom given the Atom structure.
PDBTools.set_position! — Functionset_position!(atom::Atom, x::Union{Tuple,AbstractVector})Sets the position (x,y,z coordinates) of the atom, given a vector or tuple of coordinates.