Пример #1
0
    def _create_atom(self, atom_type):
        """Simple, private helper function for __init__
        """
        element = atom_type
        name = element + str(0)
        
        at = Atom(name=name, chemicalElement=element)

        at._charges = {'gridmap': 1.0}
        at.chargeSet = 'gridmap'
        at.number = 1
        at._coords = [[0., 0., 0.]]
        at.conformation = 0

        #these 2 would change between maps:
        at.autodock_element = element
        return at
Пример #2
0
    def _create_atom(self, atom_type):
        """Simple, private helper function for __init__
        """
        element = atom_type
        name = element + str(0)

        at = Atom(name=name, chemicalElement=element)

        at._charges = {'gridmap': 1.0}
        at.chargeSet = 'gridmap'
        at.number = 1
        at._coords = [[0., 0., 0.]]
        at.conformation = 0

        #these 2 would change between maps:
        at.autodock_element = element
        return at
Пример #3
0
    def build2LevelsTree(self, atomlines):
        """
        Function to build a two level tree. 
        """
        print 'try to build a 2 level tree'
        self.mol = Molecule()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(
                os.path.splitext(self.filename)[0])

        self.mol.children = AtomSet([])
        self.mol.childrenName = 'atoms'
        self.mol.childrenSetClass = AtomSet
        self.mol.elementType = Atom
        self.mol.levels = [Molecule, Atom]
        ##1/18:self.mol.levels = [Protein, Atom]
        for atmline in atomlines:
            atom = Atom(atmline[1],
                        self.mol,
                        chemicalElement=string.split(atmline[5], '.')[0],
                        top=self.mol)
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [[
                float(atmline[2]),
                float(atmline[3]),
                float(atmline[4])
            ]]
            if len(atmline) >= 9:
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        self.mol.atoms = self.mol.children
Пример #4
0
    def _create_atom(self, atom_type):
        """Simple, private helper function for __init__
        """
        element = atom_type
        name = element + str(0)

        at = Atom(name=name, chemicalElement=element)

        at._charges = {'gridmap': 1.0}
        at.chargeSet = 'gridmap'
        at.number = 1
        at._coords = [[0., 0., 0.]]
        at.conformation = 0

        #these 2 would change between maps:
        at.autodock_element = element
        #volumes are in the scorer
        #at.AtVol = self.at_vols.get(element, 0.0)
        #print "set AtVol to", at.AtVol

        return at
Пример #5
0
    def _create_atom(self, atom_type):
        """Simple, private helper function for __init__
        """
        element = atom_type
        name = element + str(0)
        
        at = Atom(name=name, chemicalElement=element)

        at._charges = {'gridmap': 1.0}
        at.chargeSet = 'gridmap'
        at.number = 1
        at._coords = [[0., 0., 0.]]
        at.conformation = 0

        #these 2 would change between maps:
        at.autodock_element = element
        #volumes are in the scorer
        #at.AtVol = self.at_vols.get(element, 0.0)
        #print "set AtVol to", at.AtVol

        return at
