pynucastro.rates.library module#

class pynucastro.rates.library.FFNLibrary[source]#

Bases: TabularLibrary

Create a Library containing all of the tabular rates inside the “ffn” subdirectory.

class pynucastro.rates.library.LangankeLibrary[source]#

Bases: TabularLibrary

Create a Library containing all of the tabular rates inside the “langanke” subdirectory.

class pynucastro.rates.library.Library(libfile=None, rates=None)[source]#

Bases: object

A Library is a container storing multiple rates that allows for filtering rates based on rules, managing duplicate rates, and selecting subsets of rates based on properties. At its heart is a dict of rates keyed by the rate id.

A library may contain rates from a single source, or be created by adding or subtracting existing Library objects.

Parameters:
  • libfile (str) – a file containing a sequence of rates in a format that we understand (for example a ReacLib database)

  • rates (list, dict, Rate) – a single Rate or an iterable of Rate objects. If it is a dictionary, then it should be keyed by the rate id.

add_rate(rate)[source]#

Manually add a rate to the library.

Parameters:

rate (Rate) – The rate to add

add_rates(ratelist)[source]#

Add multiple rates to the library

Parameters:

ratelist (list of Rate) – the list of rates to add to the library.

backward()[source]#

Select only the reverse rates, obtained by detailed balance. Note: “reverse” here means that it was derived by detailed balance, and not that Q < 0.

Return type:

Library

derived_backward(compute_Q=False, use_pf=False)[source]#

Loop over all of the forward rates that can be used to derive inverse rates (as returned by forward_for_detailed_balance()) and derive the inverses, potentially taking into account the partition function and recomputing Q.

Parameters:
  • compute_Q (bool) – do we recompute the Q value based on the masses?

  • use_pf (bool) – do we use the temperature-dependent partition function?

Return type:

Library

filter(filter_spec)[source]#

Filter the rates in the library based on a set of rules.

Parameters:

filter_spec (RateFilter, list) – a filter (or list of filters) to apply to the library to define a subset of rates.

Return type:

Library

Find instances of multiple rates having the same reactants and products. These may not be the same Rate object (e.g., one could be tabular the other a simple decay), but they will present themselves in the network as the same link.

Returns:

duplicate_rates – a list where each entry is a list of all the rates that share the same link.

Return type:

list

forward()[source]#

Select only the forward rates, discarding the inverse rates obtained by detailed balance. Note: “forward” here means that it is not a reverse rate derived from detailed balance, and does not necessarily mean Q > 0.

Return type:

Library

forward_for_detailed_balance()[source]#

Loop over the forward rates (as filtered by forward()) and return those that can be used to derive reverse rates via detailed balance. This means that they cannot be tabular or weak rates.

Return type:

Library

get_nuclei()[source]#

Get the list of unique nuclei in the library

Return type:

set

get_rate(rid)[source]#

Return a rate matching the id provided.

Return type:

Rate

get_rate_by_name(name)[source]#

Given a string representing a rate in the form ‘A(x,y)B’ (or a list of strings for multiple rates) return the Rate objects that match from the Library. If there are multiple inputs, then a list of Rate objects is returned.

Returns:

rates – A single rate or a list of rates

Return type:

list, Rate

get_rate_by_nuclei(reactants, products)[source]#

Given a list of reactants and products, return any matching rates

Parameters:
  • reactants (list of Nucleus or str) – the list of nuclei that serve as reactants.

  • products (list of Nucleus or str) – the list of nuclei that serve as products.

Returns:

a list of Rate object or a single Rate (if there is only one)

Return type:

Rate, list(Rate)

get_rates()[source]#

Return a list of the rates in this library.

Return type:

list

heaviest()[source]#

Return the heaviest nuclide in this library.

Return type:

Nucleus

lightest()[source]#

Return the lightest nuclide in this library.

Return type:

Nucleus

linking_nuclei(nuclist, *, with_reverse=True, print_warning=True)[source]#

Return a library containing the rates linking the list of nuclei passed in.

Parameters:
  • nuclist (list of str or Nucleus) – the nuclei to link (either the string names or the Nucleus objects)

  • with_reverse (bool) – do we include reverse rates?

  • print_warning (bool) – if True, then print a warning if one of the input nuclei is not linked.

Return type:

Library

property num_rates#

Get the total number of rates in the Library

Return type:

int

remove_rate(rate)[source]#

Manually remove a rate from the library by supplying the short name “A(x,y)B”, a Rate object, or the rate id

Parameters:

rate (str, Rate) – The rate to remove from the library.

write_to_file(filename, *, prepend_rates_dir=False)[source]#

Write the library out to a file of the given name in Reaclib format.

Parameters:
  • filename (str) – The filename to use for the library

  • prepend_rates_dir (bool) – If True, then output to the pynucastro rate file directory.

class pynucastro.rates.library.RateFilter(reactants=None, products=None, exact=True, reverse=None, min_reactants=None, max_reactants=None, min_products=None, max_products=None, filter_function=None)[source]#

Bases: object

RateFilter filters out a specified rate or set of rates A RateFilter stores selection rules specifying a rate or group of rates to assist in searching for rates stored in a Library.

invert()[source]#

Return a RateFilter matching the inverse rate.

matches(r)[source]#

Given a Rate r, see if it matches this RateFilter.

class pynucastro.rates.library.ReacLibLibrary[source]#

Bases: Library

Create a Library containing all of the rates in the latest stored version of the ReacLib library.

class pynucastro.rates.library.SuzukiLibrary[source]#

Bases: TabularLibrary

Create a Library containing all of the tabular rates inside the “suzuki” subdirectory.

class pynucastro.rates.library.TabularLibrary(ordering=None)[source]#

Bases: Library

Create a Library containing all of the tabular rates we know (excluding duplications) across multiple sources.

Parameters:

ordering (list of str) – The list of sources of the rates from lowest to highest precedence. We will read from the first source, and then for any later sources, for any duplicate rates, we will replace the existing rate with the version from the higher-priority library. The default ordering is ["ffn", "langanke", "suzuki"]

lib_path = PosixPath('/home/runner/work/pynucastro/pynucastro/pynucastro/library/tabular')#
pynucastro.rates.library.capitalize_rid(rid, delimiter)[source]#
pynucastro.rates.library.list_known_rates()[source]#

Print a list of all of the rates found in the library