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.0

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.0
File Interpreter ABI Platform Actions
magicsoup-2.0.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for magicsoup-2.0.0-cp39-abi3-win_amd64.whl
magicsoup-2.0.0-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.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
magicsoup-2.0.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for magicsoup-2.0.0-cp39-abi3-macosx_11_0_arm64.whl

Total release size: 1.3 MB

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

Download URL magicsoup-2.0.0-cp39-abi3-win_amd64.whl
Size 349.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
de5d9e398a5c3d93480d3722ea91c3ec5a03a0bfaef0e02fe2dfb9a4cf2731ac
BLAKE2b-256 checksum
How to use checksums
f8cb42b6a507e5c4d3087c410bdb9ba466ebdbaeaad35cefe218336146978140
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.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL magicsoup-2.0.0-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
25011a314f9e84fec19f6b8a0dcd35d044c4f9ae9e7da7925cd4faefd16b4bdb
BLAKE2b-256 checksum
How to use checksums
92568b58bd8a535c7a7ed13a488698d6c3bf6ef33329e68fcd2b00caf526ed9c
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.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL magicsoup-2.0.0-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
6115c3ca11c0adf6f81bc157365279952c6c28dddcdabbac3fb7c3a6e4197335
BLAKE2b-256 checksum
How to use checksums
b063abeff78f518a7cf8d469cf536cd807066d0bcf25ea6f098c87c1304c6376
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.0

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.0 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