Exemplo n.º 1
0
def writepdb(mol, atids, fname):

    wf = open(fname, 'w')
    print('REMARK, BUILD BY MCPB.PY', file=wf)

    resids = []
    for i in atids:
        if mol.atoms[i].resid not in resids:
            resids.append(mol.atoms[i].resid)

    reslist = get_reslist(mol, resids)

    terlist = reslist.nterm + reslist.nonstd + reslist.water

    terlist = list(set(terlist))

    for i in resids:
        if (i in terlist) and (i != min(resids)):
            print('TER', file=wf)
        for j in mol.residues[i].resconter:
            atm = mol.atoms[j]
            gtype = atm.gtype
            atid = atm.atid
            if len(atm.atname) == 3:
                atname = atm.atname
            else:
                atname = atm.atname.center(4)
            crd = atm.crd
            resid = atm.resid
            resname = mol.residues[resid].resname
            print("%-6s%5d %4s %3s %1s%4d    %8.3f%8.3f%8.3f%6.2f%6.2f" \
                     %(gtype, atid, atname, resname, 'A', resid, crd[0], crd[1], crd[2], 1.00, 0.00), file=wf)
    print('END', file=wf)
    wf.close()
Exemplo n.º 2
0
def writepdb(mol, atids, fname):

    wf = open(fname, 'w')
    print('REMARK, BUILD BY MCPB.PY', file=wf)

    resids = []
    for i in atids:
      if mol.atoms[i].resid not in resids:
        resids.append(mol.atoms[i].resid)

    reslist = get_reslist(mol, resids)

    terlist = reslist.nterm + reslist.nonstd + reslist.water

    terlist = list(set(terlist))

    for i in resids:
      if (i in terlist) and (i != min(resids)):
        print('TER', file=wf)     
      for j in mol.residues[i].resconter:
        atm = mol.atoms[j]
        gtype = atm.gtype
        atid = atm.atid
        if len(atm.atname) == 3:
          atname = atm.atname
        else:
          atname = atm.atname.center(4)
        crd = atm.crd
        resid = atm.resid
        resname = mol.residues[resid].resname
        print("%-6s%5d %4s %3s %1s%4d    %8.3f%8.3f%8.3f%6.2f%6.2f" \
                 %(gtype, atid, atname, resname, 'A', resid, crd[0], crd[1], crd[2], 1.00, 0.00), file=wf)
    print('END', file=wf)
    wf.close()
