enum Chem::IO::FileFormat

Defined in:

chem/io/formats.cr

Enum Members

Chgcar = 0
Cube = 1
DX = 2
Gen = 3
Locpot = 4
Mol2 = 5
PDB = 6
Poscar = 7
PyMOL = 8
Stride = 9
VMD = 10
XYZ = 11

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.from_ext(extname : String) : self #

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

@[FileType(format: Image, ext: %w(tiff png jpg))]
...

FileFormat.from_ext("img.tiff") # => FileFormat::Image
FileFormat.from_ext("img.TIFF") # => FileFormat::Image
FileFormat.from_ext("img.png")  # => FileFormat::Image
FileFormat.from_ext("img.txt")  # => raises ArgumentError

NOTE it performs a case-insensitive search so .tiff and .TIFF return the same.


[View source]
def self.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 in filename via .from_ext?. If this yields no result, then it executes a case-insensitive search with the stem in filename via .from_stem?.

@[FileType(format: Image, ext: %w(tiff png jpg), names: %w(IMG*))]
...

FileFormat.from_filename("IMG_2314.tiff") # => FileFormat::Image
FileFormat.from_filename("IMG_2314.png")  # => FileFormat::Image
FileFormat.from_filename("IMG_2314")      # => FileFormat::Image
FileFormat.from_filename("img_2314")      # => FileFormat::Image
FileFormat.from_filename("img2314")       # => FileFormat::Image
FileFormat.from_filename("Imi")           # => raises ArgumentError

[View source]
def self.from_stem(stem : Path | String) : self #

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

The comparison is made using String#camelcase and String#downcase, so a file format named ChgCar will match "CHGCAR", "ChgCar", "chgcar", "CHG_CAR" and "chg_car".

@[FileType(format: Image, names: %w(IMG*))]
...

FileFormat.from_stem("IMG_2314") # => FileFormat::Image
FileFormat.from_stem("img_2314") # => FileFormat::Image
FileFormat.from_stem("img2314")  # => FileFormat::Image
FileFormat.from_stem("Imi")      # => raises ArgumentError

[View source]

Class Method Detail

def self.from_ext?(extname : String) : self | Nil #

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

@[FileType(format: Image, ext: %w(tiff png jpg))]
...

FileFormat.from_ext?("img.tiff") # => FileFormat::Image
FileFormat.from_ext?("img.TIFF") # => FileFormat::Image
FileFormat.from_ext?("img.png")  # => FileFormat::Image
FileFormat.from_ext?("img.txt")  # => nil

NOTE it performs a case-insensitive search so .tiff and .TIFF return the same.


[View source]
def self.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 in filename via .from_ext?. If this yields no result, then it executes a case-insensitive search with the stem in filename via .from_stem?.

@[FileType(format: Image, ext: %w(tiff png jpg), names: %w(IMG*))]
...

FileFormat.from_filename?("IMG_2314.tiff") # => FileFormat::Image
FileFormat.from_filename?("IMG_2314.png")  # => FileFormat::Image
FileFormat.from_filename?("IMG_2314")      # => FileFormat::Image
FileFormat.from_filename?("img_2314")      # => FileFormat::Image
FileFormat.from_filename?("img2314")       # => FileFormat::Image
FileFormat.from_filename?("Imi")           # => nil

[View source]
def self.from_stem?(stem : String) : self | Nil #

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

The comparison is made using String#camelcase and String#downcase, so a file format named ChgCar will match "CHGCAR", "ChgCar", "chgcar", "CHG_CAR" and "chg_car".

@[FileType(format: Image, names: %w(IMG*))]
...

FileFormat.from_stem?("IMG_2314") # => FileFormat::Image
FileFormat.from_stem?("img_2314") # => FileFormat::Image
FileFormat.from_stem?("img2314")  # => FileFormat::Image
FileFormat.from_stem?("Imi")      # => nil

[View source]

Instance Method Detail

def chgcar? : Bool #

[View source]
def cube? : Bool #

[View source]
def dx? : Bool #

[View source]
def extnames : Array(String) #

[View source]
def gen? : Bool #

[View source]
def locpot? : Bool #

[View source]
def mol2? : Bool #

[View source]
def pdb? : Bool #

[View source]
def poscar? : Bool #

[View source]
def py_mol? #

[View source]
def pymol? : Bool #

[View source]
def stride? : Bool #

[View source]
def vmd? : Bool #

[View source]
def xyz? : Bool #

[View source]