class

Array(T)

Inherits Comparable / Indexable::Mutable / Indexable / Enumerable / Iterable / Reference / Object

An Array is an ordered, integer-indexed collection of objects of type T.

Array indexing starts at 0. A negative index is assumed to be relative to the end of the array: -1 indicates the last element, -2 is the next to last element, and so on.

An Array can be created using the usual new method (several are provided), or with an array literal:

Array(Int32).new  # => []
[1, 2, 3]         # Array(Int32)
[1, "hello", 'x'] # Array(Int32 | String | Char)

See Array literals in the language reference.

An Array can have mixed types, meaning T will be a union of types, but these are determined when the array is created, either by specifying T or by using an array literal. In the latter case, T will be set to the union of the array literal elements' types.

When creating an empty array you must always specify T:

[] of Int32 # same as Array(Int32)
[]          # syntax error

An Array is implemented using an internal buffer of some capacity and is reallocated when elements are pushed to it when more capacity is needed. This is normally known as a dynamic array.

You can use a special array literal syntax with other types too, as long as they define an argless new method and a << method. Set is one such type:

set = Set{1, 2, 3} # => Set{1, 2, 3}
set.class          # => Set(Int32)

The above is the same as this:

set = Set(typeof(1, 2, 3)).new
set << 1
set << 2
set << 3

Constructors

from_mol2(input : IO | Path | String, indexes : Array(Int)) : self

Creates a new array of Chem::Structure with the entries at indexes encoded in input using the Chem::Mol2 file format. Arguments are fowarded to Chem::Mol2::Reader.open.

Source
from_mol2(input : IO | Path | String) : self

Creates a new array of Chem::Structure with the entries encoded in input using the Chem::Mol2 file format. Arguments are fowarded to Chem::Mol2::Reader.open.

Source
from_pdb(input : IO | Path | String, alt_loc : Char | Nil = nil, chains : Enumerable(Char) | String | Nil = nil, guess_bonds : Bool = false, het : Bool = true) : self

Creates a new array of Chem::Structure with the entries encoded in input using the Chem::PDB file format. Arguments are fowarded to Chem::PDB::Reader.open.

Source
from_pdb(input : IO | Path | String, indexes : Array(Int), alt_loc : Char | Nil = nil, chains : Enumerable(Char) | String | Nil = nil, guess_bonds : Bool = false, het : Bool = true) : self

Creates a new array of Chem::Structure with the entries at indexes encoded in input using the Chem::PDB file format. Arguments are fowarded to Chem::PDB::Reader.open.

Source
from_sdf(input : IO | Path | String, indexes : Array(Int)) : self

Creates a new array of Chem::Structure with the entries at indexes encoded in input using the Chem::SDF file format. Arguments are fowarded to Chem::SDF::Reader.open.

Source
from_sdf(input : IO | Path | String) : self

Creates a new array of Chem::Structure with the entries encoded in input using the Chem::SDF file format. Arguments are fowarded to Chem::SDF::Reader.open.

Source
from_xyz(input : IO | Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self

Creates a new array of Chem::Structure with the entries encoded in input using the Chem::XYZ file format. Arguments are fowarded to Chem::XYZ::Reader.open.

Source
from_xyz(input : IO | Path | String, indexes : Array(Int), guess_bonds : Bool = false, guess_names : Bool = false) : self

Creates a new array of Chem::Structure with the entries at indexes encoded in input using the Chem::XYZ file format. Arguments are fowarded to Chem::XYZ::Reader.open.

Source
read(input : IO | Path | String, format : String) : self

Returns the entries encoded in the specified file using format. Raises ArgumentError if format is invalid.

Source
read(input : IO | Path | String, format : Chem::Format) : self

Returns the entries encoded in the specified file using format. Raises ArgumentError if format cannot read the element type or it is write only.

Source
read(path : Path | String) : self

Returns the entries encoded in 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.

Source

Instance methods

sort(range : Range(Int, Int)) : self
Source
sort(range : Range(Int, Int), &block : T, T -> Int32 | Nil) : self
Source
sort!(range : Range(Int, Int)) : self
Source
sort!(range : Range(Int, Int), &block : T, T -> Int32 | Nil) : self
Source
to_mol2(output : IO | Path | String) : Nil

Writes the elements to output using the Chem::Mol2 file format. Arguments are fowarded to Chem::Mol2::Writer.open.

Source
to_mol2

Returns a string representation of the elements encoded in the Chem::Mol2 file format. Arguments are fowarded to Chem::Mol2::Writer.open.

Source
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 elements encoded in the Chem::PDB file format. Arguments are fowarded to Chem::PDB::Writer.open.

Source
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 elements to output using the Chem::PDB file format. Arguments are fowarded to Chem::PDB::Writer.open.

Source
to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String

Returns a string representation of the elements encoded in the Chem::XYZ file format. Arguments are fowarded to Chem::XYZ::Writer.open.

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

Writes the elements to output using the Chem::XYZ file format. Arguments are fowarded to Chem::XYZ::Writer.open.

Source
write(output : IO | Path | String, format : String) : Nil

Writes the elements to output using format. Raises ArgumentError if format is invalid.

Source
write(output : IO | Path | String, format : Chem::Format) : Nil

Writes the elements to output using format. Raises ArgumentError if format cannot write the element type or it is read only.

Source
write(path : Path | String) : Nil

Writes the elements 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.

Source