Пример #6
0
    def build2LevelsTree (self, atomlines):
        """
        Function to build a two level tree. 
        """
        print 'try to build a 2 level tree'
        self.mol= Molecule()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(os.path.splitext
                                             (self.filename)[0])

        self.mol.children = AtomSet([])
        self.mol.childrenName = 'atoms'
        self.mol.childrenSetClass = AtomSet
        self.mol.elementType = Atom
        self.mol.levels = [Molecule, Atom]
        ##1/18:self.mol.levels = [Protein, Atom]
        for atmline in atomlines:
            atom = Atom(atmline[1], self.mol,
                        chemicalElement = string.split(atmline[5], '.')[0],
            top = self.mol)
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [ [float(atmline[2]), float(atmline[3]),
                                  float(atmline[4]) ] ]
            if len(atmline)>=9:
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        self.mol.atoms = self.mol.children
Пример #7
0
def makeMoleculeFromAtoms(molname, atomSet):
    """
    create a new molecule from a list of atoms

    mol <- makeMoleculeFromAtoms(molname, atomSet)
"""
    from MolKit.molecule import Atom, AtomSet
    from MolKit.protein import Protein, Chain, Residue


    # create the top object
    mol = Protein(name=molname)

    # find out all residues
    residues = atomSet.parent.uniq()

    # find out all chains
    chains = residues.parent.uniq()

    # create all chains
    chainsd = {}
    for c in chains:
        newchain = Chain(c.id, mol, top=mol)
        chainsd[c] = newchain

    # create all residues
    resd = {}
    for res in residues:
        newres = Residue(res.name[:3], res.name[3:], res.icode,
                         chainsd[res.parent], top=mol)
        resd[res] = newres
        newres.hasCA = 0
        newres.hasO = 0

    # create all the atoms
    newats = []
    for num, at in enumerate(atomSet):
        name = at.name
        res = resd[at.parent]
        if name == 'CA':
            res.hasCA = 1
        if name == 'O' or name == 'OXT' or (len(name)>3 and name[:3]=='OCT'):
            res.hasO = 2
        
        newat = Atom(name, res, at.element, top=mol)
        newats.append(newat)
        # set constructotr attributes
        newat._coords = []
        for coords in at._coords:
            newat._coords.append(coords[:])
        newat.conformation = at.conformation
        newat.chemElem = at.chemElem
        newat.atomicNumber = at.atomicNumber
        newat.bondOrderRadius = at.bondOrderRadius
        newat.covalentRadius = at.covalentRadius
        newat.vdwRadius = at.vdwRadius
        newat.maxBonds = at.maxBonds
        newat.organic = at.organic
        newat.colors = at.colors.copy()
        newat.opacities = at.opacities.copy()
        newat._charges = at._charges.copy()
        newat.chargeSet = at.chargeSet

        # set attributes from PDB parser
        newat.segID = at.segID
        newat.hetatm = at.hetatm
        newat.normalname = at.normalname
        newat.number = num #at.number
        newat.occupancy = at.occupancy
        newat.temperatureFactor = at.temperatureFactor
        newat.altname = at.altname

        # attribute created by PQR parser
        if hasattr(at, 'pqrRadius'):
            newat.pqrRadius = at.pqrRadius

        # attribute created by F2D parser
        if hasattr(at, 'hbstatus'):
            newat.hbstatus = at.hbstatus

        # attribute created by PDBQ parser
        if hasattr(at, 'autodock_element'):
            newat.autodock_element = at.autodock_element

        # attribute created by PDBQT parser
        #if hasattr(at, ''):
        #    newat. = at.

        # attribute created by PDBQS parser
        if hasattr(at, 'AtVol'):
            newat.AtVol = at.AtVol
            newat.AtSolPar = at.AtSolPar

    mol.allAtoms = AtomSet(newats)
    return mol
