module Enumerable(T)

Overview

Gather, check and annotate types registering a format

Direct including types

Defined in:

chem/core_ext/enumerable.cr
chem/register_format.cr

Instance Method Summary

Instance Method Detail

def ===(atom : Chem::Atom) : Bool #

Case equality. Delegates to Chem::Atom#matches?.


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

Case equality. Delegates to Chem::Chain#matches?.


[View source]
def ===(residue : Chem::Residue) : Bool #

Case equality. Delegates to Chem::Residue#matches?.


[View source]
def average(weights : Indexable(Number)) #

Returns the weighted average of the elements in the collection. Raises EmptyError if the collection is empty or ArgumentError if weights has a different number of elements.

Expects all element types to respond to #+ and #/ methods.

[1, 2, 3, 4, 5, 6].average((1..6).to_a) # => 4.333333333333333
(1..6).average((1..6).to_a)             # => 4.333333333333333
([] of Int32).average([1, 1, 1])        # raises EmptyError
(1..6).average([1, 1])                  # raises ArgumentError

NOTE This method calls .additive_identity on the element type and weights' element type to determine the type of the intermediate sum values.


[View source]
def average(weights : Indexable(Number), & : T -> _) #

Returns the weighted average of the results of the passed block for each element in the collection. Raises EmptyError if the collection is empty or ArgumentError if weights has a different number of elements.

Expects all element types to respond to #+ and #/ methods.

["Alice", "Bob"].average([7, 2], &.size)    # => 4.555555555555555
('a'..'z').average((0..25).to_a, &.ord)     # => 4.333333333333333
([] of String).average([1, 1], &.size)      # raises EmptyError
["Alice", "Bob"].average([1, 1, 1], &.size) # raises ArgumentError

NOTE This method calls .additive_identity on the yielded type and weights' element type to determine the type of the intermediate sum values.


[View source]
def find(pattern, if_none default = nil) #

Returns the first element in the collection for which pattern === element.

[1, 3, 2, 5, 4, 6].find(3..5) # => 3
["Alice", "Bob"].find(/^A/)   # => "Alice"
[1, 2, 3, 4].find(8..)        # => nil

[View source]
def find!(pattern) #

Returns the first element in the collection for which pattern === element.

[1, 3, 2, 5, 4, 6].find!(3..5) # => 3
["Alice", "Bob"].find!(/^A/)   # => "Alice"
[1, 2, 3, 4].find(8..)         # raises Enumerable::NotFoundError

[View source]
def mean #

Returns the arithmetic mean of the elements in the collection. Raises EmptyError if the collection is empty.

Expects all element types to respond to #+ and #/ methods.

[1, 2, 3, 4, 5, 6].mean # => 3.5
(1..6).mean             # => 3.5
([] of Int32).mean      # raises EmptyError

NOTE This method calls .additive_identity on the element type to determine the type of the intermediate sum.


[View source]
def mean(& : T -> _) #

Returns the arithmetic mean of the results of the passed block for each element in the collection. Raises EmptyError if the collection is empty.

Expects all element types to respond to #+ and #/ methods.

["Alice", "Bob"].mean(&.size) # => 4
('a'..'z').mean(&.ord)        # => 109.5
([] of String).mean(&.size)   # raises EmptyError

NOTE This method calls .additive_identity on the yielded type to determine the type of the intermediate sum.


[View source]
def to_dcd(io : IO, title : String | Nil = nil) : Nil #

[View source]
def to_dcd(title : String | Nil = nil) : String #

[View source]
def to_dcd(path : Path | String, title : String | Nil = nil) : Nil #

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

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

[View source]
def to_mol2 : String #

[View source]
def to_pdb(io : IO, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil #

[View source]
def to_pdb(conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : String #

[View source]
def to_pdb(path : Path | String, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil #

[View source]
def to_sdf(io : IO, variant : Mol::Variant = :v2000) : Nil #

[View source]
def to_sdf(path : Path | String, variant : Mol::Variant = :v2000) : Nil #

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

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

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

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

[View source]