enum

Chem::Format

Inherits Enum / Comparable / Value / Object

List of the registered file formats.

This enum is populated based on the RegisterFormat annotation. Methods that deals with extensions and file patterns uses the information declared in the annotations.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe)), names: %w(IMG*)]
module JPEG; end

@[Chem::RegisterFormat(ext: %w(.tiff .tif))]
module TIFF; end

Chem::Format.names                 # => ["JPEG", "TIFF"]
Chem::Format::JPEG                 # => JPEG
Chem::Format::JPEG.extnames        # => [".jpg", ".jpeg", ".jpe"]
Chem::Format::JPEG.file_patterns   # => ["IMG*"]
Chem::Format::TIFF.extnames        # => [".tiff", ".tif"]
Chem::Format::TIFF.file_patterns   # => []

Chem::Format.from_ext("foo.jpg")   # => JPEG
Chem::Format.from_ext("foo.tiff")  # => TIFF
Chem::Format.from_stem("IMG_2015") # => JPEG

Constants

Chgcar = 0

The Chgcar format implemented by Chem::VASP::Chgcar.

Cube = 1

The Cube format implemented by Chem::Cube.

DX = 2

The DX format implemented by Chem::DX.

Gen = 3

The Gen format implemented by Chem::Gen.

Locpot = 4

The Locpot format implemented by Chem::VASP::Locpot.

Mol = 5

The Mol format implemented by Chem::Mol.

Mol2 = 6

The Mol2 format implemented by Chem::Mol2.

PDB = 7

The PDB format implemented by Chem::PDB.

PSF = 8

The PSF format implemented by Chem::PSF.

Poscar = 9

The Poscar format implemented by Chem::VASP::Poscar.

PyMOL = 10

The PyMOL format implemented by Chem::PyMOL.

SDF = 11

The SDF format implemented by Chem::SDF.

Stride = 12

The Stride format implemented by Chem::Protein::Stride.

VMD = 13

The VMD format implemented by Chem::VMD.

XYZ = 14

The XYZ format implemented by Chem::XYZ.

Constructors

from_ext(extname : String) : self

Returns the file format registered to the file extension, or raises ArgumentError otherwise.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe))]
module JPEG; end

Chem::Format.from_ext(".jpg")  # => JPEG
Chem::Format.from_ext(".JPG")  # => JPEG
Chem::Format.from_ext(".jpeg") # => JPEG
Chem::Format.from_ext(".jpe")  # => JPEG
Chem::Format.from_ext(".txt")  # raises ArgumentError

NOTE: It performs a case-insensitive search so .jpg and .JPG return the same.

Source
from_filename(filename : Path | String) : self

Returns the file format associated with filename, or raises ArgumentError otherwise.

It first looks up the file format associated with the extension of filename via the .from_ext? method. If the latter returns nil, then it executes a case-insensitive search with the stem of filename via .from_stem?.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe), names: %w(IMG*))]
module JPEG; end

Chem::Format.from_filename("foo.jpg")      # => JPEG
Chem::Format.from_filename("foo.JPG")      # => JPEG
Chem::Format.from_filename("IMG_2314.jpg") # => JPEG
Chem::Format.from_filename("IMG_2314.png") # => JPEG
Chem::Format.from_filename("IMG_2314")     # => JPEG
Chem::Format.from_filename("img_2314")     # => JPEG
Chem::Format.from_filename("img2314")      # => JPEG
Chem::Format.from_filename("foo")          # raises ArgumentError
Source
from_stem(stem : Path | String) : self

Returns the file format that matches the file stem, or raises ArgumentError otherwise.

The file stem is matched against the file patterns registered by the file formats until one match is found. File patterns can contain valid filename characters and the * wildcard, which matches an unlimited number of arbitrary characters:

  • "c*" matches file stems beginning with c.
  • "*c" matches file stems ending with c.
  • "*c*" matches file stems that have c in them (including at the beginning or end).
@[Chem::RegisterFormat(names: %w(IMG*))]
module JPEG; end

Chem::Format.from_stem("IMG_2314") # => JPEG
Chem::Format.from_stem("img_2314") # => JPEG
Chem::Format.from_stem("img2314")  # => JPEG
Chem::Format.from_stem("himg")     # raises ArgumentError
Chem::Format.from_stem("foo")      # raises ArgumentError

NOTE: The comparison is made using String#camelcase and String#downcase, so the file pattern FooBar will match FOOBAR, FooBar, foobar, FOO_BAR and foo_bar.

Source

Class methods

from_ext?(extname : String) : self | Nil

Returns the file format registered to the file extension, or nil otherwise.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe))]
module JPEG; end

