Class MolEnumerable
Parent: Object
Includes: Enumerable

Description

Overview

The class MolEnumerable provides array-like interfaces (i.e. methods of the module Enumerable) for collective data in Molecule. MolEnumerable does not implement initialize nor new methods. Instead, an instance of MolEnumerable is created by methods of Molecule, i.e. Molecule#atoms, Molecule#bonds, Molecule#angles, Molecule#dihedrals, Molecule#impropers, and Molecule#residues. These methods give MolEnumerable objects that are tied to the Molecule object and have a designated type (atom, bond, etc.)

The index operator MolEnumerable#[] gives an access to the index-th entry of the given type in the associated Molecule. The assignment operator ([]=) is not implemented, because any modification should be performed through methods of Molecule or AtomRef.

Among the six types of MolEnumerable objects, by far the most useful is the "atom" type object, which gives an AtomRef object.

Public Instance methods

self[n] → AtomRef
self[n] → Array of Integers
self[n] → String

Get the n-th atom, bond, etc. of the associated Molecule. For the atom, the return value is AtomRef. For the residue, the return value is a String. Otherwise, the return value is an Array of Integers. For the atom type, a string description of the atom is also acceptable. See "Atom index" description of Molecule.

% mol.dump
   0 MNO.1   Mn1  Mn   Mn  10.802   3.764  12.297  0.000 [3,22,4,7,10,13]
   1 MNO.1   Mn2  Mn   Mn  12.443   2.189  14.627  0.000 [3,33,11,14,16,19]
   2 MNO.1   Mn3  Mn   Mn  10.196   4.404  15.428  0.000 [3,44,17,20,5,8]
   3 MNO.1   O1   ox   O   11.148   3.452  14.117  0.000 [0,1,2]
...
-->
% a = mol.atoms  #  A MolEnumerable object
-->#<MolEnumerable:0x16493688>
% ap = a["Mn1"]  #  Get an AtomRef object
-->#<AtomRef:0x1648a54c>
% ap.name
-->"Mn1"
%
each {|obj| ...}

Call the block for each atom, bond, etc. The block argument is an AtomRef for atoms, a String for residues, and an Array of Integers for others. For the atoms, a same AtomRef object is passed (with different internal information) for each invocation of block. Otherwise, a new Ruby object will be created and passed for each iteration.

length → Integer
size → Integer

Returns the number of entries that can be accessed by this object.