Beispiel #1
0
def get_diS_bond(mol, atids):

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

    disul = []
    for i in resids:
      if mol.residues[i].resname in ['CYX', 'CYS']:
        #for atom in CYX or 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].resname in ['CYX', 'CYS']:
                if mol.atoms[k].atname == 'SG' and k != j:
                  atkcrd = mol.atoms[k].crd
                  dis = calc_bond(sgcrd, atkcrd)
                  if dis <= 2.50:
                    if (j < k) and ((j, k) not in disul):
                      disul.append((j, k))
                    elif ((k, j) not in disul):
                      disul.append((k, j))

    return disul
Beispiel #2
0
def get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, scalef, bondavg):

    crd1 = crds[3*nat1-3:3*nat1]
    crd2 = crds[3*nat2-3:3*nat2]
    disbohr = calc_bond(crd1, crd2) #unit is bohr
    dis = disbohr * B_TO_A #Transfer bohr to angstrom

    vec12 = array(crd2) - array(crd1) #vec12 is vec2 - vec1
    vec12 = [i/(disbohr) for i in vec12]
    vec12 = array(vec12)
 
    #bond force constant matrix, size 3 * 3
    bfcmatrix = array([[float(0) for x in range(3)] for x in range(3)])
   
    #1. First way to chose the matrix-----------------
    for i in range(0, 3):
      for j in range(0, 3):
        bfcmatrix[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat2-1)+j]
    eigval, eigvector = eig(bfcmatrix)
    fc = 0.0
    for i in range(0, 3):
      ev = eigvector[:,i]
      fc = fc + eigval[i] * abs(dot(ev, vec12))
    fcfinal1 = fc * HB2_TO_KCAL_MOL_A2 * 0.5

    if bondavg == 1:
      #2. Second way to chose the matrix-----------------
      for i in range(0, 3):
        for j in range(0, 3):
          bfcmatrix[i][j] = -fcmatrix[3*(nat2-1)+i][3*(nat1-1)+j]
      eigval, eigvector = eig(bfcmatrix)
      fc = 0.0
      for i in range(0, 3):
        ev = eigvector[:,i]
        fc = fc + eigval[i] * abs(dot(ev, vec12))
      fcfinal2 = fc * HB2_TO_KCAL_MOL_A2 * 0.5

      #Hatree/(Bohr^2) to kcal/(mol*angstrom^2)
      #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2

      fcfinal = average([fcfinal1, fcfinal2])
      stdv = std([fcfinal1, fcfinal2])
      fcfinal = fcfinal * scalef * scalef
      stdv = stdv * scalef * scalef
      return dis, fcfinal, stdv

    elif bondavg == 0:

      fcfinal = fcfinal1 * scalef * scalef
      return dis, fcfinal
Beispiel #3
0
def get_blist(mol, atids):
    blist = []
    for i in range(0, len(atids)):
        crdi = mol.atoms[atids[i]].crd
        ati = mol.atoms[atids[i]].element
        if (len(ati) == 2):
            ati = ati[0] + ati[1].lower()
        radiusi = CoRadiiDict[ati]
        for j in range(i + 1, len(atids)):
            crdj = mol.atoms[atids[j]].crd
            atj = mol.atoms[atids[j]].element
            if (len(atj) == 2):
                atj = atj[0] + atj[1].lower()
            radiusj = CoRadiiDict[atj]
            radiusij = radiusi + radiusj + 0.40
            dis = calc_bond(crdi, crdj)
            if (dis > 0.1) and (dis <= radiusij):
                blist.append((atids[i], atids[j], 1))
    return blist
Beispiel #4
0
def get_blist(mol, atids):
    blist = []
    for i in range(0, len(atids)):
      crdi = mol.atoms[atids[i]].crd
      ati = mol.atoms[atids[i]].element
      if (len(ati) == 2):
        ati = ati[0] + ati[1].lower()
      radiusi = CoRadiiDict[ati]
      for j in range(i+1, len(atids)):
        crdj = mol.atoms[atids[j]].crd
        atj = mol.atoms[atids[j]].element
        if (len(atj) == 2):
          atj = atj[0] + atj[1].lower()
        radiusj = CoRadiiDict[atj]
        radiusij = radiusi + radiusj + 0.40
        dis = calc_bond(crdi, crdj)
        if (dis > 0.1) and (dis <= radiusij):
          blist.append((atids[i], atids[j], 1))
    return blist
Beispiel #5
0
def get_mc_blist(mol, atids, ionids, fpf):

    blist = []

    rlnk = open(fpf, 'r')
    for line in rlnk:
        if line[0:4] == "LINK":
            line = line.strip('\n')
            line = line.split()
            ati = line[1].split('-')
            atidi = int(ati[0])
            atj = line[2].split('-')
            atidj = int(atj[0])
            if atidi < atidj:
                blist.append((atidi, atidj, 1))
            else:
                blist.append((atidj, atidi, 1))
    rlnk.close()

    for i in range(0, len(atids)):
        crdi = mol.atoms[atids[i]].crd
        ati = mol.atoms[atids[i]].element
        if (len(ati) == 2):
            ati = ati[0] + ati[1].lower()
        radiusi = CoRadiiDict[ati]
        for j in range(i + 1, len(atids)):
            crdj = mol.atoms[atids[j]].crd
            atj = mol.atoms[atids[j]].element
            if (len(atj) == 2):
                atj = atj[0] + atj[1].lower()
            radiusj = CoRadiiDict[atj]
            radiusij = radiusi + radiusj + 0.40
            dis = calc_bond(crdi, crdj)

            if list(set([atids[i], atids[j]]) & set(ionids)) == []:
                #If there is no metal ion in the bond
                if (dis > 0.1) and (dis <= radiusij):
                    blist.append((atids[i], atids[j], 1))

    blist = sorted(blist)

    return blist
Beispiel #6
0
def get_mc_blist(mol, atids, ionids, fpf):

    blist = []

    rlnk = open(fpf, 'r')
    for line in rlnk:
      if line[0:4] == "LINK":
        line = line.strip('\n')
        line = line.split()
        ati = line[1].split('-')
        atidi = int(ati[0])
        atj = line[2].split('-')
        atidj = int(atj[0])
        if atidi < atidj:
          blist.append((atidi, atidj, 1))
        else:
          blist.append((atidj, atidi, 1))
    rlnk.close()

    for i in range(0, len(atids)):
      crdi = mol.atoms[atids[i]].crd
      ati = mol.atoms[atids[i]].element
      if (len(ati) == 2):
        ati = ati[0] + ati[1].lower()
      radiusi = CoRadiiDict[ati]
      for j in range(i+1, len(atids)):
        crdj = mol.atoms[atids[j]].crd
        atj = mol.atoms[atids[j]].element
        if (len(atj) == 2):
          atj = atj[0] + atj[1].lower()
        radiusj = CoRadiiDict[atj]
        radiusij = radiusi + radiusj + 0.40
        dis = calc_bond(crdi, crdj)

        if list(set([atids[i], atids[j]]) & set(ionids)) == []: 
        #If there is no metal ion in the bond
          if (dis > 0.1) and (dis <= radiusij):
            blist.append((atids[i], atids[j], 1))
    
    blist = sorted(blist)

    return blist
