semvec/pypi-packages huggingface dataset:
nershcalculator 0.3.1
Calculator module

# Calculator

> Does basic math operations

Methods :

-   _add_ - Adds the given number to the current number in the calculator memory
-   _subtract_ - Subtracts the given number from the current number in the calculator memory
-   _multiply_ - Multiplies current number in the calculator memory by the given number
-   _divide_ - Divides current number in the calculator memory by the given number
-   _root_ - Takes the given number root of the current number in the calculator
-  _reset_ - Resets calculator memory, default: 0

## Installation

```sh
pip install nershcalculator
```

## Usage

Addition of numbers:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator()
>>> calculations.add(5)
'5.0'
>>> calculations.add(10)
'15.0'
```

Subtraction of numbers:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator()
>>> calculations.subtract(5)
'-5.0'
>>> calculations.subtract(10)
'-15.0'
```

Number multiplication:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator(5)
>>> calculations.multiply(10)
'50.0'
>>> calculations.multiply(5)
'250.0'
```

Number division:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator(5)
>>> calculations.divide(5)
'1.0'
>>> calculations.divide(5)
'0.2'
```

Taking n root out of a number:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator(125)
>>> calculations.root(3)
'5.0'
```

Resetting calculator:

```python
>>> from nershcalculator import Calculator
>>> calculations = Calculator()
>>> calculations.add(100)
'100.0'
>>> calculations.reset()
'0.0'
```

## [Changelog](CHANGELOG.md)

## License

[MIT](https://choosealicense.com/licenses/mit/)
sofacomponents 0.1.17
Sofa helper to build scenes

# Easily build complex simulation graphs for SOFA

Install
```bash
pip install sofacomponents
```

## Quick start

```python
from sofacomponents import Node, SofaFactory

# build the factory
fa = SofaFactory(debug=False)

# create the root node
root = Node()
# add attributes
root.attrs(dt=0.05, gravity=[0, -1, 0])
# add sofa components from the factory
root.add(
    fa.VisualStyle(displayFlags="showVisual"),
    fa.DefaultAnimationLoop(),
    fa.RequiredPlugin(pluginName="SofaOpenglVisual SofaPython"),
)
# add child node
childNode = root.child("childNode").add(
    fa.MeshVTKLoader(filename="mesh.vtk"),
    # add components not from the factory
    fa.UnknownComponent(data="foo"),
)

# display the scene
print(root)

# Export the scene
root.write_scene_to("scene.py")

# Export the graph
root.write_graph_to("graph.txt")
```

Output:
```text
root
  └ VisualStyle (displayFlags=showVisual)
  └ DefaultAnimationLoop ()
  └ RequiredPlugin (pluginName=SofaOpenglVisual SofaPython)
  └ childNode
    └ MeshVTKLoader (filename=mesh.vtk)
    └ UnknownComponent (data=foo)
```

Python generated scene:
```python
import Sofa

class SceneElectroMechanical(Sofa.PythonScriptController):
    def __init__(self, node):
        self.createGraph(node)

    def createGraph(self, root):
        # root
        root.dt = 0.05
        root.gravity = [0, -1, 0]
        root.createObject("VisualStyle", displayFlags="showVisual")
        root.createObject("DefaultAnimationLoop",)
        root.createObject("RequiredPlugin", pluginName="SofaOpenglVisual SofaPython")

        # root/childNode
        childNode = root.createChild("childNode")
        childNode.createObject("MeshVTKLoader", filename="mesh.vtk")
        childNode.createObject("UnknownComponent", data="foo")

def createScene(root_node):
    SceneElectroMechanical(root_node)
```



## Extend

Create a factory instanciating the `SofaFactory` class.

The `sofa_component` decorator allows to update the parameters directory with:
1. the general default parameters (See `SofaFactory._defaults`)
2. the `params` you choose for your component
3. the custom `kwargs` given by the user



```python
from sofacomponents import SofaFactory, sofa_component

class MyFactory(SofaFactory):
    def __init__(self, debug=False):
        super().__init__(debug)
   
    @sofa_component
    def MyComponentNoParams(self, **kwargs):
        """ Minimum signature to register the component to the factory """
        return "MyComponentName"

    @sofa_component
    def MyComponent(self, **kwargs):
        params = dict(
            data="foo",
            # ...
        )
        return "MyComponentName", params
```

And then
```python
# build the factory
fa = MyFactory()
```


## Embeded documentation

![pycharm documentation](sofacomponents/lib/FEM_doc.png)