class Chem::Residue

Included Modules

Defined in:

chem/core/residue.cr
chem/register_format.cr

Constructors

Instance Method Summary

Constructor Detail

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

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

[View source]

Instance Method Detail

def <=>(other : 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 : Templates::Atom) : Atom #

Returns the atom that matches atom_t.

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

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

TODO Move to Templates or other namespace


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

TODO Remove this delegate. Use #dig methods


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

TODO Remove this delegate. Use #dig methods


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

Returns the atom that matches atom_t.

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

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

TODO Move to Templates or other namespace


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

TODO Remove this delegate. Use #dig methods


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

TODO Remove this delegate. Use #dig methods


[View source]
def atoms : AtomView #

[View source]
def bonded?(other : self, bond_t : Templates::Bond, 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 = Templates::Bond.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 = Templates::Bond.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 = Templates::Bond.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 : Templates::Atom | String, rhs : Templates::Atom | String, order : BondOrder | 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 template, or elements:

a, b = Templates::Atom.new("C"), Templates::Atom.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 template are specified, this method returns false if missing:

missing_atom_t = Templates::Atom.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 : Templates::Atom | String, rhs : Element, order : BondOrder | 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 template, or elements:

a, b = Templates::Atom.new("C"), Templates::Atom.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 template are specified, this method returns false if missing:

missing_atom_t = Templates::Atom.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 : Templates::Atom | String, order : BondOrder | 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 template, or elements:

a, b = Templates::Atom.new("C"), Templates::Atom.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 template are specified, this method returns false if missing:

missing_atom_t = Templates::Atom.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 : Element, order : BondOrder | 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 template, or elements:

a, b = Templates::Atom.new("C"), Templates::Atom.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 template are specified, this method returns false if missing:

missing_atom_t = Templates::Atom.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 : Templates::Bond, forward_only : Bool = true, strict : Bool = true) : Array(Residue) #

Returns residues bonded through bond_t. 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 = Templates::Bond.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: false).map(&.name) # => ["CYS"]
residues[1].bonded_residues(bond_t, forward_only: false).map(&.name) # => ["ALA", "THR"]
residues[2].bonded_residues(bond_t, forward_only: false).map(&.name) # => ["CYS"]
residues[3].bonded_residues(bond_t, forward_only: false).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 = Templates::Bond.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. 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 code(default : Char = 'X') : Char #

Returns a single-letter code associated with the residue's template. If the residue has no associated template or it doesn't have a code, the method returns default.


