Fortran namelists
Index
QuantumEspressoIO.find_cardQuantumEspressoIO.parse_card!QuantumEspressoIO.parse_card_optionQuantumEspressoIO.read_namelistQuantumEspressoIO.read_namelistsQuantumEspressoIO.write_namelistQuantumEspressoIO.write_namelistQuantumEspressoIO.write_namelistsQuantumEspressoIO.write_namelists
Documentation
QuantumEspressoIO.find_card — Method
find_card(lines, name)
Find a card in the lines. Ignore comments and empty lines.
Arguments
lines::AbstractVector: The lines to read from.name::AbstractString: The name of the card to read.
Returns
- The index of the card in the lines. If not found, return
nothing.
Examples
lines = [
" ! This is a comment",
" input",
" name1 = value1 ! comment 2",
" name2 = value2",
]
name = "input"
find_card(lines, name)
# output
2QuantumEspressoIO.parse_card! — Function
parse_card!(lines, name)
parse_card!(lines, name, n_lines)
From lines, get the card with name name and n_lines following lines.
Arguments
lines: The lines to read from.name: The name of the card to read.n_lines: The number of lines to read after the card name. Comment lines are ignored and not counted asn_lines. Ifnothing, read everything after the card.
Example
lines = [
" input option1",
" ! This is a comment",
" name1 = value1 ! comment 2",
" name2 = value2",
]
name = "input"
n_lines = 1
card = parse_card!(lines, name, n_lines)
println(card)
println(lines)
# output
("option1", ["name1 = value1"])
[" name2 = value2"]QuantumEspressoIO.parse_card_option — Method
parse_card_option(line)
Get the option of a card.
Arguments
line::AbstractString: The line of the card.
Returns
- The option of the card. If no option is found, return
nothing.
Examples
julia> parse_card_option("POSITIONS angstrom ! comment")
"angstrom"julia> parse_card_option("POSITIONS {angstrom} ! comment")
"angstrom"QuantumEspressoIO.read_namelist — Method
read_namelist(io_or_filename, name; all_lines)
Read a single Fortran namelist from a file or IO stream.
Arguments
io_or_filename: The IO stream or filename to read from.name: The name of the namelist to read.
Keyword Arguments
all_lines: Return the remaining lines outside of the namelist. Default tofalse.
Returns
params: The key-value pairs of the namelist.others: Optional. A vector of strings, which are the remaining lines in the file.
Examples
io = IOBuffer("""
&input
a = 1
b = 2.0
c = 'test'
d = .true.
/
additional line
""")
namelist, others = read_namelist(io, "input"; all_lines=true)
# output
(OrderedCollections.OrderedDict{Symbol, Any}(:a => 1, :b => 2.0, :c => "test", :d => true), ["additional line"])QuantumEspressoIO.read_namelists — Method
read_namelists(io; all_lines)
Read fortran namelists file.
Arguments
io: The IO stream to read from.
Keyword Arguments
all_lines: Return the remaining lines outside of namelists. Default tofalse.
Returns
namelists::OrderedDict: A dictionary of namelists, each key is a symbol and the value is aOrderedDictof key-value pairs.others::Vector: Optional. A vector of strings, which are the remaining lines in the file. For example, QEpw.xinput files may contain "cards" for additional parameters (e.g. atomic positions, k-points, etc.), whose syntax are customarily defined bypw.x.
Examples
io = IOBuffer("""
&input
a = 1
b = 2.0
c = 'test'
d = .true.
/
additional line
""")
namelists, others = read_namelists(io; all_lines=true)
# output
(OrderedCollections.OrderedDict{Symbol, Any}(:input => OrderedCollections.OrderedDict{Symbol, Any}(:a => 1, :b => 2.0, :c => "test", :d => true)), ["additional line"])QuantumEspressoIO.write_namelist — Method
write_namelist(filename, name, params)
Write a Fortran namelist to a file.
Arguments
filename: The name of the file to write to.name: The name of the namelist.params: The key-value pairs to write, which is a dictionary-like object.
QuantumEspressoIO.write_namelist — Method
write_namelist(io, name, params)
Write a Fortran namelist.
Arguments
io::IO: The IO stream to write to.name::StrOrSym: The name of the namelist.params::AbstractDict: The key-value pairs to write, which is a dictionary-like object.
Examples
using OrderedCollections
name = :input
params = OrderedDict(
"a" => 1,
"b" => 2.0,
"c" => [3, 4, 5],
"d" => "test",
"e" => true,
)
write_namelist(stdout, name, params)
# output
&input
a = 1
b = 2.0
c(1) = 3
c(2) = 4
c(3) = 5
d = 'test'
e = .true.
/QuantumEspressoIO.write_namelists — Method
write_namelists(filename, namelists)
Write multiple Fortran namelists to a file.
Arguments
filename::AbstractString: The name of the file to write to.namelists::AbstractDict: The input parameters, seewrite_namelists(io::IO, namelists::AbstractDict)for details.
QuantumEspressoIO.write_namelists — Method
write_namelists(io, namelists)
Write multiple Fortran namelists to a file.
Arguments
io: The IO stream to write to.namelists: The namelists, each key-value pair is treated as a namelist.
Examples
using OrderedCollections
# Use OrderedDict to preserve the order of the keys
inputs = OrderedDict(
:control => OrderedDict("calculation" => "scf", "prefix" => "qe"),
:system => OrderedDict("ecutwfc" => 30.0, "ecutrho" => 300.0),
:electrons => OrderedDict("mixing_beta" => 0.7),
)
write_namelists(stdout, inputs)
# output
&control
calculation = 'scf'
prefix = 'qe'
/
&system
ecutwfc = 30.0
ecutrho = 300.0
/
&electrons
mixing_beta = 0.7
/