Example #1
0
    def addSmallMolToXml( self, parsedSmallMol, xmlElement ):
        smallMolElt = XmlObject("small-mol")
        smallMolElt.addAttribute( "name", parsedSmallMol.getName() )

        smallMolElt.attachToParent( xmlElement)

        return smallMolElt
Example #2
0
    def addSmallMolToXml(self, parsedSmallMol, xmlElement):
        smallMolElt = XmlObject("small-mol")
        smallMolElt.addAttribute("name", parsedSmallMol.getName())

        smallMolElt.attachToParent(xmlElement)

        return smallMolElt
    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 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 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 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 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 __constructXMLRepresentation(self):
        rootNode = XmlObject("moleculizer-input")
        modelElmt = XmlObject("model")
        modelElmt.attachToParent(rootNode)

        self.__addModifications(modelElmt)
        self.__addMols(modelElmt)
        self.__addAllostericPlexes(modelElmt)
        self.__addAllostericOmnis(modelElmt)
        self.__addReactionGens(modelElmt)
        self.__addExplicitSpecies(modelElmt)
        self.__addExplicitReactions(modelElmt)
        self.__addVolume(modelElmt)

        # This adds the streams and events elements.
        if self.streamsAndEventsFile:
            rootNode.addSubFile(self.streamsAndEventsFile)

        return rootNode
    def __constructXMLRepresentation(self):
        rootNode = XmlObject("moleculizer-input")
        modelElmt = XmlObject("model")
        modelElmt.attachToParent(rootNode)

        self.__addModifications( modelElmt )
        self.__addMols( modelElmt )
        self.__addAllostericPlexes( modelElmt )
        self.__addAllostericOmnis( modelElmt )
        self.__addReactionGens( modelElmt )
        self.__addExplicitSpecies( modelElmt )
        self.__addExplicitReactions( modelElmt )
        self.__addVolume( modelElmt )

        # This adds the streams and events elements.
        if self.streamsAndEventsFile:
            rootNode.addSubFile(self.streamsAndEventsFile)

        return rootNode
Example #10
0
    def __constructXMLRepresentation(self):

        rootNode = XmlObject("moleculizer-input")
        modelElmt = XmlObject("model")
        modelElmt.attachToParent(rootNode)

        streamsElmt = XmlObject("streams", rootNode)

        self.__addModifications(modelElmt)

        self.__addMols(modelElmt)
        self.__addAllostericPlexes(modelElmt)
        self.__addAllostericOmnis(modelElmt)
        self.__addReactionGens(modelElmt)
        self.__addExplicitSpecies(modelElmt)
        self.__addExplicitReactions(modelElmt)

        self.__addSpeciesStreams(streamsElmt)

        return rootNode
Example #11
0
    def __constructXMLRepresentation(self):
        
        rootNode = XmlObject("moleculizer-input")
        modelElmt = XmlObject("model")
        modelElmt.attachToParent(rootNode)

        streamsElmt = XmlObject("streams", rootNode)

        self.__addModifications( modelElmt )

        self.__addMols( modelElmt )
        self.__addAllostericPlexes( modelElmt )
        self.__addAllostericOmnis( modelElmt )
        self.__addReactionGens( modelElmt )
        self.__addExplicitSpecies( modelElmt )
        self.__addExplicitReactions( modelElmt )

        self.__addSpeciesStreams( streamsElmt )

        return rootNode
    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
Example #13
0
    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
Example #14
0
 def __addAllostericPlexes(self, parentObject):
     allostericPlexesElmt = XmlObject("allosteric-plexes")
     allostericPlexesElmt.attachToParent(parentObject)
Example #15
0
 def __addAllostericOmnis(self, parentObject):
     allostericOmnisElmt = XmlObject("allosteric-omnis")
     allostericOmnisElmt.attachToParent(parentObject)
     self.reactionRules.addAllostericOmnis(allostericOmnisElmt)
Example #16
0
 def __addReactionGens(self, parentObject):
     rxnGenElmt = XmlObject("reaction-gens")
     rxnGenElmt.attachToParent(parentObject)
     self.reactionRules.writeReactionGensElement(rxnGenElmt)
Example #17
0
    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 __addMols(self, parentObject):
     molsElmt = XmlObject("mols")
     molsElmt.attachToParent(parentObject)
     self.moleculeDictionary.addMols(molsElmt)
Example #19
0
 def __addModifications(self, parentObject):
     modificationListElmt = XmlObject("modifications")
     modificationListElmt.attachToParent(parentObject)
     self.moleculeDictionary.addModifications(modificationListElmt)
Example #20
0
    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)
Example #21
0
    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 __addAllostericOmnis(self, parentObject):
     allostericOmnisElmt = XmlObject("allosteric-omnis")
     allostericOmnisElmt.attachToParent(parentObject)
     self.reactionRules.addAllostericOmnis(allostericOmnisElmt)
 def __addAllostericPlexes(self, parentObject):
     allostericPlexesElmt = XmlObject("allosteric-plexes")
     allostericPlexesElmt.attachToParent(parentObject)
Example #24
0
 def __addMols(self, parentObject):
     molsElmt = XmlObject("mols")
     molsElmt.attachToParent(parentObject)
     self.moleculeDictionary.addMols(molsElmt)
Example #25
0
 def __addExplicitSpecies(self, parentObject):
     explicitSpeciesElmt = XmlObject("explicit-species")
     explicitSpeciesElmt.attachToParent(parentObject)
     self.seedSpecies.writeExplicitSpecies(explicitSpeciesElmt)
 def __addReactionGens(self, parentObject):
     rxnGenElmt = XmlObject("reaction-gens")
     rxnGenElmt.attachToParent(parentObject)
     self.reactionRules.writeReactionGensElement(rxnGenElmt)
 def __addModifications(self, parentObject):
     modificationListElmt = XmlObject("modifications")
     modificationListElmt.attachToParent(parentObject)
     self.moleculeDictionary.addModifications(modificationListElmt)
    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 __addExplicitSpecies(self, parentObject):
     explicitSpeciesElmt = XmlObject("explicit-species")
     explicitSpeciesElmt.attachToParent(parentObject)
     self.seedSpecies.writeExplicitSpecies(explicitSpeciesElmt)