Skip to content

Commit

Permalink
Python refactoring and API update
Browse files Browse the repository at this point in the history
  • Loading branch information
favreau committed May 15, 2024
1 parent a94f09e commit 3746d0f
Show file tree
Hide file tree
Showing 92 changed files with 2,310 additions and 2,003 deletions.
10 changes: 4 additions & 6 deletions bioexplorer/backend/science/BioExplorerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ void BioExplorerPlugin::init()
endPoint = PLUGIN_API_PREFIX + "get-model-transformation";
PLUGIN_REGISTER_ENDPOINT(endPoint);
actionInterface->registerRequest<ModelIdDetails, ModelTransformationDetails>(
endPoint,
[&](const ModelIdDetails &payload) -> ModelTransformationDetails
endPoint, [&](const ModelIdDetails &payload) -> ModelTransformationDetails
{ return _getModelTransformation(payload); });

endPoint = PLUGIN_API_PREFIX + "get-model-bounds";
Expand Down Expand Up @@ -490,8 +489,7 @@ void BioExplorerPlugin::init()

endPoint = PLUGIN_API_PREFIX + "get-vasculature-info";
PLUGIN_REGISTER_ENDPOINT(endPoint);
actionInterface->registerRequest<NameDetails, Response>(endPoint,
[&](const NameDetails &payload) -> Response
actionInterface->registerRequest<NameDetails, Response>(endPoint, [&](const NameDetails &payload) -> Response
{ return _getVasculatureInfo(payload); });

endPoint = PLUGIN_API_PREFIX + "set-vasculature-report";
Expand Down Expand Up @@ -1772,13 +1770,13 @@ Response BioExplorerPlugin::_buildFields(const BuildFieldsDetails &payload)

switch (payload.dataType)
{
case FieldDataType::point:
case FieldDataType::fdt_points:
{
PointFieldBuilder builder;
builder.buildOctree(engine, *model, payload.voxelSize, payload.density, payload.modelIds);
break;
}
case FieldDataType::vector:
case FieldDataType::fdt_vectors:
{
VectorFieldBuilder builder;
builder.buildOctree(engine, *model, payload.voxelSize, payload.density, payload.modelIds);
Expand Down
4 changes: 2 additions & 2 deletions bioexplorer/backend/science/common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,9 +1219,9 @@ typedef struct
enum class FieldDataType
{
/** Point field (spheres) */
point = 0,
fdt_points = 0,
/** Vector field */
vector = 1
fdt_vectors = 1
};

/**
Expand Down
62 changes: 24 additions & 38 deletions bioexplorer/pythonsdk/bioexplorer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The Blue Brain BioExplorer is a tool for scientists to extract and analyse
# scientific data from visualization
#
# Copyright 2020-2023 Blue BrainProject / EPFL
# Copyright 2020-2024 Blue BrainProject / EPFL
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
Expand All @@ -22,41 +22,30 @@
# this program. If not, see <https://www.gnu.org/licenses/>.

from .version import VERSION as __version__
from .bio_explorer import (
BioExplorer,
Volume,
Membrane,
AssemblyProtein,
Protein,
Sugar,
RNASequence,
Cell,
Surfactant,
Virus,
EnzymeReaction,
MolecularSystemAnimationParams,
CellAnimationParams,
NeuronDisplacementParams,
NeuronReportParams,
AstrocyteDisplacementParams,
VasculatureDisplacementParams,
SynapseDisplacementParams,
Vector2,
Vector3,
Quaternion,
Transformation,
)

from .math_utils import (Vector2, Vector3, Quaternion, Bounds, Transformation)
from .animation_parameters import (
MolecularSystemAnimationParams, CellAnimationParams)
from .displacement_parameters import (
NeuronDisplacementParams, AstrocyteDisplacementParams, VasculatureDisplacementParams,
SynapseDisplacementParams)
from .molecular_systems import (Volume, Membrane, Protein, Sugar, RNASequence,
Cell, Surfactant, Virus, EnzymeReaction)
from .report_parameters import NeuronReportParams
from .movie_maker import MovieMaker
from .movie_scenario import MovieScenario
from .metabolism import Metabolism
from .sonata_explorer import SonataExplorer
from .notebook_widgets import Widgets
from .transfer_function import TransferFunction
from .bio_explorer import BioExplorer

__all__ = [
"Widgets",
"__version__",
"BioExplorer",
"Vector2",
"Vector3",
"Bounds",
"Transformation",
"Membrane",
"Protein",
"AssemblyProtein",
Expand All @@ -65,22 +54,19 @@
"Volume",
"Surfactant",
"Cell",
"Vector2",
"Vector3",
"MolecularSystemAnimationParams",
"CellAnimationParams",
"Quaternion",
"Virus",
"MovieMaker",
"TransferFunction",
"MovieScenario",
"Metabolism",
"EnzymeReaction",
"MolecularSystemAnimationParams",
"CellAnimationParams",
"NeuronDisplacementParams",
"NeuronReportParams",
"AstrocyteDisplacementParams",
"VasculatureDisplacementParams",
"SynapseDisplacementParams",
"NeuronReportParams",
"MovieMaker",
"SonataExplorer",
"__version__",
"Metabolism",
"MovieScenario",
"TransferFunction",
"Widgets"
]
144 changes: 144 additions & 0 deletions bioexplorer/pythonsdk/bioexplorer/animation_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# !/usr/bin/env python
"""BioExplorer class"""

# -*- coding: utf-8 -*-

# The Blue Brain BioExplorer is a tool for scientists to extract and analyse
# scientific data from visualization
#
# Copyright 2020-2024 Blue BrainProject / EPFL
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.


class MolecularSystemAnimationParams:
"""
Parameters used to introduce some randomness in the position and orientation of the protein.
This approach is used to make assemblies appear more realistic and for animation purposes.
"""

def __init__(
self,
seed=0,
position_seed=0,
position_strength=0.0,
rotation_seed=0,
rotation_strength=0.0,
morphing_step=0.0,
):
"""
Initialize the animation parameters using a dictionary to store components.
:param seed: int, optional: Randomization seed for initial setup. Defaults to 0.
:param position_seed: int, optional: Seed for position randomization. Defaults to 0.
:param position_strength: float, optional: Strength of position randomization. Defaults to 0.0.
:param rotation_seed: int, optional: Seed for rotation randomization. Defaults to 0.
:param rotation_strength: float, optional: Strength of rotation randomization. Defaults to 0.0.
:param morphing_step: float, optional: Step for morphing between shapes. Defaults to 0.0.
"""
self.components = {
'seed': seed,
'position_seed': position_seed,
'position_strength': position_strength,
'rotation_seed': rotation_seed,
'rotation_strength': rotation_strength,
'morphing_step': morphing_step
}

def get_params(self, component):
"""
Retrieve parameters for a specific component.
:param component: str: Name of the component.
:return: float: Parameters for the specified component.
"""
return self.components.get(component, 0)

def to_list(self):
"""
Convert all animation parameters into a list format.
:return: List of values representing all components.
:rtype: list
"""
return list(self.components.values())

def copy(self):
"""
Create a copy of the current object, preserving all parameters.
:return: MolecularSystemAnimationParams: A new instance with duplicated settings.
"""
return MolecularSystemAnimationParams(**self.components)

def __repr__(self):
"""
Return the official string representation of the object for debugging and logging purposes.
"""
return f"MolecularSystemAnimationParams({', '.join(f'{k}={v}' for k, v in self.components.items())})"


class CellAnimationParams:
"""
Parameters used to introduce some sinusoidal function in a cell structure.
This class is used to define how cells should be animated using sinusoidal motion.
"""

def __init__(self, seed=0, offset=0, amplitude=1.0, frequency=1.0):
"""
Initialize the animation parameters with sinusoidal characteristics.
:param seed: int, optional: Initial position in the sinusoidal function. Defaults to 0.
:param offset: int, optional: Offset in the sinusoidal function. Defaults to 0.
:param amplitude: float, optional: Amplitude of the sinusoidal function.
:param frequency: float, optional: Frequency of the sinusoidal function.
"""
self.components = {
'seed': seed,
'offset': offset,
'amplitude': amplitude,
'frequency': frequency
}

def get_params(self, component):
"""
Retrieve parameters for a specific component.
:param component: str: Name of the component.
:return: float: Parameters for the specified component.
"""
return self.components.get(component, 0)

def to_list(self):
"""
Convert all animation parameters into a list format.
:return: List of values representing all components.
:rtype: list
"""
return list(self.components.values())

def copy(self):
"""
Create a copy of the current object, preserving all parameters.
:return: CellAnimationParams: A new instance with duplicated settings.
"""
return CellAnimationParams(**self.components)

def __repr__(self):
"""
Return the official string representation of the object for debugging and logging purposes.
"""
return f"CellAnimationParams({', '.join(f'{k}={v}' for k, v in self.components.items())})"
Loading

0 comments on commit 3746d0f

Please sign in to comment.