Esempio n. 1
0
def test_1():
    capi = mdtraj.capi()
    assert os.path.isdir(capi['lib_dir'])
    assert os.path.isdir(capi['include_dir'])
    if sys.platform == 'win32':
        assert os.path.isfile(os.path.join(capi['lib_dir'], 'libtheobald.lib'))
    else:
        assert os.path.isfile(os.path.join(capi['lib_dir'], 'libtheobald.a'))
Esempio n. 2
0
def test_1():
    capi = mdtraj.capi()
    assert os.path.isdir(capi['lib_dir'])
    assert os.path.isdir(capi['include_dir'])
    assert os.path.isfile(os.path.join(capi['lib_dir'], 'libtheobald.a'))
Esempio n. 3
0
import sys
import glob
import traceback
import numpy as np
from os.path import join as pjoin
from setuptools import setup, Extension, find_packages
try:
    sys.dont_write_bytecode = True
    sys.path.insert(0, '.')
    from basesetup import write_version_py, CompilerDetection, check_dependencies
finally:
    sys.dont_write_bytecode = False

try:
    import mdtraj
    mdtraj_capi = mdtraj.capi()
except (ImportError, AttributeError):
    print('=' * 80)
    print('MDTraj version 1.1.X or later is required')
    print('=' * 80)
    traceback.print_exc()
    sys.exit(1)

if '--debug' in sys.argv:
    sys.argv.remove('--debug')
    DEBUG = True
else:
    DEBUG = False
if '--disable-openmp' in sys.argv:
    sys.argv.remove('--disable-openmp')
    DISABLE_OPENMP = True
Esempio n. 4
0
import sys
import glob
import traceback
import numpy as np
from os.path import join as pjoin
from setuptools import setup, Extension, find_packages
try:
    sys.dont_write_bytecode = True
    sys.path.insert(0, '.')
    from basesetup import write_version_py, CompilerDetection, check_dependencies
finally:
    sys.dont_write_bytecode = False

try:
    import mdtraj
    mdtraj_capi = mdtraj.capi()
except (ImportError, AttributeError):
    print('='*80)
    print('MDTraj version 1.1.X or later is required')
    print('='*80)
    traceback.print_exc()
    sys.exit(1)

if '--debug' in sys.argv:
    sys.argv.remove('--debug')
    DEBUG = True
else:
    DEBUG = False
if '--disable-openmp' in sys.argv:
    sys.argv.remove('--disable-openmp')
    DISABLE_OPENMP = True
Esempio n. 5
0
def extensions():
    """How do we handle cython:
    1. when on git, require cython during setup time (do not distribute
    generated .c files via git)
     a) cython present -> fine
     b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
    This is solved via a lazy evaluation of the extension list. This is needed,
    because build_ext is being called before cython will be available.
    https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires

    2. src dist install (have pre-converted c files and pyx files)
     a) cython present -> fine
     b) no cython -> use .c files
    """
    USE_CYTHON = False
    try:
        from Cython.Build import cythonize
        USE_CYTHON = True
    except ImportError:
        warnings.warn('Cython not found. Using pre cythonized files.')

    # setup OpenMP support
    from setup_util import detect_openmp
    openmp_enabled, needs_gomp = detect_openmp()

    import mdtraj
    from numpy import get_include as _np_inc
    np_inc = _np_inc()

    exts = []

    if sys.platform.startswith('win'):
        lib_prefix = 'lib'
    else:
        lib_prefix = ''
    regspatial_module = \
        Extension('pyemma.coordinates.clustering.regspatial',
                  sources=[
                      'pyemma/coordinates/clustering/src/regspatial.c',
                      'pyemma/coordinates/clustering/src/clustering.c'],
                  include_dirs=[
                      mdtraj.capi()['include_dir'],
                      np_inc,
                      'pyemma/coordinates/clustering/include',
                  ],
                  libraries=[lib_prefix+'theobald'],
                  library_dirs=[mdtraj.capi()['lib_dir']],
                  extra_compile_args=['-std=c99', '-g', '-O3', '-pg'])
    kmeans_module = \
        Extension('pyemma.coordinates.clustering.kmeans_clustering',
                  sources=[
                      'pyemma/coordinates/clustering/src/kmeans.c',
                      'pyemma/coordinates/clustering/src/clustering.c'],
                  include_dirs=[
                      mdtraj.capi()['include_dir'],
                      np_inc,
                      'pyemma/coordinates/clustering/include'],
                  libraries=[lib_prefix+'theobald'],
                  library_dirs=[mdtraj.capi()['lib_dir']],
                  extra_compile_args=['-std=c99'])

    covar_module = \
        Extension('pyemma.coordinates.estimators.covar.covar_c.covartools',
                  sources=['pyemma/coordinates/estimators/covar/covar_c/covartools.pyx',
                           'pyemma/coordinates/estimators/covar/covar_c/_covartools.c'],
                  include_dirs=['pyemma/coordinates/estimators/covar/covar_c/',
                                np_inc,
                                ],
                  extra_compile_args=['-std=c99', '-O3'])

    exts += [
        regspatial_module,
        kmeans_module,
        covar_module,
    ]

    if not USE_CYTHON:
        # replace pyx files by their pre generated c code.
        for e in exts:
            new_src = []
            for s in e.sources:
                new_src.append(s.replace('.pyx', '.c'))
            e.sources = new_src
    else:
        exts = cythonize(exts)

    if openmp_enabled:
        warnings.warn('enabled openmp')
        omp_compiler_args = ['-fopenmp']
        omp_libraries = ['-lgomp'] if needs_gomp else []
        omp_defines = [('USE_OPENMP', None)]
        for e in exts:
            e.extra_compile_args += omp_compiler_args
            e.extra_link_args += omp_libraries
            e.define_macros += omp_defines

    return exts
