Skip to content
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ features = ["extension-module"]
name = "rust"
crate-type = ["cdylib"]
path = "src/rust/lib.rs"

# Enable optimizations in dev mode for better performance during development
[profile.dev]
opt-level = 3
13 changes: 11 additions & 2 deletions benchmarks/structure/benchmark_celllist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ def benchmark_cell_list_creation(atoms):
struc.CellList(atoms, 5.0)


@pytest.mark.parametrize(
"result_format",
[
struc.CellList.Result.MAPPING,
struc.CellList.Result.MASK,
struc.CellList.Result.PAIRS,
],
ids=lambda format: str(format).split(".")[-1],
)
@pytest.mark.benchmark
def benchmark_cell_list_compute_contacts(cell_list, atoms):
def benchmark_cell_list_compute_contacts(cell_list, atoms, result_format):
"""
Find all contacts in a structure using an existing cell list.
"""
cell_list.get_atoms(atoms.coord, 5.0)
cell_list.get_atoms(atoms.coord, 5.0, result_format=result_format)
42 changes: 33 additions & 9 deletions doc/apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,51 @@ def skip_nonrelevant(app, what, name, obj, skip, options):
return True
if not _is_relevant_type(obj):
return True
if obj.__module__ is None:
# Some built-in functions have '__module__' set to None
module = _get_module(obj)
if module is None:
return True
package_name = obj.__module__.split(".")[0]
package_name = module.split(".")[0]
if package_name != "biotite":
return True
return False


def _get_module(obj):
"""
Get the module name of an object.

For most objects, this is simply ``obj.__module__``.
However, some extension types (e.g. PyO3 method descriptors)
don't have a ``__module__`` attribute, so we fall back to
``obj.__objclass__.__module__``.
"""
module = getattr(obj, "__module__", None)
if module is not None:
return module
# Fallback for PyO3 method descriptors that don't have __module__
objclass = getattr(obj, "__objclass__", None)
if objclass is not None:
return getattr(objclass, "__module__", None)
return None


def _is_relevant_type(obj):
if type(obj).__name__ == "method_descriptor":
# These are some special built-in Python methods
return False
return (
(
# Functions
type(obj)
in [types.FunctionType, types.BuiltinFunctionType, types.MethodType]
isinstance(
obj,
(
types.FunctionType,
types.BuiltinFunctionType,
types.MethodType,
types.BuiltinMethodType,
types.MethodDescriptorType,
),
)
)
| (
# Functions from C-extensions and wrapped functions
# Functions from Cython extensions and wrapped functions
type(obj).__name__
in [
"cython_function_or_method",
Expand Down
4 changes: 2 additions & 2 deletions doc/contribution/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ Therefore, the code should be vectorized as much as possible using *NumPy*.
In cases the problem cannot be reasonably or conveniently solved this way,
writing modules in *Rust* using `PyO3 <https://pyo3.rs>` is the
preferred way to go.
The *Rust* part of the codebase is located in ``src/biotite/rust/`` and mirrors the
The *Rust* part of the codebase is located in ``src/rust/`` and mirrors the
structure of the *Python* side.
For example *Rust* functionalities for ``biotite.structure.io.pdb`` residue in
For example *Rust* functionalities for ``biotite.structure.io.pdb`` reside in
``biotite.rust.structure.io.pdb``.
``biotite.rust`` itself is not publicly exposed, but its functionalities are instead
internally used or reexported in ``biotite`` subpackages.
Expand Down
Loading
Loading