Beispiel #7
0
def afqmmm_nmr(cresids, mol, atids, resids):
    #==========================================================================
    # For each core residue, do the analysis and print out work
    #==========================================================================
    bdld = {'CH': 1.090, 'NH': 1.010}

    #determine the amino acid residues
    aaresids = []
    for j in resids:
      hasatoms = []
      for k in mol.residues[j].resconter:
        hasatoms.append(mol.atoms[k].atname)
      if set(['C', 'O', 'CA', 'N']) <= set(hasatoms):
        aaresids.append(j)

    for i in cresids:
      if i == 0:
        raise pymsmtError('Residue number could not be %s.' % i)
      if i not in aaresids:
        raise pymsmtError('The core residue %s is not an amino acid.' % i)

      fp = open('number' + str(i) + '.com', 'w') #Gaussian input file
      fpf = open('number' + str(i) + '.fpf', 'w') #finger print file
      infof = open('number' + str(i) + '.info', 'w') #information file
      xyzf = open('number' + str(i) + '.xyz', 'w') #xyz file

      print >> xyzf, 'NNNNN'
      print >> xyzf, 'Title'

      print >> infof, 'This molecule has ' + str(len(resids)) + ' residues.'
      print >> infof, 'Core residue = ', i

      print >> fp, '%%chk=number%d.chk' % i
      print >> fp, '%mem=22GB'
      print >> fp, '%nproc=8'
      print >> fp, '#b3lyp/6-31G* charge nmr'
      print >> fp, ' '
      print >> fp, 'Have a nice day'

      bresids = [] #buffer region
      ccaps = [] #C terminal capped residue
      ncaps = [] #N terminal capped residue

      catoms = []
      im1 = i - 1

      if (im1 not in aaresids) and (im1 != 0):
        raise pymsmtError('Could not find the C, O backbone atoms in '
                          'the residue %s, which is connect to the core '
                          'residue %s' % (im1, i))
      ##=======================================================================
      ##  get the core atoms
      ##=======================================================================
      for j in mol.residues[i].resconter:
        atname = mol.atoms[j].atname
        if atname not in ['C', 'O']:
          catoms.append(j)
      if i != 1:
        for j in mol.residues[im1].resconter:
          atname = mol.atoms[j].atname
          if atname in ['C', 'O']:
            catoms.append(j)
      ##=======================================================================
      ##  get the buffer residues
      ##=======================================================================
      #1. distance creteria
      for j in catoms:
        hnum1 = 0
        elmt1 = mol.atoms[j].element
        crd1 = mol.atoms[j].crd
        if elmt1 == 'H':
          hnum1 = 1
        for k in atids:
          if k != j:
            hnum2 = 0
            elmt2 = mol.atoms[k].element
            crd2 = mol.atoms[k].crd
            dis = calc_bond(crd1, crd2)
            at2 = mol.atoms[k].atname
            resid2 = mol.atoms[k].resid
            if elmt2 == 'H':
              hnum2 = 1
            hnums = hnum1 + hnum2
            #first criterion
            if hnums == 2 and dis <= 3.0:
              if mol.atoms[k].atname not in ['C', 'O']:
                if mol.atoms[k].resid not in bresids:
                  bresids.append(mol.atoms[k].resid)
              else:
                if (mol.atoms[k].resid+1 not in bresids):
                  bresids.append(mol.atoms[k].resid+1)
            #second criterion
            elif hnums == 1 and dis <= 4.0:
              if mol.atoms[k].atname not in ['C', 'O']:
                if mol.atoms[k].resid not in bresids:
                  bresids.append(mol.atoms[k].resid)
              else:
                if mol.atoms[k].resid+1 not in bresids:
                  bresids.append(mol.atoms[k].resid+1)
            #third criterion
            elif (mol.atoms[k].resname in ['HIE', 'HIP', 'HID', 'HIS', 'PHE', \
                 'TYR', 'TRP']) and (at2 not in ['O', 'C', 'N', 'H', 'CA', \
                 'HA', 'CB', 'HB2', 'HB3', 'OH', 'HO']) and (dis <= 5.0):
              if mol.atoms[k].atname not in ['C', 'O']:
                if mol.atoms[k].resid not in bresids:
                  bresids.append(mol.atoms[k].resid)
              else:
                if mol.atoms[k].resid+1 not in bresids:
                  bresids.append(mol.atoms[k].resid+1)
      print >> infof, 'After the distance criterion: Buffer residues =       '\
               , sorted(bresids)
      #2. core creteria
      for j in range(i-2, i+3):
        if (j > 0) and (j <= max(resids)):
          if (j in aaresids) and (j not in bresids):
            bresids.append(j)
      print >> infof, 'After the core criterion: Buffer residues =           '\
               , sorted(bresids)
      #3. disulfur bond creteria
      for j in bresids:
        if j<= max(resids):
          if mol.residues[j].resname == 'CYX':
            for k in mol.residues[j].resconter:
              if mol.atoms[k].atname == 'SG':
                for l in atids:
                  if (l != k) and (mol.atoms[l].atname == 'SG') and \
                  (mol.atoms[l].resname == 'CYX'):
                    dis = calc_bond(mol.atoms[l].crd, mol.atoms[k].crd)
                    if (dis <= 2.5) and (mol.atoms[l].resid not in bresids):
                      bresids.append(mol.atoms[l].resid)
      print >> infof, 'After the disulfide bond criterion: Buffer residues = '\
               , sorted(bresids)
      ####=====================================================================
      ####  For special situation
      ####=====================================================================
      #for N terminal
      if (resids[0] in bresids) and (resids[1] not in bresids):
        if (resids[1] in aaresids):
          bresids.append(resids[1])

      #for C terminal
      if (max(aaresids)+1 in bresids):
        hasct = 1
        bresids.remove(max(aaresids)+1)
        if (max(aaresids) not in bresids):
          bresdis.append(max(aaresids))
      else:
        hasct = 0

      #get C-terminal and N-terminal caps
      for j in bresids:
        if (j-1 not in bresids) and (j-1 > 0) and (j-1 in aaresids):
          ncaps.append(j-1)#ncaps

      if hasct == 1:
        for j in bresids:
          if (j+1 not in bresids) and (j != max(aaresids)):
            ccaps.append(j)
      else:
        for j in bresids:
          if (j+1 not in bresids):
            ccaps.append(j)#ccaps

      bresids = list(set(bresids) - set(ccaps))
      bresids.sort()

      print >> infof, 'After the special case criterion: Buffer residues =   '\
               , sorted(bresids)
      print >> infof, 'After the special case criterion: N-terimal caps =    '\
               , sorted(ncaps)
      print >> infof, 'After the special case criterion: C-terimal caps =    '\
               , sorted(ccaps)
      ####=====================================================================
      ####  get the charge and spin of the two structures
      ####=====================================================================
      totchg = 0.0
      chgres = [i]
      chgres = list(set(chgres + bresids))

      for j in chgres:
        chglist = [mol.atoms[k].charge for k in mol.residues[j].resconter]
        chgj = sum(chglist)
        totchg = totchg + float(chgj)

      print >> fp, ' '
      print >> fp, '%-5d %5s' %(int(round(totchg, 0)), 'SSSSS')
      ####=====================================================================
      ####  Print the core region
      ####=====================================================================
      #print >> fp, "Core region residue: ", i

      for j in catoms:
        element = mol.atoms[j].element
        crdx = mol.atoms[j].crd[0]
        crdy = mol.atoms[j].crd[1]
        crdz = mol.atoms[j].crd[2]
        print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, crdz)
        print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, crdz)
        print >> fpf, str(mol.atoms[j].resid) + '-' + \
                 mol.atoms[j].resname + '-' + mol.atoms[j].atname
      ####=====================================================================
      ####  Print the N-terminal cap
      ####=====================================================================
      hcapnum = 0
      batoms = [] #buffer atoms

      for j in ncaps:
        #print >> infof, "N-terminal cap residues: ", j
        for k in mol.residues[j].resconter:
          if mol.atoms[k].atname == 'C':
            ccrd = mol.atoms[k].crd
        for k in mol.residues[j].resconter:
          if mol.atoms[k].atname in ['O', 'C']:
            batoms.append(k)
            element = mol.atoms[k].element
            crdx = mol.atoms[k].crd[0]
            crdy = mol.atoms[k].crd[1]
            crdz = mol.atoms[k].crd[2]
            print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
            print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
          elif mol.atoms[k].atname == 'CA': #change to H
            hcapnum += 1
            element = 'H'
            bvec = calc_bond(ccrd, mol.atoms[k].crd)
            crdx = ccrd[0] + bdld['CH'] * (mol.atoms[k].crd[0] - ccrd[0])/bvec
            crdy = ccrd[1] + bdld['CH'] * (mol.atoms[k].crd[1] - ccrd[1])/bvec
            crdz = ccrd[2] + bdld['CH'] * (mol.atoms[k].crd[2] - ccrd[2])/bvec
            crdx = round(crdx, 3)
            crdy = round(crdy, 3)
            crdz = round(crdz, 3)
            print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
            print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
      ####=====================================================================
      ####  print the C-terminal cap
      ####=====================================================================
      for j in ccaps:
        #print >> fp, "C-terminal cap residues: ", j
        for k in mol.residues[j].resconter:
          if mol.atoms[k].atname == 'CA':
            cacrd = mol.atoms[k].crd

        for k in mol.residues[j].resconter:
          if mol.atoms[k].atname != 'O':
            if mol.atoms[k].atname == 'C': #change to H
              hcapnum += 1
              element = 'H'
              bvec = calc_bond(cacrd, mol.atoms[k].crd)
              crdx = cacrd[0] + bdld['CH'] * (mol.atoms[k].crd[0] - cacrd[0])\
                     /bvec
              crdy = cacrd[1] + bdld['CH'] * (mol.atoms[k].crd[1] - cacrd[1])\
                     /bvec
              crdz = cacrd[2] + bdld['CH'] * (mol.atoms[k].crd[2] - cacrd[2])\
                     /bvec
              crdx = round(crdx, 3)
              crdy = round(crdy, 3)
              crdz = round(crdz, 3)
              print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                       crdz)
              print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                       crdz)
            else:
              batoms.append(k)
              element = mol.atoms[k].element
              crdx = mol.atoms[k].crd[0]
              crdy = mol.atoms[k].crd[1]
              crdz = mol.atoms[k].crd[2]
              print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                       crdz)
              print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                       crdz)

      ##for the speicial case
      if hasct == 1:
        j = max(aaresids)
        for k in mol.residues[j].resconter:
          if mol.atoms[i].atname in ['C', 'O', 'OXT']:
            batoms.append(k)
            element = mol.atoms[k].element
            crdx = mol.atoms[k].crd[0]
            crdy = mol.atoms[k].crd[1]
            crdz = mol.atoms[k].crd[2]
            print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
            print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                     crdz)
      ####=====================================================================
      ####  print the other buffer resids
      ####=====================================================================
      for j in bresids:
        #print >> fp, "Buffer residues: ", j
        for k in mol.residues[j].resconter:
          if k not in catoms:
            batoms.append(k)
            element = mol.atoms[k].element
            crdx = mol.atoms[k].crd[0]
            crdy = mol.atoms[k].crd[1]
            crdz = mol.atoms[k].crd[2]
            print >> fp, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \
                     crdz)
            print >> xyzf, '%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\
                     crdz)

      print >> fp, ' '
      ####=====================================================================
      ####  print the other parts, background charge
      ####=====================================================================
      #print len(atids), len(catoms), len(batoms)
      nums = 0
      for j in atids:
        if (j not in catoms) and (j not in batoms):
          crdx = mol.atoms[j].crd[0]
          crdy = mol.atoms[j].crd[1]
          crdz = mol.atoms[j].crd[2]
          resname = mol.atoms[j].resname
          atname = mol.atoms[j].atname
          chg = mol.atoms[j].charge
          print >> fp,'%10.3f %10.3f %10.3f %10.5f' %(crdx, crdy, crdz, chg)
          nums += 1
          #elif mol.atoms[j].resid == resids[-2]:
          #  crdx = mol.atoms[j].crd[0]
          #  crdy = mol.atoms[j].crd[1]
          #  crdz = mol.atoms[j].crd[2]
          #  resname = mol.atoms[j].resname
          #  atname = mol.atoms[j].atname
          #  chg = mol.atoms[j].charge
          #  print >> fp,'%10.3f %10.3f %10.3f %10.5f' %(crdx, crdy, crdz, chg)
          #elif mol.residues[mol.atoms[j].resid].resname != 'LIG':
          #  crdx = mol.atoms[j].crd[0]
          #  crdy = mol.atoms[j].crd[1]
          #  crdz = mol.atoms[j].crd[2]
          #  resname = mol.atoms[j].resname
          #  atname = mol.atoms[j].atname
          #  chg = mol.atoms[j].charge
          #  print >> fp,'%10.3f %10.3f %10.3f %10.5f' %(crdx, crdy, crdz, chg)
      #print nums
      if nums + len(catoms) + len(batoms) == len(atids):
        pass
      else:
        raise pymsmtError('The output atom numbers are not consistent with '
                          'former toplogy file.')

      print >> fp, ' '
      print >> fp, ' '
      print >> fp, ' '

      fp.close()
      fpf.close()
      infof.close()
      xyzf.close()

      #get spin
      spin = get_spin('number' + str(i) + '.com', totchg)
      os.system("sed -i '' 's/SSSSS/%-5d/g' %s" %(spin, 'number' + str(i) + \
                '.com'))

      #get the xyz number
      xyznum = \
        os.popen("awk 'END {print NR}' %s" %('number'+str(i)+'.xyz')).read()
      xyznum = int(xyznum) - 2
      os.system("sed -i '' 's/NNNNN/%-5d/g' %s" %(xyznum, \
        'number' + str(i) + '.xyz'))

      #check whether the atom number is the same
      cfatnum = \
        os.popen("awk 'END {print NR}' %s" %('number'+str(i)+'.com')).read()
      cfatnum = int(cfatnum) - 12 #com file atom number
      topatnum = len(atids) + hcapnum #top file atom number

      if cfatnum == topatnum:
        pass
      else:
        raise pymsmtError('The atnum are not consistent between the com file '
                          'and toplogy file.')
