class Chem::Residue

Included Modules

Defined in:

chem/core/residue.cr

Constructors

Instance Method Summary

Instance methods inherited from module Chem::AtomCollection

atoms : AtomView atoms, bonds : Array(Bond) bonds, coords : Spatial::CoordinatesProxy coords, each_atom : Iterator(Atom)
each_atom(&block : Atom -> )
each_atom
, each_fragment(& : AtomView -> ) : Nil each_fragment, formal_charge : Int32 formal_charge, formal_charges : Array(Int32) formal_charges, fragments : Array(AtomView) fragments, has_hydrogens? : Bool has_hydrogens?, n_atoms : Int32 n_atoms, to_gen(output : ::IO | Path | String, *args, **options) : Nil
to_gen(*args, **options) : String
to_gen
, to_mol2(output : ::IO | Path | String, *args, **options) : Nil
to_mol2(*args, **options) : String
to_mol2
, to_pdb(output : ::IO | Path | String, *args, **options) : Nil
to_pdb(*args, **options) : String
to_pdb
, to_poscar(output : ::IO | Path | String, *args, **options) : Nil
to_poscar(*args, **options) : String
to_poscar
, to_xyz(output : ::IO | Path | String, *args, **options) : Nil
to_xyz(*args, **options) : String
to_xyz

Constructor Detail

def self.new(name : String, number : Int32, insertion_code : Char | Nil, chain : Chain) #

[View source]
def self.new(name : String, number : Int32, chain : Chain) #

[View source]

Instance Method Detail

def <=>(rhs : self) : Int32 #

The comparison operator.

Returns -1, 0 or 1 depending on whether self precedes rhs, equals to rhs or comes after rhs. The comparison is done based on chain id, residue number, and insertion code if present.

residues = Structure.read "peptide.pdb"
residues[0] # => <Residue A:TRP1>
residues[1] # => <Residue A:GLY1A>
residues[2] # => <Residue A:SER1B>
residues[3] # => <Residue A:ASN1C>
residues[4] # => <Residue A:VAL2>
residues[5] # => <Residue B:THR1>
residues[6] # => <Residue B:ASN2>

residues[0] <=> residues[1] # => -1
residues[1] <=> residues[1] # => 0
residues[2] <=> residues[1] # => 1
residues[0] <=> residues[5] # => -1
residues[5] <=> residues[6] # => -1

[View source]
def ==(rhs : self) : Bool #

Returns true if this residue is the same as rhs, else false.

NOTE overrides the equality operator included by Comparable, which uses the <=> operator thus returning true for two different residues that have the same chain id, number and insertion code.


[View source]
def [](atom_t : Topology::AtomType) : Atom #

Returns the atom that matches atom_t.

Atom must match both atom type's name and element, otherwise it raises IndexError.

residue = Structure.read("peptide.pdb").residues[0]
residue[Topology::AtomType("CA")]               # => <Atom A:TRP1:CA(2)
residue[Topology::AtomType("CA", element: "N")] # raises IndexError
residue[Topology::AtomType("CX")]               # raises IndexError

[View source]
def [](*args, **options) #

[View source]
def [](*args, **options, &) #

[View source]
def []?(atom_t : Topology::AtomType) : Atom | Nil #

Returns the atom that matches atom_t.

Atom must match both atom type's name and element, otherwise it returns nil.

residue = Structure.read("peptide.pdb").residues[0]
residue[Topology::AtomType("CA")]               # => <Atom A:TRP1:CA(2)
residue[Topology::AtomType("CA", element: "N")] # => nil
residue[Topology::AtomType("CX")]               # => nil

[View source]
def []?(*args, **options) #

[View source]
def []?(*args, **options, &) #

[View source]
def bonded?(other : self, bond_t : Topology::BondType, strict : Bool = true) : Bool #

Returns true if self is bonded to other through bond_t, otherwise false.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues
bond_t = Topology::BondType.new "C", "N"
residues[0].bonded?(residues[1], bond_t) # => true
residues[1].bonded?(residues[2], bond_t) # => true
residues[2].bonded?(residues[3], bond_t) # => false
residues[1].bonded?(residues[3], bond_t) # => false

Bond check follows the directionality of bond_t, that is, the left and right atoms are looked up in self and other, respectively:

residues[0].bonded?(residues[1], bond_t) # => true
residues[1].bonded?(residues[0], bond_t) # => false

Note that bond order is taken into account, e.g.:

bond_t = Topology::BondType.new "C", "N", order: 2
residues[0].bonded?(residues[1], bond_t) # => false

If strict is false, it uses elements only instead to look for bonded atoms, and bond order is ignored.

