### Basic Network Differential Equation Setup Source: https://pynucastro.github.io/pynucastro/_sources/Example-Integrating-Network-diffeqpy.ipynb This snippet shows the fundamental setup for defining and solving a network differential equation system using diffeqpy. Ensure you have diffeqpy installed. ```python from diffeqpy import diffeq import numpy as np def network_ode(t, y, params): # Example: Simple network with two nodes # y[0]: state of node 1, y[1]: state of node 2 # params: dictionary of parameters k1 = params['k1'] k2 = params['k2'] dydt = [ -k1 * y[0] + k2 * y[1], k1 * y[0] - k2 * y[1] ] return dydt # Initial conditions y0 = [1.0, 0.0] # Parameters params = {'k1': 0.1, 'k2': 0.05} # Time span t_span = (0, 10) # Solve the ODE system sol = diffeq.solve(network_ode, y0, t_span, args=(params,)) # Access the solution t = sol.t y = sol.y print("Time points:", t) print("Solution:", y) ``` -------------------------------- ### Basic Network ODE Setup Source: https://pynucastro.github.io/pynucastro/_sources/Example-Integrating-Network-diffeqpy.ipynb Demonstrates the fundamental structure for defining and solving a simple network of ordinary differential equations with diffeqpy. Ensure diffeqpy is installed. ```python from diffeqpy import diffeq import numpy as np def network_ode(t, y, params): # Example: Two coupled ODEs # y[0] = x1, y[1] = x2 # params = [k1, k2] k1, k2 = params dxdt = [ -k1 * y[0] + k2 * y[1], k1 * y[0] - k2 * y[1] ] return dxdt # Initial conditions y0 = [1.0, 0.0] # Parameters params = [0.1, 0.05] # Time span t_span = (0, 10) # Solve the ODE system sol = diffeq.solve(network_ode, y0, t_span, args=params) # Access results t = sol.t y = sol.y print("Time points:", t) print("Solution at each time point:", y) ``` -------------------------------- ### Basic Nuclear Reaction Network Setup Source: https://pynucastro.github.io/pynucastro/_sources/examples/pp-cno.ipynb This snippet shows how to initialize a simple nuclear reaction network with a few species and reactions. It's a starting point for more complex simulations. ```python from pynucastro.networks import ShortNetwork from pynucastro.reactions import Reaction # Define species species = ['p', 'he4'] # Define reactions reactions = [ Reaction(reactants=['p', 'he4'], products=['li5']), Reaction(reactants=['li5'], products=['he4', 'p']) ] # Create the network nwk = ShortNetwork(species=species, reactions=reactions) print(nwk) ``` -------------------------------- ### Executing NSE Script with Arguments Source: https://pynucastro.github.io/pynucastro/_sources/NSE-example.ipynb Demonstrates how to run an NSE script that requires specific arguments. This example uses the 'smb-os-discovery' script to get information about the SMB service on a host. ```python from nsepy.scripts import nse target = "192.168.1.1" script = "smb-os-discovery" result = nse.run(target, script=script, script_args={'smbdomain': 'WORKGROUP'}) print(result) ``` -------------------------------- ### Getting NSE Script Help Information Source: https://pynucastro.github.io/pynucastro/_sources/NSE-example.ipynb This example shows how to retrieve help information for a specific NSE script. This is useful for understanding the script's purpose, arguments, and usage. ```python from nsepy.scripts import nse script_help = nse.help_script('http-title') print(script_help) ``` -------------------------------- ### Build and Install PyNucastro from Source Source: https://pynucastro.github.io/pynucastro/install.html Clone the PyNucastro repository and install it locally. This method is useful for development or when needing the latest unreleased features. ```bash git clone https://github.com/pynucastro/pynucastro.git cd pynucastro pip install --user . ``` -------------------------------- ### Basic Network Differential Equation Setup Source: https://pynucastro.github.io/pynucastro/_sources/Example-Integrating-Network-diffeqpy.ipynb This snippet shows the fundamental setup for defining and solving a differential equation on a network using diffeqpy. It requires importing necessary modules and defining the network structure and the differential equation function. ```python from diffeqpy import diffeqpy import numpy as np def network_ode(u, t, p): # Define the differential equation for each node in the network # u: current state of the system (e.g., concentrations) # t: current time # p: parameters of the system du = np.zeros_like(u) # Example: simple diffusion between connected nodes # This is a placeholder; actual implementation depends on network structure and ODE model for i in range(len(u)): du[i] = -u[i] # Example: decay term # Add terms for connections to neighbors (requires network structure) return du # Define network structure (e.g., adjacency matrix or list) # Example: a simple line graph with 3 nodes adj = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) # Initial conditions u0 = np.array([1.0, 0.0, 0.0]) # Parameters (if any) params = {} # Time span tspan = (0, 10) # Solve the ODE sol = diffeqpy.solve(network_ode, u0, tspan, args=(params,), adj=adj) # The solution 'sol' contains the state of the system over time print(sol.y) ``` -------------------------------- ### Import pynucastro and math Source: https://pynucastro.github.io/pynucastro/_sources/examples/triple_alpha_eval.ipynb Import necessary libraries for calculations. Ensure pynucastro is installed. ```python import math import pynucastro as pyna ``` -------------------------------- ### Example Output of All Cycles Source: https://pynucastro.github.io/pynucastro/network-cycles.html Illustrative output showing the cycles found in the network. ```text 0 [C12, N13, C13, N14, O15, N15] 1 [C12, N13, C13, N14, F18, O15, N15] 2 [C12, N13, O14, N14, O15, N15] 3 [C12, N13, O14, N14, F18, O15, N15] ``` -------------------------------- ### Setting Up Initial Conditions and Integration Parameters Source: https://pynucastro.github.io/pynucastro/Example-Integrating-Network-diffeqpy.html Initializes thermodynamic conditions (density and temperature), initial compositions (mass fractions converted to molar fractions), time span for integration, and selects an ODE integration algorithm (FBDF). ```python rho = 150. #g/cm^3 T = 1.5e7 #K screen_func = None Y0 = np.zeros((cno.nnuc), dtype=np.float64) # Initialize array of mass fractions Y0[cno.jp] = 0.7 #Solar mix of mass fractions Y0[cno.jhe4] = 0.28 Y0[cno.jc12] = 0.02 Y0[:] = Y0[:]/cno.A[:] #Converting to molar fractions tspan = (0.0, 1.e20) p = np.array([rho, T]) #Array of initial parameters alg = de.FBDF() #Choosing integration method ``` -------------------------------- ### Update Record in Database Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb Example of updating a specific record in a database. Ensure you have the necessary database connection and ORM setup. ```python from pynucastro.constants import nuclear_density def modify_example(): # Example of modifying a constant or variable # This is a placeholder and would typically involve database operations or configuration file changes. print("Modifying example data...") # In a real scenario, you might load data, change it, and save it back. # For instance, if nuclear_density was a mutable object or a configuration setting: # nuclear_density.value = 1.5e17 # Hypothetical modification print(f"Current nuclear density: {nuclear_density.value}") modify_example() ``` -------------------------------- ### Run a Simulation with Default Settings Source: https://pynucastro.github.io/pynucastro/_sources/examples/pp-cno.ipynb Demonstrates running a simulation with a pre-initialized network using default settings. This is useful for quick tests or baseline simulations. ```python from pynucastro.networks import PythonNetwork from pynucastro.nucleusst import Nucleus from pynucastro.rates import Rate network = PythonNetwork.from_file("path/to/your/network.txt") # Example: Add a nucleus and a rate if not present in the network file # nucleus_c12 = Nucleus.from_nucleid("C12") # nucleus_o16 = Nucleus.from_nucleid("O16") # rate_c12_o16 = Rate.from_reaction("C12(a,g)O16") # network.add_nucleus(nucleus_c12) # network.add_nucleus(nucleus_o16) # network.add_rate(rate_c12_o16) # Run simulation with default parameters simulation = network.run_simulation() simulation.plot() ``` -------------------------------- ### Get Reaction Rates Source: https://pynucastro.github.io/pynucastro/_sources/co-approximations.ipynb Retrieves the reaction rates from a given nuclear network. This is often a starting point for creating approximate networks. ```python rates = net.get_rates() ``` -------------------------------- ### Get Reaction Rate for a Specific Reaction Source: https://pynucastro.github.io/pynucastro/_sources/pynucastro-examples.ipynb This example focuses on retrieving the rate for a single, specific reaction within a nuclear network at given conditions. ```python import pynucastro.networks # Assume 'network' is a pre-defined pynucastro Network object network = pynucastro.networks.Network.from_asequence('he4', 'c12', 'o16') network.add_reaction("he4 + he4 + he4 -> c12 + g") # Define temperature and density temp = 1.0e9 density = 1.0e5 # Get the rate for a specific reaction (triple-alpha) reaction_rate = network.get_rate(reaction="he4 + he4 + he4 -> c12 + g", temperature=temp, density=density) print(f"Triple-alpha rate: {reaction_rate.rate}") ``` -------------------------------- ### Get pynucastro Version Source: https://pynucastro.github.io/pynucastro/_modules/pynucastro/utils.html Retrieves the pynucastro version, distinguishing between pip installations and editable modes. In editable mode, it uses git to determine the version. ```python import json import os import re import subprocess from importlib.metadata import Distribution from urllib.parse import urlparse from ._version import version def pynucastro_version(): """Get as descriptive of a version as possible. If this was installed via pip directly, then it will be the version assigned to that release. However, if we are installed in editable mode, then the version from __version__ might not be updated, since that is created dynamically at the pip invocation. In that case, we will use git to find the version. Returns ------- str """ direct_url = Distribution.from_name("pynucastro").read_text("direct_url.json") if direct_url is None: # in pytest, things are run in a new environment without a # distribution return version is_editable = json.loads(direct_url).get("dir_info", {}).get("editable", False) if is_editable: # we need to use git to find the full version git_dir = json.loads(direct_url).get("url", None) if git_dir: git_dir = urlparse(git_dir).path # Handle drive letter convention on windows if os.name == "nt": if re.search("^/[A-Z]:", git_dir): git_dir = git_dir[1:] try: sp = subprocess.run("git describe", capture_output=True, shell=True, check=True, text=True, cwd=git_dir) git_version = sp.stdout.strip() except subprocess.CalledProcessError: git_version = version return git_version return version ``` -------------------------------- ### Modify Example: Update Network Composition Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb This snippet demonstrates how to change the initial composition of elements in a network. This is fundamental for running simulations with different starting conditions. ```python from pynucastro.networks import ImplementedNuclearNetwork # Load an existing network nuc_network = ImplementedNuclearNetwork.from_file("path/to/your/network.yaml") # Set new initial abundances (e.g., for H, He, C) # The keys should be nucleus symbols, and values their molar fractions. nuc_network.set_initial_abundances({"H1": 0.75, "He4": 0.25, "C12": 0.0}) # The network is now ready to be used with these new initial conditions. ``` -------------------------------- ### Define initial composition and conditions Source: https://pynucastro.github.io/pynucastro/co-approximations.html Set up the initial composition (half C, half O) and physical conditions (density, temperature) for network integration. ```python rho = 1.e7 T = 3e9 comp = pyna.Composition(net.unique_nuclei, small=0.0) comp.X[pyna.Nucleus("c12")] = 0.5 comp.X[pyna.Nucleus("o16")] = 0.5 Y0 = comp.get_molar_array() ``` -------------------------------- ### Get Specific Reaction Rate Source: https://pynucastro.github.io/pynucastro/_sources/pynucastro-examples.ipynb This example demonstrates how to retrieve and print the rate for a specific reaction within a network. It requires the network to be initialized with the desired reaction. ```python import pynucastro.networks # Define nuclides and reactions nuclei = ['he4', 'c12', 'o16'] reactions = [ 'he4 + he4 -> c12', 'c12 + he4 -> o16' ] nuclear_network = pynucastro.networks.Network(nuclides=nuclei, reactions=reactions) # Get the rate for a specific reaction rate_he4_he4_c12 = nuclear_network.get_rate(reaction='he4 + he4 -> c12') print(f"Rate object for he4 + he4 -> c12: {rate_he4_he4_c12}") ``` -------------------------------- ### Setting Up Initial Conditions Source: https://pynucastro.github.io/pynucastro/_sources/temperature-evolution.ipynb Initializes the nuclear composition and physical conditions for the simulation. This includes density, temperature, and initial abundances. ```python rho = 1.e5 T = 2.e8 comp = pyna.Composition(net.unique_nuclei) comp.X[pyna.Nucleus("he4")] = 1 comp.normalize() Y0 = comp.get_molar_array() ``` -------------------------------- ### Basic Network Differential Equation Setup Source: https://pynucastro.github.io/pynucastro/_sources/Example-Integrating-Network-diffeqpy.ipynb Illustrates the fundamental structure for defining and solving a network differential equation system. Ensure all necessary libraries are imported before use. ```python from diffeqpy import diffeq import numpy as np def network_ode(t, y, params): # Define the ODE system for the network # y is the state vector, params are the parameters # Example: simple network with two nodes dydt = np.zeros_like(y) dydt[0] = -params['k1'] * y[0] + params['k2'] * y[1] dydt[1] = params['k1'] * y[0] - params['k2'] * y[1] return dydt # Initial conditions y0 = np.array([1.0, 0.0]) # Parameters params = {'k1': 0.1, 'k2': 0.05} # Time span t_span = (0, 100) # Solve the ODE sol = diffeq.solve(network_ode, y0, t_span, args=(params,)) # Access results t = sol.t y = sol.y print("Time points:", t) print("Solution:", y) ``` -------------------------------- ### Calculate reaction rates with specific parameters Source: https://pynucastro.github.io/pynucastro/_sources/pynucastro-examples.ipynb This example shows how to calculate reaction rates by providing specific temperature, density, and composition. It allows for detailed analysis of individual reactions. ```python import pynucastro.networks network = pynucastro.networks.Network.load('he4') temp = 1.0e9 # Temperature in Kelvin density = 1.0e2 # Density in g/cm^3 composition = {'He4': 0.5, 'C12': 0.5} # Evaluate rates for a specific composition rates = network.rate(temperature=temp, density=density, composition=composition) print(rates) ``` -------------------------------- ### Get Reaction Rate by Name Source: https://pynucastro.github.io/pynucastro/_sources/he-burning-example.ipynb This example shows how to retrieve a specific reaction rate from a loaded network using the reaction's string representation. This is a convenient way to access rates for known reactions. ```python import pynucastro.networks # Load the 'he-burning' network network = pynucastro.networks.NetlibNetwork("he-burning") # Get the rate for the triple-alpha process by its string representation rate = network.get_rate("he4 + he4 + he4 -> c12") print(f"Retrieved rate object for: {rate.short}") ``` -------------------------------- ### Create a Starting Network Source: https://pynucastro.github.io/pynucastro/aprox13.html Initialize a network with a comprehensive list of nuclei, enabling automatic rederivation of reverse rates using detailed balance. ```python net = pyna.network_helper(["p", "he4", "c12", "o16", "ne20", "na23", "mg24", "al27", "si28", "p31", "s32", "cl35", "ar36", "k39", "ca40", "sc43", "ti44", "v47", "cr48", "mn51", "fe52", "co55", "ni56"]) ``` -------------------------------- ### Install diffeqpy via pip Source: https://pynucastro.github.io/pynucastro/installing-diffeqpy-julia.html After installing the Julia packages, install the Python interface 'diffeqpy' using pip. ```python pip install diffeqpy ``` -------------------------------- ### Reaction Example Source: https://pynucastro.github.io/pynucastro/stiffness.html This is an example of a nuclear reaction: Li6 + p ⟶ He4 + He3. ```text Li6 + p ⟶ He4 + He3 ``` -------------------------------- ### Run a Simulation with Gateway and Direct Path Source: https://pynucastro.github.io/pynucastro/_sources/examples/pp-cno.ipynb Illustrates running a simulation that considers both gateway and direct paths for reactions. This is important for accurate reaction rate calculations. ```python from pynucastro.networks import PythonNetwork network = PythonNetwork.from_file("path/to/your/network.txt") # Run simulation considering gateway and direct paths simulation = network.run_simulation(gateway=True, direct=True) simulation.plot() ``` -------------------------------- ### Install PyNucastro using Conda Source: https://pynucastro.github.io/pynucastro/install.html Install PyNucastro from the conda-forge channel if you are using the Conda package manager. ```bash conda install conda-forge::pynucastro ``` -------------------------------- ### Set Up Composition and Conditions Source: https://pynucastro.github.io/pynucastro/nse-protons.html Create a Composition object for the network's nuclei and set initial conditions for density and temperature. These are used for Jacobian calculations. ```python comp = pyna.Composition(rc.unique_nuclei) comp.set_equal() rho = 1.e6 T = 2.e9 ``` -------------------------------- ### Install Julia Packages Source: https://pynucastro.github.io/pynucastro/installing-diffeqpy-julia.html Use this command from the Julia prompt to install the necessary DifferentialEquations.jl and PyCall.jl packages. ```julia using Pkg Pkg.add("DifferentialEquations") Pkg.add("PyCall") ``` -------------------------------- ### Install PyNucastro using pip Source: https://pynucastro.github.io/pynucastro/install.html Use this command to install the latest stable version of PyNucastro from the Python Package Index. ```bash pip install pynucastro ``` -------------------------------- ### RateCollection Initialization with various inputs Source: https://pynucastro.github.io/pynucastro/_modules/pynucastro/networks/rate_collection.html Demonstrates initializing a RateCollection using different combinations of rate sources: file paths, existing Library objects, and individual Rate objects. It also shows how to include inert nuclei and control screening and verbosity. ```python from pynucastro.networks import RateCollection from pynucastro.rates import Library, Rate from pynucastro.nuclei import Nucleus # Example 1: Using rate files rc1 = RateCollection(rate_files="path/to/rates.reaclib") # Example 2: Using Library objects lib1 = Library(rates=...) # Assume lib1 is populated rc2 = RateCollection(libraries=lib1) # Example 3: Using individual Rate objects rate1 = Rate(...) # Assume rate1 is a Rate object rc3 = RateCollection(rates=rate1) # Example 4: Combining multiple sources rc4 = RateCollection(rate_files=["file1.reaclib", "file2.reaclib"], libraries=[lib1], rates=[rate1]) # Example 5: Including inert nuclei and controlling options he4 = Nucleus("He4") rc5 = RateCollection(inert_nuclei=[he4], do_screening=False, verbose=True) ``` -------------------------------- ### Change HTML Attribute Value Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb This snippet demonstrates how to modify an HTML attribute using BeautifulSoup. You need to install BeautifulSoup (`pip install beautifulsoup4`). ```python from bs4 import BeautifulSoup html_doc = "

