WIP argproc.py constant T-matrix

This commit is contained in:
Marek Nečada 2022-05-29 15:31:32 +03:00
parent 8a2d4a2969
commit 68d894ec96
1 changed files with 15 additions and 0 deletions

View File

@ -193,6 +193,15 @@ def material_spec(string):
raise argparse.ArgumentTypeError("Material specification must be a supported material name %s, or a number" % (str(lorentz_drude.keys()),)) from ve
return lemat
def string2hashable_complex_matrix(string):
"""
Converts string to a hashable equivalent of two-dimensional
numpy.ndarray(..., dtype=complex) (which by itself is not hashable)
"""
matrix = np.ndarray(ast.literal_eval(string), dtype=complex)
# TODO here could be some dimensionality checks etc.
return tuple(tuple(row) for row in matrix)
def string2bspec(string):
"""
Converts string representation of list to BaseSpec.
@ -263,6 +272,12 @@ class ArgParser:
mpgrp.add_argmuent("+w", "++vswf-set", nargs=2, default={},
action=make_dict_action(argtype=string2basespec, postaction='store', first_is_key=True),
help='Manual specification of VSWF set codes (format as a python list of integers); see docs on qpms_uvswfi_t for valid codes or simply use ++lMax instead. Overrides ++lMax and --lMax.')
mpgrp.add_argmuent("-T", "--constant-tmatrix", nargs=1, default={},
action=make_dict_action(argtype=string2hashable_complex_matrix, postaction='store', first_is_key=False),
help='constant T-matrix (elements must correspond to --vswf-set)')
mpgrp.add_argmuent("+T", "++constant-tmatrix", nargs=2, default={},
action=make_dict_action(argtype=string2hashable_complex_matrix, postaction='store', first_is_key=True),
help='constant T-matrix (elements must correspond to ++vswf-set)')
atomic_arguments = {
'rectlattice2d_periods': lambda ap: ap.add_argument("-p", "--period", type=float, nargs='+', required=True, help='square/rectangular lattice periods', metavar=('px','[py]')),