def test_Reaction_addProduct1(self): m = libsbml.Reaction(2, 2) p = libsbml.SpeciesReference(2, 2) p1 = libsbml.SpeciesReference(2, 2) p1.setSpecies("k") p1.setId("k1") i = m.addProduct(p) self.assert_(i == libsbml.LIBSBML_INVALID_OBJECT) p.setSpecies("k") p.setId("k1") i = m.addProduct(p) self.assert_(i == libsbml.LIBSBML_OPERATION_SUCCESS) self.assert_(m.getNumProducts() == 1) i = m.addProduct(p1) self.assert_(i == libsbml.LIBSBML_DUPLICATE_OBJECT_ID) self.assert_(m.getNumProducts() == 1) _dummyList = [p] _dummyList[:] = [] del _dummyList _dummyList = [p1] _dummyList[:] = [] del _dummyList _dummyList = [m] _dummyList[:] = [] del _dummyList pass
def test_SpeciesReference_copyConstructor(self): o1 = libsbml.SpeciesReference(2,4) o1.setId("c") self.assert_( o1.getId() == "c" ) o2 = libsbml.SpeciesReference(o1) self.assert_( o2.getId() == "c" ) self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() ) o2 = None o1 = None pass
def test_SpeciesReference_assignmentOperator(self): o1 = libsbml.SpeciesReference(2,4) o1.setId("c") self.assert_( o1.getId() == "c" ) o2 = libsbml.SpeciesReference(2,4) o2 = o1 self.assert_( o2.getId() == "c" ) self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() ) o2 = None o1 = None pass
def test_SpeciesReference_setId3(self): c = libsbml.SpeciesReference(2, 1) i = c.setId("cell") _dummyList = [c] _dummyList[:] = [] del _dummyList pass
def test_SpeciesReference(self): sr = libsbml.SpeciesReference(2, 4) self.assertEqual(False, (sr.hasRequiredAttributes())) sr.setSpecies("sr") self.assertEqual(True, sr.hasRequiredAttributes()) sr = None pass
def setProducts(self, productIDString): if self.Type != TYPE.REACTION: # can only do this for Reactions return False productIDs = productIDString.replace(" ", "").split(",") if productIDs is None or len(productIDs) == 0: return False productRefs = self.Item.getListOfProducts() IDsToRemove = [] for productRef in productRefs: orgID = productRef.getSpecies() IDsToRemove.append(orgID) for ID in IDsToRemove: logging.info("Removing Product: %s" % ID) self.Item.removeProduct(ID) for ID in productIDs: if self.speciesIDExists(ID): speciesRef = libsbml.SpeciesReference(self.Item.getLevel(), self.Item.getVersion()) speciesRef.setSpecies(ID) self.Item.addProduct(speciesRef) return True
def test_SpeciesReference_setSpecies2(self): c = libsbml.SpeciesReference(2,2) i = c.setSpecies( "1cell") self.assert_( i == libsbml.LIBSBML_INVALID_ATTRIBUTE_VALUE ) self.assertEqual( False, c.isSetSpecies() ) _dummyList = [ c ]; _dummyList[:] = []; del _dummyList pass
def test_SpeciesReference_setName3(self): c = libsbml.SpeciesReference(2,1) i = c.setName( "cell") self.assert_( i == libsbml.LIBSBML_UNEXPECTED_ATTRIBUTE ) self.assertEqual( False, c.isSetName() ) _dummyList = [ c ]; _dummyList[:] = []; del _dummyList pass
def setReactants(self, reactantIDString): if self.Type != TYPE.REACTION: # can only do this for Reactions return False reactantIDs = reactantIDString.replace(" ", "").split(",") if reactantIDs is None or len(reactantIDs) == 0: return False reactantRefs = self.Item.getListOfReactants() IDsToRemove = [] for reactantRef in reactantRefs: orgID = reactantRef.getSpecies() IDsToRemove.append(orgID) for ID in IDsToRemove: logging.debug("Removing Reactant: %s" % ID) self.Item.removeReactant(ID) for ID in reactantIDs: if self.speciesIDExists(ID): speciesRef = libsbml.SpeciesReference(self.Item.getLevel(), self.Item.getVersion()) speciesRef.setSpecies(ID) self.Item.addReactant(speciesRef) return True
def test_SpeciesReference_setStoichiometry2(self): c = libsbml.SpeciesReference(2,2) i = c.setStoichiometry(4) self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( c.getStoichiometry() == 4.0 ) _dummyList = [ c ]; _dummyList[:] = []; del _dummyList pass
def test_L3_SpeciesReference_createWithNS(self): xmlns = libsbml.XMLNamespaces() xmlns.add( "http://www.sbml.org", "testsbml") sbmlns = libsbml.SBMLNamespaces(3,1) sbmlns.addNamespaces(xmlns) sr = libsbml.SpeciesReference(sbmlns) self.assert_( sr.getTypeCode() == libsbml.SBML_SPECIES_REFERENCE ) self.assert_( sr.getMetaId() == "" ) self.assert_( sr.getNotes() == None ) self.assert_( sr.getAnnotation() == None ) self.assert_( sr.getLevel() == 3 ) self.assert_( sr.getVersion() == 1 ) self.assert_( sr.getNamespaces() != None ) self.assert_( sr.getNamespaces().getLength() == 2 ) self.assert_( sr.getId() == "" ) self.assert_( sr.getName() == "" ) self.assert_( sr.getSpecies() == "" ) self.assertEqual( True, isnan(sr.getStoichiometry()) ) self.assert_( sr.getConstant() == False ) self.assertEqual( False, sr.isSetId() ) self.assertEqual( False, sr.isSetName() ) self.assertEqual( False, sr.isSetSpecies() ) self.assertEqual( False, sr.isSetStoichiometry() ) self.assertEqual( False, sr.isSetConstant() ) _dummyList = [ sr ]; _dummyList[:] = []; del _dummyList pass
def test_SpeciesReference_setDenominator2(self): c = libsbml.SpeciesReference(2,2) i = c.setDenominator(4) self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_( c.getDenominator() == 4 ) _dummyList = [ c ]; _dummyList[:] = []; del _dummyList pass
def test_SpeciesReference_setStoichiometryMath7(self): sr1 = libsbml.SpeciesReference(1, 2) i = sr1.unsetStoichiometryMath() self.assert_(i == libsbml.LIBSBML_UNEXPECTED_ATTRIBUTE) _dummyList = [sr1] _dummyList[:] = [] del _dummyList pass
def test_SpeciesReference_setSpecies3(self): c = libsbml.SpeciesReference(2,2) i = c.setSpecies( "mole") self.assert_( i == libsbml.LIBSBML_OPERATION_SUCCESS ) self.assert_(( "mole" == c.getSpecies() )) self.assertEqual( True, c.isSetSpecies() ) _dummyList = [ c ]; _dummyList[:] = []; del _dummyList pass
def test_StoichiometryMath_parent_add(self): m = libsbml.StoichiometryMath(2, 4) m.setMath(libsbml.parseFormula("1")) sr = libsbml.SpeciesReference(2, 4) sr.setStoichiometryMath(m) m = None self.assert_(sr == sr.getStoichiometryMath().getParentSBMLObject()) sr = None pass
def test_L3_SpeciesReference_hasRequiredAttributes(self): sr = libsbml.SpeciesReference(3,1) self.assertEqual( False, sr.hasRequiredAttributes() ) sr.setSpecies( "id") self.assertEqual( False, sr.hasRequiredAttributes() ) sr.setConstant(False) self.assertEqual( True, sr.hasRequiredAttributes() ) _dummyList = [ sr ]; _dummyList[:] = []; del _dummyList pass
def test_SpeciesReference_Reactant_parent_add(self): sr = libsbml.SpeciesReference(2, 4) r = libsbml.Reaction(2, 4) sr.setSpecies("s") r.addReactant(sr) sr = None lo = r.getListOfReactants() self.assert_(lo == r.getReactant(0).getParentSBMLObject()) self.assert_(r == lo.getParentSBMLObject()) pass
def test_SpeciesReference_clone(self): o1 = libsbml.SpeciesReference(2,4) o1.setId("c") self.assert_( o1.getId() == "c" ) o2 = o1.clone() self.assert_( o2.getId() == "c" ) self.assert_( o2.getParentSBMLObject() == o1.getParentSBMLObject() ) o2 = None o1 = None pass
def test_Reaction_addReactant(self): sr = libsbml.SpeciesReference(2, 4) sr.setSpecies("s") self.R.addReactant(sr) self.assert_(self.R.getNumReactants() == 1) self.assert_(self.R.getNumProducts() == 0) self.assert_(self.R.getNumModifiers() == 0) _dummyList = [sr] _dummyList[:] = [] del _dummyList pass
def test_StoichiometryMath_ancestor_create(self): sr = libsbml.SpeciesReference(2,4) sm = sr.createStoichiometryMath() self.assert_( sm.getAncestorOfType(libsbml.SBML_SPECIES_REFERENCE) == sr ) self.assert_( sm.getAncestorOfType(libsbml.SBML_DOCUMENT) == None ) self.assert_( sm.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None ) obj = sr.getStoichiometryMath() self.assert_( obj.getAncestorOfType(libsbml.SBML_SPECIES_REFERENCE) == sr ) self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None ) self.assert_( obj.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None ) pass
def test_Reaction_getReactantById(self): sr1 = libsbml.SpeciesReference(2, 4) sr1.setSpecies("R1") sr2 = libsbml.SpeciesReference(2, 4) sr2.setSpecies("R2") self.R.addReactant(sr1) self.R.addReactant(sr2) self.assert_(self.R.getNumReactants() == 2) self.assert_(self.R.getNumProducts() == 0) self.assert_(self.R.getNumModifiers() == 0) self.assert_(self.R.getReactant("R1") != sr1) self.assert_(self.R.getReactant("R2") != sr2) self.assert_(self.R.getReactant("R3") == None) _dummyList = [sr1] _dummyList[:] = [] del _dummyList _dummyList = [sr2] _dummyList[:] = [] del _dummyList pass
def test_Reaction_getReactant(self): sr1 = libsbml.SpeciesReference(2, 4) sr2 = libsbml.SpeciesReference(2, 4) sr1.setSpecies("R1") sr2.setSpecies("R2") self.R.addReactant(sr1) self.R.addReactant(sr2) _dummyList = [sr1] _dummyList[:] = [] del _dummyList _dummyList = [sr2] _dummyList[:] = [] del _dummyList self.assert_(self.R.getNumReactants() == 2) self.assert_(self.R.getNumProducts() == 0) self.assert_(self.R.getNumModifiers() == 0) sr1 = self.R.getReactant(0) sr2 = self.R.getReactant(1) self.assert_(("R1" == sr1.getSpecies())) self.assert_(("R2" == sr2.getSpecies())) pass
def test_StoichiometryMath_ancestor_add(self): m = libsbml.StoichiometryMath(2,4) m.setMath(libsbml.parseFormula("1")) sr = libsbml.SpeciesReference(2,4) sr.setStoichiometryMath(m) m = None obj = sr.getStoichiometryMath() self.assert_( obj.getAncestorOfType(libsbml.SBML_SPECIES_REFERENCE) == sr ) self.assert_( obj.getAncestorOfType(libsbml.SBML_MODEL) == None ) self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None ) sr = None pass
def test_SpeciesReference_Reactant_ancestor_add(self): sr = libsbml.SpeciesReference(2,4) r = libsbml.Reaction(2,4) sr.setSpecies("s") r.addReactant(sr) sr = None lo = r.getListOfReactants() obj = r.getReactant(0) self.assert_( obj.getAncestorOfType(libsbml.SBML_REACTION) == r ) self.assert_( obj.getAncestorOfType(libsbml.SBML_LIST_OF) == lo ) self.assert_( obj.getAncestorOfType(libsbml.SBML_DOCUMENT) == None ) self.assert_( obj.getAncestorOfType(libsbml.SBML_COMPARTMENT) == None ) pass
def test_Reaction_addProduct3(self): m = libsbml.Reaction(2, 2) p = libsbml.SpeciesReference(1, 2) p.setSpecies("k") i = m.addProduct(p) self.assert_(i == libsbml.LIBSBML_LEVEL_MISMATCH) self.assert_(m.getNumProducts() == 0) _dummyList = [p] _dummyList[:] = [] del _dummyList _dummyList = [m] _dummyList[:] = [] del _dummyList pass
def test_Reaction_addReactant2(self): m = libsbml.Reaction(2, 2) p = libsbml.SpeciesReference(2, 1) p.setSpecies("k") i = m.addReactant(p) self.assert_(i == libsbml.LIBSBML_VERSION_MISMATCH) self.assert_(m.getNumReactants() == 0) _dummyList = [p] _dummyList[:] = [] del _dummyList _dummyList = [m] _dummyList[:] = [] del _dummyList pass
def test_SpeciesReference_setStoichiometryMath5(self): sr1 = libsbml.SpeciesReference(1,2) sm = libsbml.StoichiometryMath(2,4) math = libsbml.ASTNode(libsbml.AST_TIMES) a = libsbml.ASTNode() b = libsbml.ASTNode() a.setName( "a") b.setName( "b") math.addChild(a) math.addChild(b) sm.setMath(math) i = sr1.setStoichiometryMath(sm) self.assert_( i == libsbml.LIBSBML_UNEXPECTED_ATTRIBUTE ) self.assertEqual( False, sr1.isSetStoichiometryMath() ) _dummyList = [ sm ]; _dummyList[:] = []; del _dummyList _dummyList = [ sr1 ]; _dummyList[:] = []; del _dummyList pass
def test_SpeciesReference_createWithNS(self): xmlns = libsbml.XMLNamespaces() xmlns.add("http://www.sbml.org", "testsbml") sbmlns = libsbml.SBMLNamespaces(2, 1) sbmlns.addNamespaces(xmlns) object = libsbml.SpeciesReference(sbmlns) self.assert_(object.getTypeCode() == libsbml.SBML_SPECIES_REFERENCE) self.assert_(object.getMetaId() == "") self.assert_(object.getNotes() == None) self.assert_(object.getAnnotation() == None) self.assert_(object.getLevel() == 2) self.assert_(object.getVersion() == 1) self.assert_(object.getNamespaces() != None) self.assert_(object.getNamespaces().getLength() == 2) _dummyList = [object] _dummyList[:] = [] del _dummyList pass
def test_internal_consistency_check_99904_speciesRef(self): d = libsbml.SBMLDocument(2,4) sr = libsbml.SpeciesReference(2,4) d.setLevelAndVersion(1,2,False) m = d.createModel() c = m.createCompartment() c.setId("c") s = m.createSpecies() s.setId("s") s.setCompartment("c") r = m.createReaction() r.setId("r") sr.setSpecies("s") sr.setMetaId("mmm") r.addProduct(sr) errors = d.checkInternalConsistency() self.assert_( errors == 1 ) self.assert_( d.getError(0).getErrorId() == 21101 ) d = None pass
def setUp(self): self.sr = libsbml.SpeciesReference(2,4) if (self.sr == None): pass pass