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
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
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
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
def get_mc_blist(mol, atids, ionids, fpf): "Get Metal Site Bond List" 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
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
def get_bonded(gatms): i = 0 j = 0 bond_list = [] while i < len(gatms): crd_1 = [gatms[i][1], gatms[i][2], gatms[i][3]] radius_1 = CoRadiiDict[gatms[i][0]] while j < len(gatms): if j in range(i, len(gatms)): crd_2 = [gatms[j][1], gatms[j][2], gatms[j][3]] radius_2 = CoRadiiDict[gatms[j][0]] rad_tot = radius_1 + radius_2 + 0.40 length = calc_bond(crd_1, crd_2) if (length > 0.1) and (length <= rad_tot): bond_list.append([i + 1, j + 1]) j += 1 j = 0 i += 1 return bond_list
def get_rmsd(initparas): global idxs, mcresids2, atompairs #Modify the C4 terms in the prmtop file for i in range(0, len(idxs)): prmtop.parm_data['LENNARD_JONES_CCOEF'][idxs[i]] = initparas[i] #Overwrite the prmtop file prmtop.write_parm('OptC4.top') #Perform the OpenMM optimization #Use AmberParm function to transfer the topology and #coordinate file to the object OpenMM can use Ambermol = AmberParm('OptC4.top', options.cfile) # Create the OpenMM system print('Creating OpenMM System') if options.simupha == 'gas': system = Ambermol.createSystem(nonbondedMethod=app.NoCutoff) elif options.simupha == 'liquid': system = Ambermol.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=8.0*u.angstroms, constraints=app.HBonds,) #Add restraints force = mm.CustomExternalForce("k*((x-x0)^2+(y-y0)^2+(z-z0)^2)") force.addGlobalParameter("k", 200.0) force.addPerParticleParameter("x0") force.addPerParticleParameter("y0") force.addPerParticleParameter("z0") #for i in range(0, len(Ambermol.atoms)): for i, atom_crd in enumerate(Ambermol.positions): #if (Ambermol.atoms[i].residue.number+1 not in mcresids2) and \ if (i+1 not in mcresids2) and \ (Ambermol.atoms[i].residue.name not in ['WAT', 'HOH']) and \ (Ambermol.atoms[i].name in ['CA', 'C', 'N']): force.addParticle(i, atom_crd.value_in_unit(u.nanometers)) system.addForce(force) # Create the integrator to do Langevin dynamics # Temperature of heat bath, Friction coefficient, Time step integrator = mm.LangevinIntegrator(300*u.kelvin, 1.0/u.picoseconds, 1.0*u.femtoseconds,) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not # specify the platform to use the default (fastest) platform # Create the Simulation object if options.platf == 'ref': platform = mm.Platform.getPlatformByName('Reference') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cpu': platform = mm.Platform.getPlatformByName('CPU') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cuda': platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) elif options.platf == 'opencl': platform = mm.Platform.getPlatformByName('OpenCL') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) # Set the particle positions sim.context.setPositions(Ambermol.positions) # Output the rst file restrt = RestartReporter(options.rfile, 100, write_velocities=False) sim.reporters.append(restrt) # Minimize the energy print('Minimizing energy ' + str(options.maxsteps) + ' steps.') sim.minimizeEnergy(maxIterations=options.maxsteps) # Overwrite the final file state = sim.context.getState(getPositions=True, enforcePeriodicBox=True) restrt.report(sim, state) val_aft_min = [] crds_aft_min = read_rstf(options.rfile) for i in atompairs: if len(i) == 2: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] bond = calc_bond(crd1, crd2) val_aft_min.append(('bond', bond)) elif len(i) == 3: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] crd3 = crds_aft_min[i[2]-1] angle = calc_angle(crd1, crd2, crd3) val_aft_min.append(('angle', angle)) elif len(i) == 4: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] crd3 = crds_aft_min[i[2]-1] crd4 = crds_aft_min[i[3]-1] dih = calc_dih(crd1, crd2, crd3, crd4) val_aft_min.append(('dih', dih)) valdiffs = [] for i in range(0, len(atompairs)): if val_bf_min[i][0] == 'bond': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 100.0 elif val_bf_min[i][0] == 'angle': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 2.0 elif val_bf_min[i][0] == 'dih': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) if (360.0 - valdiff < valdiff): valdiff = 360.0 - valdiff valdiffs.append(valdiff) fnldiff = numpy.sum(valdiffs) print(fnldiff) return fnldiff
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)
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
mettyps.append(atyp) mettypind = prmtop.parm_data['ATOM_TYPE_INDEX'][i] mettypinds.append(mettypind) smcids = [] #Metal site ligating atom IDs mcresids = [] #Metal Site Residue IDs atompairs = [] #Distance pair 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'): smcids.append(j) atompairs.append((i, j)) if mol.atoms[j].resid not in mcresids: mcresids.append(mol.atoms[j].resid) for i in alist: if len(i) != 3: raise ValueError('More than 3 atoms in one angle! ' + i) j = [k-1 for k in i] atnums = [prmtop.parm_data['ATOMIC_NUMBER'][l] for l in j] if (list(set(metids) & set(i)) != []) and (1 not in atnums): atompairs.append(i)
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
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
def gene_by_empirical_way(smpdbf, ionids, stfpf, pref, finf): print("******************************************************************") print("* *") print("*===========Using the empirical way to solve the problem=========*") print("* *") print("******************************************************************") #Read from small pdb mol, atids, resids = get_atominfo_fpdb(smpdbf) 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')
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('NNNNN', file=xyzf) print('Title', file=xyzf) print('This molecule has ' + str(len(resids)) + ' residues.', file=infof) print('Core residue = ', i, file=infof) print('%%chk=number%d.chk' % i, file=fp) print('%mem=22GB', file=fp) print('%nproc=8', file=fp) print('#b3lyp/6-31G* charge nmr', file=fp) print(' ', file=fp) print('Have a nice day', file=fp) 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('After the distance criterion: Buffer residues = '\ , sorted(bresids), file=infof) #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('After the core criterion: Buffer residues = '\ , sorted(bresids), file=infof) #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('After the disulfide bond criterion: Buffer residues = '\ , sorted(bresids), file=infof) ####===================================================================== #### 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('After the special case criterion: Buffer residues = '\ , sorted(bresids), file=infof) print('After the special case criterion: N-terimal caps = '\ , sorted(ncaps), file=infof) print('After the special case criterion: C-terimal caps = '\ , sorted(ccaps), file=infof) ####===================================================================== #### 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(' ', file=fp) print('%-5d %5s' %(int(round(totchg, 0)), 'SSSSS'), file=fp) ####===================================================================== #### 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, crdz), file=xyzf) print(str(mol.atoms[j].resid) + '-' + \ mol.atoms[j].resname + '-' + mol.atoms[j].atname, file=fpf) ####===================================================================== #### 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=xyzf) 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=xyzf) ####===================================================================== #### 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=xyzf) 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=xyzf) ##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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=xyzf) ####===================================================================== #### 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('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy, \ crdz), file=fp) print('%2s %10.3f %10.3f %10.3f' %(element, crdx, crdy,\ crdz), file=xyzf) print(' ', file=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('%10.3f %10.3f %10.3f %10.5f' %(crdx, crdy, crdz, chg), file=fp) 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(' ', file=fp) print(' ', file=fp) print(' ', file=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.')
def extract_adduct(mol, residue_ids, external_ids, fname, gatms, reslist, extlist): ACE = ['C', 'O', 'CA', 'HA', 'CB', 'N', 'HA2', 'HA3'] NME = ['N', 'H', 'HN', 'CA', 'HA', 'CB', 'C', 'HA2', 'HA3'] dict_ace = {"CB":"HA2", "N":"HA3"} dict_nme = {"CB":"HA2", "C":"HA3"} adduct_file = open(fname + "_capped.pdb", 'w') adduct_file.write('BUILD BY MRP.PY' + '\n') #record residue names for each residue in adduct for i in residue_ids: reslist.append(mol.residues[i].resname) #record molecule names for each non-residue in adduct for i in external_ids: reslist.append(mol.residues[i].resname) #convert necessary atoms in original pdb to obtain ACE/NME caps #In ACE: #CA -> CH3 #C, O remain the same #HA -> HA1 such that during the second stage of RESP (isomerization) methyl group is recognized #CB, N -> HA2, HA3 #In NME: #CA -> CH3 #HN -> C #N, H remain the same #HA -> HA1 such that during the second stage of RESP (isomerization) methyl group is recognized #CB, C -> HA2, HA3 for i in residue_ids + external_ids: if (i in residue_ids): if i != 1: for j in mol.residues[i-1].resconter: atom = mol.atoms[j].atname if (atom == 'CA'): cacrd = mol.atoms[j].crd for j in mol.residues[i-1].resconter: gtype = "ATOM" atom = mol.atoms[j].atname if (atom in ACE): atomid = mol.atoms[j].atid resid = mol.atoms[j].resid element = mol.atoms[j].element if (atom == 'C') or (atom == 'O'): crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] element = atom elif (atom == 'CA'): atom = 'CH3' crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] element = 'C' elif (atom == 'HA'): atom = 'HA1' crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] elif (atom in ['CB', 'N']): atom = dict_ace[atom] bvec = calc_bond(cacrd, mol.atoms[j].crd) crdx = cacrd[0] + bdld['CH'] * (mol.atoms[j].crd[0] - cacrd[0])/bvec crdy = cacrd[1] + bdld['CH'] * (mol.atoms[j].crd[1] - cacrd[1])/bvec crdz = cacrd[2] + bdld['CH'] * (mol.atoms[j].crd[2] - cacrd[2])/bvec element = 'H' crdx = round(crdx, 3) crdy = round(crdy, 3) crdz = round(crdz, 3) resname = 'ACE' adduct_file.write("%-6s%5d %4s %3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f" \ %(gtype, atomid, atom, resname, 'A', resid, crdx, crdy, crdz, 1.00, 0.00) + '\n' ) gatms.append([element, mol.atoms[j].crd[0], mol.atoms[j].crd[1], mol.atoms[j].crd[2], atom, resname, "", 0, atomid, resid]) for j in mol.residues[i].resconter: gtype = "ATOM" atm = mol.atoms[j] atid = atm.atid atomid = mol.atoms[j].atid atom = mol.atoms[j].atname element = mol.atoms[j].element 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 adduct_file.write("%-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) + '\n' ) gatms.append([element, mol.atoms[j].crd[0], mol.atoms[j].crd[1], mol.atoms[j].crd[2], atom, resname, "", 0, atomid, resid]) for j in mol.residues[i+1].resconter: gtype = "ATOM" atom = mol.atoms[j].atname element = mol.atoms[j].element if (atom in NME): if (atom == 'N') or (atom == 'H'): crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] element = atom elif (atom == 'HN'): atom = 'H' crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] cacrd = [crdx, crdy, crdz] element = 'C' if (atom == 'CA'): atom = 'CH3' crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] cacrd = [crdx, crdy, crdz] element = 'C' elif (atom == 'HA'): atom = 'HA1' crdx = mol.atoms[j].crd[0] crdy = mol.atoms[j].crd[1] crdz = mol.atoms[j].crd[2] cacrd = [crdx, crdy, crdz] elif (atom in ['CB', 'C']): atom = dict_nme[atom] bvec = calc_bond(cacrd, mol.atoms[j].crd) crdx = cacrd[0] + bdld['CH'] * (mol.atoms[j].crd[0] - cacrd[0])/bvec crdy = cacrd[1] + bdld['CH'] * (mol.atoms[j].crd[1] - cacrd[1])/bvec crdz = cacrd[2] + bdld['CH'] * (mol.atoms[j].crd[2] - cacrd[2])/bvec element = 'H' crdx = round(crdx, 3) crdy = round(crdy, 3) crdz = round(crdz, 3) atomid = mol.atoms[j].atid resid = mol.atoms[j].resid resname = 'NME' adduct_file.write("%-6s%5d %4s %3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f" \ %(gtype, atomid, atom, resname, 'A', resid, crdx, crdy, crdz, 1.00, 0.00) + '\n' ) gatms.append([element, mol.atoms[j].crd[0], mol.atoms[j].crd[1], mol.atoms[j].crd[2], atom, resname, "", 0, atid, resid]) if (i in external_ids): for j in mol.residues[i].resconter: atm = mol.atoms[j] atid = atm.atid atom = mol.atoms[j].atname element = mol.atoms[j].element 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 adduct_file.write("%-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) + '\n' ) gatms.append([element, mol.atoms[j].crd[0], mol.atoms[j].crd[1], mol.atoms[j].crd[2], atom, resname, "", 0, atid, resid]) adduct_file.write('END') adduct_file.close() return gatms, reslist, extlist, mol
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
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
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
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
def get_rmsd(initparas): global idxs, mcresids2, atompairs #Modify the C4 terms in the prmtop file for i in range(0, len(idxs)): prmtop.parm_data['LENNARD_JONES_CCOEF'][idxs[i]] = initparas[i] #Overwrite the prmtop file prmtop.write_parm('OptC4.top') #Perform the OpenMM optimization #Use AmberParm function to transfer the topology and #coordinate file to the object OpenMM can use Ambermol = AmberParm('OptC4.top', options.cfile) # Create the OpenMM system print('Creating OpenMM System') if options.simupha == 'gas': system = Ambermol.createSystem(nonbondedMethod=app.NoCutoff) elif options.simupha == 'liquid': system = Ambermol.createSystem( nonbondedMethod=app.PME, nonbondedCutoff=8.0 * u.angstroms, constraints=app.HBonds, ) #Add restraints force = mm.CustomExternalForce("k*((x-x0)^2+(y-y0)^2+(z-z0)^2)") force.addGlobalParameter("k", 200.0) force.addPerParticleParameter("x0") force.addPerParticleParameter("y0") force.addPerParticleParameter("z0") #for i in range(0, len(Ambermol.atoms)): for i, atom_crd in enumerate(Ambermol.positions): #if (Ambermol.atoms[i].residue.number+1 not in mcresids2) and \ if (i+1 not in mcresids2) and \ (Ambermol.atoms[i].residue.name not in ['WAT', 'HOH']) and \ (Ambermol.atoms[i].name in ['CA', 'C', 'N']): force.addParticle(i, atom_crd.value_in_unit(u.nanometers)) system.addForce(force) # Create the integrator to do Langevin dynamics # Temperature of heat bath, Friction coefficient, Time step integrator = mm.LangevinIntegrator( 300 * u.kelvin, 1.0 / u.picoseconds, 1.0 * u.femtoseconds, ) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not # specify the platform to use the default (fastest) platform # Create the Simulation object if options.platf == 'ref': platform = mm.Platform.getPlatformByName('Reference') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cpu': platform = mm.Platform.getPlatformByName('CPU') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cuda': platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision=options.presn) sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) elif options.platf == 'opencl': platform = mm.Platform.getPlatformByName('OpenCL') prop = dict(OpenCLPrecision=options.presn) sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) # Set the particle positions sim.context.setPositions(Ambermol.positions) # Output the rst file restrt = RestartReporter(options.rfile, 100, write_velocities=False) sim.reporters.append(restrt) # Minimize the energy print('Minimizing energy ' + str(options.maxsteps) + ' steps.') sim.minimizeEnergy(maxIterations=options.maxsteps) # Overwrite the final file state = sim.context.getState(getPositions=True, enforcePeriodicBox=True) restrt.report(sim, state) val_aft_min = [] crds_aft_min = read_rstf(options.rfile) for i in atompairs: if len(i) == 2: crd1 = crds_aft_min[i[0] - 1] crd2 = crds_aft_min[i[1] - 1] bond = calc_bond(crd1, crd2) val_aft_min.append(('bond', bond)) elif len(i) == 3: crd1 = crds_aft_min[i[0] - 1] crd2 = crds_aft_min[i[1] - 1] crd3 = crds_aft_min[i[2] - 1] angle = calc_angle(crd1, crd2, crd3) val_aft_min.append(('angle', angle)) elif len(i) == 4: crd1 = crds_aft_min[i[0] - 1] crd2 = crds_aft_min[i[1] - 1] crd3 = crds_aft_min[i[2] - 1] crd4 = crds_aft_min[i[3] - 1] dih = calc_dih(crd1, crd2, crd3, crd4) val_aft_min.append(('dih', dih)) valdiffs = [] for i in range(0, len(atompairs)): if val_bf_min[i][0] == 'bond': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 100.0 elif val_bf_min[i][0] == 'angle': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 2.0 elif val_bf_min[i][0] == 'dih': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) if (360.0 - valdiff < valdiff): valdiff = 360.0 - valdiff valdiffs.append(valdiff) fnldiff = numpy.sum(valdiffs) print(fnldiff) return fnldiff
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
mettyps.append(atyp) mettypind = prmtop.parm_data['ATOM_TYPE_INDEX'][i] mettypinds.append(mettypind) smcids = [] #Metal site ligating atom IDs mcresids = [] #Metal Site Residue IDs atompairs = [] #Distance pair 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'): smcids.append(j) atompairs.append((i, j)) if mol.atoms[j].resid not in mcresids: mcresids.append(mol.atoms[j].resid) for i in alist: if len(i) != 3: raise ValueError('More than 3 atoms in one angle! ' + i) j = [k - 1 for k in i] atnums = [prmtop.parm_data['ATOMIC_NUMBER'][l] for l in j] if (list(set(metids) & set(i)) != []) and (1 not in atnums): atompairs.append(i)
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:
def get_imp_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, nat4, scalef): #nat1 is the central atom A 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 dis24 = calc_bond(crd2, 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 vec24 = array(crd4) - array(crd2) vec42 = -vec24 # Calculate the distance from A to plane BCD cp = cross(vec24, vec23) a, b, c = cp d = dot(cp, crd4) disAtoBCD = abs(a * crd1[0] + b * crd1[1] + c * crd1[2] - d) disAtoBCD = disAtoBCD / math.sqrt(a**2 + b**2 + c**2) 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]) vec24 = array([i / dis24 for i in vec24]) vec42 = array([i / dis24 for i in vec42]) #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 BCD 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) * HB2_TO_KCAL_MOL_A2 * 0.5 fcfinal = kAN * scalef * scalef #1: B, 2: C, 3: A, 4: D #dAtoBC = cal_height(dis12, dis13, dis23) #dDtoBC = cal_height(dis12, dis14, dis) #def cal_height(dis12, dis13, dis23): #pval = (dis12 + dis23 + dis13)/2.0 #sqABC = math.sqrt(pval*(pval-dis12)*(pval-dis23)*(pval-dis13)) #Get area of ABC #disAH = sqABC * 2.0 / dis23 #distance between A and BC side, unit is bohr #disDH = math.sqrt(disAH**2 + dis34**2) #hADH = disAH * disDH #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]) #hABCD = disAtoBC * dot(vecUNABC, vecUNBCD) #fcfinal = (disAH ** 2) * kAN / 2.0 #return fcfinal1, fcfinal return fcfinal, disAtoBCD