Beispiel #8
0
def get_all_list(mol, blist, atids, cutoff):

    ###1. Bond list
    blist = sorted(blist)

    ###2. Angle list
    alist = []

    for i in range(0, len(blist)):
        ati1 = blist[i][0]
        ati2 = blist[i][1]
        for j in range(i + 1, len(blist)):
            atj1 = blist[j][0]
            atj2 = blist[j][1]
            if (ati1 == atj1):
                at1 = atj2
                at2 = ati1
                at3 = ati2
                angats = (at1, at2, at3)
                alist.append(angats)
            elif (ati1 == atj2):
                at1 = atj1
                at2 = ati1
                at3 = ati2
                angats = (at1, at2, at3)
                alist.append(angats)
            elif (ati2 == atj1):
                at1 = ati1
                at2 = ati2
                at3 = atj2
                angats = (at1, at2, at3)
                alist.append(angats)
            elif (ati2 == atj2):
                at1 = ati1
                at2 = ati2
                at3 = atj1
                angats = (at1, at2, at3)
                alist.append(angats)

    alist = get_pure_type(alist)

    ###3. Dihedral list
    dlist = []

    for i in range(0, len(alist)):
        ati1 = alist[i][0]
        ati2 = alist[i][1]
        ati3 = alist[i][2]
        for j in range(i + 1, len(alist)):
            atj1 = alist[j][0]
            atj2 = alist[j][1]
            atj3 = alist[j][2]
            if (ati2 == atj1) & (ati3 == atj2) & (ati1 != atj3):
                at1 = ati1
                at2 = ati2
                at3 = ati3
                at4 = atj3
                dihats = (at1, at2, at3, at4)
                dlist.append(dihats)
            elif (ati2 == atj3) & (ati3 == atj2) & (ati1 != atj1):
                at1 = ati1
                at2 = ati2
                at3 = ati3
                at4 = atj1
                dihats = (at1, at2, at3, at4)
                dlist.append(dihats)
            elif (ati1 == atj2) & (ati2 == atj3) & (atj1 != ati3):
                at1 = atj1
                at2 = ati1
                at3 = ati2
                at4 = ati3
                dihats = (at1, at2, at3, at4)
                dlist.append(dihats)
            elif (ati1 == atj2) & (ati2 == atj1) & (atj3 != ati3):
                at1 = atj3
                at2 = ati1
                at3 = ati2
                at4 = ati3
                dihats = (at1, at2, at3, at4)
                dlist.append(dihats)

    dlist = get_pure_type(dlist)

    ###4. Improper torsion list
    ilist = []  #Second is the centeral atom
    for i in range(0, len(alist)):
        ati1 = alist[i][0]
        ati2 = alist[i][1]
        ati3 = alist[i][2]
        for j in range(0, len(blist)):
            atj1 = blist[j][0]
            atj2 = blist[j][1]
            if (ati2 == atj1) and (atj2 != ati1) and (atj2 != ati3):
                at1 = ati1
                at2 = ati3
                at3 = ati2
                at4 = atj2
                impats = (at1, at2, at3, at4)
                ilist.append(impats)
            elif (ati2 == atj2) and (atj1 != ati1) and (atj1 != ati3):
                at1 = ati1
                at2 = ati3
                at3 = ati2
                at4 = atj1
                impats = (at1, at2, at3, at4)
                ilist.append(impats)

    ilist2 = []  #Third is the centeral atoms
    for imp in ilist:
        imp1 = (imp[0], imp[1], imp[2], imp[3])
        imp2 = (imp[0], imp[3], imp[2], imp[1])
        imp3 = (imp[1], imp[0], imp[2], imp[3])
        imp4 = (imp[1], imp[3], imp[2], imp[0])
        imp5 = (imp[3], imp[0], imp[2], imp[1])
        imp6 = (imp[3], imp[1], imp[2], imp[0])
        if (imp1 not in ilist2) and (imp2 not in ilist2) and (imp3 not in ilist2) \
          and (imp4 not in ilist2) and (imp5 not in ilist2) and (imp6 not in ilist2):
            ilist2.append(imp)

    ###5. nonbonded array
    ##get bonded atom list
    bondedatomlist = []

    #bond
    for i in range(0, len(blist)):
        atm1 = blist[i][0]
        atm2 = blist[i][1]
        if (atm1 < atm2):
            bondedatomlist.append((atm1, atm2))
        else:
            bondedatomlist.append((atm2, atm1))

    #angle
    for i in range(0, len(alist)):
        atm1 = alist[i][0]
        atm2 = alist[i][-1]
        if (atm1 < atm2):
            bondedatomlist.append((atm1, atm2))
        else:
            bondedatomlist.append((atm2, atm1))

    #dihedral
    for i in range(0, len(dlist)):
        atm1 = dlist[i][0]
        atm2 = dlist[i][-1]
        if (atm1 < atm2):
            bondedatomlist.append((atm1, atm2))
        else:
            bondedatomlist.append((atm2, atm1))

    bondedatomlist = set(bondedatomlist)

    ##get total atom list
    totlist = []
    for i in range(0, len(atids)):
        for j in range(i + 1, len(atids)):
            atm1 = atids[i]
            atm2 = atids[j]
            if (atm1 < atm2):
                totlist.append((atm1, atm2))
            else:
                totlist.append((atm2, atm1))

    totlist = set(totlist)

    ##Get total nb list
    nblist = totlist - bondedatomlist
    nblist = sorted(list(nblist))

    fnblist = []

    for i in range(0, len(nblist)):
        atm1 = nblist[i][0]
        atm2 = nblist[i][1]

        crd1 = mol.atoms[atm1].crd
        crd2 = mol.atoms[atm2].crd

        dis = calc_bond(crd1, crd2)

        if (dis <= cutoff):
            fnblist.append(nblist[i])

    del nblist
    del totlist
    del bondedatomlist

    all_list = Linklist(blist, alist, dlist, ilist2, fnblist)

    return all_list