Пример #8
0
    def getMolecule(self, molInd):

        molecules = []
        if molInd == len(self.molIndex) - 1:
            lastLine = -1
        else:
            lastLine = self.molIndex[molInd + 1]
        # lines fotr that molecule
        lines = self.allLines[self.molIndex[molInd]:lastLine]
        lineIndex = 0
        atomsSeen = {}  # dict of atom types and number of atoms seen

        # parser header
        molName = lines[lineIndex].strip()
        lineIndex += 3

        # create molecule
        mol = Protein(name=molName)
        mol.info = lines[lineIndex + 1]
        mol.comment = lines[lineIndex + 1]
        #self.mol.parser = self
        chain = Chain(id='1', parent=mol, top=mol)
        res = Residue(type='UNK', number='1', parent=chain, top=mol)
        mol.levels = [Protein, Chain, Residue, Atom]

        # parse count line
        line = lines[lineIndex]
        assert line[
            33:
            39] == " V2000", "Format error: only V2000 is suported, got %s" % line[
                33:39]
        nba = int(line[0:3])  # number of atoms
        nbb = int(line[3:6])  # number of bonds
        nbal = int(line[6:9])  # number of atom lists
        ccc = int(line[12:15])  # chiral flag: 0=not chiral, 1=chiral
        sss = int(line[15:18])  # number of stext entries
        lineIndex += 1

        # parse atoms
        for anum in range(nba):
            line = lines[lineIndex]
            element = line[31:34].strip()
            if element in atomsSeen:
                atomsSeen[element] += 1
            else:
                atomsSeen[element] = 1
            atom = Atom(name='%s_%s' % (element, atomsSeen[element]),
                        parent=res,
                        chemicalElement=element,
                        top=mol)

            atom._coords = [[
                float(line[0:10]),
                float(line[10:20]),
                float(line[20:30])
            ]]
            atom._charges['sdf'] = int(line[35:38])
            atom.chargeSet = 'sdf'
            mol.allAtoms.append(atom)

            atom.massDiff = int(line[34:36])
            atom.stereo = int(line[38:41])
            atom.hcount = line[41:44]
            atom.valence = int(line[47:50])
            atom.hetatm = 1
            atom.occupancy = 0.0
            atom.temperatureFactor = 0.0
            lineIndex += 1

        # parse bonds
        for bnum in range(nba):
            line = lines[lineIndex]
            at1 = mol.allAtoms[int(line[0:3]) - 1]
            at2 = mol.allAtoms[int(line[3:6]) - 1]
            if at1.isBonded(at2): continue
            bond = Bond(at1, at2, check=0)

            bond.bondOrder = int(line[6:9])
            #1 = Single, 2 = Double,
            #3 = Triple, 4 = Aromatic,
            #5 = Single or Double,
            #6 = Single or Aromatic,
            #7 = Double or Aromatic, 8 = Any

            bond.stereo = int(line[9:12])
            #Single bonds: 0 = not stereo,
            #1 = Up, 4 = Either,
            #6 = Down, Double bonds: 0 = Use x-, y-, z-coords
            #from atom block to determine cis or trans,
            #3 = Cis or trans (either) double bond

            bond.topo = int(line[15:18])
            # 0 = Either, 1 = Ring, 2 = Chain

            try:
                bond.ReactionCenter = int(line[18:21])
            except ValueError:
                bond.ReactionCenter = 0
            #0 = unmarked, 1 = a center, -1 = not a center,
            #Additional: 2 = no change,
            #4 = bond made/broken,
            #8 = bond order changes
            #12 = 4+8 (both made/broken and changes);
            #5 = (4 + 1), 9 = (8 + 1), and 13 = (12 + 1)

        # "M END" and properties are not parsed at this point
        self.mol = mol
        mname = mol.name
        strRpr = mname + ':::'
        mol.allAtoms.setStringRepr(strRpr)
        strRpr = mname + ':'
        mol.chains.setStringRepr(strRpr)
        for c in mol.chains:
            cname = c.id
            strRpr = mname + ':' + cname + ':'
            c.residues.setStringRepr(strRpr)
            for r in c.residues:
                rname = r.name
                strRpr = mname + ':' + cname + ':' + rname + ':'
                r.atoms.setStringRepr(strRpr)
        molList = mol.setClass()
        molList.append(mol)
        mol.parser = self
        for n in molList.name:
            name = n + ','
        name = name[:-1]
        molList.setStringRepr(name)
        strRpr = name + ':::'
        molList.allAtoms.setStringRepr(strRpr)

        return molList
