Exemplo n.º 1
0
    def findAll(self, structure):
        """ Use the description of this matcher to find all examples in structure.
        """
        matches = []

        # top level is Structure -> search through combinations of Chains
        if self.description.levelCode == "S":
            logging.debug("structure description")

            # select chains of a particular type and get matches
            matchMap = {}
            chainIDLists = []
            for chainDescription in self.description:
                chainIDs = []
                for chain in structure.chainsOfType(chainDescription.chainType):
                    matchMap[chain.chainID] = self.findMatchesInChain(chainDescription, chain)
                    logging.debug("adding chain %s" % chain.chainID)
                    chainIDs.append(chain.chainID)
                chainIDLists.append(chainIDs)

            # work on tuples of chains
            chainCombinations = combine(*chainIDLists)
            for chainCombo in chainCombinations:
                logging.debug("trying chains: %s" % chainCombo)

                # combine these matches into whole motifs
                # TODO XXX this should really be cross-product!
                # currently only works with pairs...
                for matchA in matchMap[chainCombo[0]]:
                    for matchB in matchMap[chainCombo[1]]:

                        # XXX AARGH! : we make the fragment before testing??!
                        fragment = Structure(self.description.name)
                        model = Model(0)
                        fragment.add(model)
                        model.add(matchA)
                        model.add(matchB)

                        if self.matchConditions(fragment):
                            matches.append(fragment)

        # top level is Chain -> search through combinations of Residues
        elif self.description.levelCode == "C":
            logging.debug("chain description")

            # find the next suitable chain to look through
            for chain in structure.chainsOfType(self.description.chainType):
                logging.debug("finding matches in chain %s" % chain.chainID)
                possibles = self.findMatchesInChain(self.description, chain)
                for p in possibles:
                    if self.matchConditions(p):
                        matches.append(p)
        return matches
Exemplo n.º 2
0
 def initModel(self):
     if self.modelID is None:
         self.modelID = 0
     else:
         self.modelID += 1
     self.model = Model(self.modelID)
     self.structure.add(self.model)
     self.chainID = None
     self.chainType = None
Exemplo n.º 3
0
    def findIn(self, structure):
        example = Structure(self.pdbid)

        # TODO : implement model stuff :(
        model = structure[0]
        modelFeature = Model(0)
        example.add(modelFeature)

        for chain in model:
            if chain.chainID == self.chain or self.chain == " ":
                #print("[%s]" % chain.chainID)
                chainFeature = Chain(chain.chainID, chainType="Protein")

                # XXX obviously better to access by index...
                for residue in chain:
                    if self.residueStart <= int(residue.number) <= self.residueEnd:

                        # XXX better to use copy()?
                        residueFeature = Residue(residue.number, residue.resname)
                        for atom in residue:
                            residueFeature.add(copy(atom))
                        chainFeature.add(residueFeature)
    
                modelFeature.add(chainFeature)
            else:
                continue
        # now add the ligand (as of this moment, a water molecule) XXX ugh!
        waterChain = Chain("Water", "Water")
        waterResidue = Residue(self.ligand_num, "HOH")
        #print("getting", self.ligand_num)
        waterchains = structure.chainsOfType("Water")
        #print("chains", waterchains)
        existingWater = waterchains[0].getResidueNumber(self.ligand_num)
        waterResidue.add(copy(existingWater.getAtom("O")))
        waterChain.add(waterResidue)
        modelFeature.add(waterChain)

        return example
Exemplo n.º 4
0
class StructureBuilder:

    def __init__(self):
        self.reset()

    def reset(self):
        self.structure  = None
        self.model      = None
        self.chain      = None
        self.residue    = None
        
        self.modelID    = None
        self.chainID    = None
        self.chainType  = None
        self.segID      = None
        self.residueID  = None
        self.resname    = None

    def getStructure(self):
        structure = self.structure
        self.reset()
        return structure

    def initStructure(self, structureID):
        self.structure = Structure(structureID)
        self.initModel()

    def initModel(self):
        if self.modelID is None:
            self.modelID = 0
        else:
            self.modelID += 1
        self.model = Model(self.modelID)
        self.structure.add(self.model)
        self.chainID = None
        self.chainType = None

    def initChain(self, chainID, chainType):
        self.chainID = chainID
        self.chainType = chainType
        self.chain = Chain(chainID, chainType)
        self.model.add(self.chain)

    def registerLine(self, residueID, resname, resseq, icode, segID, chainID, chainType):
        if self.chainID != chainID or chainType != self.chainType:
            self.initChain(chainID, chainType)
            self.initResidue(residueID, resname, resseq, icode)

        elif self.residueID != residueID or self.resname != resname:
            self.initResidue(residueID, resname, resseq, icode)

        if self.segID != segID:
            self.segID = segID

    def initResidue(self, residueID, resname, resnum, icode):
        self.residueID = residueID
        self.resname   = resname
        self.residue   = Residue(residueID, resname, self.segID)
        self.chain.add(self.residue)

    def initAtom(self, name, coord, b_factor, occupancy, altloc):
        atom = Atom(name, coord, b_factor, occupancy, altloc)
        self.residue.add(atom)