Exemplo n.º 3
0
def gene_leaprc(gname, orpdbf, fipdbf, stpdbf, stfpf, ionids,\
                ionmol2fs, ioninf, mcresname, naamol2fs, ff_choice, frcmodfs,
                finfcdf, ileapf, model, watermodel='tip3p', paraset='cm'):

    print("******************************************************************")
    print("*                                                                *")
    print("*=================Generating input file for leap=================*")
    print("*                                                                *")
    print("******************************************************************")

    #---------------------Generate the new pdb file--------------------------
    #mol0 is the old mol while mol is new mol file with new names

    mol0, atids0, resids0 = get_atominfo_fpdb(orpdbf)

    reslist0 = get_reslist(mol0, resids0)

    mol, atids, resids = get_atominfo_fpdb(orpdbf)

    #rename the residue names into AMBER style, e.g. HIS --> HID, HIP, HIE
    mol = rename_res(mol, atids)

    #get the disulfur bond information
    disul = get_diS_bond(mol, atids)

    #resname the old residue names to new ones if it is not metal ion
    if model in [1, 2]:
      metcenres1 = [] #Old residue ids
      fp = open(stfpf, 'r')
      for line in fp:
        if line[0:4] != "LINK":
          line = line.split('-')
          if int(line[0]) not in metcenres1:
            metcenres1.append(int(line[0]))
      fp.close()
      metcenres2 = mcresname #New residue names
      resndict = {}
      resns = []
      for i in range(0, len(metcenres1)):
          resndict[metcenres1[i]] = metcenres2[i]
          resns.append(metcenres2[i])

      for i in resndict.keys():
        mol.residues[i].resname = resndict[i]

    writepdb(mol, atids, fipdbf)
    #----------------------------get the atom names which changed atom type
    if model in [1, 2]:
      atomdefs = {}
      fp0 = open(stfpf, 'r')
      for line in fp0:
        if line[0:4] != "LINK":
          line = line.strip('\n')
          line = line.split()
          if line[2] != line[4]:
            atnewtype = line[4]
            element = mol.atoms[int(line[1])].element
            if atnewtype not in atomdefs.keys():
              atomdefs[atnewtype] = element
            else:
              if element != atomdefs[atnewtype]:
                raise pymsmtError('There are atoms in fingerprint file '
                                  'of standard model with same atom type '
                                  'but different element.')
      fp0.close()
    #---------------------Get the bond information, mol2 is the standard model

    if model == 1:
      mol2, atids2, resids2 = get_atominfo_fpdb(stpdbf)
      blist = get_mc_blist(mol2, atids2, ionids, stfpf)
      blist1 = [(i[0], i[1]) for i in blist]

    #----------------------Generate the lib file and get the frcmod file name
    if model == 2:
      frcmodfs = []
      for ionmol2f in ionmol2fs:
        ionmol, ionatids, ionresids = get_atominfo(ionmol2f)
        for i in ionatids:
          element = ionmol.atoms[i].element
          chg = int(ionmol.atoms[i].charge)
          frcmodf = get_frcmod_fname(element, chg, watermodel, paraset)
          if frcmodf not in frcmodfs:
            frcmodfs.append(frcmodf)
    elif model == 3 and ioninf != []:
      #get the metal information
      metresns = ioninf[0::4]
      metatns = ioninf[1::4]
      metelmts = ioninf[2::4]
      metelmts = [i[0] + i[1:].lower() for i in metelmts]
      metchgs = ioninf[3::4]
      metchgs = [int(i) for i in metchgs]
      #check the charge of the metal ions
      for metchg in metchgs:
        if metchg < -1 or metchg > 4:
          raise pymsmtError('Could not deal with atomic ion which has charge '
                            'less than -1 or bigger than +4.')
      frcmodfs = []
      for i in range(0, len(metresns)):
        if metchgs[i] > 1: #if it is -1 or +1 ions, no need to create the lib file
          gene_ion_libfile(metresns[i], metatns[i], metelmts[i], metchgs[i])
          frcmodf = get_frcmod_fname(metelmts[i], metchgs[i], watermodel, paraset)
          if frcmodf not in frcmodfs:
            frcmodfs.append(frcmodf)

    #-----------------------Generate the leap input file-----------------------

    print('Generating the leap input file...')

    ##Generate the tleap.in file
    lp = open(ileapf, 'w')
    if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff10']:
      print('source oldff/leaprc.%s' %ff_choice, file=lp)
    elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']:
      print('source leaprc.%s' %ff_choice, file=lp)
    print('source leaprc.gaff', file=lp)
    #Add atom types, for bonded model
    if model in [1, 2]:
      if atomdefs.keys() != []:
        print('addAtomTypes {', file=lp)
        for i in sorted(list(atomdefs.keys())):
          print('        { "%s"  "%s" "sp3" }' %(i, atomdefs[i]), file=lp)
        print('}', file=lp)

    #load lib and frcmod files for monovalent ions (for salt)
    if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']:
      print('loadoff atomic_ions.lib', file=lp)
    print('loadamberparams frcmod.ions1lsm_hfe_%s' %watermodel, file=lp)

    #Load mol2 file for the refitting charge residues
    if model in [1, 2]:
      for i in resns:
        print('%s = loadmol2 %s.mol2' %(i, i), file=lp)
    elif model == 3:
      for i in naamol2fs:
        print('%s = loadmol2 %s.mol2' %(i, i), file=lp)

    #Load frcmod files for non-standard residues and metal site
    for i in frcmodfs:
      print('loadamberparams %s' %i, file=lp)

    if model == 1:
      print('loadamberparams %s' %finfcdf, file=lp)
    elif model == 2:
      for frcmodf in frcmodfs:
        print('loadamberparams %s' %frcmodf, file=lp)
    elif model == 3:
      for metresn in metresns:
        print('loadoff %s.lib' %metresn, file=lp)
      for frcmodf in frcmodfs:
        print('loadamberparams %s' %frcmodf, file=lp)

    #load pdb file
    print('mol = loadpdb %s' %fipdbf, file=lp)

    ##The Disulfur Bond information
    if disul != []:
      for i in disul:
        at1 = i[0]
        at2 = i[1]
        resid1 = mol.atoms[at1].resid
        resid2 = mol.atoms[at2].resid
        atname1 = mol.atoms[at1].atname
        atname2 = mol.atoms[at2].atname
        print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \
              str(resid2) + '.' + atname2, file=lp)

    ##Bond including the metal ions
    if model == 1:
      for bond in blist1:
        if list(set(bond) & set(ionids)) != []:
          at1 = bond[0]
          at2 = bond[1]
          resid1 = mol.atoms[at1].resid
          resid2 = mol.atoms[at2].resid
          atname1 = mol.atoms[at1].atname
          atname2 = mol.atoms[at2].atname
          print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \
                str(resid2) + '.' + atname2, file=lp)

    ##Nonstandard residues with nearby residues

    if model in [1, 2]:
      bondcmds = []
      for i in metcenres1:
        resname = mol0.residues[i].resname
        print('Renamed residues includes: ' + str(i) + '-' + resname)
        if i in reslist0.nterm:
          cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i+i) + '.N'
          if cmdi not in bondcmds:
            bondcmds.append(cmdi)
        elif i in reslist0.cterm:
          cmdi = 'bond mol.' + str(i-1) + '.C' + ' mol.' + str(i) + '.N'
          if cmdi not in bondcmds:
            bondcmds.append(cmdi)
        elif i in reslist0.std:
          cmdi = 'bond mol.' + str(i-1) + '.C' + ' mol.' + str(i) + '.N'
          if cmdi not in bondcmds:
            bondcmds.append(cmdi)
          cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i+1) + '.N'
          if cmdi not in bondcmds:
            bondcmds.append(cmdi)
      for j in bondcmds:
          print(j, file=lp)

    #Save dry structure
    print('savepdb mol %s_dry.pdb' %gname, file=lp)
    print('saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \
          %(gname, gname), file=lp)
    #Solvatebox
    if watermodel == 'tip3p':
      print('solvatebox mol TIP3PBOX 10.0', file=lp)
    elif watermodel == 'spce':
      print('solvatebox mol SPCBOX 10.0', file=lp)
      print('loadamberparams frcmod.spce', file=lp)
    elif watermodel == 'tip4pew':
      print('solvatebox mol TIP4PEWBOX 10.0', file=lp)
      print('loadamberparams frcmod.tip4pew', file=lp)
    #Add counter ions
    print('addions mol Na+ 0', file=lp)
    print('addions mol Cl- 0', file=lp)
    #Save solvated structure
    print('savepdb mol %s_solv.pdb' %gname, file=lp)
    print('saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \
          %(gname, gname), file=lp)
    print('quit', file=lp)
    print(' ', file=lp)

    lp.close()

    print('Finish generating the leap input file.')
Exemplo n.º 4
0
def rename_res(mol, atids):

    #Residue IDs
    resids = []
    for i in atids:
      if mol.atoms[i].resid not in resids:
        resids.append(mol.atoms[i].resid)

    #Correct the names of the HIS, ASP, GLU, LYS, CYS
    for i in resids:
      #HIS
      if mol.residues[i].resname == 'HIS':
        hasatoms = []
        for j in mol.residues[i].resconter:
          atname = mol.atoms[j].atname
          hasatoms.append(atname)
        if ('HD1' in hasatoms) and ('HE2' in hasatoms):
          mol.residues[i].resname = 'HIP'
        elif ('HD1' in hasatoms):
          mol.residues[i].resname = 'HID'
        elif ('HE2' in hasatoms):
          mol.residues[i].resname = 'HIE'
      #ASP
      elif mol.residues[i].resname == 'ASP':
        hasatoms = []
        for j in mol.residues[i].resconter:
          atname = mol.atoms[j].atname
          hasatoms.append(atname)
        if ('HD1' in hasatoms) or ('HD2' in hasatoms):
          mol.residues[i].resname = 'ASH'
      #GLU
      elif mol.residues[i].resname == 'GLU':
        hasatoms = []
        for j in mol.residues[i].resconter:
          atname = mol.atoms[j].atname
          hasatoms.append(atname)
        if ('HE1' in hasatoms) or ('HE2' in hasatoms):
          mol.residues[i].resname = 'GLH'
      #LYS
      elif mol.residues[i].resname == 'LYS':
        hasatoms = []
        for j in mol.residues[i].resconter:
          atname = mol.atoms[j].atname
          hasatoms.append(atname)
        if ('HZ1' not in hasatoms):
          mol.residues[i].resname = 'LYN'
      #CYS
      elif mol.residues[i].resname == 'CYS':
        hasatoms = []
        for j in mol.residues[i].resconter:
          atname = mol.atoms[j].atname
          hasatoms.append(atname)
        if ('HG' not in hasatoms): ##There are two different situations
          #for atom in CYS residue
          for j in mol.residues[i].resconter:
            if mol.atoms[j].atname == 'SG':
              sgcrd = mol.atoms[j].crd
              #for every atom
              for k in atids:
                if mol.atoms[k].atname == 'SG' and k != j:
                  atkcrd = mol.atoms[k].crd
                  dis = calc_bond(sgcrd, atkcrd)
                  if dis <= 2.50:
                    mol.residues[i].resname = 'CYX'
                  else:
                    mol.residues[i].resname = 'CYM'

    reslist = get_reslist(mol, resids)

    #rename the HN atom to H atom in amino acid residues
    for i in resids:
      if i in reslist.std:
        for j in mol.residues[i].resconter:
          if mol.atoms[j].atname == 'HN':
            mol.atoms[j].atname = 'H'

    return mol
Exemplo n.º 5
0
def gene_leaprc(gname, orpdbf, fipdbf, stpdbf, stfpf, ionids,\
                ionmol2fs, ioninf, mcresname, naamol2fs, ff_choice, frcmodfs,
                finfcdf, ileapf, model, watermodel='tip3p', paraset='cm'):

    print("******************************************************************")
    print("*                                                                *")
    print("*=================Generating input file for leap=================*")
    print("*                                                                *")
    print("******************************************************************")

    #---------------------Generate the new pdb file--------------------------
    #mol0 is the old mol while mol is new mol file with new names

    mol0, atids0, resids0 = get_atominfo_fpdb(orpdbf)

    reslist0 = get_reslist(mol0, resids0)

    mol, atids, resids = get_atominfo_fpdb(orpdbf)

    #rename the residue names into AMBER style, e.g. HIS --> HID, HIP, HIE
    mol = rename_res(mol, atids)

    #get the disulfur bond information
    disul = get_diS_bond(mol, atids)

    #resname the old residue names to new ones if it is not metal ion
    if model in [1, 2]:
        metcenres1 = []  #Old residue ids
        fp = open(stfpf, 'r')
        for line in fp:
            if line[0:4] != "LINK":
                line = line.split('-')
                if int(line[0]) not in metcenres1:
                    metcenres1.append(int(line[0]))
        fp.close()
        metcenres2 = mcresname  #New residue names
        resndict = {}
        resns = []
        for i in range(0, len(metcenres1)):
            resndict[metcenres1[i]] = metcenres2[i]
            resns.append(metcenres2[i])

        for i in resndict.keys():
            mol.residues[i].resname = resndict[i]

    writepdb(mol, atids, fipdbf)
    #----------------------------get the atom names which changed atom type
    if model in [1, 2]:
        atomdefs = {}
        fp0 = open(stfpf, 'r')
        for line in fp0:
            if line[0:4] != "LINK":
                line = line.strip('\n')
                line = line.split()
                if line[2] != line[4]:
                    atnewtype = line[4]
                    element = mol.atoms[int(line[1])].element
                    if atnewtype not in atomdefs.keys():
                        atomdefs[atnewtype] = element
                    else:
                        if element != atomdefs[atnewtype]:
                            raise pymsmtError(
                                'There are atoms in fingerprint file '
                                'of standard model with same atom type '
                                'but different element.')
        fp0.close()
    #---------------------Get the bond information, mol2 is the standard model

    if model == 1:
        mol2, atids2, resids2 = get_atominfo_fpdb(stpdbf)
        blist = get_mc_blist(mol2, atids2, ionids, stfpf)
        blist1 = [(i[0], i[1]) for i in blist]

    #----------------------Generate the lib file and get the frcmod file name
    if model == 2:
        frcmodfs = []
        for ionmol2f in ionmol2fs:
            ionmol, ionatids, ionresids = get_atominfo(ionmol2f)
            for i in ionatids:
                element = ionmol.atoms[i].element
                chg = int(ionmol.atoms[i].charge)
                frcmodf = get_frcmod_fname(element, chg, watermodel, paraset)
                if frcmodf not in frcmodfs:
                    frcmodfs.append(frcmodf)
    elif model == 3 and ioninf != []:
        #get the metal information
        metresns = ioninf[0::4]
        metatns = ioninf[1::4]
        metelmts = ioninf[2::4]
        metelmts = [i[0] + i[1:].lower() for i in metelmts]
        metchgs = ioninf[3::4]
        metchgs = [int(i) for i in metchgs]
        #check the charge of the metal ions
        for metchg in metchgs:
            if metchg < -1 or metchg > 4:
                raise pymsmtError(
                    'Could not deal with atomic ion which has charge '
                    'less than -1 or bigger than +4.')
        frcmodfs = []
        for i in range(0, len(metresns)):
            if metchgs[
                    i] > 1:  #if it is -1 or +1 ions, no need to create the lib file
                gene_ion_libfile(metresns[i], metatns[i], metelmts[i],
                                 metchgs[i])
                frcmodf = get_frcmod_fname(metelmts[i], metchgs[i], watermodel,
                                           paraset)
                if frcmodf not in frcmodfs:
                    frcmodfs.append(frcmodf)

    #-----------------------Generate the leap input file-----------------------

    print('Generating the leap input file...')

    ##Generate the tleap.in file
    lp = open(ileapf, 'w')
    if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff10']:
        print('source oldff/leaprc.%s' % ff_choice, file=lp)
    elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']:
        print('source leaprc.%s' % ff_choice, file=lp)
    print('source leaprc.gaff', file=lp)
    #Add atom types, for bonded model
    if model in [1, 2]:
        if atomdefs.keys() != []:
            print('addAtomTypes {', file=lp)
            for i in sorted(list(atomdefs.keys())):
                print('        { "%s"  "%s" "sp3" }' % (i, atomdefs[i]),
                      file=lp)
            print('}', file=lp)

    #load lib and frcmod files for monovalent ions (for salt)
    if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']:
        print('loadoff atomic_ions.lib', file=lp)
    print('loadamberparams frcmod.ions1lsm_hfe_%s' % watermodel, file=lp)

    #Load mol2 file for the refitting charge residues
    if model in [1, 2]:
        for i in resns:
            print('%s = loadmol2 %s.mol2' % (i, i), file=lp)
    elif model == 3:
        for i in naamol2fs:
            print('%s = loadmol2 %s.mol2' % (i, i), file=lp)

    #Load frcmod files for non-standard residues and metal site
    for i in frcmodfs:
        print('loadamberparams %s' % i, file=lp)

    if model == 1:
        print('loadamberparams %s' % finfcdf, file=lp)
    elif model == 2:
        for frcmodf in frcmodfs:
            print('loadamberparams %s' % frcmodf, file=lp)
    elif model == 3:
        for metresn in metresns:
            print('loadoff %s.lib' % metresn, file=lp)
        for frcmodf in frcmodfs:
            print('loadamberparams %s' % frcmodf, file=lp)

    #load pdb file
    print('mol = loadpdb %s' % fipdbf, file=lp)

    ##The Disulfur Bond information
    if disul != []:
        for i in disul:
            at1 = i[0]
            at2 = i[1]
            resid1 = mol.atoms[at1].resid
            resid2 = mol.atoms[at2].resid
            atname1 = mol.atoms[at1].atname
            atname2 = mol.atoms[at2].atname
            print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \
                  str(resid2) + '.' + atname2, file=lp)

    ##Bond including the metal ions
    if model == 1:
        for bond in blist1:
            if list(set(bond) & set(ionids)) != []:
                at1 = bond[0]
                at2 = bond[1]
                resid1 = mol.atoms[at1].resid
                resid2 = mol.atoms[at2].resid
                atname1 = mol.atoms[at1].atname
                atname2 = mol.atoms[at2].atname
                print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \
                      str(resid2) + '.' + atname2, file=lp)

    ##Nonstandard residues with nearby residues

    if model in [1, 2]:
        bondcmds = []
        for i in metcenres1:
            resname = mol0.residues[i].resname
            print('Renamed residues includes: ' + str(i) + '-' + resname)
            if i in reslist0.nterm:
                cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i +
                                                                   i) + '.N'
                if cmdi not in bondcmds:
                    bondcmds.append(cmdi)
            elif i in reslist0.cterm:
                cmdi = 'bond mol.' + str(i -
                                         1) + '.C' + ' mol.' + str(i) + '.N'
                if cmdi not in bondcmds:
                    bondcmds.append(cmdi)
            elif i in reslist0.std:
                cmdi = 'bond mol.' + str(i -
                                         1) + '.C' + ' mol.' + str(i) + '.N'
                if cmdi not in bondcmds:
                    bondcmds.append(cmdi)
                cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i +
                                                                   1) + '.N'
                if cmdi not in bondcmds:
                    bondcmds.append(cmdi)
        for j in bondcmds:
            print(j, file=lp)

    #Save dry structure
    print('savepdb mol %s_dry.pdb' % gname, file=lp)
    print('saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \
          %(gname, gname), file=lp)
    #Solvatebox
    if watermodel == 'tip3p':
        print('solvatebox mol TIP3PBOX 10.0', file=lp)
    elif watermodel == 'spce':
        print('solvatebox mol SPCBOX 10.0', file=lp)
        print('loadamberparams frcmod.spce', file=lp)
    elif watermodel == 'tip4pew':
        print('solvatebox mol TIP4PEWBOX 10.0', file=lp)
        print('loadamberparams frcmod.tip4pew', file=lp)
    #Add counter ions
    print('addions mol Na+ 0', file=lp)
    print('addions mol Cl- 0', file=lp)
    #Save solvated structure
    print('savepdb mol %s_solv.pdb' % gname, file=lp)
    print('saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \
          %(gname, gname), file=lp)
    print('quit', file=lp)
    print(' ', file=lp)

    lp.close()

    print('Finish generating the leap input file.')
Exemplo n.º 6
0
def rename_res(mol, atids):

    #Residue IDs
    resids = []
    for i in atids:
        if mol.atoms[i].resid not in resids:
            resids.append(mol.atoms[i].resid)

    #Correct the names of the HIS, ASP, GLU, LYS, CYS
    for i in resids:
        #HIS
        if mol.residues[i].resname == 'HIS':
            hasatoms = []
            for j in mol.residues[i].resconter:
                atname = mol.atoms[j].atname
                hasatoms.append(atname)
            if ('HD1' in hasatoms) and ('HE2' in hasatoms):
                mol.residues[i].resname = 'HIP'
            elif ('HD1' in hasatoms):
                mol.residues[i].resname = 'HID'
            elif ('HE2' in hasatoms):
                mol.residues[i].resname = 'HIE'
        #ASP
        elif mol.residues[i].resname == 'ASP':
            hasatoms = []
            for j in mol.residues[i].resconter:
                atname = mol.atoms[j].atname
                hasatoms.append(atname)
            if ('HD1' in hasatoms) or ('HD2' in hasatoms):
                mol.residues[i].resname = 'ASH'
        #GLU
        elif mol.residues[i].resname == 'GLU':
            hasatoms = []
            for j in mol.residues[i].resconter:
                atname = mol.atoms[j].atname
                hasatoms.append(atname)
            if ('HE1' in hasatoms) or ('HE2' in hasatoms):
                mol.residues[i].resname = 'GLH'
        #LYS
        elif mol.residues[i].resname == 'LYS':
            hasatoms = []
            for j in mol.residues[i].resconter:
                atname = mol.atoms[j].atname
                hasatoms.append(atname)
            if ('HZ1' not in hasatoms):
                mol.residues[i].resname = 'LYN'
        #CYS
        elif mol.residues[i].resname == 'CYS':
            hasatoms = []
            for j in mol.residues[i].resconter:
                atname = mol.atoms[j].atname
                hasatoms.append(atname)
            if ('HG' not in hasatoms): ##There are two different situations
                #for atom in CYS residue
                for j in mol.residues[i].resconter:
                    if mol.atoms[j].atname == 'SG':
                        sgcrd = mol.atoms[j].crd
                        #for every atom
                        for k in atids:
                            if mol.atoms[k].atname == 'SG' and k != j:
                                atkcrd = mol.atoms[k].crd
                                dis = calc_bond(sgcrd, atkcrd)
                                if dis <= 2.50:
                                    mol.residues[i].resname = 'CYX'
                                else:
                                    mol.residues[i].resname = 'CYM'

    reslist = get_reslist(mol, resids)

    #rename the HN atom to H atom in amino acid residues
    for i in resids:
        if i in reslist.std:
            for j in mol.residues[i].resconter:
                if mol.atoms[j].atname == 'HN':
                    mol.atoms[j].atname = 'H'

    return mol
Exemplo n.º 7
0
def gene_resp_input_file(lgpdbf, ionids, stfpf, ffchoice, mol2fs, chgmod,
                         fixchg_resids, lgchg):

    libdict, chargedict = get_lib_dict(ffchoice)

    for mol2f in mol2fs:
        libdict1, chargedict1 = get_lib_dict(mol2f)
        libdict.update(libdict1)
        chargedict.update(chargedict1)

    mol, atids, resids = get_atominfo_fpdb(lgpdbf)

    reslist = get_reslist(mol, resids)

    blist = get_mc_blist(mol, atids, ionids, stfpf)

    bnoatids = []  #Binding backbone N and C Atom IDs

    mcresids = []  #Metal site residues
    stfpff = open(stfpf, 'r')
    for line in stfpff:
        if line[0:4] != 'LINK':
            line = line.split()
            line = line[0].split('-')
            mcresids.append(int(line[0]))
        else:
            line = line.strip('\n')
            line = line.split()
            if (line[-1][-1] in ['N3', 'N', 'O', 'OXT']):
                atid, atom = line[-1].split('-')
                bnoatids.append(int(atid))
    stfpff.close()

    bnoresids = []  #Binding Backbone N and C Residue IDs, which are not fitted
    #with backbone restriction in the charge fitting
    for i in bnoatids:
        resid = mol.atoms[i].resid
        if resid not in bnoresids:
            bnoresids.append(resid)

    angresids = []  #ACE, NME, GLY residues
    for i in resids:
        if i not in mcresids:
            angresids.append(i)

    #Get the total charge of the system-------------------------------------
    totchg = 0.0

    for i in resids:
        resname = mol.residues[i].resname
        if i in reslist.nterm:
            reschg = chargedict['N' + resname]
        elif i in reslist.cterm:
            reschg = chargedict['C' + resname]
        else:
            reschg = chargedict[resname]
        totchg = totchg + reschg

    totchg = int(round(totchg, 0))

    if lgchg == -99:
        lgchg = totchg

    #-------------------------------------------------------------------------
    ##############RESP1.IN file###############################################
    #-------------------------------------------------------------------------

    print("***Generating the 1st stage resp charge fitting input file...")

    #print the 1st part, the title
    fresp1 = open('resp1.in', 'w')
    print("Resp charges for organic molecule", file=fresp1)
    print(" ", file=fresp1)
    print(" &cntrl", file=fresp1)
    print(" ", file=fresp1)
    print(" nmol = 1,", file=fresp1)
    print(" ihfree = 1,", file=fresp1)
    print(" ioutopt = 1,", file=fresp1)
    print(" ", file=fresp1)
    print(" &end", file=fresp1)
    print("    1.0", file=fresp1)
    print("Resp charges for organic molecule", file=fresp1)
    print("%5d" % lgchg, end=' ', file=fresp1)
    print("%4d" % len(atids), file=fresp1)

    #2. print the 2nd part, the free and fozen atoms---------------------------
    natids = [i for i in range(1, len(atids) + 1)]  #new atids

    iddict = {
    }  #First number in iddict is new atom id, second is atomic number

    for i in range(0, len(atids)):
        iddict[atids[i]] = natids[i]

    for i in atids:
        element = mol.atoms[i].element
        elenum = Atnum[element]
        iddict[i] = (iddict[i], elenum)

    for i in resids:
        get_equal_atoms(mol, i, blist, iddict)

    #other atoms (except the CH2 and CH3 groups) are frozen
    for i in atids:
        if (len(iddict[i]) == 2):
            iddict[i] = (iddict[i][0], iddict[i][1], -99)

    for i in atids:
        #if iddict[i][2] == -99:
        print("%5d" % iddict[i][1], end=' ', file=fresp1)
        print("%4s" % '0', file=fresp1)
        #else:
        #  print >> fresp1, "%5d" %iddict[i][1],
        #  print >> fresp1, "%4s" %iddict[i][2]
    fresp1.close()

    add_restriction('resp1.in', libdict, mol, resids, reslist, mcresids,
                    bnoresids, angresids, iddict, chgmod, fixchg_resids)

    #-------------------------------------------------------------------------
    ####################RESP2.IN file#########################################
    #-------------------------------------------------------------------------
    print("***Generating the 2nd stage resp charge fitting input file...")

    #1. print the 1st part, the title------------------------------------------
    fresp2 = open('resp2.in', 'w')
    print("Resp charges for organic molecule", file=fresp2)
    print(" ", file=fresp2)
    print(" &cntrl", file=fresp2)
    print(" ", file=fresp2)
    print(" nmol = 1,", file=fresp2)
    print(" ihfree = 1,", file=fresp2)
    print(" ioutopt = 1,", file=fresp2)
    print(" iqopt = 2,", file=fresp2)
    print(" qwt = 0.001,", file=fresp2)
    print(" ", file=fresp2)
    print(" &end", file=fresp2)
    print("    1.0", file=fresp2)
    print("Resp charges for organic molecule", file=fresp2)
    print("%5d" % lgchg, end=' ', file=fresp2)
    print("%4d" % len(atids), file=fresp2)

    #2. print the 2nd part, the free or frozen information---------------------
    for i in atids:
        print("%5d" % iddict[i][1], end=' ', file=fresp2)
        print("%4s" % iddict[i][2], file=fresp2)
    fresp2.close()

    add_restriction('resp2.in', libdict, mol, resids, reslist, mcresids,
                    bnoresids, angresids, iddict, chgmod, fixchg_resids)
Exemplo n.º 8
0
def gene_resp_input_file(lgpdbf, ionids, stfpf, ffchoice, mol2fs,
                         chgmod, fixchg_resids, lgchg):

    libdict, chargedict = get_lib_dict(ffchoice)

    for mol2f in mol2fs:
      libdict1, chargedict1 = get_lib_dict(mol2f)
      libdict.update(libdict1)
      chargedict.update(chargedict1)

    mol, atids, resids = get_atominfo_fpdb(lgpdbf)

    reslist = get_reslist(mol, resids)

    blist = get_mc_blist(mol, atids, ionids, stfpf)

    bnoatids = [] #Binding backbone N and C Atom IDs

    mcresids = [] #Metal site residues
    stfpff = open(stfpf, 'r')
    for line in stfpff:
      if line[0:4] != 'LINK':
        line = line.split()
        line = line[0].split('-')
        mcresids.append(int(line[0]))
      else:
        line = line.strip('\n')
        line = line.split()
        if (line[-1][-1] in ['N3', 'N', 'O', 'OXT']):
          atid, atom = line[-1].split('-')
          bnoatids.append(int(atid))
    stfpff.close()

    bnoresids = [] #Binding Backbone N and C Residue IDs, which are not fitted
                   #with backbone restriction in the charge fitting
    for i in bnoatids:
      resid = mol.atoms[i].resid
      if resid not in bnoresids:
        bnoresids.append(resid)

    angresids = [] #ACE, NME, GLY residues
    for i in resids:
      if i not in mcresids:
        angresids.append(i)

    #Get the total charge of the system-------------------------------------
    totchg = 0.0

    for i in resids:
      resname = mol.residues[i].resname
      if i in reslist.nterm:
        reschg = chargedict['N' + resname]
      elif i in reslist.cterm:
        reschg = chargedict['C' + resname]
      else:
        reschg = chargedict[resname]
      totchg = totchg + reschg

    totchg = int(round(totchg, 0))

    if lgchg == -99:
      lgchg = totchg

    #-------------------------------------------------------------------------
    ##############RESP1.IN file###############################################
    #-------------------------------------------------------------------------

    print("***Generating the 1st stage resp charge fitting input file...")

    #print the 1st part, the title
    fresp1 = open('resp1.in', 'w')
    print("Resp charges for organic molecule", file=fresp1)
    print(" ", file=fresp1)
    print(" &cntrl", file=fresp1)
    print(" ", file=fresp1)
    print(" nmol = 1,", file=fresp1)
    print(" ihfree = 1,", file=fresp1)
    print(" ioutopt = 1,", file=fresp1)
    print(" ", file=fresp1)
    print(" &end", file=fresp1)
    print("    1.0", file=fresp1)
    print("Resp charges for organic molecule", file=fresp1)
    print("%5d" %lgchg, end=' ', file=fresp1)
    print("%4d" %len(atids), file=fresp1)

    #2. print the 2nd part, the free and fozen atoms---------------------------
    natids = [i for i in range(1, len(atids)+1)] #new atids

    iddict = {} #First number in iddict is new atom id, second is atomic number

    for i in range(0, len(atids)):
      iddict[atids[i]] = natids[i]

    for i in atids:
      element = mol.atoms[i].element
      elenum = Atnum[element]
      iddict[i] = (iddict[i], elenum)

    for i in resids:
      get_equal_atoms(mol, i, blist, iddict)

    #other atoms (except the CH2 and CH3 groups) are frozen
    for i in atids:
      if (len(iddict[i]) == 2):
        iddict[i] = (iddict[i][0], iddict[i][1], -99)

    for i in atids:
      #if iddict[i][2] == -99:
      print("%5d" %iddict[i][1], end=' ', file=fresp1)
      print("%4s" %'0', file=fresp1)
      #else:
      #  print >> fresp1, "%5d" %iddict[i][1],
      #  print >> fresp1, "%4s" %iddict[i][2]
    fresp1.close()

    add_restriction('resp1.in', libdict, mol, resids, reslist, mcresids,
                    bnoresids, angresids, iddict, chgmod, fixchg_resids)

    #-------------------------------------------------------------------------
    ####################RESP2.IN file#########################################
    #-------------------------------------------------------------------------
    print("***Generating the 2nd stage resp charge fitting input file...")

    #1. print the 1st part, the title------------------------------------------
    fresp2 = open('resp2.in', 'w')
    print("Resp charges for organic molecule", file=fresp2)
    print(" ", file=fresp2)
    print(" &cntrl", file=fresp2)
    print(" ", file=fresp2)
    print(" nmol = 1,", file=fresp2)
    print(" ihfree = 1,", file=fresp2)
    print(" ioutopt = 1,", file=fresp2)
    print(" iqopt = 2,", file=fresp2)
    print(" qwt = 0.001,", file=fresp2)
    print(" ", file=fresp2)
    print(" &end", file=fresp2)
    print("    1.0", file=fresp2)
    print("Resp charges for organic molecule", file=fresp2)
    print("%5d" %lgchg, end=' ', file=fresp2)
    print("%4d" %len(atids), file=fresp2)

    #2. print the 2nd part, the free or frozen information---------------------
    for i in atids:
      print("%5d" %iddict[i][1], end=' ', file=fresp2)
      print("%4s" %iddict[i][2], file=fresp2)
    fresp2.close()

    add_restriction('resp2.in', libdict, mol, resids, reslist, mcresids,
                    bnoresids, angresids, iddict, chgmod, fixchg_resids)