Chem::Format.from_ext?(".jpg")  # => JPEG
Chem::Format.from_ext?(".JPG")  # => JPEG
Chem::Format.from_ext?(".jpeg") # => JPEG
Chem::Format.from_ext?(".jpe")  # => JPEG
Chem::Format.from_ext?(".txt")  # => nil

NOTE: It performs a case-insensitive search so .jpg and .JPG return the same.

Source
from_filename?(filename : Path | String) : self | Nil

Returns the file format associated with filename, or nil otherwise.

It first looks up the file format associated with the extension of filename via the .from_ext? method. If the latter returns nil, then it executes a case-insensitive search with the stem of filename via .from_stem?.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe), names: %w(IMG*))]
module JPEG; end

Chem::Format.from_filename?("foo.jpg")      # => JPEG
Chem::Format.from_filename?("foo.JPG")      # => JPEG
Chem::Format.from_filename?("IMG_2314.jpg") # => JPEG
Chem::Format.from_filename?("IMG_2314.png") # => JPEG
Chem::Format.from_filename?("IMG_2314")     # => JPEG
Chem::Format.from_filename?("img_2314")     # => JPEG
Chem::Format.from_filename?("img2314")      # => JPEG
Chem::Format.from_filename?("foo")          # => nil
Source
from_stem?(stem : String) : self | Nil

Returns the file format that matches the file stem, or nil otherwise.

The file stem is matched against the file patterns registered by the file formats until one match is found. File patterns can contain valid filename characters and the * wildcard, which matches an unlimited number of arbitrary characters:

  • "c*" matches file stems beginning with c.
  • "*c" matches file stems ending with c.
  • "*c*" matches file stems that have c in them (including at the beginning or end).
@[Chem::RegisterFormat(names: %w(IMG*))]
module JPEG; end

Chem::Format.from_stem?("IMG_2314") # => JPEG
Chem::Format.from_stem?("img_2314") # => JPEG
Chem::Format.from_stem?("img2314")  # => JPEG
Chem::Format.from_stem?("himg")     # => nil
Chem::Format.from_stem?("foo")      # => nil

NOTE: The comparison is made using String#camelcase and String#downcase, so the file pattern FooBar will match FOOBAR, FooBar, foobar, FOO_BAR and foo_bar.

Source

Instance methods

chgcar?

Returns true if the member is the Chgcar format.

Source
cube?

Returns true if the member is the Cube format.

Source
dx?

Returns true if the member is the DX format.

Source
encodes?(type : Array(T).class) : Bool forall T

Returns true if the format can write an instance of type.

Chem::Format::XYZ.encodes?(Chem::AtomCollection)      # => true
Chem::Format::XYZ.encodes?(Chem::Structure)           # => true
Chem::Format::XYZ.encodes?(Array(Chem::Structure))    # => true
Chem::Format::Poscar.encodes?(Chem::AtomCollection)   # => false
Chem::Format::Poscar.encodes?(Chem::Structure)        # => true
Chem::Format::Poscar.encodes?(Array(Chem::Structure)) # => false
Chem::Format::XYZ.encodes?(Int32)                     # => false
Chem::Format::XYZ.encodes?(Array(Int32))              # => false
Source
encodes?(type : T.class) : Bool forall T

Returns true if the format can write an instance of type.

Chem::Format::XYZ.encodes?(Chem::AtomCollection)      # => true
Chem::Format::XYZ.encodes?(Chem::Structure)           # => true
Chem::Format::XYZ.encodes?(Array(Chem::Structure))    # => true
Chem::Format::Poscar.encodes?(Chem::AtomCollection)   # => false
Chem::Format::Poscar.encodes?(Chem::Structure)        # => true
Chem::Format::Poscar.encodes?(Array(Chem::Structure)) # => false
Chem::Format::XYZ.encodes?(Int32)                     # => false
Chem::Format::XYZ.encodes?(Array(Int32))              # => false
Source
extnames

Returns the file extensions associated with the file format.

@[Chem::RegisterFormat(ext: %w(.jpg .jpeg .jpe))]
module JPEG; end

Chem::Format::JPEG.extnames # => [".jpg", ".jpeg", ".jpe"]
Source
file_patterns

Returns the file patterns associated with the file format.

@[Chem::RegisterFormat(names: %w(IMG*))]
module JPEG; end

Chem::Format::JPEG.file_patterns # => ["IMG*"]
Source
gen?

Returns true if the member is the Gen format.

Source
locpot?

Returns true if the member is the Locpot format.

Source
mol2?

Returns true if the member is the Mol2 format.

Source
mol?

Returns true if the member is the Mol format.

Source
pdb?

Returns true if the member is the PDB format.

