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
The Chgcar format implemented by Chem::VASP::Chgcar.
The Cube format implemented by Chem::Cube.
The DX format implemented by Chem::DX.
The Gen format implemented by Chem::Gen.
The Locpot format implemented by Chem::VASP::Locpot.
The Mol format implemented by Chem::Mol.
The Mol2 format implemented by Chem::Mol2.
The PDB format implemented by Chem::PDB.
The PSF format implemented by Chem::PSF.
The Poscar format implemented by Chem::VASP::Poscar.
The PyMOL format implemented by Chem::PyMOL.
The SDF format implemented by Chem::SDF.
The Stride format implemented by Chem::Protein::Stride.
The VMD format implemented by Chem::VMD.
The XYZ format implemented by Chem::XYZ.
Constructors
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.
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
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 withc."*c"matches file stems ending withc."*c*"matches file stems that havecin 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.
Class methods
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.
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
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 withc."*c"matches file stems ending withc."*c*"matches file stems that havecin 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.
Instance methods
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
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
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"]
Returns the file patterns associated with the file format.
@[Chem::RegisterFormat(names: %w(IMG*))]
module JPEG; end
Chem::Format::JPEG.file_patterns # => ["IMG*"]
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
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
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
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
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
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
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