Пример #1
0
def energy(prm, crd, mdin):
    """Evaluate the energy of a .prmtop, .inpcrd and .in file combination.

    Parameters
    ----------
    prm : str
    crd : str
    mdin : str

    Returns
    -------
    energies : OrderedDict

    """
    mdin = os.path.abspath(mdin)

    directory, _ = os.path.split(os.path.abspath(prm))

    mdout = ''
    stdout_path = os.path.join(directory, 'amber_stdout.txt')
    stderr_path = os.path.join(directory, 'amber_stderr.txt')


    # Run sander.
    sander = ['sander']
    sander.extend(['-i', mdin,
                   '-O', mdout,
                   '-p', prm,
                   '-c', crd,
                   '-O', mdout])
    run_subprocess(sander, stdout_path, stderr_path)

    # TODO: Fix mdout filenaming.
    energy = _parse_energy_mdout(mdout or 'mdout')
    return canonicalize_energy_names(energy, 'amber')
Пример #2
0
def energy(top, gro, mdp):
    """Evaluate the energy of a .top, .gro and .mdp file combination.

    Parameters
    ----------
    top : str
    gro : str
    mdp : str

    Returns
    -------
    energies : OrderedDict

    """
    mdp = os.path.abspath(mdp)

    directory, _ = os.path.split(os.path.abspath(top))

    tpr = os.path.join(directory, 'topol.tpr')
    ener = os.path.join(directory, 'ener.edr')
    ener_xvg = os.path.join(directory, 'energy.xvg')
    conf = os.path.join(directory, 'confout.gro')
    mdout = os.path.join(directory, 'mdout.mdp')
    state = os.path.join(directory, 'state.cpt')
    traj = os.path.join(directory, 'traj.trr')
    log = os.path.join(directory, 'md.log')
    stdout_path = os.path.join(directory, 'gromacs_stdout.txt')
    stderr_path = os.path.join(directory, 'gromacs_stderr.txt')

    grompp, mdrun, genergy = binaries()

    # Run grompp.
    grompp.extend(['-f', mdp,
                   '-c', gro,
                   '-p', top,
                   '-o', tpr,
                   '-po', mdout,
                   '-maxwarn', '5'])
    run_subprocess(grompp, stdout_path, stderr_path)

    # Run single-point calculation with mdrun.
    mdrun.extend(['-nt', '1',
                  '-s', tpr,
                  '-o', traj,
                  '-cpo', state,
                  '-c', conf,
                  '-e', ener,
                  '-g', log])
    run_subprocess(mdrun, stdout_path, stderr_path)

    # Extract energies using g_energy
    select = " ".join(map(str, range(1, 20))) + " 0 "
    genergy.extend(['-f', ener,
                    '-o', ener_xvg,
                    '-dp'])
    run_subprocess(genergy, stdout_path, stderr_path, stdin=select)

    energy = _parse_energy_xvg(ener_xvg)
    return canonicalize_energy_names(energy, 'gromacs')