This module allows the use of command-line options in HALMD scripts.
Example:
halmd liquid.lua --lennard-jones epsilon=2 sigma=2 --disable-gpu
Create new command-line parser.
Example:
local options = require("halmd.utility.program_options")
local parser = options.argument_parser()
Add argument to parser.
| Parameters: |
|
|---|
The following value types are supported:
| Type | Description |
|---|---|
| boolean | Boolean |
| string | String |
| accumulate | Increment integer |
| vector | 1-dimensional array of type dtype |
| matrix | 2-dimensional array of type dtype |
These integral and floating-point value types are supported:
| Type | Description |
|---|---|
| number | Double-precision floating-point |
| integer | Signed 64-bit integer |
| int32 | Signed 32-bit integer |
| int64 | Signed 64-bit integer |
| uint32 | Unsigned 32-bit integer |
| uint64 | Unsigned 64-bit integer |
| float32 | Single-precision floating-point |
| float64 | Double-precision floating-point |
Example:
parser:add_argument("disable-gpu", {type = "boolean", help = "disable GPU acceleration"})
An optional table choices may be used to constrain the value of an argument:
parser.add_argument("ensemble", {type = "string", choices = {
nve = "Constant NVE",
nvt = "Constant NVT",
npt = "Constant NPT",
}, help = "statistical ensemble"})
Note that only arguments of type string are supported.
The optional action function receives the following arguments:
| Parameters: |
|
|---|
Note that if you specify action, the argument value will not be stored in the table returned by parse_args(), i.e. the argument handler function has to store a value in args[key] itself.
Example:
parser:add_argument("filename", {type = "string", action = function(args, key, value)
-- substitute current time
args[key] = os.date(value)
end, default = "halmd_%Y%m%d_%H%M%S.trj", help = "trajectory filename"})
Add argument group.
| Parameters: |
|
|---|---|
| Returns: | argument group |
Example:
local group = parser:add_argument_group("lennard-jones")
group:add_argument("epsilon", {type = "number", help = "potential well depths"})
group:add_argument("sigma", {type = "number", help = "collision diameter"})
Set default option values.
| Parameters: | defaults (table) – argument names with default values |
|---|
Example:
parser:set_defaults({particles = {9000, 1000}, number_density = 0.8})
Parse arguments.
| Parameters: | args (table) – sequence of arguments (optional) |
|---|---|
| Returns: | parsed arguments |
If args is not specified, the command-line arguments are parsed.
Example:
local args = parser:parse_args()