Пример #9
0
def makeMoleculeFromAtoms(molname, atomSet):
    """
    create a new molecule from a list of atoms

    mol <- makeMoleculeFromAtoms(molname, atomSet)
"""
    from MolKit.molecule import Atom, AtomSet
    from MolKit.protein import Protein, Chain, Residue

    # create the top object
    mol = Protein(name=molname)

    # find out all residues
    residues = atomSet.parent.uniq()

    # find out all chains
    chains = residues.parent.uniq()

    # create all chains
    chainsd = {}
    for c in chains:
        newchain = Chain(c.id, mol, top=mol)
        chainsd[c] = newchain

    # create all residues
    resd = {}
    for res in residues:
        newres = Residue(res.name[:3],
                         res.name[3:],
                         res.icode,
                         chainsd[res.parent],
                         top=mol)
        resd[res] = newres
        newres.hasCA = 0
        newres.hasO = 0

    # create all the atoms
    newats = []
    for num, at in enumerate(atomSet):
        name = at.name
        res = resd[at.parent]
        name1 = name
        if hasattr(at, "altname") and at.altname != None:
            name = at.name.split("@")[0]
        if name == 'CA':
            res.hasCA = 1
        if name == 'O' or name == 'OXT' or (len(name) > 3
                                            and name[:3] == 'OCT'):
            res.hasO = 2

        newat = Atom(name, res, at.element, top=mol)
        if name != name1:
            newat.name = name1
            newat.altname = at.altname
        newats.append(newat)
        # set constructotr attributes
        newat._coords = []
        for coords in at._coords:
            newat._coords.append(coords[:])
        newat.conformation = at.conformation
        newat.chemElem = at.chemElem
        newat.atomicNumber = at.atomicNumber
        newat.bondOrderRadius = at.bondOrderRadius
        newat.covalentRadius = at.covalentRadius
        newat.vdwRadius = at.vdwRadius
        newat.maxBonds = at.maxBonds
        newat.organic = at.organic
        newat.colors = at.colors.copy()
        newat.opacities = at.opacities.copy()
        newat._charges = at._charges.copy()
        newat.chargeSet = at.chargeSet

        # set attributes from PDB parser
        try:  # pdbqs do not have this
            newat.segID = at.segID
        except AttributeError:
            pass
        newat.hetatm = at.hetatm
        try:  # pdbqs do not have this
            newat.normalname = at.normalname
        except AttributeError:
            pass
        newat.number = num  #at.number
        newat.occupancy = at.occupancy
        newat.temperatureFactor = at.temperatureFactor
        newat.altname = at.altname

        # attribute created by PQR parser
        if hasattr(at, 'pqrRadius'):
            newat.pqrRadius = at.pqrRadius

        # attribute created by F2D parser
        if hasattr(at, 'hbstatus'):
            newat.hbstatus = at.hbstatus

        # attribute created by PDBQ parser
        if hasattr(at, 'autodock_element'):
            newat.autodock_element = at.autodock_element

        # attribute created by PDBQT parser
        #if hasattr(at, ''):
        #    newat. = at.

        # attribute created by PDBQS parser
        if hasattr(at, 'AtVol'):
            newat.AtVol = at.AtVol
            newat.AtSolPar = at.AtSolPar

    mol.allAtoms = AtomSet(newats)
    return mol