Beispiel #9
0
def get_imp_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, nat4, scalef):

    crd1 = crds[3*nat1-3:3*nat1]
    crd2 = crds[3*nat2-3:3*nat2]
    crd3 = crds[3*nat3-3:3*nat3]
    crd4 = crds[3*nat4-3:3*nat4]

    dis12 = calc_bond(crd1, crd2) #unit is bohr
    dis13 = calc_bond(crd1, crd3) #unit is bohr
    dis23 = calc_bond(crd2, crd3) #unit is bohr
    dis34 = calc_bond(crd3, crd4) #unit is bohr

    #get the unit vector
    vec12 = array(crd2) - array(crd1) #vec12 is vec2 - vec1
    vec21 = - vec12
    vec23 = array(crd3) - array(crd2)
    vec32 = - vec23
    vec34 = array(crd4) - array(crd3)
    vec43 = - vec34

    vec12 = array([i/dis12 for i in vec12])
    vec21 = array([i/dis12 for i in vec21])
    vec23 = array([i/dis23 for i in vec23])
    vec32 = array([i/dis23 for i in vec32])
    vec34 = array([i/dis34 for i in vec34])
    vec43 = array([i/dis34 for i in vec43])

    #get the normalized vector
    vecUNp = cross(vec43, vec23)
    vecUN = array([i/norm(vecUNp) for i in vecUNp]) #vecUN is the vector
                                     #perpendicular to the plance of ABC

    afcmatrix12 = array([[float(0) for x in range(3)] for x in range(3)])
    afcmatrix13 = array([[float(0) for x in range(3)] for x in range(3)])
    afcmatrix14 = array([[float(0) for x in range(3)] for x in range(3)])
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix12[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat2-1)+j]
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix13[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat3-1)+j]
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix14[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat4-1)+j]

    eigval12, eigvector12 = eig(afcmatrix12)
    eigval13, eigvector13 = eig(afcmatrix13)
    eigval14, eigvector14 = eig(afcmatrix14)
    contri12 = 0.0
    contri13 = 0.0
    contri14 = 0.0
    for i in range(0, 3):
      ev12 = eigvector12[:,i]
      ev13 = eigvector13[:,i]
      ev14 = eigvector14[:,i]
      contri12 = contri12 + eigval12[i] * abs(dot(vecUN, ev12))
      contri13 = contri13 + eigval13[i] * abs(dot(vecUN, ev13))
      contri14 = contri14 + eigval14[i] * abs(dot(vecUN, ev14))

    kAN = (contri12 + contri13 + contri14) * H_TO_KCAL_MOL * 0.5

    fcfinal1 = kAN/(B_TO_A**2)

    #Get hABCD
    pval = (dis12 + dis23 + dis13)/2.0
    sqABC = math.sqrt(pval*(pval-dis12)*(pval-dis23)*(pval-dis13))
    disAtoBC = sqABC * 2.0 / dis23 #distance between A and BC side, unit is bohr

    #get the normalized vector
    vecUNABCp = cross(vec32, vec12)
    vecUNABC = array([i/norm(vecUNABCp) for i in vecUNABCp])
    vecUNBCDp = cross(vec43, vec23)
    vecUNBCD = array([i/norm(vecUNBCDp) for i in vecUNBCDp])

    #dihang = math.acos(dot(vecUNABC, vecUNBCD))

    #hABCD = disAtoBC * dot(vecUNABC, vecUNBCD)

    fcfinal = (disAtoBC ** 2) * kAN / 2.0 #H_TO_KCAL_MOL #HB2_TO_KCAL_MOL_A2

    fcfinal1 = fcfinal1 * scalef * scalef
    fcfinal = fcfinal * scalef * scalef

    return fcfinal1, fcfinal