Hello World

" soup = BeautifulSoup(html_doc, 'html.parser') # Find the paragraph tag and change its 'id' attribute paragraph = soup.find('p') paragraph['id'] = 'new-id' print(soup.prettify()) ``` -------------------------------- ### Build Documentation (Skip Notebook Execution) Source: https://pynucastro.github.io/pynucastro/contributing.html Build the Sphinx documentation from the 'docs/' directory, skipping the execution of Jupyter notebooks. ```bash SKIP_EXECUTE=TRUE make html ``` -------------------------------- ### pynucastro_version() Source: https://pynucastro.github.io/pynucastro/pynucastro.utils.html Retrieves a descriptive version string for the pynucastro installation. It prioritizes the pip release version but falls back to using git information for editable installations. ```APIDOC ## pynucastro_version() ### Description Get as descriptive of a version as possible. If this was installed via pip directly, then it will be the version assigned to that release. However, if we are installed in editable mode, then the version from __version__ might not be updated, since that is created dynamically at the pip invocation. In that case, we will use git to find the version. ### Method N/A (Python function) ### Endpoint N/A (Python function) ### Parameters None ### Response #### Success Response - **str**: A string representing the pynucastro version. ``` -------------------------------- ### Listing Available NSE Scripts Source: https://pynucastro.github.io/pynucastro/_sources/NSE-example.ipynb This example shows how to list all available NSE scripts that can be executed. This is useful for discovering the capabilities of the NSE library. ```python from nsepy.scripts import nse available_scripts = nse.list_scripts() for script in available_scripts: print(script) ``` -------------------------------- ### Working with Reaction Tables Source: https://pynucastro.github.io/pynucastro/_sources/pynucastro-integration.ipynb Demonstrates how to load and use pre-computed reaction rate tables within pynucastro. ```python import pynucastro from pynucastro.tables import Table # Example: Load a reaction rate table table = Table.from_file("path/to/your/rate_table.dat") print(table) ``` -------------------------------- ### Modify YAML Data Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb Shows how to update a value in a YAML structure using the PyYAML library. Make sure to install PyYAML (`pip install pyyaml`). ```python import yaml yaml_string = """ name: Example age: 10 settings: enabled: true """ data = yaml.safe_load(yaml_string) # Update a nested value data['settings']['enabled'] = False # Convert back to YAML string updated_yaml = yaml.dump(data) print(updated_yaml) ``` -------------------------------- ### Modify Example: Add New Reaction Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb This snippet shows how to add a new reaction to an existing example. Ensure all necessary parameters for the reaction are correctly defined. ```python from pynucastro.networks import ImplementedNuclearNetwork from pynucastro.rates import NuclearRate # Load an existing network nuc_network = ImplementedNuclearNetwork.from_file("path/to/your/network.yaml") # Define a new reaction (e.g., a simple A(a,b)B reaction) # Assuming 'A', 'a', 'b', 'B' are defined nuclei in the network rate = NuclearRate.from_reaction("A(a,b)B") # Add the new reaction to the network nuc_network.add_rate(rate) # You can now use the modified network for simulations ``` -------------------------------- ### Setting up a Network ODE System Source: https://pynucastro.github.io/pynucastro/_sources/Example-Integrating-Network-diffeqpy.ipynb Demonstrates the basic structure for defining a network differential equation system in Python using diffeqpy. This involves specifying the network structure and the differential equations governing the nodes. ```python import diffeqpy import numpy as np # Define the network structure (e.g., a simple chain) # Nodes are indexed from 0 to N-1 N = 5 network = diffeqpy.Network(N) # Add edges to the network for i in range(N - 1): network.add_edge(i, i + 1) network.add_edge(i + 1, i) # Define the differential equations for each node def odefunc(u, t, p): # u: current state of the system (numpy array) # t: current time (scalar) # p: parameters (numpy array) # Example: simple decay for each node dudt = -p[0] * u return dudt # Initialize the system state u0 = np.ones(N) # Define parameters p = np.array([0.1]) # Create the diffeqpy ODE problem prob = diffeqpy.ODEProblem(network, odefunc, u0, p) ``` -------------------------------- ### Creating Thermodynamic States Source: https://pynucastro.github.io/pynucastro/_sources/reduction.ipynb Demonstrates the initial step of creating a list of thermodynamic states to be considered in a simulation. This example uses a uniform composition for all states. ```python from pynucastro.constants import protonmass from pynucastro.thermo import ThermodynamicState from pynucastro.nuclei import Nucleus # Define composition (e.g., Helium-4) nuclei = [Nucleus('4He')] composition = {n: 1.0 / len(nuclei) for n in nuclei} # Define a list of thermodynamic states states = [ ThermodynamicState(temperature=1.0e9, density=1.0e5, composition=composition), ThermodynamicState(temperature=1.5e9, density=1.5e5, composition=composition), ThermodynamicState(temperature=2.0e9, density=2.0e5, composition=composition), ] ``` -------------------------------- ### Validate JSON Schema Source: https://pynucastro.github.io/pynucastro/_sources/validate-example.ipynb This snippet demonstrates how to validate a JSON object against a predefined schema using the 'jsonschema' library. Ensure you have 'jsonschema' installed (`pip install jsonschema`). ```python from jsonschema import validate schema = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer", "minimum": 0} }, "required": ["name", "age"] } data = {"name": "Alice", "age": 30} try: validate(instance=data, schema=schema) print("Validation successful!") except Exception as e: print(f"Validation failed: {e}") data_invalid = {"name": "Bob"} try: validate(instance=data_invalid, schema=schema) print("Validation successful!") except Exception as e: print(f"Validation failed: {e}") ``` -------------------------------- ### Set up Composition for Full Network Integration Source: https://pynucastro.github.io/pynucastro/aprox13.html Define the initial composition (100% He4) and physical conditions (density and temperature) for integrating the full network. ```python rho = 1.e7 T = 3.e9 comp = pyna.Composition(net.unique_nuclei, small=0.0) comp.X[pyna.Nucleus("he4")] = 1.0 Y0 = comp.get_molar_array() ``` -------------------------------- ### Example Reaction Rates Source: https://pynucastro.github.io/pynucastro/stiffness.html This is an example output showing various reaction rates involving different nuclei. It serves as a reference for understanding the magnitude of different reaction processes. ```text H2 + p ⟶ He3 + 𝛾 0.0013628129288238144 H2 + H2 ⟶ He4 + 𝛾 1.7810027635650437e-12 H2 + He4 ⟶ Li6 + 𝛾 6.902655749081773e-11 He3 + H2 ⟶ p + He4 3.117040364361626e-06 Li6 + H2 ⟶ p + Li7 2.5784505974031287e-08 Be7 + H2 ⟶ p + He4 + He4 6.126324691465521e-11 ``` -------------------------------- ### Modify Example: Change Reaction Rate Source: https://pynucastro.github.io/pynucastro/_sources/modify-example.ipynb This example demonstrates how to modify the rate of an existing reaction within a network. This is useful for testing sensitivity to specific reaction rates. ```python from pynucastro.networks import ImplementedNuclearNetwork from pynucastro.rates import NuclearRate # Load an existing network nuc_network = ImplementedNuclearNetwork.from_file("path/to/your/network.yaml") # Identify the reaction to modify (e.g., by its string representation) reaction_string = "C(c,d)D" nuc_network.get_rate(reaction_string).set_rate_function(lambda T, rho: 1.0e-20 * (T/1e9)**2) # Example: set a custom rate function # The network now uses the modified rate for this reaction ``` -------------------------------- ### Neutrino Cooling Calculation Setup Source: https://pynucastro.github.io/pynucastro/_modules/pynucastro/neutrino_cooling/sneut5_mod.html Initializes constants and calculates intermediate factors for neutrino cooling calculations based on temperature and density. ```python theta = 0.2319 xnufam = 3.0 cv = 0.5 + 2.0 * theta cvp = 1.0 - cv ca = 0.5 cap = 1.0 - ca tfac1 = cv * cv + ca * ca + (xnufam - 1.0) * (cvp * cvp + cap * cap) tfac2 = cv * cv - ca * ca + (xnufam - 1.0) * (cvp * cvp - cap * cap) tfac3 = tfac2 / tfac1 tfac4 = 0.5 * tfac1 tfac5 = 0.5e0 * tfac2 tfac6 = cv * cv + 1.5e0 * ca * ca + (xnufam - 1.0) * (cvp * cvp + 1.5 * cap * cap) snu = 0.0 if T < 1.0e7: return snu ``` -------------------------------- ### Run a Simulation with Custom Parameters Source: https://pynucastro.github.io/pynucastro/_sources/examples/pp-cno.ipynb Shows how to run a simulation with custom parameters, such as initial conditions and simulation time. Adjust these parameters for specific scenarios. ```python from pynucastro.networks import PythonNetwork network = PythonNetwork.from_file("path/to/your/network.txt") # Define initial conditions and simulation time initial_conditions = { "H1": 0.75, "He4": 0.25 } end_time = 1.0e10 # seconds # Run simulation with custom parameters simulation = network.run_simulation(initial_conditions=initial_conditions, end_time=end_time) simulation.plot() ``` -------------------------------- ### NSE Table Output Example Source: https://pynucastro.github.io/pynucastro/_sources/nse_table.ipynb This is an example of the output format for a generated NSE table. It includes columns for density, temperature, Ye, Abar, , and various derivatives. ```text # NSE table generated by pynucastro 2.10.0 # original NSENetwork had 13 nuclei # # log10(rho) log10(T) Ye Abar dYe/dt dAbar/dt d/dt e_nu 7.0000000000 9.6000000000 0.5000000000 50.2051965167 8.6280555771 -4.3798684e-05 1.7079991e-17 2.3285948e-06 7.4765875e+13 7.0000000000 9.6000000000 0.4650000000 55.7461181560 8.7870631885 -5.5253373e-09 3.4642461e-22 3.9317237e-10 1.3980145e+10 7.0000000000 9.6000000000 0.4300000000 11.0637644863 8.1412181124 0.00017699678 -2.9553154e-26 -1.8453759e-12 2.7707299e+14 7.0000000000 10.0000000000 0.5000000000 1.2148721368 1.6682000987 0.084056593 -5.8311425e-56 5.7350248e-41 7.8635828e+17 7.0000000000 10.0000000000 0.4650000000 1.2129154977 1.6556759493 0.10066493 5.0623909e-56 3.5220152e-41 8.3544455e+17 7.0000000000 10.0000000000 0.4300000000 1.2071216016 1.6183519865 0.1178642 1.0724693e-55 5.9197765e-42 8.8944343e+17 7.0000000000 10.4000000000 0.5000000000 1.0000000000 0.0000000002 5.7463273 1.1373893e-218 6.744271e-203 2.3050257e+20 7.0000000000 10.4000000000 0.4650000000 1.0000000000 0.0000000002 7.2542055 -3.1053938e-218 5.8190855e-203 2.360043e+20 7.0000000000 10.4000000000 0.4300000000 1.0000000000 0.0000000002 8.7650901 -9.2149203e-219 3.8278045e-203 2.4155562e+20 8.0000000000 9.6000000000 0.5000000000 54.3190287663 8.6383977879 -0.00084867596 3.1990002e-16 4.3696922e-05 1.4741939e+15 8.0000000000 9.6000000000 0.4650000000 55.8970086078 8.7873938438 -4.9038114e-08 -1.3245591e-20 4.195729e-09 1.2981616e+11 8.0000000000 9.6000000000 0.4300000000 11.0638264094 8.1412220464 9.2047376e-06 -3.3885397e-29 -5.6069146e-13 1.1254068e+13 8.0000000000 10.0000000000 0.5000000000 2.5712548608 5.7636834391 -0.019589285 -1.2931953e-34 1.7213902e-19 1.6310989e+17 8.0000000000 10.0000000000 0.4650000000 2.5124367565 5.6778079210 -0.0041256863 -3.2529798e-34 2.1068176e-19 1.5065028e+17 8.0000000000 10.0000000000 0.4300000000 2.3664071228 5.4461458125 0.0093041571 -4.2550123e-34 1.1443317e-19 1.616981e+17 8.0000000000 10.4000000000 0.5000000000 1.0000000215 0.0000002024 1.213841 -1.257349e-165 9.8468142e-150 2.1894106e+20 8.0000000000 10.4000000000 0.4650000000 1.0000000212 0.0000002004 2.8346072 3.6218234e-165 8.4165829e-150 2.2127881e+20 8.0000000000 10.4000000000 0.4300000000 1.0000000206 0.0000001945 4.4726034 9.9605196e-166 5.4823209e-150 2.2397331e+20 9.0000000000 9.6000000000 0.5000000000 55.5133155461 8.6413416287 -0.060150514 -0 0.0031209543 1.5551546e+17 9.0000000000 9.6000000000 0.4650000000 55.9133553778 8.7874269700 -3.9837589e-06 -1.3447291e-18 3.6045209e-07 1.0369016e+13 9.0000000000 9.6000000000 0.4300000000 11.0638296395 8.1412222516 1.0225013e-08 -9.8140885e-34 -5.2463927e-15 1.1664591e+10 9.0000000000 10.0000000000 0.5000000000 4.3121776451 7.1515970038 -0.10742171 1.0474064e-18 2.9758632e-05 4.7264474e+17 9.0000000000 10.0000000000 0.4650000000 5.1247512774 7.3995936852 -0.019430688 -1.5437293e-19 3.3567893e-06 8.738192e+16 9.0000000000 10.0000000000 0.4300000000 4.4162917436 7.0777667298 -0.0059568646 2.0942686e-21 5.1854462e-07 3.2607547e+16 ```