예제 #1
0
def energies(top, gro, mdp, gmx_path=GMX_PATH, grosuff='', grompp_check=False):
    """Compute single-point energies using GROMACS.

    Args:
        top (str):
        gro (str):
        mdp (str):
        gmx_path (str):
        grosuff (str):
        grompp_check (bool):

    Returns:
        e_out:
        ener_xvg:
    """

    if not os.path.isfile(mdp):
        logger.error("Can't find mdp file %s to compute energies" % (mdp))
    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_bin, mdrun_bin, genergy_bin = binaries(gmx_path, grosuff)

    # Run grompp.
    grompp_bin.extend(['-f', mdp, '-c', gro, '-p', top, '-o', tpr, '-po', mdout, '-maxwarn', '5'])
    proc = run_subprocess(grompp_bin, 'gromacs', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('grompp failed. See %s' % stderr_path)

    # Run single-point calculation with mdrun.
    mdrun_bin.extend(['-nt', '1', '-s', tpr, '-o', traj, '-cpo', state, '-c', conf, '-e', ener, '-g', log])
    proc = run_subprocess(mdrun_bin, 'gromacs', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('mdrun failed. See %s' % stderr_path)

    # Extract energies using g_energy
    select = " ".join(map(str, range(1, 20))) + " 0 "
    genergy_bin.extend(['-f', ener, '-o', ener_xvg, '-dp'])
    proc = run_subprocess(genergy_bin, 'gromacs', stdout_path, stderr_path, stdin=select)
    if proc.returncode != 0:
        logger.error('g_energy failed. See %s' % stderr_path)

    return _group_energy_terms(ener_xvg)
예제 #2
0
파일: __init__.py 프로젝트: ctk3b/InterMol
def energies(top, gro, mdp, gmx_path=GMX_PATH, grosuff='', grompp_check=False):
    """Compute single-point energies using GROMACS.

    Args:
        top (str):
        gro (str):
        mdp (str):
        gmx_path (str):
        grosuff (str):
        grompp_check (bool):

    Returns:
        e_out:
        ener_xvg:
    """

    if not os.path.isfile(mdp):
        logger.error("Can't find mdp file %s to compute energies" % (mdp))
    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_bin, mdrun_bin, genergy_bin = binaries(gmx_path, grosuff)

    # Run grompp.
    grompp_bin.extend(['-f', mdp, '-c', gro, '-p', top, '-o', tpr, '-po', mdout, '-maxwarn', '5'])
    proc = run_subprocess(grompp_bin, 'gromacs', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('grompp failed. See %s' % stderr_path)

    # Run single-point calculation with mdrun.
    mdrun_bin.extend(['-nt', '1', '-s', tpr, '-o', traj, '-cpo', state, '-c', conf, '-e', ener, '-g', log])
    proc = run_subprocess(mdrun_bin, 'gromacs', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('mdrun failed. See %s' % stderr_path)

    # Extract energies using g_energy
    select = " ".join(map(str, range(1, 20))) + " 0 "
    genergy_bin.extend(['-f', ener, '-o', ener_xvg, '-dp'])
    proc = run_subprocess(genergy_bin, 'gromacs', stdout_path, stderr_path, stdin=select)
    if proc.returncode != 0:
        logger.error('g_energy failed. See %s' % stderr_path)

    return _group_energy_terms(ener_xvg)
예제 #3
0
파일: __init__.py 프로젝트: maaren/InterMol
def amber_energies(prmtop, crd, input, amb_path):
    """Compute single-point energies using AMBER.

    Args:
        prmtop (str):
        crd (str):
        input (str)
        amb_path (str):

    Returns:
        e_out:
        ener_xvg:
    """

    logger.info('Evaluating energy of {0}'.format(crd))

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

    if not prmtop:
        prmtop = os.path.join(directory, 'parm.prmtop')
    if not crd:
        crd = os.path.join(directory, 'ener.edr')
    mdout = os.path.join(directory, 'amber.out')
    stdout_path = os.path.join(directory, 'amber_stdout.txt')
    stderr_path = os.path.join(directory, 'amber_stderr.txt')

    # did they give a path, or the name of the file?
    islastbin = os.path.basename(os.path.normpath(amb_path))
    if islastbin == 'sander':
        amber_bin = amb_path
    else:
        amber_bin = os.path.join(amb_path, 'sander')
    if not which(amber_bin):
        raise IOError('Unable to find AMBER executable (sander).')

    # run sander
    cmd = [amber_bin, '-i', input, '-c', crd, '-p', prmtop, '-o', mdout, '-O']
    proc = run_subprocess(cmd, 'amber', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('sander failed. See %s' % stderr_path)

    # Extract energies from amber output

    return _group_energy_terms(mdout)
예제 #4
0
파일: __init__.py 프로젝트: ctk3b/InterMol
def amber_energies(prmtop, crd, input, amb_path):
    """Compute single-point energies using AMBER.

    Args:
        prmtop (str):
        crd (str):
        input (str)
        amb_path (str):

    Returns:
        e_out:
        ener_xvg:
    """

    logger.info("Evaluating energy of {0}".format(crd))

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

    if not prmtop:
        prmtop = os.path.join(directory, "parm.prmtop")
    if not crd:
        crd = os.path.join(directory, "ener.edr")
    mdout = os.path.join(directory, "amber.out")
    stdout_path = os.path.join(directory, "amber_stdout.txt")
    stderr_path = os.path.join(directory, "amber_stderr.txt")

    # did they give a path, or the name of the file?
    islastbin = os.path.basename(os.path.normpath(amb_path))
    if islastbin == "sander":
        amber_bin = amb_path
    else:
        amber_bin = os.path.join(amb_path, "sander")
    if not which(amber_bin):
        raise IOError("Unable to find AMBER executable (sander).")

    # run sander
    cmd = [amber_bin, "-i", input, "-c", crd, "-p", prmtop, "-o", mdout, "-O"]
    proc = run_subprocess(cmd, "amber", stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error("sander failed. See %s" % stderr_path)

    # Extract energies from amber output

    return _group_energy_terms(mdout)
예제 #5
0
def energies(inpfile, crm_path):
    """Compute single-point energies using CHARMM.

    Args:
        inpfile (str)
        crm_path (str):

    Returns:
        e_out:
        ener_xvg:
    """

    logger.info('Evaluating energy of {0}'.format(inpfile))

    # find the directory the input file is in.
    directory, _ = os.path.split(os.path.abspath(inpfile))

    # create files for output
    stdout_path = os.path.join(directory, 'charmm_stdout.txt')
    stderr_path = os.path.join(directory, 'charmm_stderr.txt')

    # delete previous stdout and stderr
    if os.path.isfile(stdout_path):
        os.remove(stdout_path)
    if os.path.isfile(stderr_path):
        os.remove(stderr_path)

    if not which(crm_path):
        raise IOError('Unable to find CHARMM executable (charmm).')
    if os.path.isdir(crm_path):
        charmm_bin = os.path.join(crm_path, 'charmm')
    else:
        charmm_bin = crm_path

    # run charmm - this assumes all files required in the input file are present
    cmd = [charmm_bin, '-i', inpfile]
    proc = run_subprocess(cmd, 'charmm', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('charmm failed. See %s' % stderr_path)

    # Extract energies from charmm output

    return _group_energy_terms(stdout_path)
예제 #6
0
파일: __init__.py 프로젝트: ctk3b/InterMol
def charmm_energies(inpfile, crm_path):
    """Compute single-point energies using CHARMM.

    Args:
        inpfile (str)
        crm_path (str):

    Returns:
        e_out:
        ener_xvg:
    """

    logger.info('Evaluating energy of {0}'.format(inpfile))

    # find the directory the input file is in.
    directory, _ = os.path.split(os.path.abspath(inpfile))

    # create files for output
    stdout_path = os.path.join(directory, 'charmm_stdout.txt')
    stderr_path = os.path.join(directory, 'charmm_stderr.txt')

    # delete previous stdout and stderr
    if os.path.isfile(stdout_path):
        os.remove(stdout_path)
    if os.path.isfile(stderr_path):
        os.remove(stderr_path)

    if not which(crm_path):
        raise IOError('Unable to find CHARMM executable (charmm).')
    if os.path.isdir(crm_path):
        charmm_bin = os.path.join(crm_path, 'charmm')
    else:
        charmm_bin = crm_path

    # run charmm - this assumes all files required in the input file are present
    cmd = [charmm_bin, '-i', inpfile]
    proc = run_subprocess(cmd, 'charmm', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('charmm failed. See %s' % stderr_path)

    # Extract energies from charmm output

    return _group_energy_terms(stdout_path)
예제 #7
0
def energies(prmtop, crd, input, amb_path):
    """Compute single-point energies using AMBER.

    Args:
        prmtop (str):
        crd (str):
        input (str)
        amb_path (str):

    Returns:
        e_out:
        ener_xvg:
    """

    logger.info('Evaluating energy of {0}'.format(crd))

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

    if not prmtop:
        prmtop = os.path.join(directory, 'parm.prmtop')
    if not crd:
        crd = os.path.join(directory, 'ener.edr')
    mdout = os.path.join(directory, 'amber.out')
    stdout_path = os.path.join(directory, 'amber_stdout.txt')
    stderr_path = os.path.join(directory, 'amber_stderr.txt')

    # Did they give a path, or the name of the file?
    islastbin = os.path.basename(os.path.normpath(amb_path))
    if islastbin == 'sander':
        amber_bin = amb_path
    else:
        amber_bin = os.path.join(amb_path, 'sander')
    if not which(amber_bin):
        raise IOError('Unable to find AMBER executable (sander).')

    # Run sander.
    cmd = [amber_bin, '-i', input, '-c', crd, '-p', prmtop, '-o', mdout, '-O']
    proc = run_subprocess(cmd, 'amber', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('sander failed. See %s' % stderr_path)

    return _group_energy_terms(mdout)
예제 #8
0
def energies(input_file, lmp_path=None):
    """Evaluate energies of LAMMPS files

    Args:
        input_file = path to input file (expects data file in same folder)
        lmp_path = path to LAMMPS binaries
    """
    if lmp_path is None and LMP_PATH is not None:
        lmp_path = LMP_PATH
    elif LMP_PATH is None:
        raise IOError('Unable to find LAMMPS executables.')

    logger.info('Evaluating energy of {0}'.format(input_file))
    directory, input_file = os.path.split(os.path.abspath(input_file))
    stdout_path = os.path.join(directory, 'lammps_stdout.txt')
    stderr_path = os.path.join(directory, 'lammps_stderr.txt')
    # TODO: Read energy info from stdout in memory instead of from log files.
    try:
        os.remove(stdout_path)
    except FileNotFoundError:
        pass
    try:
        os.remove(stderr_path)
    except FileNotFoundError:
        pass

    # Step into the directory.
    saved_path = os.getcwd()
    os.chdir(directory)

    cmd = [lmp_path, '-in', input_file]
    proc = run_subprocess(cmd, 'lammps', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('LAMMPS failed. See %s/lammps_stderr.txt' % directory)

    # Step back out.
    os.chdir(saved_path)

    return _group_energy_terms(stdout_path)
예제 #9
0
파일: __init__.py 프로젝트: ctk3b/InterMol
def energies(input_file, lmp_path=None):
    """Evaluate energies of LAMMPS files

    Args:
        input_file = path to input file (expects data file in same folder)
        lmp_path = path to LAMMPS binaries
    """
    if lmp_path is None:
        lmp_path = LMP_PATH

    logger.info('Evaluating energy of {0}'.format(input_file))
    directory, input_file = os.path.split(os.path.abspath(input_file))
    stdout_path = os.path.join(directory, 'lammps_stdout.txt')
    stderr_path = os.path.join(directory, 'lammps_stderr.txt')
    # TODO: Read energy info from stdout in memory instead of from log files.
    try:
        os.remove(stdout_path)
    except FileNotFoundError:
        pass
    try:
        os.remove(stderr_path)
    except FileNotFoundError:
        pass

    # Step into the directory.
    saved_path = os.getcwd()
    os.chdir(directory)

    cmd = [lmp_path, '-in', input_file]
    proc = run_subprocess(cmd, 'lammps', stdout_path, stderr_path)
    if proc.returncode != 0:
        logger.error('LAMMPS failed. See %s/lammps_stderr.txt' % directory)

    # Step back out.
    os.chdir(saved_path)

    return _group_energy_terms(stdout_path)