<commit_before>package analysis.dynamicsim.hierarchical.util.setup;

import org.sbml.jsbml.SpeciesReference;

import analysis.dynamicsim.hierarchical.states.ModelState;
import analysis.dynamicsim.hierarchical.util.math.ReactionNode;
import analysis.dynamicsim.hierarchical.util.math.SpeciesNode;
import analysis.dynamicsim.hierarchical.util.math.SpeciesReferenceNode;

public class SpeciesReferenceSetup
{

	public static void setupSingleModifier(ModelState modelstate, ReactionNode reactionNode, String modifierID)
	{
		// VariableNode node = modelstate.getNode(modifierID);
		// if (node != null)
		// {
		// reactionNode.addModifier(node);
		// }
	}

	public static void setupSingleProduct(ModelState modelstate, ReactionNode reaction, String productID, SpeciesReference product)
	{

		if (product.isSetId() && modelstate.isDeletedBySId(product.getId()))
		{
			return;
		}
		if (product.isSetMetaId() && modelstate.isDeletedByMetaId(product.getMetaId()))
		{
			return;
		}

		double stoichiometryValue = Double.isNaN(product.getStoichiometry()) ? 1 : product.getStoichiometry();

		SpeciesReferenceNode speciesReferenceNode = new SpeciesReferenceNode(stoichiometryValue);

		SpeciesNode species = (SpeciesNode) modelstate.getNode(productID);
		speciesReferenceNode.setSpecies(species);
		reaction.addProduct(speciesReferenceNode);

		if (!product.getConstant())
		{
			if (product.getId().length() > 0)
			{
				speciesReferenceNode.setName(product.getId());
				modelstate.addVariable(speciesReferenceNode);
				speciesReferenceNode.setIsVariableConstant(false);
			}
		}
		species.addODERate(reaction, speciesReferenceNode);

	}

	public static void setupSingleReactant(ModelState modelstate, ReactionNode reaction, String reactantID, SpeciesReference reactant)
	{

		double stoichiometryValue = Double.isNaN(reactant.getStoichiometry()) ? 1 : reactant.getStoichiometry();
		SpeciesReferenceNode speciesReferenceNode = new SpeciesReferenceNode(stoichiometryValue);
		SpeciesNode species = (SpeciesNode) modelstate.getNode(reactantID);
		speciesReferenceNode.setSpecies(species);
		reaction.addReactant(speciesReferenceNode);

		if (!reactant.getConstant())
		{
			if (reactant.getId().length() > 0)
			{
				speciesReferenceNode.setName(reactant.getId());
				modelstate.addVariable(speciesReferenceNode);
				speciesReferenceNode.setIsVariableConstant(false);<commit_msg>Fixed a bug in species reference where the model initial assignment was trying to set the value of a species reference but it could't find it<commit_after>package analysis.dynamicsim.hierarchical.util.setup;

import org.sbml.jsbml.SpeciesReference;

import analysis.dynamicsim.hierarchical.states.ModelState;
import analysis.dynamicsim.hierarchical.util.math.ReactionNode;
import analysis.dynamicsim.hierarchical.util.math.SpeciesNode;
import analysis.dynamicsim.hierarchical.util.math.SpeciesReferenceNode;

public class SpeciesReferenceSetup
{

	public static void setupSingleModifier(ModelState modelstate, ReactionNode reactionNode, String modifierID)
	{
		// VariableNode node = modelstate.getNode(modifierID);
		// if (node != null)
		// {
		// reactionNode.addModifier(node);
		// }
	}

	public static void setupSingleProduct(ModelState modelstate, ReactionNode reaction, String productID, SpeciesReference product)
	{

		if (product.isSetId() && modelstate.isDeletedBySId(product.getId()))
		{
			return;
		}
		if (product.isSetMetaId() && modelstate.isDeletedByMetaId(product.getMetaId()))
		{
			return;
		}

		double stoichiometryValue = Double.isNaN(product.getStoichiometry()) ? 1 : product.getStoichiometry();

		SpeciesReferenceNode speciesReferenceNode = new SpeciesReferenceNode(stoichiometryValue);

		SpeciesNode species = (SpeciesNode) modelstate.getNode(productID);
		speciesReferenceNode.setSpecies(species);
		reaction.addProduct(speciesReferenceNode);

		if (product.isSetId() && product.getId().length() > 0)
		{
			speciesReferenceNode.setName(product.getId());

			if (!product.getConstant())
			{
				modelstate.addVariable(speciesReferenceNode);
				speciesReferenceNode.setIsVariableConstant(false);
			}
			else
			{
				modelstate.addConstant(speciesReferenceNode);
			}
		}
		species.addODERate(reaction, speciesReferenceNode);

	}

	public static void setupSingleReactant(ModelState modelstate, ReactionNode reaction, String reactantID, SpeciesReference reactant)
	{

		double stoichiometryValue = Double.isNaN(reactant.getStoichiometry()) ? 1 : reactant.getStoichiometry();
		SpeciesReferenceNode speciesReferenceNode = new SpeciesReferenceNode(stoichiometryValue);
		SpeciesNode species = (SpeciesNode) modelstate.getNode(reactantID);
		speciesReferenceNode.setSpecies(species);
		reaction.addReactant(speciesReferenceNode);

		if (reactant.isSetId() && reactant.getId().length() > 0)
		{
			speciesReferenceNode.setName(reactant.getId());

			if (!reactant.getConstant())
			{
				modelstate.addVariable(speciesReferenceNode);
				speciesReferenceNode.setIsVariableConstant(false);
			}
			else
			{
				modelstate.addConstant(speciesReferenceNode);
{'fraction_non_alphanumeric': 0.10207305034550838, 'fraction_numerical': 0.0015794669299111549, 'mean_word_length': 5.79088471849866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1568500', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1473, 'n_words': 248}