Пример #10
0
    def build4LevelsTree(self, subst_chain, atomlines):
        """
        Function to build a 4 level hierarchy Protein-Chain-Residue-Atom.

        """
        self.mol = Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(
                os.path.splitext(self.filename)[0])
        self.mol.curChain = Chain()
        self.mol.curRes = Residue()
        self.mol.levels = [Protein, Chain, Residue, Atom]
        i = 1
        for atmline in atomlines:
            if len(atmline) >= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            if len(atmline) == 8:
                tmp = [atmline[5][:5], atmline[5][5:]]
                atmline[5] = tmp[0]
                atmline.insert(6, tmp[1])

            if status and status[0] == 'WATER':
                chainID = 'W'
                atmline[7] = 'HOH' + str(i)
                subst_chain[atmline[7]] = chainID
                i = i + 1

            if subst_chain == {}:
                chainID = 'default'

            elif not subst_chain.has_key(atmline[7]):
                if subst_chain.has_key('****'):
                    try:
                        chainID = subst_chain[atmline[7]]
                    except:
                        chainID = 'default'
                else:
                    chainID = 'default'

            elif type(subst_chain[atmline[7]]) is types.StringType:
                # that is to say that only chains has this substructure name.
                chainID = subst_chain[atmline[7]]

            elif type(subst_chain[atmline[7]]) is types.ListType:
                # That is to say that several chains have the same substructure.
                chainID = subst_chain[atmline[7]][0]
                subst_chain[atmline[7]] = subst_chain[atmline[7]].remove(
                    chainID)

            if chainID != self.mol.curChain.id:
                if not self.mol.chains.id or not chainID in self.mol.chains.id:
                    self.mol.curChain = Chain(chainID, self.mol, top=self.mol)
                else:
                    self.mol.curChain = self.mol.chains.get(chainID)[0]

            if len(atmline) < 7:
                # test if the atmline has a res name and resseq:
                resName = 'RES'
                resSeq = '1'
            else:
                resName = atmline[7][:3]
                resSeq = atmline[7][3:]

            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.curChain.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName,
                                              resSeq,
                                              '',
                                              self.mol.curChain,
                                              top=self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O': self.mol.curRes.hasO = 2
            atom = Atom(name,
                        self.mol.curRes,
                        top=self.mol,
                        chemicalElement=string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [[
                float(atmline[2]),
                float(atmline[3]),
                float(atmline[4])
            ]]
            if len(atmline) >= 9:
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        delattr(self.mol, 'curRes')
        delattr(self.mol, 'curChain')
Пример #11
0
    def build3LevelsTree(self, atomlines):
        """ Function to build a 3 levels hierarchy Molecule-substructure-atoms."""

        self.mol = Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(
                os.path.splitext(self.filename)[0])
        self.mol.children = ResidueSet([])
        self.mol.childrenName = 'residues'
        self.mol.childrenSetClass = ResidueSet
        self.mol.elementType = Residue
        self.mol.curRes = Residue()
        self.mol.curRes.hasCA = 0
        self.mol.curRes.hasO = 0

        self.mol.levels = [Protein, Residue, Atom]
        for atmline in atomlines:
            if len(atmline) >= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            resName = atmline[7][:3]
            resSeq = atmline[7][3:]
            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName,
                                              resSeq,
                                              '',
                                              self.mol,
                                              top=self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O': self.mol.curRes.hasO = 2
            atom = Atom(name,
                        self.mol.curRes,
                        top=self.mol,
                        chemicalElement=string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [[
                float(atmline[2]),
                float(atmline[3]),
                float(atmline[4])
            ]]
            atom._charges['mol2'] = float(atmline[8])
            atom.chargeSet = mol2
            #            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)

        self.mol.residues = self.mol.children
        assert hasattr(self.mol, 'chains')
        delattr(self.mol, 'chains')
        delattr(self.mol, 'curRes')
Пример #12
0
    def build4LevelsTree(self, subst_chain, atomlines):
        """
        Function to build a 4 level hierarchy Protein-Chain-Residue-Atom.

        """
        self.mol= Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(os.path.splitext
                                             (self.filename)[0])
        self.mol.curChain = Chain()
        self.mol.curRes = Residue()
        self.mol.levels = [Protein, Chain, Residue, Atom]
        i = 1
        for atmline in atomlines:
            if len(atmline)>= 10:
                status = string.split(atmline[9], '|')
            else: status = None
            if len(atmline) == 8:
                tmp = [atmline[5][:5], atmline[5][5:]]
                atmline[5] = tmp[0]
                atmline.insert(6, tmp[1])

            if status and status[0]=='WATER':
                chainID = 'W'
                atmline[7] = 'HOH'+str(i)
                subst_chain[atmline[7]] = chainID
                i = i+1

            if subst_chain == {}:
                chainID = 'default'

            elif not subst_chain.has_key(atmline[7]):
                if subst_chain.has_key('****'):
                    try:
                        chainID = subst_chain[atmline[7]]
                    except:
                        chainID = 'default'
                else:
                    chainID = 'default'

            elif type(subst_chain[atmline[7]]) is types.StringType:
                # that is to say that only chains has this substructure name.
                chainID = subst_chain[atmline[7]]

            elif type(subst_chain[atmline[7]]) is types.ListType:
                # That is to say that several chains have the same substructure.
                 chainID = subst_chain[atmline[7]][0]
                 subst_chain[atmline[7]] = subst_chain[atmline[7]].remove(chainID)
                 
            if chainID != self.mol.curChain.id:
                if not self.mol.chains.id or not chainID in self.mol.chains.id:
                    self.mol.curChain = Chain(chainID, self.mol,
                                          top = self.mol)
                else:
                    self.mol.curChain = self.mol.chains.get(chainID)[0]

            if len(atmline)<7:
                # test if the atmline has a res name and resseq:
                resName = 'RES'
                resSeq = '1'
            else:
                resName = atmline[7][:3]
                resSeq = atmline[7][3:]

            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.curChain.get( na )
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName, resSeq, '',
                                              self.mol.curChain,
                                              top = self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O' : self.mol.curRes.hasO = 2
            atom = Atom(name, self.mol.curRes, top = self.mol,
            chemicalElement = string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [ [float(atmline[2]), float(atmline[3]),
                              float(atmline[4]) ] ]
            if len(atmline)>=9:                
                atom._charges['mol2'] = float(atmline[8])
                atom.chargeSet = 'mol2'
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
        delattr(self.mol, 'curRes')
        delattr(self.mol, 'curChain')
Пример #13
0
    def build3LevelsTree(self,atomlines):
        """ Function to build a 3 levels hierarchy Molecule-substructure-atoms."""

        self.mol= Protein()
        self.mol.allAtoms = AtomSet()
        self.mol.atmNum = {}
        self.mol.parser = self
        if self.mol.name == 'NoName':
            self.mol.name = os.path.basename(os.path.splitext
                                             (self.filename)[0])
        self.mol.children = ResidueSet([])
        self.mol.childrenName = 'residues'
        self.mol.childrenSetClass = ResidueSet
        self.mol.elementType = Residue
        self.mol.curRes = Residue()
        self.mol.curRes.hasCA = 0
        self.mol.curRes.hasO = 0
        
        self.mol.levels = [Protein, Residue, Atom]
        for atmline in atomlines:
            if len(atmline)>= 10:
                status = string.split(atmline[9], '|')
            else:
                status = None
            resName = atmline[7][:3]
            resSeq = atmline[7][3:]
            if resSeq != self.mol.curRes.number or \
               resName != self.mol.curRes.type:
                # check if this residue already exists
                na = string.strip(resName) + string.strip(resSeq)
                res = self.mol.get(na)
                if res:
                    self.mol.curRes = res[0]
                else:
                    self.mol.curRes = Residue(resName, resSeq, '',
                                              self.mol,
                                              top = self.mol)
            name = atmline[1]
            if name == 'CA': self.mol.curRes.hasCA = 1
            if name == 'O' : self.mol.curRes.hasO = 2
            atom = Atom(name, self.mol.curRes, top = self.mol,
            chemicalElement = string.split(atmline[5], '.')[0])
            #atom.element = atmline[5][0]
            atom.element = atom.chemElem
            atom.number = int(atmline[0])
            self.mol.atmNum[atom.number] = atom
            atom._coords = [ [float(atmline[2]), float(atmline[3]),
                              float(atmline[4]) ] ]
            atom._charges['mol2'] = float(atmline[8])
            atom.chargeSet = mol2
#            atom.conformation = 0
            atom.hetatm = 0
            #Add a data member containing a list of string describing
            # the Sybyl status bis of the atoms.
            atom.status = status 
            #add altname so buildBondsByDist doesn't croak
            atom.altname = None
            self.mol.allAtoms.append(atom)
            
        self.mol.residues = self.mol.children
        assert hasattr(self.mol, 'chains')
        delattr(self.mol, 'chains')
        delattr(self.mol, 'curRes')