[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 #

Returns true if the residue is a DNA residue, else false.


[View source]
def each_bonded_residue(bond_t : Templates::Bond, forward_only : Bool = true, strict : Bool = true, & : Residue -> ) : Nil #

Yields each residue bonded through bond_t.

If forward_only is false, then bond directionality is ignored.

If strict is false, bond search checks elements only, and bond order is ignored (fuzzy search).

See #bonded_residues(bond_t, forward_only, strict) for examples.


[View source]
def each_bonded_residue(& : Residue -> ) : Nil #

Yields each bonded residue. Residues may be bonded through any atom.

See #bonded_residues for examples.


[View source]
def has_backbone? : Bool #

[View source]
def het? : Bool #

Returns true if the residue is a non-standard (HET) residue, else false.


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

[View source]
def includes?(atom : Atom) : Bool #

Returns true if the residue contains atom, else false.

The check is done by name first, and then by atom equality.


[View source]
def insertion_code : Char | Nil #

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

[View source]
def inspect(io : IO) : Nil #
Description copied from class Reference

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>

[View source]
def ion? : Bool #

Returns true if the residue is a ion residue, else false.


[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 matches?(number : Int) : Bool #

Returns true if the residue number equals the given number, else false.


[View source]
def matches?(str : String) : Bool #

Returns true if the residue name equals the given name, else false.


[View source]
def matches?(code : Char) : Bool #

Returns true if the residue code equals the given character, else false.


[View source]
def matches?(pattern : Regex) : Bool #

Returns true if the residue name matches the given pattern, else false.


[View source]
def matches?(numbers : Range(Int, Int) | Range(Nil, Int) | Range(Int, Nil) | Range(Nil, Nil)) : Bool #

Returns true if the residue number is included in the given range, else false.


[View source]
def matches?(numbers : Enumerable(Int)) : Bool #

Returns true if the residue number is included in the given numbers, else false.


[View source]
def matches?(names : Enumerable(String)) : Bool #

Returns true if the residue name is included in the given names, else false.


[View source]
def matches?(codes : Enumerable(Char)) : Bool #

Returns true if the residue code is included in the given characters, else false.


[View source]
def membrane? : Bool #

Returns true if the residue is a membrane residue, else false.


[View source]
def name : String #

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

[View source]
def number : Int32 #

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

[View source]
def omega : Float64 #

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

[View source]
def other? : Bool #

Returns true if the residue is an unknown residue, else false.


[View source]
def phi : Float64 #

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

[View source]
def polymer? : Bool #

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

Returns the preceding residue if exists, else raises Error. Refer to #pred? for details.


[View source]
def pred?(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 template, 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 #

Returns true if the residue is a protein residue, else false.


[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 #

Returns true if the residue is a solvent residue, else false.


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

Writes the residue specification to the given IO.

Residue specification is a short string representation encoding residue information including chain, name, number, and insertion code.


[View source]
def spec : String #

Returns the residue specification.

Residue specification is a short string representation encoding residue information including chain, name, number, and insertion code.


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

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

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

Returns the following residue if exists, else raises Error. Refer to #succ? for details.


[View source]
def succ?(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 template, 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 template : Templates::Residue | Nil #

Returns associated residue template if registered, otherwise nil.

The template is fetched by the residue name.


[View source]
def to_gen(fractional : Bool = false) : String #

Returns a string representation of the residue using the Chem::Gen file format. Arguments are forwarded to Chem::Gen::Writer.open.


[View source]
def to_gen(output : IO | Path | String, fractional : Bool = false) : Nil #

Writes the residue to output using the Chem::Gen file format. Arguments are forwarded to Chem::Gen::Writer.open.


[View source]
def to_mol(variant : Chem::Mol::Variant = :v2000) : String #

Returns a string representation of the residue using the Chem::Mol file format. Arguments are forwarded to Chem::Mol::Writer.open.


[View source]
def to_mol(output : IO | Path | String, variant : Chem::Mol::Variant = :v2000) : Nil #

Writes the residue to output using the Chem::Mol file format. Arguments are forwarded to Chem::Mol::Writer.open.


[View source]
def to_mol2(output : IO | Path | String) : Nil #

Writes the residue to output using the Chem::Mol2 file format. Arguments are forwarded to Chem::Mol2::Writer.open.


[View source]
def to_mol2 : String #

Returns a string representation of the residue using the Chem::Mol2 file format. Arguments are forwarded to Chem::Mol2::Writer.open.


[View source]
def to_pdb(bonds : Chem::PDB::Writer::BondOptions = Chem::PDB::Writer::BondOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : String #

Returns a string representation of the residue using the Chem::PDB file format. Arguments are forwarded to Chem::PDB::Writer.open.


[View source]
def to_pdb(output : IO | Path | String, bonds : Chem::PDB::Writer::BondOptions = Chem::PDB::Writer::BondOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil #

Writes the residue to output using the Chem::PDB file format. Arguments are forwarded to Chem::PDB::Writer.open.


[View source]
def to_s(io : IO) #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

[View source]
def to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String #

Returns a string representation of the residue using the Chem::XYZ file format. Arguments are forwarded to Chem::XYZ::Writer.open.


[View source]
def to_xyz(output : IO | Path | String, extended : Bool = false, fields : Array(String) = [] of String) : Nil #

Writes the residue to output using the Chem::XYZ file format. Arguments are forwarded to Chem::XYZ::Writer.open.


[View source]
def trans? : Bool #

[View source]
def type : ResidueType #

[View source]
def type=(type : ResidueType) #

[View source]
def water? : Bool #

Returns true if the residue is a water residue, else false. This is done by checking if the associated residue template (if any) correspond to the water template.


[View source]
def write(output : IO | Path | String, format : Chem::Format | String) : Nil #

Writes the residue to output using format. Raises ArgumentError if format has required arguments or cannot write Chem::Residue.

The supported file formats are Chem::Gen, Chem::Mol2, Chem::Mol, Chem::PDB, Chem::XYZ. Use the #to_* methods to customize how the object is written in the corresponding file format if possible.


[View source]
def write(path : Path | String) : Nil #

Writes the residue to the specified file. The file format is chosen based on the filename (see Chem::Format#from_filename). Raises ArgumentError if the file format cannot be determined.

The supported file formats are the following:

Use the #to_* methods to customize how the object is written in the corresponding file format if possible.


[View source]