def __init__(self, time_units='second', extent_units='mole', \ sub_units='mole', level=3, version=1): if level == 1: raise SystemExit('Error: SimpleSBML does not support SBML level 1') try: self.document = libsbml.SBMLDocument(level, version) except ValueError: raise SystemExit('Could not create SBMLDocument object') self.model = self.document.createModel() self.check(self.model, 'create model') if self.document.getLevel() == 3: self.check(self.model.setTimeUnits(time_units), 'set model-wide time units') self.check(self.model.setExtentUnits(extent_units), 'set model units of extent') self.check(self.model.setSubstanceUnits(sub_units), 'set model substance units') per_second = self.model.createUnitDefinition() self.check(per_second, 'create unit definition') self.check(per_second.setId('per_second'), 'set unit definition id') unit = per_second.createUnit() self.check(unit, 'create unit on per_second') self.check(unit.setKind(libsbml.UNIT_KIND_SECOND), 'set unit kind') self.check(unit.setExponent(-1), 'set unit exponent') self.check(unit.setScale(0), 'set unit scale') self.check(unit.setMultiplier(1), 'set unit multiplier') self.addCompartment()
def __init__( self, time_units="second", extent_units="mole", sub_units="mole", level=3, version=1, ): if level == 1: raise SystemExit("Error: SimpleSBML does not support SBML level 1") try: self.document = libsbml.SBMLDocument(level, version) except ValueError: raise SystemExit("Could not create SBMLDocument object") self.model = self.document.createModel() self.check(self.model, "create model") if self.document.getLevel() == 3: self.check(self.model.setTimeUnits(time_units), "set model-wide time units") self.check(self.model.setExtentUnits(extent_units), "set model units of extent") self.check(self.model.setSubstanceUnits(sub_units), "set model substance units") per_second = self.model.createUnitDefinition() self.check(per_second, "create unit definition") self.check(per_second.setId("per_second"), "set unit definition id") unit = per_second.createUnit() self.check(unit, "create unit on per_second") self.check(unit.setKind(libsbml.UNIT_KIND_SECOND), "set unit kind") self.check(unit.setExponent(-1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(1), "set unit multiplier") per_min = self.model.createUnitDefinition() self.check(per_min, "create unit definition") self.check(per_min.setId("per_min"), "set unit definition id") unit = per_min.createUnit() self.check(unit, "create unit on per_min") self.check(unit.setKind(libsbml.UNIT_KIND_SECOND), "set unit kind") self.check(unit.setExponent(-1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(60), "set unit multiplier") molperLmin = self.model.createUnitDefinition() self.check(molperLmin, "create unit definition") self.check(molperLmin.setId("molperLmin"), "set unit definition id") unit = molperLmin.createUnit() self.check(unit, "create unit on per_second") self.check(unit.setKind(libsbml.UNIT_KIND_MOLE), "set unit kind") self.check(unit.setExponent(1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(1), "set unit multiplier") unit = molperLmin.createUnit() self.check(unit, "create unit on per_second") self.check(unit.setKind(libsbml.UNIT_KIND_LITRE), "set unit kind") self.check(unit.setExponent(-1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(1), "set unit multiplier") unit = molperLmin.createUnit() self.check(unit, "create unit on per_second") self.check(unit.setKind(libsbml.UNIT_KIND_SECOND), "set unit kind") self.check(unit.setExponent(-1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(60), "set unit multiplier") molperL = self.model.createUnitDefinition() self.check(molperL, "create unit definition") self.check(molperL.setId("molperL"), "set unit definition id") unit = molperL.createUnit() self.check(unit, "create unit") self.check(unit.setKind(libsbml.UNIT_KIND_MOLE), "set unit kind") self.check(unit.setExponent(1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(1), "set unit multiplier") unit = molperL.createUnit() self.check(unit, "create unit") self.check(unit.setKind(libsbml.UNIT_KIND_LITRE), "set unit kind") self.check(unit.setExponent(-1), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(1), "set unit multiplier") Dimension_less = self.model.createUnitDefinition() self.check(Dimension_less, "create unit definition") self.check(Dimension_less.setId("Dimension_less"), "set unit definition id") unit = Dimension_less.createUnit() self.check(unit, "create unit") self.check(unit.setKind(libsbml.UNIT_KIND_DIMENSIONLESS), "set unit kind") self.check(unit.setExponent(0), "set unit exponent") self.check(unit.setScale(0), "set unit scale") self.check(unit.setMultiplier(0), "set unit multiplier") self.addCompartment()