Skip to main content

MagicSoup


Documentation: https://magic-soup.readthedocs.io/

Source Code: https://github.com/mRcSchwering/magic-soup

PyPI: https://pypi.org/project/magicsoup/


This is a simulation for cell metabolic and transduction pathway evolution. Define a world with molecules and reactions. Add a few cells and create evolutionary pressure by selectively replicating and killing them. Then run and see what random mutations can do.

random cells

Cell growth of 1000 cells with different genomes was simulated. Top row: Cell maps showing all cells (all) and the 3 fastest growing celllines (CL0-2). Middle and bottom rows: Development of total cell count and molecule concentrations over time.

Installation

For CPU alone you can just do:

pip install magicsoup

This simulation relies on PyTorch. You can move almost all calculations to a GPU. This increases performance a lot and is recommended. In this case first setup PyTorch with CUDA as described in Get Started (pytorch.org), then install MagicSoup afterwards.

Example

The basic building blocks of what a cell can do are defined by the world's chemistry. There are molecules and reactions that can convert these molecules. Cells can develop proteins with domains that can catalyze reactions, transport molecules and be regulated by them. Reactions and transports always progress into the energetically favourable direction. Below, defines a chemistry with reaction CO2 + NADPH $\rightleftharpoons$ formiat + NADP.

import torch
import magicsoup as ms

NADPH = ms.Molecule("NADPH", 62, half_life=3, diffusivity=4e-6, permeability=0)
NADP = ms.Molecule("NADP", 2, half_life=60, diffusivity=4e-6, permeability=0)
co2 = ms.Molecule("CO2", 10, half_life=-1, diffusivity=2e-5, permeability=1)
formiat = ms.Molecule("formiat", 77, half_life=-1, diffusivity=1.5e-5, permeability=1e-6)

co2_nadph_to_formiat_NADP = ms.Reaction([co2, NADPH], [formiat, NADP])

chemistry = ms.Chemistry(reactions=[co2_nadph_to_formiat_NADP], molecules=[NADPH, NADP, formiat, co2])
world = ms.World(chemistry=chemistry)

By coupling multiple domains within the same protein, energetically unfavourable actions can be powered with the energy of energetically favourable ones. These domains, their specifications, and how they are coupled in proteins, is all encoded in the cell's genome. The following generates 100 cells with random genomes and place them randomly on a world map with some initial molecules.

world.culture.molecule_map[:] = 10
genomes = [ms.random_genome(s=500) for _ in range(100)]
world.spawn_cells(genomes=genomes)

The simulation advances in time by letting cells work and molecules diffuse. Cells discover new proteins by chance through mutations. Evolutionary pressure can be applied by selectively killing or dividing cells. E.g.:

for _ in range(1000):
    world.advance_time()
    world.kill_cells(mask=world.cells.molecules[:, 3] < 0.1)
    divided = world.divide_cells(mask=world.cells.molecules[:, 1] > 0.5)
    world.mutate_cells(mask=divided)

See the Docs for more details.

Metadata

Release files for magicsoup 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for magicsoup 2.0.1
File Interpreter ABI Platform Actions
magicsoup-2.0.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for magicsoup-2.0.1-cp39-abi3-win_amd64.whl
magicsoup-2.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for magicsoup-2.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
magicsoup-2.0.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for magicsoup-2.0.1-cp39-abi3-macosx_11_0_arm64.whl

Total release size: 1.3 MB

Release files / magicsoup-2.0.1-cp39-abi3-win_amd64.whl

Download URL magicsoup-2.0.1-cp39-abi3-win_amd64.whl
Size 349.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7afc986c3597e786e9556e52db9e0f8cbf3d46845db2af3229084abdca5d0d7d
BLAKE2b-256 checksum
How to use checksums
0d716e5ffeaadd5eb113a138f8570a62b4cb9ecafe60133ef36eb9965445c11d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / magicsoup-2.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL magicsoup-2.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 528.4 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
20d53046962560e07e2819352a85fd772288617743cbe3f817f344b202b8637f
BLAKE2b-256 checksum
How to use checksums
2bd0eee13bdf0bb69600053bbb2e281cd6c79d9357af1755da9f26e85b4af477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / magicsoup-2.0.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL magicsoup-2.0.1-cp39-abi3-macosx_11_0_arm64.whl
Size 466.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
93bd1c469d43a279e8e8cc883a0f35414f87418f6ba99f35f475b5e618d74221
BLAKE2b-256 checksum
How to use checksums
8e79b7fbf0a9d4aca6ec3c3743f1457ba6aad0124080bccbfde7f7a187fc2ca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for magicsoup 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.1 This release

3 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page