struct Chem::ResidueView

Included Modules

Defined in:

chem/core/residue_view.cr
chem/register_format.cr

Instance Method Summary

Instance methods inherited from module Indexable(Chem::Residue)

[](idxs : Tuple) : Tuple
[](idxs : Enumerable(Int)) : Array(T)
[](*idxs : Int) : Tuple
[]
, sentence(io : IO, separator : String = ", ", *, pair_separator : String = " and ", tail_separator : String = ", and ", & : T, IO -> ) : Nil
sentence(io : IO, separator : String = ", ", *, pair_separator : String = " and ", tail_separator : String = ", and ") : Nil
sentence(separator : String = ", ", *, pair_separator : String = " and ", tail_separator : String = ", and ", & : T -> ) : String
sentence(separator : String = ", ", *, pair_separator : String = " and ", tail_separator : String = ", and ") : String
sentence

Instance methods inherited from module Enumerable(Chem::Residue)

===(atom : Chem::Atom) : Bool
===(chain : Chem::Chain) : Bool
===(residue : Chem::Residue) : Bool
===
, average(weights : Indexable(Number))
average(weights : Indexable(Number), & : T -> _)
average
, find(pattern, if_none default = nil) find, find!(pattern) find!, mean
mean(& : T -> _)
mean

Instance Method Detail

def atoms : AtomView #

[View source]
def chains : ChainView #

[View source]
def each_residue_fragment(& : ResidueView -> ) : Nil #

Iterates over residue-wise fragments.

A fragment is an array of inter-connected residues. Fragments are dynamically computed by iterating over Residue#bonded_residues of the selected residues.

NOTE fragments are scoped to the current list of residues such that bonded residues not contained in the list are omitted, e.g., given the list of residues [1, 2, 3, 4, 7, 8] belonging to the sequence 1-2-3-4-5-6 7-8-9, this method will return [[1, 2, 3, 4], [7, 8]], not [[1, 2, 3, 4, 5, 6], [7, 8, 9]].

TODO Rename to #each_fragment.


[View source]
def each_secondary_structure(reuse : Bool | Array(Residue) = false, strict : Bool = true, handedness : Bool = true) : Iterator(ResidueView) #

Returns an iterator over secondary structure elements (SSEs).

SSEs are defined as segments of consecutive, bonded residues that have the same secondary structure. If strict is false, residues are grouped by their secondary structure type. If handedness is false, handedness is not taken into account when strict is false. See Protein::SecondaryStructure#equals?.

Let's say a structure has 25 residues with two beta strands spanning residues 3-12 and 18-23, then:

iter = structure.each_secondary_structure
iter.next.map &.number # => [1, 2]
iter.next.map &.number # => [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
iter.next.map &.number # => [13, 14, 15, 16, 17]
iter.next.map &.number # => [18, 19, 20, 21, 22, 23]
iter.next.map &.number # => [24, 25]
iter.next              # => Iterator::Stop::INSTANCE

Note that non-protein residues are skipped over.

By default, a new array is created and yielded for each slice when invoking next.

  • If reuse is false, a new array is created for each chunk.
  • If reuse is true, an array is created once and reused.
  • If reuse is an Array, it will be reused instead.

The latter can be used to prevent many memory allocations when each slice of interest is to be used in a read-only fashion.

TODO Rename to chunk_by_sec


[View source]
def each_secondary_structure(reuse : Bool | Array(Residue) = false, strict : Bool = true, handedness : Bool = true, & : ResidueView, Protein::SecondaryStructure -> ) : Nil #

Iterates over secondary structure elements (SSEs), yielding both the residues and secondary structure.

SSEs are defined as segments of consecutive, bonded residues that have the same secondary structure. If strict is false, residues are grouped by their secondary structure type. If handedness is false, handedness is not taken into account when strict is false. See Protein::SecondaryStructure#equals?.

Let's say a structure has 25 residues with two beta strands spanning residues 3-12 and 18-23, then:

structure.each_secondary_structure do |sec, ary|
  puts "#{sec.to_s} at #{ary[0].number}..#{ary[-1].number}"
end

Prints:

None at 1..2
BetaStrand at 3..12
None at 13..17
BetaStrand at 18..23
None at 24..25

Note that non-protein residues are skipped over.

By default, a new array is created and yielded for each slice when invoking next.

  • If reuse is false, a new array is created for each chunk.
  • If reuse is true, an array is created once and reused.
  • If reuse is an Array, it will be reused instead.

The latter can be used to prevent many memory allocations when each slice of interest is to be used in a read-only fashion.

TODO Rename to each_chunk_by_sec

TODO yield the sec first (similar to #chunks)


[View source]
def link_bond : Templates::Bond | Nil #

[View source]
def reset_secondary_structure : self #

Sets secondary structure of every residue to none.

TODO remove this (residues.sec = :none is clear and shorter)


[View source]
def residue_fragments : Array(ResidueView) #

Returns residue-wise fragments. See #each_residue_fragment.

TODO rename to #fragments


[View source]

[View source]

[View source]
def secondary_structures(strict : Bool = true, handedness : Bool = true) : Array(ResidueView) #

TODO rename to #chunks_by_sec or #sec_chunks


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

Returns a string representation of the residue view 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 view 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 view 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 view 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 view 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 view 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 view 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 view to output using the Chem::PDB file format. Arguments are forwarded to Chem::PDB::Writer.open.


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

Returns a string representation of the residue view 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 view to output using the Chem::XYZ file format. Arguments are forwarded to Chem::XYZ::Writer.open.


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

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

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 view 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]