Esempio n. 6
0
def extensions():
    """How do we handle cython:
    1. when on git, require cython during setup time (do not distribute
    generated .c files via git)
     a) cython present -> fine
     b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
    This is solved via a lazy evaluation of the extension list. This is needed,
    because build_ext is being called before cython will be available.
    https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires

    2. src dist install (have pre-converted c files and pyx files)
     a) cython present -> fine
     b) no cython -> use .c files
    """
    USE_CYTHON = False
    try:
        from Cython.Build import cythonize
        USE_CYTHON = True
    except ImportError:
        warnings.warn('Cython not found. Using pre cythonized files.')

    import mdtraj
    from numpy import get_include as _np_inc
    np_inc = _np_inc()

    pybind_inc = os.path.join(os.path.dirname(__file__), 'pybind11', 'include')
    assert os.path.exists(pybind_inc)

    exts = []
    lib_prefix = 'lib' if sys.platform.startswith('win') else ''
    common_cflags = [
        '-O3',
    ]

    clustering_module = \
        Extension('pyemma.coordinates.clustering._ext',
                  sources=['pyemma/coordinates/clustering/src/clustering_module.cpp'],
                  include_dirs=[
                      mdtraj.capi()['include_dir'],
                      np_inc,
                      pybind_inc,
                      'pyemma/coordinates/clustering/include',
                  ],
                  language='c++',
                  libraries=[lib_prefix+'theobald'],
                  library_dirs=[mdtraj.capi()['lib_dir']],
                  extra_compile_args=common_cflags)

    covar_module = \
        Extension('pyemma._ext.variational.estimators.covar_c._covartools',
                  sources=['pyemma/_ext/variational/estimators/covar_c/covartools.cpp'],
                  include_dirs=['pyemma/_ext/variational/estimators/covar_c/',
                                np_inc,
                                pybind_inc,
                                ],
                  language='c++',
                  extra_compile_args=common_cflags)

    eig_qr_module = \
        Extension('pyemma._ext.variational.solvers.eig_qr.eig_qr',
                  sources=['pyemma/_ext/variational/solvers/eig_qr/eig_qr.pyx'],
                  include_dirs=['pyemma/_ext/variational/solvers/eig_qr/', np_inc],
                  extra_compile_args=['-std=c99'] + common_cflags)

    orderedset = \
        Extension('pyemma._ext.orderedset._orderedset',
                  sources=['pyemma/_ext/orderedset/_orderedset.pyx'],
                  include_dirs=[np_inc],
                  extra_compile_args=['-std=c99'] + common_cflags)

    exts += [clustering_module, covar_module, eig_qr_module, orderedset]

    if not USE_CYTHON:
        # replace pyx files by their pre generated c code.
        for e in exts:
            new_src = []
            for s in e.sources:
                new_src.append(s.replace('.pyx', '.c'))
            e.sources = new_src
    else:
        exts = cythonize(exts)

    return exts
