示例#1
0
        /// <summary>
        /// [ ReactionStruct ]
        /// [[ Id , Name , [ KineticLawStruct ] , Reversible , Fast , [ ReactantStruct ] , [ ProductStruct ] , [ ModifierSpecies ] ]]
        /// </summary>
        /// <param name="aSBMLmodel"></param>
        /// <returns></returns>
        public static List<ReactionStruct> getReaction(Model aSBMLmodel)
        {
            List<ReactionStruct> list = new List<ReactionStruct>();

            ListOfReactions reactions = aSBMLmodel.getListOfReactions();
            for (int i = 0; i < reactions.size(); i++ )
            {
                Reaction aReaction = aSBMLmodel.getReaction(i);

                string anId = aReaction.getId();
                string aName =aReaction.getName();

                //----------KineticLaw----------------------------------
                List<KineticLawStruct> ListOfKineticLaw = new List<KineticLawStruct>();
                if( aReaction.isSetKineticLaw())
                {
                    KineticLaw aKineticLaw = aReaction.getKineticLaw();
                    if( aKineticLaw != null)
                    {
                        string aFormula_KL;
                        if( aKineticLaw.isSetFormula())
                            aFormula_KL = aKineticLaw.getFormula();
                        else
                            aFormula_KL = "";

                        List<string> aString_KL = new List<string>();
                        if (aSBMLmodel.getLevel() == 1)
                        {
                            aString_KL.Add( "" );
                        }
                        else
                        {
                            if (aKineticLaw.isSetMath())
                            {
                                ASTNode anASTNode_KL = aKineticLaw.getMath();
                                aString_KL.Add( libsbml.libsbml.formulaToString( anASTNode_KL ) );
                            }
                            else
                                aString_KL.Add( "" );
                        }

                        string aTimeUnit_KL = aKineticLaw.getTimeUnits();
                        string aSubstanceUnit_KL = aKineticLaw.getSubstanceUnits();

                        List<ParameterStruct> listOfParameters = new List<ParameterStruct>();

                        ListOfParameters parameters = aKineticLaw.getListOfParameters();
                        for (int j = 0; j < parameters.size(); j++ )
                        {
                            Parameter aParameter = aKineticLaw.getParameter(j);
                            if (aParameter == null)
                                continue;
                            string anId_KL_P = aParameter.getId();
                            string aName_KL_P = aParameter.getName();
                            double aValue_KL_P = aParameter.getValue();
                            string aUnit_KL_P = aParameter.getUnits();
                            bool aConstant_KL_P = aParameter.getConstant();

                            ParameterStruct parameter = new ParameterStruct(
                                anId_KL_P,
                                aName_KL_P,
                                aValue_KL_P,
                                aUnit_KL_P,
                                aConstant_KL_P);

                            listOfParameters.Add( parameter );
                        }

                        XMLNode anExpressionAnnotation = aKineticLaw.getAnnotation();

                        KineticLawStruct kineticLaw = new KineticLawStruct(
                            aFormula_KL,
                            aString_KL,
                            aTimeUnit_KL,
                            aSubstanceUnit_KL,
                            listOfParameters,
                            anExpressionAnnotation );

                        ListOfKineticLaw.Add(kineticLaw);
                    }
                }

                bool aReversible = aReaction.getReversible();
                bool aFast = aReaction.getFast();

                //----------Reactants----------------------------------
                List<ReactantStruct> ListOfReactants = new List<ReactantStruct>();

                ListOfSpeciesReferences reactants = aReaction.getListOfReactants();
                for (int k = 0; k < reactants.size(); k++ )
                {
                    SpeciesReference aSpeciesReference = aReaction.getReactant(k);

                    string aSpecies_R = aSpeciesReference.getSpecies();
                    int aStoichiometry_R = (int)aSpeciesReference.getStoichiometry();

                    string aString_R = GetStoichiometryMath(aSpeciesReference);

                    int aDenominator_R = aSpeciesReference.getDenominator();

                    ReactantStruct reactant = new ReactantStruct(
                        aSpecies_R,
                        aStoichiometry_R,
                        aString_R,
                        aDenominator_R);

                    ListOfReactants.Add( reactant );
                }

                //----------Products----------------------------------
                List<ProductStruct> ListOfProducts = new List<ProductStruct>();

                ListOfSpeciesReferences products = aReaction.getListOfProducts();
                long max = products.size();
                for (int l = 0; l < max; l++)
                {
                    SpeciesReference aSpeciesReference = aReaction.getProduct(l);

                    string aSpecies_P = aSpeciesReference.getSpecies();
                    double aStoichiometry_P = aSpeciesReference.getStoichiometry();

                    string aString_P = GetStoichiometryMath(aSpeciesReference);

                    int aDenominator_P = aSpeciesReference.getDenominator();

                    ProductStruct product = new ProductStruct(
                        aSpecies_P,
                        aStoichiometry_P,
                        aString_P,
                        aDenominator_P);

                    ListOfProducts.Add( product );
                }

                //----------Modifiers----------------------------------
                List<string> ListOfModifiers = new List<string>();
                ListOfSpeciesReferences modifiers = aReaction.getListOfModifiers();
                for (long l = 0; l < modifiers.size(); l++ )
                {
                    ModifierSpeciesReference aSpeciesReference = aReaction.getModifier(l);

                    string aSpecies_M = aSpeciesReference.getSpecies();
                    ListOfModifiers.Add( aSpecies_M );
                }
                ReactionStruct reaction = new ReactionStruct(
                    anId,
                    aName,
                    ListOfKineticLaw,
                    aReversible,
                    aFast,
                    ListOfReactants,
                    ListOfProducts,
                    ListOfModifiers );

                list.Add(reaction);
            }
            return list;
        }