Source
poscar?

Returns true if the member is the Poscar format.

Source
psf?

Returns true if the member is the PSF format.

Source
py_mol?

Returns true if this enum value equals PyMOL

Source
pymol?

Returns true if the member is the PyMOL format.

Source
reader(type : Chem::Spatial::Grid.class)

Returns the reader associated with the format. Raises ArgumentError if the format does not decode type or it is write only.

Chem::Format::XYZ.reader(Chem::Structure)           # => Chem::XYZ::Reader
Chem::Format::DX.reader(Chem::Spatial::Grid)        # => Chem::DX::Reader
Chem::Format::XYZ.reader(Array(Chem::Structure))    # => Chem::XYZ::Reader
Chem::Format::DX.reader(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::VMD.reader(Chem::Structure)           # raises ArgumentError
Chem::Format::XYZ.reader(Int32)                     # raises ArgumentError
Source
reader(type : Chem::Structure.class)

Returns the reader associated with the format. Raises ArgumentError if the format does not decode type or it is write only.

Chem::Format::XYZ.reader(Chem::Structure)           # => Chem::XYZ::Reader
Chem::Format::DX.reader(Chem::Spatial::Grid)        # => Chem::DX::Reader
Chem::Format::XYZ.reader(Array(Chem::Structure))    # => Chem::XYZ::Reader
Chem::Format::DX.reader(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::VMD.reader(Chem::Structure)           # raises ArgumentError
Chem::Format::XYZ.reader(Int32)                     # raises ArgumentError
Source
reader(type : Array(Chem::Structure).class)

Returns the reader associated with the format. Raises ArgumentError if the format does not decode type or it is write only.

Chem::Format::XYZ.reader(Chem::Structure)           # => Chem::XYZ::Reader
Chem::Format::DX.reader(Chem::Spatial::Grid)        # => Chem::DX::Reader
Chem::Format::XYZ.reader(Array(Chem::Structure))    # => Chem::XYZ::Reader
Chem::Format::DX.reader(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::VMD.reader(Chem::Structure)           # raises ArgumentError
Chem::Format::XYZ.reader(Int32)                     # raises ArgumentError
Source
sdf?

Returns true if the member is the SDF format.

Source
stride?

Returns true if the member is the Stride format.

Source
vmd?

Returns true if the member is the VMD format.

Source
writer(type : Chem::Spatial::Grid.class)

Returns the writer associated with the format. Raises ArgumentError if the format does not encode type or it is read only.

Chem::Format::XYZ.writer(Chem::Structure)           # => Chem::XYZ::Writer
Chem::Format::DX.writer(Chem::Spatial::Grid)        # => Chem::DX::Writer
Chem::Format::XYZ.writer(Array(Chem::Structure))    # => Chem::XYZ::Writer
Chem::Format::DX.writer(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::XYZ.writer(Int32)                     # raises ArgumentError
Source
writer(type : Chem::Structure.class)

Returns the writer associated with the format. Raises ArgumentError if the format does not encode type or it is read only.

Chem::Format::XYZ.writer(Chem::Structure)           # => Chem::XYZ::Writer
Chem::Format::DX.writer(Chem::Spatial::Grid)        # => Chem::DX::Writer
Chem::Format::XYZ.writer(Array(Chem::Structure))    # => Chem::XYZ::Writer
Chem::Format::DX.writer(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::XYZ.writer(Int32)                     # raises ArgumentError
Source
writer(type : Chem::AtomCollection.class)

Returns the writer associated with the format. Raises ArgumentError if the format does not encode type or it is read only.

Chem::Format::XYZ.writer(Chem::Structure)           # => Chem::XYZ::Writer
Chem::Format::DX.writer(Chem::Spatial::Grid)        # => Chem::DX::Writer
Chem::Format::XYZ.writer(Array(Chem::Structure))    # => Chem::XYZ::Writer
Chem::Format::DX.writer(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::XYZ.writer(Int32)                     # raises ArgumentError
Source
writer(type : Array(Chem::AtomCollection).class)

Returns the writer associated with the format. Raises ArgumentError if the format does not encode type or it is read only.

Chem::Format::XYZ.writer(Chem::Structure)           # => Chem::XYZ::Writer
Chem::Format::DX.writer(Chem::Spatial::Grid)        # => Chem::DX::Writer
Chem::Format::XYZ.writer(Array(Chem::Structure))    # => Chem::XYZ::Writer
Chem::Format::DX.writer(Array(Chem::Spatial::Grid)) # raises ArgumentError
Chem::Format::XYZ.writer(Int32)                     # raises ArgumentError
Source
xyz?

Returns true if the member is the XYZ format.

Source