Beispiel #10
0
def get_dih_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, nat4, n1, n2, scalef):

    crd1 = crds[3*nat1-3:3*nat1]
    crd2 = crds[3*nat2-3:3*nat2]
    crd3 = crds[3*nat3-3:3*nat3]
    crd4 = crds[3*nat4-3:3*nat4]

    dihval = calc_dih(crd1, crd2, crd3, crd4)

    dis12 = calc_bond(crd1, crd2) #unit is bohr
    dis23 = calc_bond(crd2, crd3) #unit is bohr
    dis34 = calc_bond(crd3, crd4) #unit is bohr

    #get the unit vector
    vec12 = array(crd2) - array(crd1) #vec12 is vec2 - vec1
    vec21 = - vec12
    vec23 = array(crd3) - array(crd2)
    vec32 = - vec23
    vec34 = array(crd4) - array(crd3)
    vec43 = - vec34

    vec12 = array([i/dis12 for i in vec12])
    vec21 = array([i/dis12 for i in vec21])
    vec23 = array([i/dis23 for i in vec23])
    vec32 = array([i/dis23 for i in vec32])
    vec34 = array([i/dis34 for i in vec34])
    vec43 = array([i/dis34 for i in vec43])

    #get the normalized vector
    vecUNABCp = cross(vec32, vec12)
    vecUNABC = array([i/norm(vecUNABCp) for i in vecUNABCp])

    vecUNBCDp = cross(vec43, vec23)
    vecUNBCD = array([i/norm(vecUNBCDp) for i in vecUNBCDp])

    afcmatrix12 = array([[float(0) for x in range(3)] for x in range(3)])
    afcmatrix43 = array([[float(0) for x in range(3)] for x in range(3)])
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix12[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat2-1)+j]
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix43[i][j] = -fcmatrix[3*(nat4-1)+i][3*(nat3-1)+j]
    eigval12, eigvector12 = eig(afcmatrix12)
    eigval43, eigvector43 = eig(afcmatrix43)

    contri12 = 0.0
    contri34 = 0.0
    for i in range(0, 3):
      ev12 = eigvector12[:,i]
      ev43 = eigvector43[:,i]
      contri12 = contri12 + eigval12[i] * abs(dot(vecUNABC, ev12))
      contri34 = contri34 + eigval43[i] * abs(dot(vecUNBCD, ev43))

    contri12 = contri12 * (norm(cross(vec12, vec23)) ** 2)
    contri34 = contri34 * (norm(cross(vec23, vec34)) ** 2)
    contri12 = 1.0 / (contri12 * dis12 * dis12)
    contri34 = 1.0 / (contri34 * dis34 * dis34)

    fcfinal1 = (1.0 / (contri12 + contri34)) * H_TO_KCAL_MOL * 0.5 #/ (math.degrees(1.0)**2)

    fcfinal = fcfinal1 * (math.radians(180.0/float(n2))) **2 / (float(n1) * float(n2))

    fcfinal = fcfinal * scalef * scalef

    return dihval, fcfinal1, fcfinal
