def _read_rate_files(self, rate_files): # get the rates self.files = rate_files for rf in self.files: try: rflib = Library(rf) except: print("Error reading library from file: {}".format(rf)) raise else: if not self.library: self.library = rflib else: self.library = self.library + rflib
def __init__(self, rate_files=None, libraries=None, rates=None): """ rate_files are the files that together define the network. This can be any iterable or single string. This can include Reaclib library files storing multiple rates. If libraries is supplied, initialize a RateCollection using the rates in the Library object(s) in list 'libraries'. If rates is supplied, initialize a RateCollection using the Rate objects in the list 'rates'. Any combination of these options may be combined. """ self.files = [] self.rates = [] self.library = None if rate_files: if isinstance(rate_files, str): rate_files = [rate_files] self._read_rate_files(rate_files) if rates: if isinstance(rates, Rate): rates = [rates] try: for r in rates: assert (isinstance(r, Rate)) except: print( 'Expected Rate object or list of Rate objects passed as the rates argument.' ) raise else: rlib = Library(rates=rates) if not self.library: self.library = rlib else: self.library = self.library + rlib if libraries: if isinstance(libraries, Library): libraries = [libraries] try: for lib in libraries: assert (isinstance(lib, Library)) except: print( 'Expected Library object or list of Library objects passed as the libraries argument.' ) raise else: if not self.library: self.library = libraries.pop(0) for lib in libraries: self.library = self.library + lib if self.library: self.rates = self.rates + self.library.get_rates() # get the unique nuclei u = [] for r in self.rates: t = set(r.reactants + r.products) u = set(list(u) + list(t)) self.unique_nuclei = sorted(u) # now make a list of each rate that touches each nucleus # we'll store this in a dictionary keyed on the nucleus self.nuclei_consumed = OrderedDict() self.nuclei_produced = OrderedDict() for n in self.unique_nuclei: self.nuclei_consumed[n] = [ r for r in self.rates if n in r.reactants ] self.nuclei_produced[n] = [ r for r in self.rates if n in r.products ] # Re-order self.rates so Reaclib rates come first, # followed by Tabular rates. This is needed if # reaclib coefficients are targets of a pointer array # in the Fortran network. # It is desired to avoid wasting array size # storing meaningless Tabular coefficient pointers. self.rates = sorted(self.rates, key=lambda r: r.chapter == 't') self.tabular_rates = [] self.reaclib_rates = [] for n, r in enumerate(self.rates): if r.chapter == 't': self.tabular_rates.append(n) elif isinstance(r.chapter, int): self.reaclib_rates.append(n) else: print('ERROR: Chapter type unknown for rate chapter {}'.format( str(r.chapter))) exit()
parser.add_argument('endpoint', help=endpoint_help) parser.add_argument('-l', '--library', default="reaclib-2017-10-20", help=library_help) args = parser.parse_args(sys.argv[1:]) endpoint = Nucleus(args.endpoint) ##################################### # Load library and generate network # ##################################### print("Loading library...") full_lib = Library(args.library) print("Building network...") core_nuclei = [ "p", "d", "he3", "he4", "li7", "be7", "be8", "b8", "c12", "n13", "n14", "n15", "o14", "o15", "o16", "o17", "o18", "f17", "f18", "f19", "f20", "ne18", "ne19", "ne20", "ne21" ] core_nuclei = list(map(Nucleus, core_nuclei)) core_lib = full_lib.linking_nuclei(core_nuclei) def is_beta_plus(rate): """ Filter for beta+ decays (and electron captures). """