Esempio n. 7
0
File: setup.py Progetto: mejk/PyEMMA
def extensions():
    """How do we handle cython:
    1. when on git, require cython during setup time (do not distribute
    generated .c files via git)
     a) cython present -> fine
     b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
    This is solved via a lazy evaluation of the extension list. This is needed,
    because build_ext is being called before cython will be available.
    https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires

    2. src dist install (have pre-converted c files and pyx files)
     a) cython present -> fine
     b) no cython -> use .c files
    """
    USE_CYTHON = False
    try:
        from Cython.Build import cythonize
        USE_CYTHON = True
    except ImportError:
        warnings.warn('Cython not found. Using pre cythonized files.')


    import mdtraj
    # Note, that we add numpy include to every extension after declaration.
    from numpy import get_include as _np_inc
    np_inc = _np_inc()

    pybind_inc = get_pybind_include()

    lib_prefix = 'lib' if sys.platform.startswith('win') else ''
    common_cflags = ['-O3', ]

    clustering_module = \
        Extension('pyemma.coordinates.clustering._ext',
                  sources=['pyemma/coordinates/clustering/src/clustering_module.cpp'],
                  include_dirs=[
                      mdtraj.capi()['include_dir'],
                      pybind_inc,
                      'pyemma/coordinates/clustering/include',
                  ],
                  language='c++',
                  libraries=[lib_prefix+'theobald'],
                  library_dirs=[mdtraj.capi()['lib_dir']],
                  extra_compile_args=common_cflags)

    covar_module = \
        Extension('pyemma._ext.variational.estimators.covar_c._covartools',
                  sources=['pyemma/_ext/variational/estimators/covar_c/covartools.cpp'],
                  include_dirs=['pyemma/_ext/variational/estimators/covar_c/',
                                pybind_inc,
                                ],
                  language='c++',
                  extra_compile_args=common_cflags)

    eig_qr_module = \
        Extension('pyemma._ext.variational.solvers.eig_qr.eig_qr',
                  sources=['pyemma/_ext/variational/solvers/eig_qr/eig_qr.pyx'],
                  include_dirs=['pyemma/_ext/variational/solvers/eig_qr/', np_inc],
                  extra_compile_args=['-std=c99'] + common_cflags)

    orderedset = \
        Extension('pyemma._ext.orderedset._orderedset',
                  sources=['pyemma/_ext/orderedset/_orderedset.pyx'],
                  extra_compile_args=['-std=c99'] + common_cflags)

    extra_compile_args = ["-O3", "-std=c99"]
    ext_bar = Extension(
        "pyemma.thermo.extensions.bar",
        sources=["pyemma/thermo/extensions/bar/bar.pyx",
                 "pyemma/thermo/extensions/bar/_bar.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_wham = Extension(
        "pyemma.thermo.extensions.wham",
        sources=["pyemma/thermo/extensions/wham/wham.pyx",
                 "pyemma/thermo/extensions/wham/_wham.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_mbar = Extension(
        "pyemma.thermo.extensions.mbar",
        sources=["pyemma/thermo/extensions/mbar/mbar.pyx",
                 "pyemma/thermo/extensions/mbar/_mbar.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_tram = Extension(
        "pyemma.thermo.extensions.tram",
        sources=["pyemma/thermo/extensions/tram/tram.pyx",
                 "pyemma/thermo/extensions/tram/_tram.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_dtram = Extension(
        "pyemma.thermo.extensions.dtram",
        sources=["pyemma/thermo/extensions/dtram/dtram.pyx",
                 "pyemma/thermo/extensions/dtram/_dtram.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_trammbar = Extension(
        "pyemma.thermo.extensions.trammbar",
        sources=["pyemma/thermo/extensions/trammbar/trammbar.pyx",
                 "pyemma/thermo/extensions/tram/_tram.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args + ["-DTRAMMBAR"])
    ext_mbar_direct = Extension(
        "pyemma.thermo.extensions.mbar_direct",
        sources=["pyemma/thermo/extensions/mbar_direct/mbar_direct.pyx",
                 "pyemma/thermo/extensions/mbar_direct/_mbar_direct.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_tram_direct = Extension(
        "pyemma.thermo.extensions.tram_direct",
        sources=["pyemma/thermo/extensions/tram_direct/tram_direct.pyx",
                 "pyemma/thermo/extensions/tram_direct/_tram_direct.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)
    ext_trammbar_direct = Extension(
        "pyemma.thermo.extensions.trammbar_direct",
        sources=["pyemma/thermo/extensions/trammbar_direct/trammbar_direct.pyx",
                 "pyemma/thermo/extensions/tram_direct/_tram_direct.c",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args + ["-DTRAMMBAR"])
    ext_util = Extension(
        "pyemma.thermo.extensions.util",
        sources=["pyemma/thermo/extensions/util/util.pyx",
                 "pyemma/thermo/extensions/util/_util.c"],
        extra_compile_args=extra_compile_args)

    exts_thermo = [
        ext_bar,
        ext_wham,
        ext_mbar,
        ext_tram,
        ext_dtram,
        ext_trammbar,
        ext_mbar_direct,
        ext_tram_direct,
        ext_trammbar_direct,
        ext_util]

    exts = [clustering_module,
             covar_module,
             eig_qr_module,
             orderedset
             ]
    exts += exts_thermo

    for e in exts:
        e.include_dirs.append(np_inc)

    if not USE_CYTHON:
        # replace pyx files by their pre generated c code.
        for e in exts:
            new_src = []
            for s in e.sources:
                new_src.append(s.replace('.pyx', '.c'))
            e.sources = new_src
    else:
        exts = cythonize(exts, language_level=sys.version_info[0])

    return exts
Esempio n. 8
0
def extensions():
    """How do we handle cython:
    1. when on git, require cython during setup time (do not distribute
    generated .c files via git)
     a) cython present -> fine
     b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
    This is solved via a lazy evaluation of the extension list. This is needed,
    because build_ext is being called before cython will be available.
    https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires

    2. src dist install (have pre-converted c files and pyx files)
     a) cython present -> fine
     b) no cython -> use .c files
    """
    USE_CYTHON = False
    try:
        from Cython.Build import cythonize
        USE_CYTHON = True
    except ImportError:
        warnings.warn('Cython not found. Using pre cythonized files.')

    # setup OpenMP support
    from setup_util import detect_openmp
    openmp_enabled, needs_gomp = detect_openmp()

    import mdtraj

    exts = []

    mle_trev_given_pi_dense_module = \
        Extension('pyemma.msm.estimation.dense.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/dense/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/dense/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_given_pi_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/sparse/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev',
                  sources=['pyemma/msm/estimation/sparse/mle_trev.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev.c'])
    if sys.platform.startswith('win'):
        lib_prefix = 'lib'
    else:
        lib_prefix = ''
    regspatial_module = \
        Extension('pyemma.coordinates.clustering.regspatial',
                  sources = ['pyemma/coordinates/clustering/regspatial.c'],
                  include_dirs = [mdtraj.capi()['include_dir']],
                  libraries = [lib_prefix+'theobald'],
                  library_dirs = [mdtraj.capi()['lib_dir']])

    exts += [
        mle_trev_given_pi_dense_module, mle_trev_given_pi_sparse_module,
        mle_trev_sparse_module, regspatial_module
    ]

    if USE_CYTHON:  # if we have cython available now, cythonize module
        exts = cythonize(exts)

    if openmp_enabled:
        warnings.warn('enabled openmp')
        omp_compiler_args = ['-fopenmp']
        omp_libraries = ['-lgomp'] if needs_gomp else []
        omp_defines = [('USE_OPENMP', None)]
        for e in exts:
            e.extra_compile_args += omp_compiler_args
            e.extra_link_args += omp_libraries
            e.define_macros += omp_defines

    return exts
Esempio n. 9
0
def extensions():
    """How do we handle cython:
    1. when on git, require cython during setup time (do not distribute
    generated .c files via git)
     a) cython present -> fine
     b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
    This is solved via a lazy evaluation of the extension list. This is needed,
    because build_ext is being called before cython will be available.
    https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires

    2. src dist install (have pre-converted c files and pyx files)
     a) cython present -> fine
     b) no cython -> use .c files
    """
    USE_CYTHON = False
    try:
        from Cython.Build import cythonize
        USE_CYTHON = True
    except ImportError:
        warnings.warn('Cython not found. Using pre cythonized files.')

    # setup OpenMP support
    from setup_util import detect_openmp
    openmp_enabled, needs_gomp = detect_openmp()

    import mdtraj

    exts = []

    mle_trev_given_pi_dense_module = \
        Extension('pyemma.msm.estimation.dense.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/dense/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/dense/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_given_pi_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/sparse/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev',
                  sources=['pyemma/msm/estimation/sparse/mle_trev.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev.c'])
    if sys.platform.startswith('win'):
        lib_prefix = 'lib'
    else:
        lib_prefix = ''
    regspatial_module = \
        Extension('pyemma.coordinates.clustering.regspatial',
                  sources = ['pyemma/coordinates/clustering/regspatial.c'],
                  include_dirs = [mdtraj.capi()['include_dir']],
                  libraries = [lib_prefix+'theobald'],
                  library_dirs = [mdtraj.capi()['lib_dir']])

    exts += [mle_trev_given_pi_dense_module,
             mle_trev_given_pi_sparse_module,
             mle_trev_sparse_module,
             regspatial_module]

    if USE_CYTHON: # if we have cython available now, cythonize module
        exts = cythonize(exts)

    if openmp_enabled:
        warnings.warn('enabled openmp')
        omp_compiler_args = ['-fopenmp']
        omp_libraries = ['-lgomp'] if needs_gomp else []
        omp_defines = [('USE_OPENMP', None)]
        for e in exts:
            e.extra_compile_args += omp_compiler_args
            e.extra_link_args += omp_libraries
            e.define_macros += omp_defines

    return exts