예제 #1
0
파일: util.py 프로젝트: jchodera/pymol
def cap(object):
    from pymol import cmd
    
    model = cmd.get_model(object)
    # guarantee identical ordering
    cmd.delete(object)
    cmd.load_model(model,object)
    n_list = cmd.identify("(n;n &!(n;c a;2.0))")
    c_list = cmd.identify("(n;c &!(n;n a;2.0))")
    print n_list
    print c_list
    for a in n_list:
        newat = copy.deepcopy(model.atom[a])
        newat.coord = [
            newat.coord[0] + random.random(),
            newat.coord[1] + random.random(),
            newat.coord[2] + random.random(),
            ]
        newat.symbol = 'H'
        newat.name = 'HN'
        newat.numeric_type = 43
        bond = Bond()
        bond.order = 1
        bond.stereo = 0
        bond.index = [ a, model.nAtom ]
        print "adding",newat.name,bond.index
        model.add_atom(newat)
        model.add_bond(bond)
    for a in c_list:
        newat = copy.deepcopy(model.atom[a])
        newat.coord = [
            newat.coord[0] + random.random(),
            newat.coord[1] + random.random(),
            newat.coord[2] + random.random(),
            ]
        newat.symbol = 'H'
        newat.name = 'HC'
        newat.numeric_type = 41
        bond = Bond()
        bond.order = 1
        bond.stereo = 0
        bond.index = [ a, model.nAtom ]
        print "adding",newat.name,bond.index
        model.add_atom(newat)
        model.add_bond(bond)
    # reload
    cmd.delete(object)
    cmd.load_model(model,object)
    cmd.sort(object)
예제 #2
0
    def fromList(self, molList):

        model = Indexed()

        # read header information
        model.molecule.title = string.strip(molList[0])
        model.molecule.dim_code = string.strip(molList[1][20:22])
        model.molecule.comments = string.strip(molList[2])
        try:
            model.molecule.chiral = int(molList[3][12:15])
        except:
            model.molecule.chiral = 0
        nAtom = int(molList[3][0:3])
        nBond = int(molList[3][3:6])

        # read atoms
        nameDict = {}
        irec = 4
        cnt = 0
        for a in range(nAtom):
            at = Atom()
            at.index = cnt
            at.coord = [
                float(molList[irec][0:10]),
                float(molList[irec][10:20]),
                float(molList[irec][20:30])
            ]
            at.symbol = string.strip(molList[irec][31:33])
            try:
                at.stereo = int(molList[irec][39:42])
            except:
                at.stereo = 0
            chg = int(molList[irec][36:39])
            if chg > 0: chg = 4 - chg
            at.formal_charge = chg
            model.atom.append(at)
            irec = irec + 1
            cnt = cnt + 1

            # read bonds
        for a in range(nBond):
            bnd = Bond()
            bnd.index = [
                int(molList[irec][0:3]) - 1,
                int(molList[irec][3:6]) - 1
            ]
            bnd.order = int(molList[irec][6:9])
            try:
                bnd.stereo = int(molList[irec][9:12])
            except:
                bnd.stereo = 0
            model.bond.append(bnd)
            irec = irec + 1

            # obtain formal charges from M  CHG record
        while molList[irec][0:6] != 'M  END':
            if molList[irec][0:6] == 'M  CHG':
                cl = string.split(string.strip(molList[irec][6:]))
                cll = int(cl[0]) * 2
                a = 1
                while a <= cll:
                    model.atom[int(cl[a]) - 1].formal_charge = int(cl[a + 1])
                    a = a + 2
            irec = irec + 1
            if irec >= len(molList): break

        return model
예제 #3
0
파일: mol.py 프로젝트: Almad/pymol
    def fromList(self,molList):

        model = Indexed()

        # read header information
        model.molecule.title = string.strip(molList[0])
        model.molecule.dim_code = string.strip(molList[1][20:22])
        model.molecule.comments = string.strip(molList[2])
        try:
            model.molecule.chiral = int(molList[3][12:15])
        except:
            model.molecule.chiral = 0
        nAtom = int(molList[3][0:3])
        nBond = int(molList[3][3:6])

        # read atoms
        nameDict = {}
        irec = 4
        cnt = 0
        for a in range(nAtom):
            at = Atom()
            at.index = cnt
            at.coord = [float(molList[irec][0:10]), 
                float(molList[irec][10:20]),float(molList[irec][20:30])]
            at.symbol = string.strip(molList[irec][31:33])
            try:
                at.stereo = int(molList[irec][39:42])
            except:
                at.stereo = 0
            chg=int(molList[irec][36:39])
            if chg>0: chg=4-chg
            at.formal_charge = chg
            model.atom.append(at)
            irec = irec + 1
            cnt = cnt + 1

            # read bonds
        for a in range(nBond):
            bnd = Bond()
            bnd.index = [ int(molList[irec][0:3])-1,int(molList[irec][3:6])-1 ]
            bnd.order = int(molList[irec][6:9])
            try:
                bnd.stereo = int(molList[irec][9:12])
            except:
                bnd.stereo = 0
            model.bond.append(bnd)
            irec = irec+1

            # obtain formal charges from M  CHG record
        while molList[irec][0:6]!='M  END':
            if molList[irec][0:6]=='M  CHG':
                cl = string.split(string.strip(molList[irec][6:]))
                cll = int(cl[0])*2
                a=1
                while a<=cll:
                    model.atom[int(cl[a])-1].formal_charge=int(cl[a+1])
                    a=a+2
            irec =irec+1
            if irec >= len(molList): break

        return model