Ejemplo n.º 1
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