pwassist.parser.AmplitudeParser#

class pwassist.parser.AmplitudeParser(scheme=NamingScheme.AUTO, final_state_parity=None)[source]#

Bases: object

Parses amplitudes and groups according to naming scheme and quantum numbers.

Can be initialized with a specific naming scheme, or allow the parser to attempt to infer the scheme from the amplitude name.

Parameters:
  • scheme (str | NamingScheme)

  • final_state_parity (int | None)

get_amplitudes(columns)[source]#

Return a list of base amplitude labels according to a naming scheme.

If no naming scheme is specified, the function will attempt to infer a common scheme from the provided columns. If multiple schemes are found, a ValueError will be raised.

Amplitudes are identified by those strings who always have a “_re” and “_im” part attached to them. Of course, other parameters may be written like this, but should most likely not get confused with an amplitude naming scheme. The reason we have to filter our amplitudes is because our columns also have coherent sums, and these formats can be easily confused for a different naming scheme.

Parameters:

columns (list[str]) – list of column names from a results dataframe.

Returns:

a list of base amplitude labels found in the provided columns.

Return type:

list[str]

get_coherent_sums(columns)[source]#

Return a dictionary of coherent sum labels and coherent sums found

The function will first attempt to find all possible coherent sums from the “base” amplitudes in the provided columns. Then, it returns only those coherent sums that are actually present in the columns.

Example: If the columns contain the following labels: [“1P+0p”, “1P+1p”, “1S-1n”, “1P”, “p”] The function determines that the possible coherent sums are (based off the JLme naming scheme): “J” -> [“1”] “e” -> [“p”, “n”] “Je” -> [“1p”, “1n”] “JL” -> [“1P”, “1S”] “JLe” -> [“1Pp”, “1Sn”] “JLm” -> [“1P0”, “1P1”, “1S-1”] Then, it returns only those sums that are actually present in the columns: {“JL”: [“1P”], “e”: [“p”]}

Parameters:

columns (list[str]) – list of column names from a results dataframe.

Returns:

a dictionary of coherent sum labels and coherent sums

The keys are the sum labels (e.g. “JL”, “e”, etc.) and the values are lists of coherent sums found in the columns.

Return type:

dict[str, list[str]]

get_phase_differences(columns)[source]#

Return a list of phase difference labels found in the provided columns.

Parameters:

columns (list[str]) – list of column names from a results dataframe.

Returns:

a list of phase difference labels found in the provided columns.

Return type:

list[str]

static infer_naming_scheme(label)[source]#
Return type:

NamingScheme

Parameters:

label (str)

parse_amplitude(label)[source]#

Parse an amplitude name into its quantum numbers

Parameters:

label (str) – the amplitude name to parse

Returns:

a dataclass containing the parsed quantum numbers

Return type:

ParsedAmplitude

Raises:

ValueError – if the naming scheme cannot be inferred or is invalid

to_latex(label, group_key=None)[source]#

LaTeX string for a given amplitude or phase difference.

Pass group_key for coherent sums, since a bare coherent sum string does not carry enough information to identify its quantum numbers.

Parameters:
  • label (str) – the amplitude, phase difference, or coherent sum label

  • group_key (str | None) – key from get_coherent_sums() for coherent sums

Returns:

a ‘J^P L_m^{(e)}’ style LaTeX string for the amplitude or phase

difference. Note that ‘$’ symbols are not included, so you can wrap the output in ‘$’ or within a LaTeX environment as needed.

Return type:

str