예제 #1
0
def read_amber_prm(pfile, cfile):

    prmtop = AmberParm(pfile)
    crds = read_rstf(cfile)

    atids = list(range(1, len(prmtop.parm_data['ATOM_NAME']) + 1))
    resids = list(range(1, len(prmtop.parm_data['RESIDUE_LABEL']) + 1))

    if len(prmtop.parm_data['ATOM_NAME']) != len(crds):
        raise ReadError('The toplogy and coordinates file are not \
                      consistent in the atom numbers.')

    residues = {}
    atoms = {}
    for i in range(0, len(prmtop.parm_data['RESIDUE_LABEL'])):

        resid = i + 1
        resname = prmtop.parm_data['RESIDUE_LABEL'][i]

        if i < len(prmtop.parm_data['RESIDUE_LABEL']) - 1:
            resconter = list(range(prmtop.parm_data['RESIDUE_POINTER'][i], \
                         prmtop.parm_data['RESIDUE_POINTER'][i+1]))
        else:
            resconter = list(range(prmtop.parm_data['RESIDUE_POINTER'][i], \
                         len(prmtop.parm_data['ATOM_NAME'])+1))

        residues[resid] = Residue(resid, resname, resconter)

        for j in resconter:
            gtype = 'ATOM'
            atid = j
            atname = prmtop.parm_data['ATOM_NAME'][j - 1]
            element = prmtop.parm_data['ATOMIC_NUMBER'][j - 1]
            atomtype = prmtop.parm_data['AMBER_ATOM_TYPE'][j - 1]
            crd = crds[j - 1]
            charge = prmtop.parm_data['CHARGE'][j - 1]

            try:
                element = AtnumRev[element]
            except:
                print(resname, atname, atomtype)
                element = 'X'

            atoms[j] = Atom(gtype, atid, atname, element, atomtype, crd, charge, \
                           resid, resname)

    mol = Molecule(atoms, residues)

    return prmtop, mol, atids, resids
예제 #2
0
def read_amber_prm(pfile, cfile):

    prmtop = AmberParm(pfile)
    crds = read_rstf(cfile)

    atids = list(range(1, len(prmtop.parm_data['ATOM_NAME'])+1))
    resids = list(range(1, len(prmtop.parm_data['RESIDUE_LABEL'])+1))

    if len(prmtop.parm_data['ATOM_NAME']) != len(crds):
        raise ReadError('The toplogy and coordinates file are not \
                          consistent in the atom numbers.')

    residues = {}
    atoms = {}
    for i in range(0, len(prmtop.parm_data['RESIDUE_LABEL'])):

        resid = i + 1
        resname = prmtop.parm_data['RESIDUE_LABEL'][i]

        if i < len(prmtop.parm_data['RESIDUE_LABEL'])-1:
            resconter = list(range(prmtop.parm_data['RESIDUE_POINTER'][i], \
                         prmtop.parm_data['RESIDUE_POINTER'][i+1]))
        else:
            resconter = list(range(prmtop.parm_data['RESIDUE_POINTER'][i], \
                         len(prmtop.parm_data['ATOM_NAME'])+1))

        residues[resid] = Residue(resid, resname, resconter)

        for j in resconter:
            gtype = 'ATOM'
            atid = j
            atname = prmtop.parm_data['ATOM_NAME'][j-1]
            element = prmtop.parm_data['ATOMIC_NUMBER'][j-1]
            atomtype = prmtop.parm_data['AMBER_ATOM_TYPE'][j-1]
            crd = crds[j-1]
            charge = prmtop.parm_data['CHARGE'][j-1]

            try:
                element = AtnumRev[element]
            except:
                print(resname, atname, atomtype)
                element = 'X'

            atoms[j] = Atom(gtype, atid, atname, element, atomtype, crd, charge, \
                           resid, resname)

    mol = Molecule(atoms, residues)

    return prmtop, mol, atids, resids
예제 #3
0
파일: OptC4.py 프로젝트: pengfeili1/pymsmt
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
예제 #4
0
파일: OptC4.py 프로젝트: pengfeili1/pymsmt
mcresids2.sort()

print('Residues in the metal site: ', mcresids2)

mcids = []  #Metal site atom IDs
if options.model == 1: #Small model
    mcids = smcids
elif options.model == 2: #Big model
    for i in mcresids:
        for j in mol.residues[i].resconter:
            if mol.atoms[j].element != 'H':
                mcids.append(j)

#Calculate the distances between metal ion and ligating atoms
val_bf_min = []
crds_bf_min = read_rstf(options.cfile)
for i in atompairs:
    if len(i) == 2:
        crd1 = crds_bf_min[i[0]-1]
        crd2 = crds_bf_min[i[1]-1]
        bond = calc_bond(crd1, crd2)
        val_bf_min.append(('bond', bond))
    elif len(i) == 3:
        crd1 = crds_bf_min[i[0]-1]
        crd2 = crds_bf_min[i[1]-1]
        crd3 = crds_bf_min[i[2]-1]
        angle = calc_angle(crd1, crd2, crd3)
        val_bf_min.append(('angle', angle))
    elif len(i) == 4:
        crd1 = crds_bf_min[i[0]-1]
        crd2 = crds_bf_min[i[1]-1]
예제 #5
0
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
예제 #6
0
mcresids2.sort()

print('Residues in the metal site: ', mcresids2)

mcids = []  #Metal site atom IDs
if options.model == 1:  #Small model
    mcids = smcids
elif options.model == 2:  #Big model
    for i in mcresids:
        for j in mol.residues[i].resconter:
            if mol.atoms[j].element != 'H':
                mcids.append(j)

#Calculate the distances between metal ion and ligating atoms
val_bf_min = []
crds_bf_min = read_rstf(options.cfile)
for i in atompairs:
    if len(i) == 2:
        crd1 = crds_bf_min[i[0] - 1]
        crd2 = crds_bf_min[i[1] - 1]
        bond = calc_bond(crd1, crd2)
        val_bf_min.append(('bond', bond))
    elif len(i) == 3:
        crd1 = crds_bf_min[i[0] - 1]
        crd2 = crds_bf_min[i[1] - 1]
        crd3 = crds_bf_min[i[2] - 1]
        angle = calc_angle(crd1, crd2, crd3)
        val_bf_min.append(('angle', angle))
    elif len(i) == 4:
        crd1 = crds_bf_min[i[0] - 1]
        crd2 = crds_bf_min[i[1] - 1]