Beispiel #11
0
def gene_by_empirical_way(scpdbf, ionids, stfpf, pref, finf):

    print "******************************************************************"
    print "*                                                                *"
    print "*===========Using the empirical way to solve the problem=========*"
    print "*                                                                *"
    print "******************************************************************"

    #Read from sidechain pdb
    mol, atids, resids = get_atominfo_fpdb(scpdbf)
    blist = get_mc_blist(mol, atids, ionids, stfpf)
    alist = get_alist(mol, blist)

    attypdict = get_attypdict(stfpf, atids)
    missbondtyps, missangtyps = get_misstyps(pref)

    finalparmdict = {}

    #for bond
    print "=======================Generate the bond parameters==============="

    for misbond in missbondtyps:
      bondlen = []
      bfconst = []
      for bond in blist:
        at1 = bond[0]
        at2 = bond[1]
        bondtyp = (attypdict[at1], attypdict[at2])
        if bondtyp == misbond or bondtyp[::-1] == misbond:
          crd1 = mol.atoms[at1].crd
          crd2 = mol.atoms[at2].crd
          dis = calc_bond(crd1, crd2)
          dis = round(dis, 4)
          bondlen.append(dis)

          #get the atom number
          elmt1 = mol.atoms[at1].element
          elmt2 = mol.atoms[at2].element
          elmts = [elmt1, elmt2]
          elmts = sorted(elmts)

          fcfinal = fcfit_ep_bond(dis, elmts)
          bfconst.append(fcfinal)

      #Get average bond parameters
      misbondat12 = misbond[0] + '-' + misbond[1]
      bond_para = avg_bond_para(misbondat12, bondlen, bfconst)
      #get the force constant
      finalparmdict[misbondat12] = bond_para

    #for angle
    print "=======================Generate the angle parameters=============="

    for misang in missangtyps:
      angvals = []
      afconst = []
      for ang in alist:
        at1 = ang[0]
        at2 = ang[1]
        at3 = ang[2]
        angtyp = (attypdict[at1], attypdict[at2], attypdict[at3])
        if angtyp == misang or angtyp[::-1] == misang:
          crd1 = mol.atoms[at1].crd
          crd2 = mol.atoms[at2].crd
          crd3 = mol.atoms[at3].crd
          angval = calc_angle(crd1, crd2, crd3)
          angvals.append(angval)

          elmt1 = mol.atoms[at1].element
          elmt2 = mol.atoms[at2].element
          elmt3 = mol.atoms[at3].element
          elmts = [elmt1, elmt2, elmt3]
          fcfinal = fcfit_ep_angle(elmts)
          afconst.append(fcfinal)

      #Get average angle parameters
      misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2]
      ang_para = avg_angle_para(misangat123, angvals, afconst)
      finalparmdict[misangat123] = ang_para

    #Print out the final frcmod file
    print_frcmod_file(pref, finf, finalparmdict, 'empirical')
