forked from SPARC-X/SPARC-X-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
459b3a8
commit a8713f6
Showing
2 changed files
with
34 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
from .io import read_sparc, write_sparc | ||
from .io import register_ase_io_sparc | ||
from .calculator import SPARC | ||
"""Initialization of sparc-x-api | ||
register_ase_io_sparc() | ||
For submodules like download_data and api, ase / numpy may be ignored, | ||
and run using standard python libaries. This may be useful for cases like | ||
conda build and CI where not all dependencies are present | ||
""" | ||
|
||
def _missing_deps_func(*args, **kwargs): | ||
raise ImportError("Importing fails for ase / numpy!") | ||
|
||
class SPARCMissingDeps: | ||
def __init__(self, *args, **kwargs): | ||
raise ImportError("Cannot initialize sparc.SPARC because the required dependencies (ase and numpy) are not available.") | ||
|
||
def __getattr__(self, name): | ||
raise ImportError(f"Cannot access '{name}' on sparc.SPARC because the required dependencies (ase and numpy) are not available.") | ||
try: | ||
import ase | ||
import numpy | ||
_import_complete = True | ||
except ImportError: | ||
_import_complete = False | ||
|
||
if _import_complete: | ||
from .io import read_sparc, write_sparc | ||
from .io import register_ase_io_sparc | ||
from .calculator import SPARC | ||
register_ase_io_sparc() | ||
else: | ||
# If importing is not complete, any code trying to directly import | ||
# the following attributes will raise ImportError | ||
read_sparc = _missing_deps_func | ||
write_sparc = _missing_deps_func | ||
SPARC = SPARCMissingDeps | ||
|