bond_t = Topology::BondType.new "C", "NX", order: 2
residues[0].bonded?(residues[1], bond_t)                # => false
residues[0].bonded?(residues[1], bond_t, strict: false) # => true

[View source]
def bonded?(other : self, lhs : Element, rhs : Element, order : Int | Nil = nil) : Bool #

Returns true if self is bonded to other through a bond between lhs and rhs, otherwise false.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues

One can use atom names, atom types or elements:

a, b = Topology::AtomType.new("C"), Topology::AtomType.new("N")
residues[0].bonded? residues[1], "C", "N"            # => true
residues[0].bonded? residues[1], a, b                # => true
residues[0].bonded? residues[1], a, PeriodicTable::N # => true
residues[0].bonded? residues[1], PeriodicTable::C, b # => true
residues[1].bonded? residues[2], a, b                # => true
residues[1].bonded? residues[3], a, b                # => false
residues[2].bonded? residues[3], a, b                # => false

Note that lhs and rhs are looked up in self and other, respectively, i.e., the arguments are not interchangeable:

residues[0].bonded? residues[1], "C", "N" # => true
residues[0].bonded? residues[1], "N", "C" # => false

When atom names or atom types are specified, this method returns false if missing:

missing_atom_t = Topology::AtomType.new("OZ5")
residues[0].bonded? residues[1], "CX1", "N"             # => false
residues[0].bonded? residues[1], missing_atom_t, "N"    # => false
residues[0].bonded? residues[1], "C", PeriodicTable::Mg # => false

When elements are specified, all atoms of that element are tested:

residues[1].bonded? residues[2], "C", PeriodicTable::N  # => true
residues[1].bonded? residues[2], "SG", PeriodicTable::C # => true

If order is specified, it also check for bond order, otherwise it is ignored:

residues[0].bonded? residues[1], "C", "N"    # => true
residues[0].bonded? residues[1], "C", "N", 1 # => true
residues[0].bonded? residues[1], "C", "N", 2 # => false

[View source]
def bonded?(other : self, lhs : Topology::AtomType | String, rhs : Element, order : Int | Nil = nil) : Bool #

Returns true if self is bonded to other through a bond between lhs and rhs, otherwise false.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues

One can use atom names, atom types or elements:

a, b = Topology::AtomType.new("C"), Topology::AtomType.new("N")
residues[0].bonded? residues[1], "C", "N"            # => true
residues[0].bonded? residues[1], a, b                # => true
residues[0].bonded? residues[1], a, PeriodicTable::N # => true
residues[0].bonded? residues[1], PeriodicTable::C, b # => true
residues[1].bonded? residues[2], a, b                # => true
residues[1].bonded? residues[3], a, b                # => false
residues[2].bonded? residues[3], a, b                # => false

Note that lhs and rhs are looked up in self and other, respectively, i.e., the arguments are not interchangeable:

residues[0].bonded? residues[1], "C", "N" # => true
residues[0].bonded? residues[1], "N", "C" # => false

When atom names or atom types are specified, this method returns false if missing:

missing_atom_t = Topology::AtomType.new("OZ5")
residues[0].bonded? residues[1], "CX1", "N"             # => false
residues[0].bonded? residues[1], missing_atom_t, "N"    # => false
residues[0].bonded? residues[1], "C", PeriodicTable::Mg # => false

When elements are specified, all atoms of that element are tested:

residues[1].bonded? residues[2], "C", PeriodicTable::N  # => true
residues[1].bonded? residues[2], "SG", PeriodicTable::C # => true

If order is specified, it also check for bond order, otherwise it is ignored:

residues[0].bonded? residues[1], "C", "N"    # => true
residues[0].bonded? residues[1], "C", "N", 1 # => true
residues[0].bonded? residues[1], "C", "N", 2 # => false

[View source]
def bonded?(other : self, lhs : Element, rhs : Topology::AtomType | String, order : Int | Nil = nil) : Bool #

Returns true if self is bonded to other through a bond between lhs and rhs, otherwise false.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues

One can use atom names, atom types or elements:

a, b = Topology::AtomType.new("C"), Topology::AtomType.new("N")
residues[0].bonded? residues[1], "C", "N"            # => true
residues[0].bonded? residues[1], a, b                # => true
residues[0].bonded? residues[1], a, PeriodicTable::N # => true
residues[0].bonded? residues[1], PeriodicTable::C, b # => true
residues[1].bonded? residues[2], a, b                # => true
residues[1].bonded? residues[3], a, b                # => false
residues[2].bonded? residues[3], a, b                # => false

Note that lhs and rhs are looked up in self and other, respectively, i.e., the arguments are not interchangeable:

