END_TEST START_TEST (test_L3_Species_initDefaults) { Species_t *s = Species_create(3,1); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( Species_getSubstanceUnits (s) == NULL ); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( !Species_isSetSubstanceUnits (s) ); fail_unless( !Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( !Species_isSetBoundaryCondition(s) ); fail_unless( !Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_initDefaults(s); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( !strcmp(Species_getSubstanceUnits (s),"mole" )); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( Species_isSetSubstanceUnits (s) ); fail_unless( Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( Species_isSetBoundaryCondition(s) ); fail_unless( Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_free(s); }
END_TEST START_TEST (test_Species_setInitialConcentration) { fail_unless( !Species_isSetInitialAmount (S) ); fail_unless( !Species_isSetInitialConcentration(S) ); Species_setInitialConcentration(S, 3.4); fail_unless( !Species_isSetInitialAmount (S) ); fail_unless( Species_isSetInitialConcentration(S) ); fail_unless( Species_getInitialConcentration(S) == 3.4 ); }
END_TEST START_TEST (test_Species_setInitialAmount1) { int i = Species_setInitialAmount(C, 2.0); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Species_getInitialAmount(C) == 2.0 ); fail_unless( Species_isSetInitialAmount(C)); i = Species_unsetInitialAmount(C); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( !Species_isSetInitialAmount(C)); }
void printSpecies(Model_t *m, FILE *f) { int i, j; Species_t *s; Compartment_t *c; fprintf(f, "\n"); fprintf(f, "# Initial Conditions for Species and Compartments:\n"); for ( i=0; i<Model_getNumCompartments(m); i++ ) { if ( i== 0 ) fprintf(f, "# Compartments:\n"); c = Model_getCompartment(m,i); if(Compartment_isSetId(c)) fprintf(f, "%s ", Compartment_getId(c)); if(Compartment_isSetName(c)) fprintf(f, "(%s) ", Compartment_getName(c)); if ( Compartment_isSetVolume(c) ) fprintf(f, "= %g; ", Compartment_getSize(c)); fprintf(f, "%s", Compartment_getConstant(c) ? "" : "variable; "); if(Compartment_isSetOutside(c)) fprintf(f, "outside %s; ", Compartment_getOutside(c)); /* fprintf(f, "\n"); */ fprintf(f, "dimensions %d; ", Compartment_getSpatialDimensions(c)); if(Compartment_isSetUnits(c)) fprintf(f, "[%s]; ", Compartment_getUnits(c)); fprintf(f, "\n"); fprintf(f, "# Species concentrations in `compartment' %s\n", Compartment_getId(c)); for(j=0;j<Model_getNumSpecies(m);j++){ s = Model_getSpecies(m,j); if(strcmp(Species_getCompartment(s), Compartment_getId(c))==0){ fprintf(f, "%s ", Species_getId(s)); if(Species_isSetName(s)) fprintf(f, "(%s) ", Species_getName(s)); if ( Species_isSetInitialAmount(s) ) fprintf(f, "= %g/%g; ", Species_getInitialAmount(s), Compartment_getSize(c)); else if ( Species_isSetInitialConcentration(s) ) fprintf(f, "= %g; ", Species_getInitialConcentration(s)); else fprintf(f, "# no initial value;"); fprintf(f, "%s", Species_getBoundaryCondition(s) ? "boundary;" : ""); fprintf(f, "%s", Species_getConstant(s) ? "constant;" : ""); if(Species_isSetCharge(s)) fprintf(f, "charge = %d; ", Species_getCharge(s)); fprintf(f, "\n"); } } fprintf(f, "\n"); } }
END_TEST START_TEST (test_L3_Species_initialAmount) { double initialAmount = 0.2; fail_unless( !Species_isSetInitialAmount(S)); fail_unless( util_isNaN(Species_getInitialAmount(S))); Species_setInitialAmount(S, initialAmount); fail_unless( Species_getInitialAmount(S) == initialAmount ); fail_unless( Species_isSetInitialAmount(S) ); Species_unsetInitialAmount(S); fail_unless( !Species_isSetInitialAmount(S) ); fail_unless( util_isNaN(Species_getInitialAmount(S))); }
END_TEST START_TEST (test_Species_setInitialAmount2) { Species_t *c = Species_create(2, 2); int i = Species_setInitialAmount(c, 4); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( Species_getInitialAmount(c) == 4.0 ); fail_unless( Species_isSetInitialAmount(c)); i = Species_unsetInitialAmount(c); fail_unless( i == LIBSBML_OPERATION_SUCCESS ); fail_unless( !Species_isSetInitialAmount(c)); Species_free(c); }
END_TEST START_TEST (test_L3_Species_createWithNS ) { XMLNamespaces_t *xmlns = XMLNamespaces_create(); XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml"); SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1); SBMLNamespaces_addNamespaces(sbmlns,xmlns); Species_t *s = Species_createWithNS (sbmlns); fail_unless( SBase_getTypeCode ((SBase_t *) s) == SBML_SPECIES ); fail_unless( SBase_getMetaId ((SBase_t *) s) == NULL ); fail_unless( SBase_getNotes ((SBase_t *) s) == NULL ); fail_unless( SBase_getAnnotation((SBase_t *) s) == NULL ); fail_unless( SBase_getLevel ((SBase_t *) s) == 3 ); fail_unless( SBase_getVersion ((SBase_t *) s) == 1 ); fail_unless( Species_getNamespaces (s) != NULL ); fail_unless( XMLNamespaces_getLength(Species_getNamespaces(s)) == 2 ); fail_unless( Species_getId (s) == NULL ); fail_unless( Species_getName (s) == NULL ); fail_unless( Species_getCompartment (s) == NULL ); fail_unless( util_isNaN(Species_getInitialAmount (s)) ); fail_unless( util_isNaN(Species_getInitialConcentration (s)) ); fail_unless( Species_getSubstanceUnits (s) == NULL ); fail_unless( Species_getHasOnlySubstanceUnits(s) == 0 ); fail_unless( Species_getBoundaryCondition(s) == 0 ); fail_unless( Species_getConstant(s) == 0 ); fail_unless( Species_getConversionFactor (s) == NULL ); fail_unless( !Species_isSetId (s) ); fail_unless( !Species_isSetName (s) ); fail_unless( !Species_isSetCompartment (s) ); fail_unless( !Species_isSetInitialAmount (s) ); fail_unless( !Species_isSetInitialConcentration (s) ); fail_unless( !Species_isSetSubstanceUnits (s) ); fail_unless( !Species_isSetHasOnlySubstanceUnits(s) ); fail_unless( !Species_isSetBoundaryCondition(s) ); fail_unless( !Species_isSetConstant(s) ); fail_unless( !Species_isSetConversionFactor (s) ); Species_free(s); XMLNamespaces_free(xmlns); SBMLNamespaces_free(sbmlns); }
/* setValues: the user can enter a species name and change its initial condition (amount or concentration) */ static void setValues(Model_t *m) { char *species; char *newIA; char *newIC; Species_t *s; printf("Please enter the id of the species to change: "); species = get_line(stdin); species = util_trim(species); if ( (s = Model_getSpeciesById(m,species) ) ) { printf("\n"); printf("Id: %s\n", Species_getId(s)); if ( Species_isSetName(s) ) { printf("Name: %s\n", Species_getName(s)); } if ( Species_isSetInitialAmount(s) ) { printf("Initial Amount: %g", Species_getInitialAmount(s)); } else if (Species_isSetInitialConcentration(s) ) { printf("Initial Concentration: %g", Species_getInitialConcentration(s)); } if ( Species_getHasOnlySubstanceUnits(s) ) { if ( Species_isSetSubstanceUnits(s) ) { printf("%s ", Species_getSubstanceUnits(s)); } } else { if ( Species_isSetSubstanceUnits(s) ) { printf("%s ", Species_getSubstanceUnits(s)); } if ( Species_isSetSpatialSizeUnits(s) ) { printf("%s%s", "/", Species_getSpatialSizeUnits(s)); } } if ( Species_getHasOnlySubstanceUnits(s) ) { printf(" (has only substance units)"); } printf("\n"); if ( Species_isSetCharge(s) ) { printf("Charge: %-10d", Species_getCharge(s)); } printf("\n"); printf("%s ", Species_getBoundaryCondition(s) ? "Species is a Boundary\n" : "\n"); printf("%s ", Species_getConstant(s) ? "Species is set constant" : "\n"); printf("\n"); if ( Species_isSetInitialAmount(s) ) { printf("Please enter new initial Amount: "); newIA = get_line(stdin); newIA = util_trim(newIA); Species_setInitialAmount(s, (float) atof(newIA)); } else if ( Species_isSetInitialConcentration(s) ) { printf("Please enter new initial Concentration: "); newIC = get_line(stdin); newIC = util_trim(newIC); Species_setInitialConcentration(s, (float) atof(newIC)); } } else { printf("%s not found.\n", species); } }