Beispiel #12
0
def get_all_list(mol, blist, atids, cutoff):

  ###1. Bond list
  blist = sorted(blist)

  ###2. Angle list
  alist = []

  for i in range(0, len(blist)):
    ati1 = blist[i][0]
    ati2 = blist[i][1]
    for j in range(i+1, len(blist)):
      atj1 = blist[j][0]
      atj2 = blist[j][1]
      if (ati1 == atj1):
        at1 = atj2
        at2 = ati1
        at3 = ati2
        angats = (at1, at2, at3)
        alist.append(angats)
      elif (ati1 == atj2):
        at1 = atj1
        at2 = ati1
        at3 = ati2
        angats = (at1, at2, at3)
        alist.append(angats)
      elif (ati2 == atj1):
        at1 = ati1
        at2 = ati2
        at3 = atj2
        angats = (at1, at2, at3)
        alist.append(angats)
      elif (ati2 == atj2):
        at1 = ati1
        at2 = ati2
        at3 = atj1
        angats = (at1, at2, at3)
        alist.append(angats)

  alist = get_pure_type(alist)

  ###3. Dihedral list
  dlist = []

  for i in range(0, len(alist)):
    ati1 = alist[i][0]
    ati2 = alist[i][1]
    ati3 = alist[i][2]
    for j in range(i + 1, len(alist)):
      atj1 = alist[j][0]
      atj2 = alist[j][1]
      atj3 = alist[j][2]
      if (ati2 == atj1) & (ati3 == atj2) & (ati1 != atj3):
        at1 = ati1
        at2 = ati2
        at3 = ati3
        at4 = atj3
        dihats = (at1, at2, at3, at4)
        dlist.append(dihats)
      elif (ati2 == atj3) & (ati3 == atj2) & (ati1 != atj1):
        at1 = ati1
        at2 = ati2
        at3 = ati3
        at4 = atj1
        dihats = (at1, at2, at3, at4)
        dlist.append(dihats)
      elif (ati1 == atj2) & (ati2 == atj3) & (atj1 != ati3):
        at1 = atj1
        at2 = ati1
        at3 = ati2
        at4 = ati3
        dihats = (at1, at2, at3, at4)
        dlist.append(dihats)
      elif (ati1 == atj2) & (ati2 == atj1) & (atj3 != ati3):
        at1 = atj3
        at2 = ati1
        at3 = ati2
        at4 = ati3
        dihats = (at1, at2, at3, at4)
        dlist.append(dihats)

  dlist = get_pure_type(dlist)


  ###4. Improper torsion list
  ilist = [] #Second is the centeral atom
  for i in range(0, len(alist)):
    ati1 = alist[i][0]
    ati2 = alist[i][1]
    ati3 = alist[i][2]
    for j in range(0, len(blist)):
      atj1 = blist[j][0]
      atj2 = blist[j][1]
      if (ati2 == atj1) and (atj2 != ati1) and (atj2 != ati3):
        at1 = ati1
        at2 = ati3
        at3 = ati2
        at4 = atj2
        impats = (at1, at2, at3, at4)
        ilist.append(impats)
      elif (ati2 == atj2) and (atj1 != ati1) and (atj1 != ati3):
        at1 = ati1
        at2 = ati3
        at3 = ati2
        at4 = atj1
        impats = (at1, at2, at3, at4)
        ilist.append(impats)

  ilist2 = [] #Third is the centeral atoms
  for imp in ilist:
    imp1 = (imp[0], imp[1], imp[2], imp[3])
    imp2 = (imp[0], imp[3], imp[2], imp[1])
    imp3 = (imp[1], imp[0], imp[2], imp[3])
    imp4 = (imp[1], imp[3], imp[2], imp[0])
    imp5 = (imp[3], imp[0], imp[2], imp[1])
    imp6 = (imp[3], imp[1], imp[2], imp[0])
    if (imp1 not in ilist2) and (imp2 not in ilist2) and (imp3 not in ilist2) \
      and (imp4 not in ilist2) and (imp5 not in ilist2) and (imp6 not in ilist2):
      ilist2.append(imp)

  ###5. nonbonded array
  ##get bonded atom list
  bondedatomlist = []

  #bond
  for i in range(0, len(blist)):
    atm1 = blist[i][0]
    atm2 = blist[i][1]
    if (atm1 < atm2):
      bondedatomlist.append((atm1, atm2))
    else:
      bondedatomlist.append((atm2, atm1))

  #angle
  for i in range(0, len(alist)):
    atm1 = alist[i][0]
    atm2 = alist[i][-1]
    if (atm1 < atm2):
      bondedatomlist.append((atm1, atm2))
    else:
      bondedatomlist.append((atm2, atm1))

  #dihedral
  for i in range(0, len(dlist)):
    atm1 = dlist[i][0]
    atm2 = dlist[i][-1]
    if (atm1 < atm2):
      bondedatomlist.append((atm1, atm2))
    else:
      bondedatomlist.append((atm2, atm1))

  bondedatomlist = set(bondedatomlist)

  ##get total atom list
  totlist = []
  for i in range(0, len(atids)):
    for j in range(i+1, len(atids)):
      atm1 = atids[i]
      atm2 = atids[j]
      if (atm1 < atm2):
        totlist.append((atm1, atm2))
      else:
        totlist.append((atm2, atm1))

  totlist = set(totlist)

  ##Get total nb list
  nblist = totlist - bondedatomlist
  nblist = sorted(list(nblist))

  fnblist = []

  for i in range(0, len(nblist)):
    atm1 = nblist[i][0]
    atm2 = nblist[i][1]

    crd1 = mol.atoms[atm1].crd
    crd2 = mol.atoms[atm2].crd
  
    dis = calc_bond(crd1, crd2)

    if (dis <= cutoff):
      fnblist.append(nblist[i])

  del nblist
  del totlist
  del bondedatomlist
  
  all_list = Linklist(blist, alist, dlist, ilist2, fnblist)

  return all_list
Beispiel #13
0
  mettypinds.append(mettypind)

mcids = []
mctyps = []
mctypinds = []

if options.model == 1: #Small model
  for i in metids:
    crdi = mol.atoms[i].crd
    atmi = mol.atoms[i].element
    radiusi = CoRadiiDict[atmi]
    for j in atids:
      if j != i:
        crdj = mol.atoms[j].crd
        atmj = mol.atoms[j].element
        dis = calc_bond(crdi, crdj)
        radiusj = CoRadiiDict[atmj]
        radiusij = radiusi + radiusj
        if (dis <= radiusij + 0.4) and (dis >= 0.1) and (atmj != 'H'):
          k = j - 1
          #Atom IDs
          mcids.append(j)
          #Amber Atom Type
          atyp = prmtop.parm_data['AMBER_ATOM_TYPE'][k]
          mctyps.append(atyp)
          #Atom Type Index
          mctypind = prmtop.parm_data['ATOM_TYPE_INDEX'][k]
          mctypinds.append(mctypind)
elif options.model == 2: #Big model
  mcresids = []
  for i in metids:
Beispiel #14
0
        atnamei = mol.atoms[i].atname
        resnamei = mol.residues[residi].resname
        radiusi = CoRadiiDict[elmti]
        mcresids = []  #MetalCenter residue IDs

        #Get the residues which is the metal site
        for j in atids:
            if j != i:
                atnamej = mol.atoms[j].atname
                crdj = mol.atoms[j].crd
                residj = mol.atoms[j].resid
                resnamej = mol.residues[residj].resname
                elmtj = mol.atoms[j].element
                radiusj = CoRadiiDict[elmtj]
                radiusij = radiusi + radiusj + 0.40
                disij = calc_bond(crdi, crdj)

                if options.cutoff == None:
                    if (disij >= 0.1) and (disij <= radiusij) \
                       and (elmtj != 'H'):
                        mccrds.append(crdi)
                        mccrds.append(crdj)
                        if (residj not in mcresids):
                            mcresids.append(residj)
                else:
                    if (disij >= 0.1) and (disij <= options.cutoff) \
                       and (elmtj != 'H'):
                        mccrds.append(crdi)
                        mccrds.append(crdj)
                        if (residj not in mcresids):
                            mcresids.append(residj)