示例#2
0
 public void TestConstructorOfStructs()
 {
     //
     CompartmentStruct c = new CompartmentStruct(
         "ID",
         "Name",
         0,
         0.0,
         0.0,
         "Unit",
         "Parent",
         false);
     //
     EventStruct e = new EventStruct(
         "ID",
         "Name",
         "Trigger",
         "delay",
         "TimeUnit",
         new List<EventAssignmentStruct>());
     //
     EventAssignmentStruct ea = new EventAssignmentStruct(
         "Variable",
         "Formula");
     //
     FunctionDefinitionStruct fd = new FunctionDefinitionStruct(
         "ID",
         "Name",
         "Formula");
     //
     ParameterStruct p = new ParameterStruct(
         "ID",
         "Name",
         0.0,
         "Unit",
         false);
     //
     ReactionStruct r = new ReactionStruct(
         "ID",
         "Name",
         new List<KineticLawStruct>(),
         false,
         false,
         new List<ReactantStruct>(),
         new List<ProductStruct>(),
         new List<string>());
     //
     KineticLawStruct k = new KineticLawStruct(
         "Formula",
         new List<string>(),
         "TimeUnit",
         "Substance",
         new List<ParameterStruct>(),
         null);
     //
     ReactantStruct rs = new ReactantStruct(
         "Species",
         0,
         "Formula",
         0);
     //
     ProductStruct ps = new ProductStruct(
         "Species",
         0.0,
         "Formula",
         0);
     //
     RuleStruct rule = new RuleStruct(
         0,
         "Formula",
         "Variable");
     //
     SpeciesStruct s = new SpeciesStruct(
         "ID",
         "Name",
         "Parent",
         0.0,
         0.0,
         "Substance",
         "Spatial",
         "Unit",
         false,
         false,
         0,
         false);
     //
     UnitDefinitionStruct ud = new UnitDefinitionStruct(
         "ID",
         "Name",
         new List<UnitStruct>());
     //
     UnitStruct u = new UnitStruct(
         "Kind",
         0,
         0,
         0.0,
         0.0);
     //
     VariableReferenceStruct v = new VariableReferenceStruct(
         "Name",
         "Variable",
         0);
     //
     InitialAssignmentStruct i = new InitialAssignmentStruct(
         "Name",
         0.0);
 }