Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bindings/rascal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .sparse_points import SparsePoints
from .krr import train_gap_model, KRR
from .kernels import Kernel
31 changes: 9 additions & 22 deletions bindings/rascal/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from .fps import fps, FPSFilter
from ..lib._rascal.utils import ostream_redirect
from ..lib import utils
from copy import deepcopy
from .io import (
BaseIO,
to_dict,
Expand All @@ -11,23 +7,14 @@
dump_obj,
load_obj,
)
from .cur import CURFilter
from .scorer import get_score, print_score

# function to redirect c++'s standard output to python's one
ostream_redirect = utils.__dict__["ostream_redirect"]
from .misc import is_notebook

# Warning potential dependency loop: FPS imports models, which imports KRR,
# which imports this file again
from .fps import fps, FPSFilter

def is_notebook():
from IPython import get_ipython

try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
# function to redirect c++'s standard output to python's one
from ..lib._rascal.utils import ostream_redirect
from copy import deepcopy
from .cur import CURFilter
from .scorer import get_score, print_score
2 changes: 1 addition & 1 deletion bindings/rascal/utils/fps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .io import BaseIO
from ..lib import sparsification
from ..models.sparse_points import SparsePoints

from .filter_utils import (
get_index_mappings_sample_per_species,
Expand Down Expand Up @@ -236,7 +237,6 @@ def select(self, managers):
raise NotImplementedError("method: {}".format(self.act_on))

def filter(self, managers, n_select=None):
from ..models import SparsePoints

if n_select is None:
n_select = self.Nselect
Expand Down
17 changes: 17 additions & 0 deletions bindings/rascal/utils/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Miscellaneous useful utilities"""


def is_notebook():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see why we have this function in librascal ... Is this used anywhere else in the code or is this just a convenience function for librascal users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used to decide whether to import tqdm in the command-line version or the notebook version, in one of the tutorials (yet to be merged, I think). I know we wanted to make the dependency on tqdm optional, but if it is present, we will probably want to import the appropriate version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was one of the i-PI tutorials actually, see e.g.: af2c7bd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, ideally I would move this function to the tutorial code itself, and not inside librascal. But this can happen as part of #307

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR is scheduled to be merged soon anyway (I split this fix off from that PR because I thought it was more urgent)

"""Is this being run inside an IPython Notebook?"""
from IPython import get_ipython

try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)
except NameError:
return False # Probably standard Python interpreter
3 changes: 2 additions & 1 deletion examples/MLIP_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"import json\n",
"\n",
"from rascal.representations import SphericalInvariants\n",
"from rascal.models import Kernel, SparsePoints, train_gap_model\n",
"from rascal.models import Kernel, train_gap_model\n",
"from rascal.models.sparse_points import SparsePoints\n",
"from rascal.models.IP_ase_interface import ASEMLCalculator\n",
"from rascal.neighbourlist import AtomsList\n",
"from rascal.utils import from_dict, to_dict, CURFilter, dump_obj, load_obj, get_score, print_score"
Expand Down
3 changes: 2 additions & 1 deletion examples/Spherical_invariants_and_database_exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"from tqdm.notebook import tqdm\n",
"\n",
"from rascal.representations import SphericalInvariants\n",
"from rascal.models import Kernel, KRR, train_gap_model, SparsePoints\n",
"from rascal.models import Kernel, KRR, train_gap_model\n",
"from rascal.models.sparse_points import SparsePoints\n",
"from rascal.utils import from_dict, to_dict, CURFilter, FPSFilter, get_score, print_score"
]
},
Expand Down
3 changes: 2 additions & 1 deletion tests/python/python_models_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rascal.representations import SphericalInvariants
from rascal.models import Kernel, SparsePoints
from rascal.models import Kernel
from rascal.models.sparse_points import SparsePoints
from rascal.models.kernels import compute_numerical_kernel_gradients
from rascal.utils import from_dict, to_dict
from test_utils import load_json_frame, BoxList, Box, compute_relative_error
Expand Down
3 changes: 2 additions & 1 deletion tests/python/python_representation_calculator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
SphericalInvariants,
)
from rascal.utils import from_dict, to_dict, FPSFilter
from rascal.models import Kernel, SparsePoints
from rascal.models import Kernel
from rascal.models.sparse_points import SparsePoints
from test_utils import load_json_frame, BoxList, Box, dot
import unittest
import numpy as np
Expand Down