Beispiel #15
0
def get_ang_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, scalef, angavg):

    #get the angle value
    crd1 = crds[3*nat1-3:3*nat1]
    crd2 = crds[3*nat2-3:3*nat2]
    crd3 = crds[3*nat3-3:3*nat3]
    dis12 = calc_bond(crd1, crd2) #unit is bohr
    dis32 = calc_bond(crd3, crd2) #unit is bohr

    #get the unit vector
    vec12 = array(crd2) - array(crd1) #vec12 is vec2 - vec1
    vec32 = array(crd2) - array(crd3)
    vec12 = array([i/dis12 for i in vec12])
    vec32 = array([i/dis32 for i in vec32])

    angval = calc_angle(crd1, crd2, crd3)

    #get the normalized vector
    vecUNp = cross(vec32, vec12)
    vecUN = array([i/norm(vecUNp) for i in vecUNp]) #vecUN is the vector
                                     #perpendicular to the plance of ABC

    vecPA = cross(vecUN, vec12)
    vecPC = cross(vec32, vecUN)

    afcmatrix12 = array([[float(0) for x in range(3)] for x in range(3)])
    afcmatrix32 = array([[float(0) for x in range(3)] for x in range(3)])

    #1. First way to chose the matrix----------------------------------
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix12[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat2-1)+j]
    for i in range(0, 3):
      for j in range(0, 3):
        afcmatrix32[i][j] = -fcmatrix[3*(nat3-1)+i][3*(nat2-1)+j]
    eigval12, eigvector12 = eig(afcmatrix12)
    eigval32, eigvector32 = eig(afcmatrix32)
    contri12 = 0.0
    contri32 = 0.0
    for i in range(0, 3):
      ev12 = eigvector12[:,i]
      ev32 = eigvector32[:,i]
      contri12 = contri12 + eigval12[i] * abs(dot(vecPA, ev12))
      contri32 = contri32 + eigval32[i] * abs(dot(vecPC, ev32))
    contri12 = 1.0 / (contri12 * dis12 * dis12)
    contri32 = 1.0 / (contri32 * dis32 * dis32)
    fcfinal1 = (1.0 / (contri12 + contri32)) * H_TO_KCAL_MOL * 0.5

    if angavg == 1:
      #2. Second way to chose the matrix----------------------------------
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix12[i][j] = -fcmatrix[3*(nat2-1)+i][3*(nat1-1)+j]
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix32[i][j] = -fcmatrix[3*(nat3-1)+i][3*(nat2-1)+j]
      eigval12, eigvector12 = eig(afcmatrix12)
      eigval32, eigvector32 = eig(afcmatrix32)
      contri12 = 0.0
      contri32 = 0.0
      for i in range(0, 3):
        ev12 = eigvector12[:,i]
        ev32 = eigvector32[:,i]
        contri12 = contri12 + eigval12[i] * abs(dot(vecPA, ev12))
        contri32 = contri32 + eigval32[i] * abs(dot(vecPC, ev32))
      contri12 = 1.0 / (contri12 * dis12 * dis12)
      contri32 = 1.0 / (contri32 * dis32 * dis32)
      fcfinal2 = (1.0 / (contri12 + contri32)) * H_TO_KCAL_MOL * 0.5
 
      #Hatree to kcal/mol
      #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2
 
      #3. Third way to chose the matrix----------------------------------
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix12[i][j] = -fcmatrix[3*(nat1-1)+i][3*(nat2-1)+j]
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix32[i][j] = -fcmatrix[3*(nat2-1)+i][3*(nat3-1)+j]
      eigval12, eigvector12 = eig(afcmatrix12)
      eigval32, eigvector32 = eig(afcmatrix32)
      contri12 = 0.0
      contri32 = 0.0
      for i in range(0, 3):
        ev12 = eigvector12[:,i]
        ev32 = eigvector32[:,i]
        contri12 = contri12 + eigval12[i] * abs(dot(vecPA, ev12))
        contri32 = contri32 + eigval32[i] * abs(dot(vecPC, ev32))
      contri12 = 1.0 / (contri12 * dis12 * dis12)
      contri32 = 1.0 / (contri32 * dis32 * dis32)
      fcfinal3 = (1.0 / (contri12 + contri32)) * H_TO_KCAL_MOL * 0.5

      #4. Fourth way to chose the matrix----------------------------------
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix12[i][j] = -fcmatrix[3*(nat2-1)+i][3*(nat1-1)+j]
      for i in range(0, 3):
        for j in range(0, 3):
          afcmatrix32[i][j] = -fcmatrix[3*(nat2-1)+i][3*(nat3-1)+j]
      eigval12, eigvector12 = eig(afcmatrix12)
      eigval32, eigvector32 = eig(afcmatrix32)
      contri12 = 0.0
      contri32 = 0.0
      for i in range(0, 3):
        ev12 = eigvector12[:,i]
        ev32 = eigvector32[:,i]
        contri12 = contri12 + eigval12[i] * abs(dot(vecPA, ev12))
        contri32 = contri32 + eigval32[i] * abs(dot(vecPC, ev32))
      contri12 = 1.0 / (contri12 * dis12 * dis12)
      contri32 = 1.0 / (contri32 * dis32 * dis32)
      fcfinal4 = (1.0 / (contri12 + contri32)) * H_TO_KCAL_MOL * 0.5
 
      fcfinal = average([fcfinal1, fcfinal2, fcfinal3, fcfinal4])
      stdv = std([fcfinal1, fcfinal2, fcfinal3, fcfinal4])
      fcfinal = fcfinal * scalef * scalef
      stdv = stdv * scalef * scalef
      return angval, fcfinal, stdv

    elif angavg == 0:
      fcfinal = fcfinal1 * scalef * scalef
      return angval, fcfinal
Beispiel #16
0
        atnamei = mol.atoms[i].atname
        resnamei = mol.residues[residi].resname
        radiusi = CoRadiiDict[elmti]
        mcresids = [] #MetalCenter residue IDs

        #Get the residues which is the metal site
        for j in atids:
            if j != i:
                atnamej = mol.atoms[j].atname
                crdj = mol.atoms[j].crd
                residj = mol.atoms[j].resid
                resnamej = mol.residues[residj].resname
                elmtj = mol.atoms[j].element
                radiusj = CoRadiiDict[elmtj]
                radiusij = radiusi + radiusj + 0.40
                disij = calc_bond(crdi, crdj)

                if options.cutoff == None:
                    if (disij >= 0.1) and (disij <= radiusij) \
                       and (elmtj != 'H'):
                        mccrds.append(crdi)
                        mccrds.append(crdj)
                        if (residj not in mcresids):
                            mcresids.append(residj)
                else:
                    if (disij >= 0.1) and (disij <= options.cutoff) \
                       and (elmtj != 'H'):
                        mccrds.append(crdi)
                        mccrds.append(crdj)
                        if (residj not in mcresids):
                            mcresids.append(residj)
Beispiel #17
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