residues[0].bonded? residues[1], "C", "N" # => true
residues[0].bonded? residues[1], "N", "C" # => false

When atom names or atom types are specified, this method returns false if missing:

missing_atom_t = Topology::AtomType.new("OZ5")
residues[0].bonded? residues[1], "CX1", "N"             # => false
residues[0].bonded? residues[1], missing_atom_t, "N"    # => false
residues[0].bonded? residues[1], "C", PeriodicTable::Mg # => false

When elements are specified, all atoms of that element are tested:

residues[1].bonded? residues[2], "C", PeriodicTable::N  # => true
residues[1].bonded? residues[2], "SG", PeriodicTable::C # => true

If order is specified, it also check for bond order, otherwise it is ignored:

residues[0].bonded? residues[1], "C", "N"    # => true
residues[0].bonded? residues[1], "C", "N", 1 # => true
residues[0].bonded? residues[1], "C", "N", 2 # => false

[View source]
def bonded?(other : self, lhs : Topology::AtomType | String, rhs : Topology::AtomType | String, order : Int | Nil = nil) : Bool #

Returns true if self is bonded to other through a bond between lhs and rhs, otherwise false.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues

One can use atom names, atom types or elements:

a, b = Topology::AtomType.new("C"), Topology::AtomType.new("N")
residues[0].bonded? residues[1], "C", "N"            # => true
residues[0].bonded? residues[1], a, b                # => true
residues[0].bonded? residues[1], a, PeriodicTable::N # => true
residues[0].bonded? residues[1], PeriodicTable::C, b # => true
residues[1].bonded? residues[2], a, b                # => true
residues[1].bonded? residues[3], a, b                # => false
residues[2].bonded? residues[3], a, b                # => false

Note that lhs and rhs are looked up in self and other, respectively, i.e., the arguments are not interchangeable:

residues[0].bonded? residues[1], "C", "N" # => true
residues[0].bonded? residues[1], "N", "C" # => false

When atom names or atom types are specified, this method returns false if missing:

missing_atom_t = Topology::AtomType.new("OZ5")
residues[0].bonded? residues[1], "CX1", "N"             # => false
residues[0].bonded? residues[1], missing_atom_t, "N"    # => false
residues[0].bonded? residues[1], "C", PeriodicTable::Mg # => false

When elements are specified, all atoms of that element are tested:

residues[1].bonded? residues[2], "C", PeriodicTable::N  # => true
residues[1].bonded? residues[2], "SG", PeriodicTable::C # => true

If order is specified, it also check for bond order, otherwise it is ignored:

residues[0].bonded? residues[1], "C", "N"    # => true
residues[0].bonded? residues[1], "C", "N", 1 # => true
residues[0].bonded? residues[1], "C", "N", 2 # => false

[View source]
def bonded?(other : self) : Bool #

Returns true if self is bonded to other, otherwise false. Residues may be bonded by any two atoms.

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues
residues[0].bonded?(residues[1]) # => true
residues[1].bonded?(residues[2]) # => true
residues[2].bonded?(residues[3]) # => false
residues[1].bonded?(residues[3]) # => true

[View source]
def bonded_residues(bond_t : Topology::BondType, forward_only : Bool = true, strict : Bool = true) : Array(Residue) #

Returns residues bonded through bond_t.

