File: core.py

package info (click to toggle)
libxc 5.2.3-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 197,020 kB
  • sloc: ansic: 31,506; f90: 3,369; perl: 1,392; python: 966; makefile: 425; sh: 318
file content (37 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Find the LibXC shared object and imports it as core.
"""

import ctypes
import ctypes.util
import numpy as np
import os

# Attempt to load the compiled C code
core = None
__libxc_path = None

# First check the local folder
try:
    __libxc_path = os.path.abspath(os.path.dirname(__file__))
    core = np.ctypeslib.load_library("libxc", __libxc_path)
except OSError:
    # If no libxc is local, check LD_LIBRARY_PATHS's
    __libxc_path = ctypes.util.find_library("xc")

    # If we still havent found it, give up and throw an error
    if __libxc_path is None:
        raise ImportError(
            "LibXC Shared object not found, searched Python module local directory and library paths"
        )
    
    # Load the C object
    core = ctypes.CDLL(__libxc_path)


def get_core_path():
    """
    Returns the path of the loaded LibXC shared object.
    """

    return __libxc_path