Fortran namelists

Index

Documentation

QuantumEspressoIO.find_cardMethod
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
2
source
QuantumEspressoIO.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 as n_lines. If nothing, 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"]
source
QuantumEspressoIO.parse_card_optionMethod
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"
source
QuantumEspressoIO.read_namelistMethod
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 to false.

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"])
source
QuantumEspressoIO.read_namelistsMethod
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 to false.

Returns

  • namelists::OrderedDict: A dictionary of namelists, each key is a symbol and the value is a OrderedDict of key-value pairs.
  • others::Vector: Optional. A vector of strings, which are the remaining lines in the file. For example, QE pw.x input files may contain "cards" for additional parameters (e.g. atomic positions, k-points, etc.), whose syntax are customarily defined by pw.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"])
source
QuantumEspressoIO.write_namelistMethod
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.
source
QuantumEspressoIO.write_namelistMethod
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.
/
source
QuantumEspressoIO.write_namelistsMethod
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
/
source