enum Chem::Format
Overview
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
Defined in:
chem/format.crEnum Members
-
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. -
.from_filename(filename : Path | String) : self
Returns the file format associated with filename, or raises
ArgumentError
otherwise. -
.from_stem(stem : Path | String) : self
Returns the file format that matches the file stem, or raises
ArgumentError
otherwise.
Class Method Summary
-
.from_ext?(extname : String) : self | Nil
Returns the file format registered to the file extension, or
nil
otherwise. -
.from_filename?(filename : Path | String) : self | Nil
Returns the file format associated with filename, or
nil
otherwise. -
.from_stem?(stem : String) : self | Nil
Returns the file format that matches the file stem, or
nil
otherwise.
Instance Method Summary
-
#chgcar? : Bool
Returns
true
if the member is theChgcar
format. -
#cube? : Bool
Returns
true
if the member is theCube
format. -
#dx? : Bool
Returns
true
if the member is theDX
format. -
#encodes?(type : Array(T).class) : Bool forall T
Returns
true
if the format can write an instance of type. -
#encodes?(type : T.class) : Bool forall T
Returns
true
if the format can write an instance of type. -
#extnames : Array(String)
Returns the file extensions associated with the file format.
-
#file_patterns : Array(String)
Returns the file patterns associated with the file format.
-
#gen? : Bool
Returns
true
if the member is theGen
format. -
#locpot? : Bool
Returns
true
if the member is theLocpot
format. -
#mol2? : Bool
Returns
true
if the member is theMol2
format. -
#mol? : Bool
Returns
true
if the member is theMol
format. -
#pdb? : Bool
Returns
true
if the member is thePDB
format. -
#poscar? : Bool
Returns
true
if the member is thePoscar
format. -
#psf? : Bool
Returns
true
if the member is thePSF
format. - #py_mol?
-
#pymol? : Bool
Returns
true
if the member is thePyMOL
format. -
#reader(type : Chem::Spatial::Grid.class)
Returns the reader associated with the format.
-
#reader(type : Chem::Structure.class)
Returns the reader associated with the format.
-
#reader(type : Array(Chem::Structure).class)
Returns the reader associated with the format.
-
#sdf? : Bool
Returns
true
if the member is theSDF
format. -
#stride? : Bool
Returns
true
if the member is theStride
format. -
#vmd? : Bool
Returns
true
if the member is theVMD
format. -
#writer(type : Chem::Spatial::Grid.class)
Returns the writer associated with the format.
-
#writer(type : Chem::Structure.class)
Returns the writer associated with the format.
-
#writer(type : Chem::AtomCollection.class)
Returns the writer associated with the format.
-
#writer(type : Array(Chem::AtomCollection).class)
Returns the writer associated with the format.
-
#xyz? : Bool
Returns
true
if the member is theXYZ
format.
Constructor Detail
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 havec
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
.
Class Method Detail
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 havec
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
.
Instance Method Detail
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