Пример #1
0
def binaries(gmxpath, gmxsuff):
    """Locate the paths to the best available gromacs binaries. """
    def gmx_path(binary_path):
        return os.path.join(gmxpath, binary_path + gmxsuff)

    if which('gmx_d'):
        logger.debug("Using double precision binaries for gromacs")
        main_binary = gmx_path('gmx_d')
        grompp_bin = [main_binary, 'grompp']
        mdrun_bin = [main_binary, 'mdrun']
        genergy_bin = [main_binary, 'energy']
    elif which('grompp_d') and which('mdrun_d') and which('g_energy_d'):
        logger.debug("Using double precision binaries")
        grompp_bin = [gmx_path('grompp_d')]
        mdrun_bin = [gmx_path('mdrun_d')]
        genergy_bin = [gmx_path('g_energy_d')]
    elif which('gmx'):
        logger.debug("Using double precision binaries")
        main_binary = gmx_path('gmx')
        grompp_bin = [main_binary, 'grompp']
        mdrun_bin = [main_binary, 'mdrun']
        genergy_bin = [main_binary, 'energy']
    elif which('grompp') and which('mdrun') and which('g_energy'):
        logger.debug("Using single precision binaries")
        grompp_bin = [gmx_path('grompp')]
        mdrun_bin = [gmx_path('mdrun')]
        genergy_bin = [gmx_path('g_energy')]
    else:
        raise IOError('Unable to find gromacs executables.')
    return grompp_bin, mdrun_bin, genergy_bin
Пример #2
0
def binaries(gmxpath, gmxsuff):
    """Locate the paths to the best available gromacs binaries. """
    def gmx_path(binary_path):
        return os.path.join(gmxpath, binary_path + gmxsuff)

    if which('gmx_d'):
        logger.debug("Using double precision binaries for gromacs")
        main_binary = gmx_path('gmx_d')
        grompp_bin = [main_binary, 'grompp']
        mdrun_bin = [main_binary, 'mdrun']
        genergy_bin = [main_binary, 'energy']
    elif which('grompp_d') and which('mdrun_d') and which('g_energy_d'):
        logger.debug("Using double precision binaries")
        grompp_bin = [gmx_path('grompp_d')]
        mdrun_bin = [gmx_path('mdrun_d')]
        genergy_bin = [gmx_path('g_energy_d')]
    elif which('gmx'):
        logger.debug("Using double precision binaries")
        main_binary = gmx_path('gmx')
        grompp_bin = [main_binary, 'grompp']
        mdrun_bin = [main_binary, 'mdrun']
        genergy_bin = [main_binary, 'energy']
    elif which('grompp') and which('mdrun') and which('g_energy'):
        logger.debug("Using single precision binaries")
        grompp_bin = [gmx_path('grompp')]
        mdrun_bin = [gmx_path('mdrun')]
        genergy_bin = [gmx_path('g_energy')]
    else:
        raise IOError('Unable to find gromacs executables.')
    return grompp_bin, mdrun_bin, genergy_bin
Пример #3
0
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
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
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
from intermol.utils import run_subprocess, which
from intermol.lammps.lammps_parser import load, save

# Python 2/3 compatibility.
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = OSError

logger = logging.getLogger('InterMolLog')


for exe in ['lammps', 'lmp_mpi', 'lmp_serial', 'lmp_openmpi',
            'lmp_mac_mpi']:
    if which(exe):
        LMP_PATH = exe
        break
else:
    warnings.warn('Found no LAMMPS executable.')


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
Пример #9
0
import simtk.unit as units

from intermol.utils import run_subprocess, which
from intermol.lammps.lammps_parser import load, save

# Python 2/3 compatibility.
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = OSError

logger = logging.getLogger('InterMolLog')

for exe in ['lammps', 'lmp_mpi', 'lmp_serial', 'lmp_openmpi', 'lmp_mac_mpi']:
    if which(exe):
        LMP_PATH = exe
        break
else:
    warnings.warn('Found no LAMMPS executable.')


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