Returned residues are ordered by their chain id, residue number and insertion code if present (refer to #<=>).

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues
bond_t = Topology::BondType.new("C", "N")
residues[0].bonded_residues(bond_t).map(&.name) # => ["CYS"]
residues[1].bonded_residues(bond_t).map(&.name) # => ["THR"]
residues[2].bonded_residues(bond_t).map(&.name) # => []
residues[3].bonded_residues(bond_t).map(&.name) # => []

If forward_only is false, then bond directionality is ignored:

residues[0].bonded_residues(bond_t, forward_only: true).map(&.name) # => ["CYS"]
residues[1].bonded_residues(bond_t, forward_only: true).map(&.name) # => ["ALA", "THR"]
residues[2].bonded_residues(bond_t, forward_only: true).map(&.name) # => ["CYS"]
residues[3].bonded_residues(bond_t, forward_only: true).map(&.name) # => []

If strict is false, bond search checks elements only, and bond order is ignored (fuzzy search). In the following example, using strict: false makes that any C-N bond is accepted regardless of atom names or bond order:

bond_t = Topology::BondType.new "C", "NX", order: 2
residues[0].bonded_residues(bond_t, strict: false).map(&.name) # => ["CYS"]
residues[1].bonded_residues(bond_t, strict: false).map(&.name) # => ["THR"]
residues[2].bonded_residues(bond_t, strict: false).map(&.name) # => []
residues[3].bonded_residues(bond_t, strict: false).map(&.name) # => []

[View source]
def bonded_residues : Array(Residue) #

Returns bonded residues. Residues may be bonded through any atom.

Returned residues are ordered by their chain id, residue number and insertion code if present (refer to #<=>).

# Covalent ligand (JG7) is bonded to CYS sidechain
residues = Structure.read("ala-cys-thr-jg7.pdb").residues
residues[0].bonded_residues.map(&.name) # => ["CYS"]
residues[1].bonded_residues.map(&.name) # => ["ALA", "THR", "JG7"]
residues[2].bonded_residues.map(&.name) # => ["CYS"]
residues[3].bonded_residues.map(&.name) # => ["CYS"]

[View source]
def chain : Chain #

[View source]
def chain=(new_chain : Chain) : Chain #

[View source]
def cis? : Bool #

[View source]
def clear : self #

[View source]
def delete(atom : Atom) : Atom | Nil #

[View source]
def dextro? : Bool #

Returns true is residue is dextrorotatory, otherwise false.

A residue is considered to be dextrorotatory if the improper angle C-CA-C-CB is negative.

Note that this method returns false if the residue doesn't have any of such atoms, therefore it's not always equal to the inverse of #levo?.


[View source]
def dig(name : String) : Atom #

[View source]
def dig?(name : String) : Atom | Nil #

[View source]
def dna? : Bool #

[View source]
def dssp : Char #

[View source]
def each_atom : Iterator(Atom) #

[View source]
def each_atom(&block : Atom -> ) #

[View source]
def has_backbone? : Bool #

[View source]
def hlxparams : Spatial::HlxParams | Nil #

[View source]
def insertion_code : Char | Nil #

[View source]
def insertion_code=(insertion_code : Char | Nil) #

[View source]
def inspect(io : ::IO) : Nil #

[View source]
def ion? : Bool #

[View source]
def kind : Kind #

[View source]
def kind=(kind : Kind) #

[View source]
def levo? : Bool #

Returns true is residue is levorotatory, otherwise false.

A residue is considered to be levorotatory if the improper angle C-CA-C-CB is positive.

Note that this method returns false if the residue doesn't have any of such atoms, therefore it's not always equal to the inverse of #dextro?.


[View source]
def n_atoms : Int32 #

[View source]
def name : String #

[View source]
def name=(str : String) : String #

[View source]
def next(strict : Bool = true, use_numbering : Bool = true) : Residue | Nil #

Returns the following residue if exists, otherwise nil.

It uses the link bond type of the associated residue type, if present, to search for the next residue. Thus, link bond determines the direction, e.g., C(i)-N(i+1). Be aware that atom types must match exactly to find a residue unless strict is false.

Otherwise, it returns a bonded residue whose number and insertion code come just after those of self. This fallback can be disabled by setting use_numbering to false.

Note that when multiple residues can be connected to the same residue (e.g., branched polymers), it returns the first residue among them.


[View source]
def number : Int32 #

[View source]
def number=(number : Int32) #

[View source]
def omega : Float64 #

[View source]
def omega? : Float64 | Nil #

[View source]
def other? : Bool #

[View source]
def phi : Float64 #

[View source]
def phi? : Float64 | Nil #

[View source]
def polymer? : Bool #

[View source]
def previous(strict : Bool = true, use_numbering : Bool = true) : Residue | Nil #

Returns the preceding residue if exists, otherwise nil.

It uses the link bond type of the associated residue type, if present, to search for the previous residue. Thus, link bond determines the direction, e.g., C(i-1)-N(i). Be aware that atom types must match exactly to find a residue unless strict is false.

Otherwise, it returns a bonded residue whose number and insertion code come just before those of self. This fallback can be disabled by setting use_numbering to false.

Note that when multiple residues can be connected to the same residue (e.g., branched polymers), it returns the last residue among them.


[View source]
def protein? : Bool #

[View source]
def psi : Float64 #

[View source]
def psi? : Float64 | Nil #

[View source]
def ramachandran_angles : Tuple(Float64, Float64) #

[View source]

[View source]
def sec=(sec : Protein::SecondaryStructure) #

[View source]
def solvent? : Bool #

[View source]
def structure(*args, **options) #

[View source]
def structure(*args, **options, &) #

[View source]
def to_s(io : ::IO) #

[View source]
def trans? : Bool #

[View source]
def type : Topology::ResidueType | Nil #

Returns associated residue type if registered, otherwise nil.

The type of a residue is fetched by its name.


[View source]