def addModMolElmtToMolsElmt(self, xmlObject, moleculizerMolObject): assert(isinstance(xmlObject, XmlObject)) assert(isinstance(moleculizerMolObject, MoleculizerMol)) newModMol = XmlObject("mod-mol") newModMol.addAttribute("name", moleculizerMolObject.getName()) weightElement = XmlObject("weight") # Obviously this is one of the big deficiencies of this thing. What shall # we set the (mandatory) weights to? For now, let's just put in something # arbitratry. But this is a big issue that ought to be fixed as soon as all # the basic facilities of the code have been built in. if moleculizerMolObject.getName() == "Pheromone": weightElement.addAttribute("daltons", 10.0) else: weightElement.addAttribute("daltons", 100.0) newModMol.addSubElement(weightElement) for binding in moleculizerMolObject.bindingSites: self.addBindingSiteElmtToModMolElmt(binding, moleculizerMolObject, newModMol) for modification in moleculizerMolObject.modificationSites: modSite, defaultModState = modification modSiteElmt = XmlObject("mod-site") modSiteElmt.addAttribute("name", modSite) defModRefElmt = XmlObject("default-mod-ref") defModRefElmt.addAttribute("name", defaultModState) defModRefElmt.attachToParent(modSiteElmt).attachToParent(newModMol) xmlObject.addSubElement(newModMol) return
def addSmallMolToXml( self, parsedSmallMol, xmlElement ): smallMolElt = XmlObject("small-mol") smallMolElt.addAttribute( "name", parsedSmallMol.getName() ) smallMolElt.attachToParent( xmlElement) return smallMolElt
def writeParsedLineAsXmlMol(self, parsedLine, xmlobject): parsedComplex = parsedLine.getParsedComponents()[0] assert (len(parsedComplex.getMols()) == 1) parsedMol = parsedComplex.getMols()[0] newMolElement = 0 if parsedMol.isSmallMol(): newMolElement = self.addSmallMolToXml(parsedMol, xmlobject) else: newMolElement = self.addModMolToXml(parsedMol, xmlobject) # Now add the mass element to the thing. mass = 0.0 if (parsedLine.hasAssignment("mass")): mass = parsedLine.getAssignment("mass") elif self.getTranslationLevel == self.STRICT: raise Exception() weightElmt = XmlObject("weight") weightElmt.addAttribute("daltons", mass) newMolElement.addSubElement(weightElmt)
def addSmallMolToXml(self, parsedSmallMol, xmlElement): smallMolElt = XmlObject("small-mol") smallMolElt.addAttribute("name", parsedSmallMol.getName()) smallMolElt.attachToParent(xmlElement) return smallMolElt
def __writeSmallMolExchange(self, reaction, parElmt): smallMolExchangesElmt = XmlObject("small-mol-exchanges", parElmt) reactant_omniplex = reaction.getReactants()[0] product_omniplex = reaction.getProducts()[0] assert (len(reactant_omniplex.getMols()) == len( product_omniplex.getMols())) for ndx in range(len(reactant_omniplex.getMols())): if reactant_omniplex.getMols()[ndx].getName( ) != product_omniplex.getMols()[ndx].getName(): assert (reactant_omniplex.getMols()[ndx].isSmallMol()) smallMolExchangeElmt = XmlObject("small-mol-exchage", smallMolExchangesElmt) smallMolInstRef = XmlObject("small-mol-instance-ref", smallMolExchangeElmt) smallMolRef = XmlObject("small-mol-ref", smallMolExchangeElmt) smallMolInstRef.addAttribute( "name", self.getMolName(reactant_omniplex.getMols()[ndx].getName(), ndx)) smallMolRef.addAttribute( "name", product_omniplex.getMols()[ndx].getName()) return
def writeParsedLineAsXmlMol(self, parsedLine, xmlobject): parsedComplex = parsedLine.getParsedComponents()[0] assert( len( parsedComplex.getMols() ) == 1) parsedMol = parsedComplex.getMols()[0] newMolElement = 0 if parsedMol.isSmallMol(): newMolElement = self.addSmallMolToXml( parsedMol, xmlobject ) else: newMolElement = self.addModMolToXml( parsedMol, xmlobject) # Now add the mass element to the thing. mass = 0.0 if ( parsedLine.hasAssignment("mass") ): mass = parsedLine.getAssignment("mass") elif self.getTranslationLevel == self.STRICT: raise Exception() weightElmt = XmlObject("weight") weightElmt.addAttribute("daltons", mass) newMolElement.addSubElement( weightElmt )
def writeSpeciesStreamLineToParent( self, line, parentElmt): omniSpeciesStreamElmt = XmlObject("omni-species-stream", parentElmt) omniSpeciesStreamElmt.addAttribute("name", line.getAssignment("name")) self.writeParsedComplexAsPlex( line.getParsedComponents()[0], omniSpeciesStreamElmt) return
def writeOmniGenLineToParent(self, line, parElmt): omniGenElment = XmlObject("omni-gen", parElmt) reaction = line.getParsedComponents()[0] enablingOmniplex = reaction.getReactants()[0] additionalReactant = 0 if len(reaction.getReactants()) > 1: additionalReactant = reaction.getReactants()[1] product = reaction.getProducts()[0] additionalProduct = 0 if len(reaction.getProducts()) > 1: additionalProduct = reaction.getProducts()[1] self.__writeEnablingOmniPlexElementToXml(enablingOmniplex, omniGenElment) self.__writeModificationExchanges(reaction, omniGenElment) self.__writeSmallMolExchange(reaction, omniGenElment) rateElmt = XmlObject("rate", omniGenElment) rateElmt.addAttribute("value", line.getAssignment("k")) return
def writeExplicitSpeciesLineToXml(self, parsedLine, parentObject): parsedComplex = parsedLine.getParsedComponents()[0] name = parsedLine.getAssignment("name") plexSpeciesElmt = XmlObject("plex-species", parentObject) plexSpeciesElmt.addAttribute("name", name) self.writeParsedComplexAsPlex(parsedComplex, plexSpeciesElmt)
def writeExplicitSpeciesLineToXml( self, parsedLine, parentObject): parsedComplex = parsedLine.getParsedComponents()[0] name = parsedLine.getAssignment("name") plexSpeciesElmt = XmlObject( "plex-species", parentObject) plexSpeciesElmt.addAttribute( "name", name) self.writeParsedComplexAsPlex( parsedComplex, plexSpeciesElmt, writeComplexInstanceStates = True)
def writeSpeciesStreamLineToParent(self, line, parentElmt): omniSpeciesStreamElmt = XmlObject("omni-species-stream", parentElmt) omniSpeciesStreamElmt.addAttribute("name", line.getAssignment("name")) self.writeParsedComplexAsPlex(line.getParsedComponents()[0], omniSpeciesStreamElmt) return
def writeModificationToXml(self, modLine, modsElmt): modElmt = XmlObject("modification", modsElmt) modElmt.addAttribute("name", modLine.getAssignment("name")) weightDeltaElmt = XmlObject("weight-delta", modElmt) weightDeltaElmt.addAttribute("daltons", modLine.getAssignment("mass")) return
def addModifications(self, parentElmt): for modification in self.getUniversalModificationList(): modificationTypeElmt = XmlObject("modification") modificationTypeElmt.addAttribute("name", modification) modificationTypeElmt.attachToParent(parentElmt) weightElmt = XmlObject("weight-delta") weightElmt.attachToParent(modificationTypeElmt) if self.representsNullModification(modification): weightDelta = 0.0 else: weightDelta = 1.0 weightElmt.addAttribute("daltons", weightDelta)
def writeUnboundStates(self, complex, patternMatchingSitesSpec, xmlobject): unboundPatterns = [x for x in patternMatchingSitesSpec if x[2] == "-"] unboundSectionElmt = XmlObject("unbound-sites", xmlobject) for pattern in unboundPatterns: mol_ndx, site_ndx = pattern[0], pattern[1] instanceRef = XmlObject("instance-ref", unboundSectionElmt) instanceRef.addAttribute("name", \ self.getMolName(complex.getMols()[mol_ndx].getName(), \ mol_ndx)) siteRef = XmlObject("site-ref", instanceRef) siteRef.addAttribute("name", pattern[1]) return
def __writeSmallMolExchange(self, reaction, parElmt): smallMolExchangesElmt = XmlObject("small-mol-exchanges", parElmt) reactant_omniplex = reaction.getReactants()[0] product_omniplex = reaction.getProducts()[0] assert(len(reactant_omniplex.getMols()) == len(product_omniplex.getMols())) for ndx in range(len(reactant_omniplex.getMols())): if reactant_omniplex.getMols()[ndx].getName() != product_omniplex.getMols()[ndx].getName(): assert( reactant_omniplex.getMols()[ndx].isSmallMol() ) smallMolExchangeElmt = XmlObject("small-mol-exchage", smallMolExchangesElmt) smallMolInstRef = XmlObject("small-mol-instance-ref", smallMolExchangeElmt) smallMolRef = XmlObject("small-mol-ref", smallMolExchangeElmt) smallMolInstRef.addAttribute("name", self.getMolName(reactant_omniplex.getMols()[ndx].getName(), ndx)) smallMolRef.addAttribute("name", product_omniplex.getMols()[ndx].getName() ) return
def writeAllostericSitesElementToElement( self, parsedComplex, parentElement): allostericSitesElmt = XmlObject("allosteric-sites", parentElement) for ndx in range(len(parsedComplex.getMols())): mol = parsedComplex.getMols()[ndx] if mol.isSmallMol(): continue # [x for x in mol.getBindingSites() \ # if x.hasBindingSiteSpecification() and \ # x.getBindingSiteSpecification().hasShapeSpecification() and \ # x.getBindingSiteSpecification().getShapeSpecification().isTransformation() ]: for bndSiteWithTrans in [x for x in mol.getBindingSites() \ if x.hasBindingSiteSpecification() and \ x.getBindingSiteSpecification().hasShapeSpecification() and \ x.getBindingSiteSpecification().getShapeSpecification().isTransformation() ]: transformation = \ bndSiteWithTrans.getBindingSiteSpecification().getShapeSpecification().getTransformation() molElmt = XmlObject("mol-instance-ref", allostericSitesElmt) molElmt.addAttribute("name", self.getMolName( mol.getName(), ndx) ) bindingRefElmt = XmlObject( "binding-site-ref", molElmt) bindingRefElmt.addAttribute( "name", bndSiteWithTrans.getName() ) siteShapeRefElmt = XmlObject( "site-shape-ref", bindingRefElmt ) siteShapeRefElmt.addAttribute( "name", transformation )
def __writeModificationExchanges(self, reaction, parElmt): modExchanges = XmlObject("modification-exchanges", parElmt) omniplex = reaction.getProducts()[0] for ndx in range(len(omniplex.getMols())): mol = omniplex.getMols()[ndx] if mol.isSmallMol(): continue for mod_site in mol.getModificationSites(): modExchange = XmlObject("modification-exchange", modExchanges) modMolInstance = XmlObject("mod-mol-instance-ref", modExchange) modMolInstance.addAttribute( "name", self.getMolName(mol.getName(), ndx)) modSiteRefElmt = XmlObject("mod-site-ref", modMolInstance) modSiteRefElmt.addAttribute("name", mod_site.getName()) installedModRefElmt = XmlObject("installed-mod-ref", modExchange) installedModRefElmt.addAttribute( "name", mod_site.getModificationSiteSpecification().getList()[0]) return
def addModMolElmtToMolsElmt(self, xmlObject, moleculizerMolObject): assert (isinstance(xmlObject, XmlObject)) assert (isinstance(moleculizerMolObject, MoleculizerMol)) newModMol = XmlObject("mod-mol") newModMol.addAttribute("name", moleculizerMolObject.getName()) weightElement = XmlObject("weight") # Obviously this is one of the big deficiencies of this thing. What shall # we set the (mandatory) weights to? For now, let's just put in something # arbitratry. But this is a big issue that ought to be fixed as soon as all # the basic facilities of the code have been built in. if moleculizerMolObject.getName() == "Pheromone": weightElement.addAttribute("daltons", 10.0) else: weightElement.addAttribute("daltons", 100.0) newModMol.addSubElement(weightElement) for binding in moleculizerMolObject.bindingSites: self.addBindingSiteElmtToModMolElmt(binding, moleculizerMolObject, newModMol) for modification in moleculizerMolObject.modificationSites: modSite, defaultModState = modification modSiteElmt = XmlObject("mod-site") modSiteElmt.addAttribute("name", modSite) defModRefElmt = XmlObject("default-mod-ref") defModRefElmt.addAttribute("name", defaultModState) defModRefElmt.attachToParent(modSiteElmt).attachToParent(newModMol) xmlObject.addSubElement(newModMol) return
def writeOmniGenLineToParent(self, line, parElmt): omniGenElment = XmlObject("omni-gen", parElmt) reaction = line.getParsedComponents()[0] enablingOmniplex = reaction.getReactants()[0] additionalReactant = 0 if len(reaction.getReactants()) > 1: additionalReactant = reaction.getReactants()[1] product = reaction.getProducts()[0] additionalProduct = 0 if len(reaction.getProducts()) > 1: additionalProduct = reaction.getProducts()[1] self.__writeEnablingOmniPlexElementToXml(enablingOmniplex, omniGenElment) self.__writeModificationExchanges( reaction, omniGenElment) self.__writeSmallMolExchange( reaction, omniGenElment) rateElmt = XmlObject("rate", omniGenElment) rateElmt.addAttribute("value", line.getAssignment("k")) return
def __writeModMolInstanceToInstanceStates(self, parsedMol, molNdx, parentElmt): modMolInstanceRefElmt = XmlObject("mod-mol-instance-ref", parentElmt) modMolInstanceRefElmt.addAttribute("name", self.getMolName( parsedMol.getName(), molNdx)) modMapElmt = XmlObject("mod-map", modMolInstanceRefElmt) for modSite in parsedMol.getModificationSites(): modSiteRefElmt = XmlObject("mod-site-ref", modMapElmt) modSiteRefElmt.addAttribute("name", modSite.getName()) modRefElmt = XmlObject("mod-ref", modSiteRefElmt) modRefElmt.addAttribute("name", modSite.getModificationSiteSpecification().getList()[0])
def __writeModMolInstanceToInstanceStates(self, parsedMol, molNdx, parentElmt): modMolInstanceRefElmt = XmlObject("mod-mol-instance-ref", parentElmt) modMolInstanceRefElmt.addAttribute( "name", self.getMolName(parsedMol.getName(), molNdx)) modMapElmt = XmlObject("mod-map", modMolInstanceRefElmt) for modSite in parsedMol.getModificationSites(): modSiteRefElmt = XmlObject("mod-site-ref", modMapElmt) modSiteRefElmt.addAttribute("name", modSite.getName()) modRefElmt = XmlObject("mod-ref", modSiteRefElmt) modRefElmt.addAttribute( "name", modSite.getModificationSiteSpecification().getList()[0])
def addBindingSiteElmtToModMolElmt(self, bindingName, moleculizerMol, xmlObject): newBindingElmt = XmlObject("binding-site") newBindingElmt.addAttribute("name", bindingName) defaultShape = XmlObject("default-shape-ref") defaultShape.addAttribute("name", "default") defaultShape.attachToParent(newBindingElmt) for shapeName in moleculizerMol.bindingSites[bindingName]: siteShapeElmt = XmlObject("site-shape") siteShapeElmt.addAttribute("name", shapeName) siteShapeElmt.attachToParent(newBindingElmt) xmlObject.addSubElement(newBindingElmt) return
def writeParsedComplexInstanceStates(self, complex, xmlobject): # This is quite inelegant, but I can't obviously think of a # better way to do it. for mol_ndx, parsed_mol in enumerate(complex.getMols()): if not parsed_mol.isModMol(): continue if not parsed_mol.getModificationSiteList(): continue break else: # If we get return instanceStatesElmt = XmlObject("instance-states", xmlobject) # For each mol in complex which is a mod map that has modifications specified for mol_ndx, parsed_mol in enumerate(complex.getMols()): if not parsed_mol.isModMol(): continue if not parsed_mol.getModificationSiteList(): continue modMolInstanceRef = XmlObject("mod-mol-instance-ref", instanceStatesElmt) modMolInstanceRef.addAttribute( "name", self.getMolName( parsed_mol.getName(), mol_ndx )) modMapElmt = XmlObject("mod-map", modMolInstanceRef) for modification in parsed_mol.getModificationSites(): modSiteRefNameElmt = XmlObject("mod-site-ref", modMapElmt) modSiteRefNameElmt.addAttribute("name", modification.getName()) modRefElmt = XmlObject("mod-ref", modSiteRefNameElmt) modState = modification.getModificationSiteSpecification().getList()[0] modRefElmt.addAttribute("name", modState) return
def __writeModificationExchanges( self, reaction, parElmt): modExchanges = XmlObject("modification-exchanges", parElmt) omniplex = reaction.getProducts()[0] for ndx in range(len(omniplex.getMols())): mol = omniplex.getMols()[ndx] if mol.isSmallMol(): continue for mod_site in mol.getModificationSites(): modExchange = XmlObject("modification-exchange", modExchanges) modMolInstance = XmlObject("mod-mol-instance-ref", modExchange) modMolInstance.addAttribute("name", self.getMolName( mol.getName(), ndx)) modSiteRefElmt = XmlObject("mod-site-ref", modMolInstance) modSiteRefElmt.addAttribute("name", mod_site.getName()) installedModRefElmt = XmlObject("installed-mod-ref", modExchange) installedModRefElmt.addAttribute("name", mod_site.getModificationSiteSpecification().getList()[0]) return
def writeAllostericSitesElementToElement(self, parsedComplex, parentElement): allostericSitesElmt = XmlObject("allosteric-sites", parentElement) for ndx in range(len(parsedComplex.getMols())): mol = parsedComplex.getMols()[ndx] if mol.isSmallMol(): continue # [x for x in mol.getBindingSites() \ # if x.hasBindingSiteSpecification() and \ # x.getBindingSiteSpecification().hasShapeSpecification() and \ # x.getBindingSiteSpecification().getShapeSpecification().isTransformation() ]: for bndSiteWithTrans in [x for x in mol.getBindingSites() \ if x.hasBindingSiteSpecification() and \ x.getBindingSiteSpecification().hasShapeSpecification() and \ x.getBindingSiteSpecification().getShapeSpecification().isTransformation() ]: try: transformation = bndSiteWithTrans.getBindingSiteSpecification( ).getShapeSpecification().getTransformation() except: pdb.set_trace() a = 10 raise e molElmt = XmlObject("mol-instance-ref", allostericSitesElmt) molElmt.addAttribute("name", self.getMolName(mol.getName(), ndx)) bindingRefElmt = XmlObject("binding-site-ref", molElmt) bindingRefElmt.addAttribute("name", bndSiteWithTrans.getName()) siteShapeRefElmt = XmlObject("site-shape-ref", bindingRefElmt) siteShapeRefElmt.addAttribute("name", transformation)
def addAllostericOmnis(self, allostericOmnisElement): # pdb.set_trace() for bindingWithAllostery in self.allosteryMapping.keys(): owningMolName, allostericBindingSiteName = bindingWithAllostery complexAllosteryPairs = [(key, self.allosteryMapping[bindingWithAllostery][key]) for key in self.allosteryMapping[bindingWithAllostery].keys()] for complex_allostery_pair in complexAllosteryPairs: complex, allostericName = complex_allostery_pair if allostericName == "default": continue allostericOmniElmt = XmlObject("allosteric-omni") allostericOmnisElement.addSubElement(allostericOmniElmt) # Now prepare the four sub-elements plexElmt = XmlObject("plex") instanceStatesElmt = XmlObject("instance-states") unboundSitesElmt = XmlObject("unbound-sites") boundSitesElmt = XmlObject("bound-sites") allostericStatesElmt = XmlObject("allosteric-sites") # First we construct the molRefToInstanceDict molRefToInstanceDict = {} tmpMolInstanceInt = {} molArray = complex.split('.') for molNdx in xrange(len(molArray)): mol = molArray[molNdx] parenNdx = mol.find("(") molType = mol[:parenNdx] if molType not in tmpMolInstanceInt: tmpMolInstanceInt[molType] = 1 molInstance = "the-" + molType else: molInstance = molType + "-" + str(tmpMolInstanceInt[molType]) tmpMolInstanceInt[molType] = tmpMolInstanceInt[molType] + 1 molRefToInstanceDict[molInstance] = molType molArray[molNdx] = molInstance + mol[parenNdx:] # So now we calculate -- the plex. bindingDict = {} genericBoundSitesArray = [] unboundSitesArray = [] modificationSitesArray = [] for molSpec in molArray: # Process the molNames molInstance = util.getMolNameFromFullMolSpec(molSpec) molInstanceElmt = XmlObject("mol-instance") molInstanceElmt.addAttribute("name", molInstance) molRefElmt = XmlObject("mol-ref") molRefElmt.addAttribute("name", molRefToInstanceDict[molInstance]) molRefElmt.attachToParent(molInstanceElmt).attachToParent(plexElmt) # Collect the bindings bindingSites = util.getBindingSites(molSpec) explicitlyBoundBindingSites = [x.split("!") for x in bindingSites if ("!" in x and x[-1] != "!" and x[-1] != "+")] boundBindingSites = [x.split("!") for x in bindingSites if ("!" in x and x[-1] != "!" and x[-1] == "+")] unboundBindingSites = [x for x in bindingSites if "!" not in x] modificationSites = [x.split("~") for x in util.getModificationList(molSpec)] for halfBinding in explicitlyBoundBindingSites: bindingSite, bindingNdx = halfBinding[0], int(halfBinding[1]) if not bindingNdx in bindingDict: bindingDict[bindingNdx] = [] bindingDict[bindingNdx].append( (molInstance, bindingSite)) # Collect the unbound binding sites. for unboundBindingSite in unboundBindingSites: unboundSitesArray.append( (molInstance, unboundBindingSite) ) for boundSite in boundBindingSites: genericBoundSitesArray.append( (molInstance, boundSite[0])) for modificationSite in modificationSites: modificationSitesArray.append( (molInstance, modificationSite[0], modificationSite[1])) # Do the bindings listOfBindings = [ bindingDict[key] for key in bindingDict.keys()] for binding in listOfBindings: try: assert(len(binding)==2) except: pdb.set_trace() a = 1 for binding in listOfBindings: bindingElmt = XmlObject("binding") bindingElmt.attachToParent(plexElmt) for halfBinding in binding: molInstance, bindingRef = halfBinding molInstanceRefElmt = XmlObject("mol-instance-ref") molInstanceRefElmt.addAttribute("name", molInstance) bindingSiteRefElmt = XmlObject("binding-site-ref") bindingSiteRefElmt.addAttribute("name", bindingRef) bindingSiteRefElmt.attachToParent(molInstanceRefElmt).attachToParent(bindingElmt) # Now we add in the modificationSitesArray for modMolName in set( [ x[0] for x in modificationSitesArray]): modMolModifications = [x for x in modificationSitesArray if x[0] == modMolName] modMolInstanceRefElmt = XmlObject("mod-mol-instance-ref") modMolInstanceRefElmt.attachToParent(instanceStatesElmt) modMolInstanceRefElmt.addAttribute("name", modMolName) modMapElmt = XmlObject("mod-map") modMapElmt.attachToParent(modMolInstanceRefElmt) for modification in modMolModifications: modSiteRefElmt = XmlObject("mod-site-ref") modSiteRefElmt.addAttribute("name", modification[1]) modRefElmt = XmlObject("mod-ref") modRefElmt.addAttribute("name", modification[2]) modRefElmt.attachToParent(modSiteRefElmt).attachToParent(modMapElmt) # Now we add in the unboundSitesArray for molWithUnboundBindings in set( [ x[0] for x in unboundSitesArray]): unboundSites = [x for x in unboundSitesArray if x[0] == molWithUnboundBindings] for site in unboundSites: instanceRefElmt = XmlObject("instance-ref") instanceRefElmt.addAttribute("name", molWithUnboundBindings) siteRefElmt = XmlObject("site-ref") siteRefElmt.addAttribute("name", site[1]) siteRefElmt.attachToParent(instanceRefElmt).attachToParent(unboundSitesElmt) # Now we add in the boundSitesArray for molWithGenericBoundBindings in set([ x[0] for x in genericBoundSitesArray]): genericBoundSites = [x for x in genericBoundSitesArray if x[0] == molWithGenericBoundBindings] for site in genericBoundSites: instanceRefElmt = XmlObject("instance-ref") instanceRefElmt.addAttribute("name", molWithGenericBoundBindings) siteRefElmt = XmlObject("site-ref") siteRefElmt.addAttribute("name", site[1]) siteRefElmt.attachToParent(instanceRefElmt).attachToParent(boundSitesElmt) molInstanceRefElmt = XmlObject("mol-instance-ref") molInstanceRefElmt.addAttribute("name", "the-" + owningMolName) bindingSiteRefElmt = XmlObject("binding-site-ref") bindingSiteRefElmt.addAttribute("name", allostericBindingSiteName) siteShapeRefElmt = XmlObject("site-shape-ref") siteShapeRefElmt.addAttribute("name", allostericName) siteShapeRefElmt.attachToParent(bindingSiteRefElmt).attachToParent(molInstanceRefElmt).attachToParent(allostericStatesElmt) ## End of function plexElmt.attachToParent(allostericOmniElmt) if instanceStatesElmt.getNumberOfChildren() > 0: instanceStatesElmt.attachToParent(allostericOmniElmt) if unboundSitesElmt.getNumberOfChildren() > 0: unboundSitesElmt.attachToParent(allostericOmniElmt) if boundSitesElmt.getNumberOfChildren(): boundSitesElmt.attachToParent(allostericOmniElmt) allostericStatesElmt.attachToParent(allostericOmniElmt)
def writeParsedComplexAsPlex( self, complex, xmlobject): plexElmt = XmlObject( "plex", xmlobject) for ndx in range(len(complex.getMols())): parsedMol = complex.getMols()[ndx] molInst = XmlObject("mol-instance", plexElmt) molInst.addAttribute( "name", self.getMolName( parsedMol.getName(), ndx )) molTypeElmt = XmlObject("mol-ref", molInst) molTypeElmt.addAttribute( "name", parsedMol.getName() ) for bindingID in complex.getBindings().keys(): # Find the two bindings with that newBindingElmt = XmlObject("binding", plexElmt) try: molNdx1, molNdx2 = complex.getBindings()[bindingID] except ValueError: pdb.set_trace() raise Exception("Error unpacking bindings '%s' associated with complex '%s' -- Binding ID only has one value." % (repr(complex.getBindings()[bindingID]), complex.getOriginalLine(), bindingID)) parsedMol1 = complex.getMols()[molNdx1] parsedMol2 = complex.getMols()[molNdx2] bindingSite1 = "" bindingSite2 = "" if parsedMol1.isModMol(): for bindingSite in parsedMol1.getBindingSiteList(): parsedBindingSite = parsedMol1.getBindingSiteWithName( bindingSite ) if parsedBindingSite.hasBindingToken(bindingID): bindingSite1 = parsedBindingSite.getName() break else: print "Error, binding site 1 not found" raise Exception() else: bindingSite1 = parsedMol1.getName() if parsedMol2.isModMol(): for bindingSite in parsedMol2.getBindingSiteList(): bindingSite = parsedMol2.getBindingSiteWithName( bindingSite ) if bindingSite.hasBindingToken( bindingID ): bindingSite2 = bindingSite.getName() break else: print "Error, binding site 2 not found" raise Exception() else: bindingSite2 = parsedMol2.getName() molInstance1 = XmlObject("mol-instance-ref", newBindingElmt) molInstance1.addAttribute( "name", self.getMolName(parsedMol1.getName(), molNdx1)) bindingSiteRef1 = XmlObject("binding-site-ref", molInstance1) bindingSiteRef1.addAttribute("name", bindingSite1) molInstance2 = XmlObject("mol-instance-ref", newBindingElmt) molInstance2.addAttribute( "name", self.getMolName(parsedMol2.getName(), molNdx2)) bindingSiteRef2 = XmlObject("binding-site-ref", molInstance2) bindingSiteRef2.addAttribute("name", bindingSite2) return plexElmt
def writeDimerGenLineToParent( self, line, reactionGens): dimerGen = XmlObject("dimerization-gen", reactionGens) parsedRxn = line.getParsedComponents()[0] theReactants = parsedRxn.getReactants() theProducts = parsedRxn.getProducts() reactant1 = theReactants[0].getMols()[0] reactant2 = theReactants[1].getMols()[0] molSpec1 = XmlObject("mol-ref", dimerGen) molSpec2 = XmlObject("mol-ref", dimerGen) molSpec1.addAttribute("name", reactant1.getName() ) molSpec2.addAttribute("name", reactant2.getName() ) siteRef1 = XmlObject("site-ref", molSpec1) siteRef2 = XmlObject("site-ref", molSpec2) self.__addSiteNameToElement( reactant1, siteRef1) self.__addSiteNameToElement( reactant2, siteRef2) defaultOnElmt = XmlObject("default-on-rate", dimerGen) defaultOffElmt = XmlObject("default-off-rate", dimerGen) defaultOnElmt.addAttribute("value", line.getAssignment("kon")) defaultOffElmt.addAttribute("value", line.getAssignment("koff")) if len( line.getParsedComponents()) == 3: return # Now add the allosteric on- and off- rates. allosteryComponents = line.getParsedComponents()[3:] allostery_index = 3 while (len(allosteryComponents) > 0): # This is used in a hacky way to find the correct parameter alloRatesElmt = XmlObject("allo-rates", dimerGen) alloReactants = allosteryComponents[0].getReactants() siteShapeRef1 = XmlObject("site-shape-ref", alloRatesElmt) siteShapeRef2 = XmlObject("site-shape-ref", alloRatesElmt) onRate = XmlObject("on-rate", alloRatesElmt) offRate = XmlObject("off-rate", alloRatesElmt) if alloReactants[0].getMols()[0].isModMol(): if alloReactants[0].getMols()[0].getBindingSites()[0].hasBindingSiteSpecification(): siteShapeRef1.addAttribute("name", alloReactants[0].getMols()[0].getBindingSites()[0].getBindingSiteSpecification().getShapeSpecification().getShapeList()[0]) else: siteShapeRef1.addAttribute("name", "default") else: siteShapeRef1.addAttribute("name", "default") if alloReactants[1].getMols()[0].isModMol(): if alloReactants[1].getMols()[0].getBindingSites()[0].hasBindingSiteSpecification(): siteShapeRef2.addAttribute("name", alloReactants[1].getMols()[0].getBindingSites()[0].getBindingSiteSpecification().getShapeSpecification().getShapeList()[0]) else: siteShapeRef2.addAttribute("name", "default") else: siteShapeRef2.addAttribute("name", "default") onRate.addAttribute("value", line.getAssignment( "kon", allostery_index) ) offRate.addAttribute("value", line.getAssignment( "koff", allostery_index) ) allosteryComponents = allosteryComponents[3:] allostery_index += 3 return
def writeDimerGenLineToParent(self, line, reactionGens): dimerGen = XmlObject("dimerization-gen", reactionGens) parsedRxn = line.getParsedComponents()[0] theReactants = parsedRxn.getReactants() theProducts = parsedRxn.getProducts() reactant1 = theReactants[0].getMols()[0] reactant2 = theReactants[1].getMols()[0] molSpec1 = XmlObject("mol-ref", dimerGen) molSpec2 = XmlObject("mol-ref", dimerGen) molSpec1.addAttribute("name", reactant1.getName()) molSpec2.addAttribute("name", reactant2.getName()) siteRef1 = XmlObject("site-ref", molSpec1) siteRef2 = XmlObject("site-ref", molSpec2) self.__addSiteNameToElement(reactant1, siteRef1) self.__addSiteNameToElement(reactant2, siteRef2) defaultOnElmt = XmlObject("default-on-rate", dimerGen) defaultOffElmt = XmlObject("default-off-rate", dimerGen) defaultOnElmt.addAttribute("value", line.getAssignment("kon")) defaultOffElmt.addAttribute("value", line.getAssignment("koff")) if len(line.getParsedComponents()) == 3: return # Now add the allosteric on- and off- rates. allosteryComponents = line.getParsedComponents()[3:] allostery_index = 3 while (len(allosteryComponents) > 0): # This is used in a hacky way to find the correct parameter alloRatesElmt = XmlObject("allo-rates", dimerGen) alloReactants = allosteryComponents[0].getReactants() siteShapeRef1 = XmlObject("site-shape-ref", alloRatesElmt) siteShapeRef2 = XmlObject("site-shape-ref", alloRatesElmt) onRate = XmlObject("on-rate", alloRatesElmt) offRate = XmlObject("off-rate", alloRatesElmt) if alloReactants[0].getMols()[0].isModMol(): if alloReactants[0].getMols()[0].getBindingSites( )[0].hasBindingSiteSpecification(): siteShapeRef1.addAttribute( "name", alloReactants[0].getMols() [0].getBindingSites()[0].getBindingSiteSpecification( ).getShapeSpecification().getShapeList()[0]) else: siteShapeRef1.addAttribute("name", "default") else: siteShapeRef1.addAttribute("name", "default") if alloReactants[1].getMols()[0].isModMol(): if alloReactants[1].getMols()[0].getBindingSites( )[0].hasBindingSiteSpecification(): siteShapeRef2.addAttribute( "name", alloReactants[1].getMols() [0].getBindingSites()[0].getBindingSiteSpecification( ).getShapeSpecification().getShapeList()[0]) else: siteShapeRef2.addAttribute("name", "default") else: siteShapeRef2.addAttribute("name", "default") onRate.addAttribute("value", line.getAssignment("kon", allostery_index)) offRate.addAttribute("value", line.getAssignment("koff", allostery_index)) allosteryComponents = allosteryComponents[3:] allostery_index += 3 return
def writeExplicitSpecies(self, parentElmt): for ss in self.seedSpeciesInModel: plexSpeciesElmt = XmlObject("plex-species") plexSpeciesElmt.attachToParent(parentElmt) speciesDefinition, number = ss # Inputs to the species numbers are given in micromolar... # The inputs we have been given are in the form: Dig1_tot_conc=Dig1_num*1e6/(Cell_volume*Avogadros_number) # So to get num we multiply by (Cell_v * Avog) / 1e6. number = number * (6.0221415e23 * 40e-15) / 1e6 plexSpeciesElmt.addAttribute("name", speciesDefinition.constructEntireComplexInstanceName()) plexElmt = XmlObject("plex") plexElmt.attachToParent(plexSpeciesElmt) populationElmt = XmlObject("population") populationElmt.attachToParent(plexSpeciesElmt) populationElmt.addAttribute("count", int(number)) # Make this a method of class bndSpeciesDefinition. for molNdx in speciesDefinition.moleculeRefsInComplex: molReferenceName = speciesDefinition.moleculeRefsInComplex[molNdx] molInstanceName = speciesDefinition.moleculeInstancesInComplex[molNdx] molInstanceElmt = XmlObject("mol-instance") molInstanceElmt.addAttribute("name", molInstanceName) molReferenceElmt = XmlObject("mol-ref") molReferenceElmt.addAttribute("name", molReferenceName) molReferenceElmt.attachToParent(molInstanceElmt).attachToParent(plexElmt) for bindingNdx in speciesDefinition.bindings: bindingElmt = XmlObject("binding") bindingElmt.attachToParent(plexElmt) for hb in speciesDefinition.bindings[bindingNdx]: molInstanceRefElmt = XmlObject("mol-instance-ref") molInstanceRefElmt.addAttribute("name", speciesDefinition.moleculeInstancesInComplex[hb[0]]) bindingSiteRefElmt = XmlObject("binding-site-ref") bindingSiteRefElmt.addAttribute("name", hb[1]) bindingSiteRefElmt.attachToParent(molInstanceRefElmt).attachToParent(bindingElmt)
def __addVolume(self, parentObject): ## So far, there is a parameter "Cell_volume" that does this. volumeElement = XmlObject("volume") volumeElement.addAttribute( "liters", self.parameterEE.getVariableValue("Cell_volume")) parentObject.addSubElement(volumeElement)
def addModMolToXml(self, parsedMol, xmlObject): modMolElmt = XmlObject("mod-mol") modMolElmt.attachToParent(xmlObject) modMolElmt.addAttribute("name", parsedMol.getName()) for bindingSiteName in parsedMol.getBindingSiteList(): bindingSiteElmt = XmlObject("binding-site") bindingSiteElmt.attachToParent(modMolElmt) bindingSiteElmt.addAttribute("name", bindingSiteName) parsedBindingSite = parsedMol.getBindingSiteWithName( bindingSiteName) if (parsedBindingSite.hasBindingSiteSpecification() and parsedBindingSite.getBindingSiteSpecification( ).hasShapeSpecification()): bindingShapeNames = parsedBindingSite.getBindingSiteSpecification( ).getShapeSpecification().getShapeList() assert (len(bindingShapeNames) > 0) defaultShapeElmt = XmlObject("default-shape-ref") defaultShapeElmt.addAttribute("name", bindingShapeNames[0]) defaultShapeElmt.attachToParent(bindingSiteElmt) for shape_name in bindingShapeNames: newShapeElmt = XmlObject("site-shape") newShapeElmt.addAttribute("name", shape_name) newShapeElmt.attachToParent(bindingSiteElmt) else: defaultShapeElmt = XmlObject("default-shape-ref") defaultShapeElmt.addAttribute("name", "default") defaultShapeElmt.attachToParent(bindingSiteElmt) shapeElmt = XmlObject("site-shape") shapeElmt.addAttribute("name", "default") shapeElmt.attachToParent(bindingSiteElmt) for modSiteName in parsedMol.getModificationSiteList(): modSiteElmt = XmlObject("mod-site", modMolElmt) modSiteElmt.addAttribute("name", modSiteName) parsedModificationSite = parsedMol.getModificationSiteWithName( modSiteName) if not parsedModificationSite.hasModificationSiteSpecification(): defaultModElmt = XmlObject("default-mod-ref", modSiteElmt) defaultModElmt.addAttribute("name", "none") else: modValueArray = parsedModificationSite.getModificationSiteSpecification( ).getList() try: assert (len(modValueArray) > 1) except: print "Error, in sectionmols::addModMolToXml for mol with line '%s'. Mod Value Array '%s' should have more than one component..." % ( parsedMol.getOriginalLine(), str(modValueArray)) defaultModification = modValueArray[0] defaultModElmt = XmlObject("default-mod-ref", modSiteElmt) defaultModElmt.addAttribute("name", defaultModification) return modMolElmt
def addAllostericOmnis(self, allostericOmnisElement): # pdb.set_trace() for bindingWithAllostery in self.allosteryMapping.keys(): owningMolName, allostericBindingSiteName = bindingWithAllostery complexAllosteryPairs = [ (key, self.allosteryMapping[bindingWithAllostery][key]) for key in self.allosteryMapping[bindingWithAllostery].keys() ] for complex_allostery_pair in complexAllosteryPairs: complex, allostericName = complex_allostery_pair if allostericName == "default": continue allostericOmniElmt = XmlObject("allosteric-omni") allostericOmnisElement.addSubElement(allostericOmniElmt) # Now prepare the four sub-elements plexElmt = XmlObject("plex") instanceStatesElmt = XmlObject("instance-states") unboundSitesElmt = XmlObject("unbound-sites") boundSitesElmt = XmlObject("bound-sites") allostericStatesElmt = XmlObject("allosteric-sites") # First we construct the molRefToInstanceDict molRefToInstanceDict = {} tmpMolInstanceInt = {} molArray = complex.split(".") for molNdx in xrange(len(molArray)): mol = molArray[molNdx] parenNdx = mol.find("(") molType = mol[:parenNdx] if molType not in tmpMolInstanceInt: tmpMolInstanceInt[molType] = 1 molInstance = "the-" + molType else: molInstance = molType + "-" + str(tmpMolInstanceInt[molType]) tmpMolInstanceInt[molType] = tmpMolInstanceInt[molType] + 1 molRefToInstanceDict[molInstance] = molType molArray[molNdx] = molInstance + mol[parenNdx:] # So now we calculate -- the plex. bindingDict = {} genericBoundSitesArray = [] unboundSitesArray = [] modificationSitesArray = [] for molSpec in molArray: # Process the molNames molInstance = util.getMolNameFromFullMolSpec(molSpec) molInstanceElmt = XmlObject("mol-instance") molInstanceElmt.addAttribute("name", molInstance) molRefElmt = XmlObject("mol-ref") molRefElmt.addAttribute("name", molRefToInstanceDict[molInstance]) molRefElmt.attachToParent(molInstanceElmt).attachToParent(plexElmt) # Collect the bindings bindingSites = util.getBindingSites(molSpec) explicitlyBoundBindingSites = [ x.split("!") for x in bindingSites if ("!" in x and x[-1] != "!" and x[-1] != "+") ] boundBindingSites = [ x.split("!") for x in bindingSites if ("!" in x and x[-1] != "!" and x[-1] == "+") ] unboundBindingSites = [x for x in bindingSites if "!" not in x] modificationSites = [x.split("~") for x in util.getModificationList(molSpec)] for halfBinding in explicitlyBoundBindingSites: bindingSite, bindingNdx = halfBinding[0], int(halfBinding[1]) if not bindingNdx in bindingDict: bindingDict[bindingNdx] = [] bindingDict[bindingNdx].append((molInstance, bindingSite)) # Collect the unbound binding sites. for unboundBindingSite in unboundBindingSites: unboundSitesArray.append((molInstance, unboundBindingSite)) for boundSite in boundBindingSites: genericBoundSitesArray.append((molInstance, boundSite[0])) for modificationSite in modificationSites: modificationSitesArray.append((molInstance, modificationSite[0], modificationSite[1])) # Do the bindings listOfBindings = [bindingDict[key] for key in bindingDict.keys()] for binding in listOfBindings: try: assert len(binding) == 2 except: pdb.set_trace() a = 1 for binding in listOfBindings: bindingElmt = XmlObject("binding") bindingElmt.attachToParent(plexElmt) for halfBinding in binding: molInstance, bindingRef = halfBinding molInstanceRefElmt = XmlObject("mol-instance-ref") molInstanceRefElmt.addAttribute("name", molInstance) bindingSiteRefElmt = XmlObject("binding-site-ref") bindingSiteRefElmt.addAttribute("name", bindingRef) bindingSiteRefElmt.attachToParent(molInstanceRefElmt).attachToParent(bindingElmt) # Now we add in the modificationSitesArray for modMolName in set([x[0] for x in modificationSitesArray]): modMolModifications = [x for x in modificationSitesArray if x[0] == modMolName] modMolInstanceRefElmt = XmlObject("mod-mol-instance-ref") modMolInstanceRefElmt.attachToParent(instanceStatesElmt) modMolInstanceRefElmt.addAttribute("name", modMolName) modMapElmt = XmlObject("mod-map") modMapElmt.attachToParent(modMolInstanceRefElmt) for modification in modMolModifications: modSiteRefElmt = XmlObject("mod-site-ref") modSiteRefElmt.addAttribute("name", modification[1]) modRefElmt = XmlObject("mod-ref") modRefElmt.addAttribute("name", modification[2]) modRefElmt.attachToParent(modSiteRefElmt).attachToParent(modMapElmt) # Now we add in the unboundSitesArray for molWithUnboundBindings in set([x[0] for x in unboundSitesArray]): unboundSites = [x for x in unboundSitesArray if x[0] == molWithUnboundBindings] for site in unboundSites: instanceRefElmt = XmlObject("instance-ref") instanceRefElmt.addAttribute("name", molWithUnboundBindings) siteRefElmt = XmlObject("site-ref") siteRefElmt.addAttribute("name", site[1]) siteRefElmt.attachToParent(instanceRefElmt).attachToParent(unboundSitesElmt) # Now we add in the boundSitesArray for molWithGenericBoundBindings in set([x[0] for x in genericBoundSitesArray]): genericBoundSites = [x for x in genericBoundSitesArray if x[0] == molWithGenericBoundBindings] for site in genericBoundSites: instanceRefElmt = XmlObject("instance-ref") instanceRefElmt.addAttribute("name", molWithGenericBoundBindings) siteRefElmt = XmlObject("site-ref") siteRefElmt.addAttribute("name", site[1]) siteRefElmt.attachToParent(instanceRefElmt).attachToParent(boundSitesElmt) molInstanceRefElmt = XmlObject("mol-instance-ref") molInstanceRefElmt.addAttribute("name", "the-" + owningMolName) bindingSiteRefElmt = XmlObject("binding-site-ref") bindingSiteRefElmt.addAttribute("name", allostericBindingSiteName) siteShapeRefElmt = XmlObject("site-shape-ref") siteShapeRefElmt.addAttribute("name", allostericName) siteShapeRefElmt.attachToParent(bindingSiteRefElmt).attachToParent(molInstanceRefElmt).attachToParent( allostericStatesElmt ) ## End of function plexElmt.attachToParent(allostericOmniElmt) if instanceStatesElmt.getNumberOfChildren() > 0: instanceStatesElmt.attachToParent(allostericOmniElmt) if unboundSitesElmt.getNumberOfChildren() > 0: unboundSitesElmt.attachToParent(allostericOmniElmt) if boundSitesElmt.getNumberOfChildren(): boundSitesElmt.attachToParent(allostericOmniElmt) allostericStatesElmt.attachToParent(allostericOmniElmt)
def __addVolume(self, parentObject): ## So far, there is a parameter "Cell_volume" that does this. volumeElement = XmlObject("volume") volumeElement.addAttribute("liters", self.parameterEE.getVariableValue("Cell_volume")) parentObject.addSubElement(volumeElement)
def addModMolToXml( self, parsedMol, xmlObject): modMolElmt = XmlObject( "mod-mol") modMolElmt.attachToParent(xmlObject) modMolElmt.addAttribute( "name", parsedMol.getName() ) for bindingSiteName in parsedMol.getBindingSiteList(): bindingSiteElmt = XmlObject("binding-site") bindingSiteElmt.attachToParent( modMolElmt) bindingSiteElmt.addAttribute("name", bindingSiteName) parsedBindingSite = parsedMol.getBindingSiteWithName( bindingSiteName ) if( parsedBindingSite.hasBindingSiteSpecification() and parsedBindingSite.getBindingSiteSpecification().hasShapeSpecification()): bindingShapeNames = parsedBindingSite.getBindingSiteSpecification().getShapeSpecification().getShapeList() assert( len(bindingShapeNames) > 0 ) defaultShapeElmt = XmlObject("default-shape-ref") defaultShapeElmt.addAttribute("name", bindingShapeNames[0] ) defaultShapeElmt.attachToParent( bindingSiteElmt ) for shape_name in bindingShapeNames: newShapeElmt = XmlObject("site-shape") newShapeElmt.addAttribute("name", shape_name) newShapeElmt.attachToParent( bindingSiteElmt ) else: defaultShapeElmt = XmlObject( "default-shape-ref" ) defaultShapeElmt.addAttribute( "name", "default") defaultShapeElmt.attachToParent( bindingSiteElmt ) shapeElmt = XmlObject("site-shape") shapeElmt.addAttribute("name", "default") shapeElmt.attachToParent( bindingSiteElmt ) for modSiteName in parsedMol.getModificationSiteList(): modSiteElmt = XmlObject("mod-site", modMolElmt) modSiteElmt.addAttribute("name", modSiteName) parsedModificationSite = parsedMol.getModificationSiteWithName( modSiteName ) if not parsedModificationSite.hasModificationSiteSpecification(): defaultModElmt = XmlObject("default-mod-ref", modSiteElmt) defaultModElmt.addAttribute("name", "none") else: modValueArray = parsedModificationSite.getModificationSiteSpecification().getList() try: assert( len(modValueArray) > 1) except: print "Error, in sectionmols::addModMolToXml for mol with line '%s'. Mod Value Array '%s' should have more than one component..." % ( parsedMol.getOriginalLine(), str(modValueArray) ) defaultModification = modValueArray[0] defaultModElmt = XmlObject("default-mod-ref", modSiteElmt) defaultModElmt.addAttribute("name", defaultModification ) return modMolElmt
def writeParsedComplexAsPlex( self, complex, xmlobject, writeComplexInstanceStates = False, writeBoundUnboundStates = False): # if writeBoundUnboundStates: # This should be a list of things like (2, 1, +) = the # first binding on the second mol must be bound. patternMatchingSitesSpec = complex.externalizePatternMatchingSites() plexElmt = XmlObject( "plex", xmlobject) for ndx in range(len(complex.getMols())): parsedMol = complex.getMols()[ndx] molInst = XmlObject("mol-instance", plexElmt) molInst.addAttribute( "name", self.getMolName( parsedMol.getName(), ndx )) molTypeElmt = XmlObject("mol-ref", molInst) molTypeElmt.addAttribute( "name", parsedMol.getName() ) for bindingID in complex.getBindings().keys(): # Find the two bindings with that newBindingElmt = XmlObject("binding", plexElmt) try: molNdx1, molNdx2 = complex.getBindings()[bindingID] except ValueError: raise Exception("Error unpacking bindings '%s' associated with complex '%s' -- Binding ID only has one value." % (repr(complex.getBindings()[bindingID]), complex.getOriginalLine(), bindingID)) parsedMol1 = complex.getMols()[molNdx1] parsedMol2 = complex.getMols()[molNdx2] bindingSite1 = "" bindingSite2 = "" if parsedMol1.isModMol(): for bindingSite in parsedMol1.getBindingSiteList(): parsedBindingSite = parsedMol1.getBindingSiteWithName( bindingSite ) if parsedBindingSite.hasBindingToken(bindingID): bindingSite1 = parsedBindingSite.getName() break else: print "Error, binding site 1 not found" raise Exception() else: bindingSite1 = parsedMol1.getName() if parsedMol2.isModMol(): for bindingSite in parsedMol2.getBindingSiteList(): bindingSite = parsedMol2.getBindingSiteWithName( bindingSite ) if bindingSite.hasBindingToken( bindingID ): bindingSite2 = bindingSite.getName() break else: print "Error, binding site 2 not found" raise Exception() else: bindingSite2 = parsedMol2.getName() molInstance1 = XmlObject("mol-instance-ref", newBindingElmt) molInstance1.addAttribute( "name", self.getMolName(parsedMol1.getName(), molNdx1)) bindingSiteRef1 = XmlObject("binding-site-ref", molInstance1) bindingSiteRef1.addAttribute("name", bindingSite1) molInstance2 = XmlObject("mol-instance-ref", newBindingElmt) molInstance2.addAttribute( "name", self.getMolName(parsedMol2.getName(), molNdx2)) bindingSiteRef2 = XmlObject("binding-site-ref", molInstance2) bindingSiteRef2.addAttribute("name", bindingSite2) #pdb.set_trace() if writeComplexInstanceStates: self.writeParsedComplexInstanceStates(complex, xmlobject) if writeBoundUnboundStates: self.writeBoundUnboundStates(complex, patternMatchingSitesSpec, xmlobject) return plexElmt