Skip to main content

Simulation for cell metabolic and transduction pathway evolution

Project description

MagicSoup


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

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

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


This game simulates cell metabolic and transduction pathway evolution. Define a 2D 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 (>=2.0.0,<2.2.0) 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][magicsoup.containers.Chemistry]. There are [molecules][magicsoup.containers.Molecule] 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, I am defining a chemistry with reaction CO2 + NADPH $\rightleftharpoons$ formiat + NADP | -90 kJ.

import torch
import magicsoup as ms

NADPH = ms.Molecule("NADPH", 200 * 1e3)
NADP = ms.Molecule("NADP", 100 * 1e3)
formiat = ms.Molecule("formiat", 20 * 1e3)
co2 = ms.Molecule("CO2", 10 * 1e3)

molecules = [NADPH, NADP, formiat, co2]
reactions = [([co2, NADPH], [formiat, NADP])]

chemistry = ms.Chemistry(reactions=reactions, molecules=molecules)
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. Here, I am generating 100 cells with random genomes of 500 base pairs each and place them randomly on a 2D world map.

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

Cells discover new proteins by chance through mutations. In the function below all cells experience 0.0001 point mutations per base pair. Then, neighbouring cells have a chance to exchange parts of their genome.

def mutate_cells(world: ms.World):
    world.mutate_cells(p=1e-4)
    world.recombinate_cells(p=1e-6)

Evolutionary pressure can be applied by selectively killing or replicating cells. Here, cells have an increased chance of dying when formiat concentrations decrease and an increased chance of replicating when formiat concentrations increase.

def sample(p: torch.Tensor) -> list[int]:
    idxs = torch.argwhere(torch.bernoulli(p))
    return idxs.flatten().tolist()

def kill_cells(world: ms.World):
    x = world.cell_molecules[:, 2]
    idxs = sample(.01 / (.01 + x))
    world.kill_cells(cell_idxs=idxs)

def replicate_cells(world: ms.World):
    x = world.cell_molecules[:, 2]
    idxs = sample(x ** 3 / (x ** 3 + 20.0 ** 3))
    world.divide_cells(cell_idxs=idxs)

Finally, the simulation itself is run in a loop by repetitively calling different methods. With [enzymatic_activity()][magicsoup.world.World.enzymatic_activity] chemical reactions and molecule transport in cells advance by one time step. [diffuse_molecules()][magicsoup.world.World.diffuse_molecules] lets molecules on the world map diffuse and permeate through cell membranes by one time step.

for _ in range(1000):
    world.enzymatic_activity()
    kill_cells(world=world)
    replicate_cells(world=world)
    mutate_cells(world=world)
    world.diffuse_molecules()

See the Docs for more examples and a description of all the mechanics of this simulation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magicsoup-1.0.5.tar.gz (13.8 MB view details)

Uploaded Source

Built Distributions

magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl (1.3 MB view details)

Uploaded PyPy manylinux: glibc 2.12+ i686

magicsoup-1.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

magicsoup-1.0.5-cp312-none-win_amd64.whl (302.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

magicsoup-1.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

magicsoup-1.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

magicsoup-1.0.5-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl (1.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.12+ i686

magicsoup-1.0.5-cp312-cp312-macosx_11_0_arm64.whl (420.3 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

magicsoup-1.0.5-cp312-cp312-macosx_10_12_x86_64.whl (434.0 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

magicsoup-1.0.5-cp311-none-win_amd64.whl (302.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

magicsoup-1.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

magicsoup-1.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

magicsoup-1.0.5-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl (1.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.12+ i686

magicsoup-1.0.5-cp311-cp311-macosx_11_0_arm64.whl (421.1 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

magicsoup-1.0.5-cp311-cp311-macosx_10_12_x86_64.whl (434.1 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

magicsoup-1.0.5-cp310-none-win_amd64.whl (302.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

magicsoup-1.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

magicsoup-1.0.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

magicsoup-1.0.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl (1.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686

magicsoup-1.0.5-cp310-cp310-macosx_11_0_arm64.whl (421.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

magicsoup-1.0.5-cp310-cp310-macosx_10_12_x86_64.whl (434.0 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

File details

Details for the file magicsoup-1.0.5.tar.gz.

File metadata

  • Download URL: magicsoup-1.0.5.tar.gz
  • Upload date:
  • Size: 13.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for magicsoup-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e1c26dff20a95c02fabde00b75e5b96c340b8ec7f7d0ca4bf9a1103bc7a6adde
MD5 b1751a21e97462b53f3fd46ebcdf8217
BLAKE2b-256 49e16c957866b1fde8d9cec344efb8a12a00a82c837cba9816ef63d3c383bd56

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 561e043e7fb82413705ef43d7349e70486a08cf3ee08e3b3497da0dbcd39f41b
MD5 d7eacf4c7d3b0d2ffae1c9302b0b184d
BLAKE2b-256 136049acac396d2cbcd2fcf84325bc258bd7a6430765c949738b76d8770a7f8f

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 06799a7418a5fbf8c69ab4e147eb9e46158b256914837891f59936101f718ecc
MD5 21846ef3fe7445f34577907d96737780
BLAKE2b-256 65f56b14d3a75097436ca10f55e435f243917a4918f8c0287e6a126d6b51f3d4

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-pp310-pypy310_pp73-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 8ec37d39bb0ab35056734aad6a4b8e85ab58e3f1c116bad1246dc662e4bcff31
MD5 d433a8e776a0914c6f1c5cf925d6e128
BLAKE2b-256 d2530f59b2aeb49175970f40db3e46add7164dba0991d8135dca6efcb0001c4f

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 759795aa7bdb2a496a2c4d49e36b9e26215bbe619ac3aea78925ea4c823e8a54
MD5 a47c60be97b6001560a3fb8ecbbb0174
BLAKE2b-256 3cd592b048c5806f45c880707a87537e81baa23e6efdf3e8dfd5634968047fad

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 0a1e947c464252759290f85caa3464e7096bd91da35dd528f70c3a1f21ac7096
MD5 b47b57a45244930fe59578e3a3dfb273
BLAKE2b-256 5ffe04bf8971cc36c4e2efc4e179f842304de1d1adfbbcdc0e95e25d2adb2f4c

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 466a30b03f1d14a29a749615cb9b0245996a032d7d1d91e3a05bccd5d55ab334
MD5 0d88e6ba651cb027241f7513658fdae0
BLAKE2b-256 1ed3e2c5108965b9a18e7c584167a7063169d7fea3698a0c0811966df964dbc5

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3af2f8b393c59744a2cde5fc88ec9b1119e1652d2365e94b337c622cb481837c
MD5 b5ea3afff9f8c13d0d4bae0fff29697b
BLAKE2b-256 3e86e27d1b1a4ef2c95eebb0562dd19c7e9eb2bf1ac7ce3867a450565c50d765

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 f0723cee34fbe4062aaad9abf081823f557d48ff44c8148de76a2212c014465c
MD5 845b8d47fba46d5da69d794ec305c509
BLAKE2b-256 587c4be7efb15ccdffc5e4c825c5613bc88dc28d50a5fb84bc4955b325096536

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee260ccfd75dbaa1f3472d3c13dec42e0c31904a2d6dc814b0548385dfb5ffb6
MD5 8b610c9e438c900b71897563b4b997f7
BLAKE2b-256 b42dbd067506196449b08451d13f7ef7501bd2ea8f13d041a80fdc0ae02121ae

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fca740aea0b330e60ec4cbb9c6ed8a6b786f36543d24109d9d1661114ef06731
MD5 48cd751d1c3ce4edf7eabae666d0dd53
BLAKE2b-256 5a7b0468579ae31bc3370edce4cc95ee01d52ab9dac0cae62d072484b19667fe

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 dc51fe22565e79152aec3660bd08d01968bfc65fcf6447f7d45f5ec9c4c9841f
MD5 1f16e82fe4247f8b63ba3d45aeda6181
BLAKE2b-256 b23baf68674ac4c7f076aa46ba330dae13e00995a75277dfbb812b20a3aa68a1

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6780d0c0ddddfaeaa3db4863f0e027f1b905ba229a7c86f071e45286d2275806
MD5 b7fade83690498fa2e8c8602ce75937d
BLAKE2b-256 47cbeefc82a60d046bd522784a1d00f341e3a40ee7cbb69e216fb4bc6287f3ac

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 039141e0abf0b48efb88974947624eb04f019314be43d2182343854d6a854488
MD5 84aeb2286352ed847483cefd8e40f2ea
BLAKE2b-256 10423466f92d5dbfae0f503268b1acf285c4db47fbe1baec75968a4badabf976

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 e24c509e44369e761b808621ca605bfd5a1e5cc86930991c4ae3956ee7ad4480
MD5 0a52b46e2c46ef7f80f914faad2932ec
BLAKE2b-256 ab20fad07ad108c85ea908cc629deb1c79b56d0a476d2d7d320ec277684f6b9a

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7584f677a72f9f2d39c4ce166e99ce8232643b299aee0fe34aea2b5ce4931f29
MD5 5b353740a7227a73676302050a001e92
BLAKE2b-256 6b1edd17747d11cd84ab510ba7a6ef64b0933bdfcdfe09370c9070c36dbe8803

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eda2c670009a0cce6aa8ff4d3e5888e1442032bd0f7101d63e7a8cdb32a56974
MD5 3c342d057fe9cead8fc4bdefe4d60751
BLAKE2b-256 4f3d7d94c1ce1179d334ee5e7b05f6ad5124c313e9ad638758c22e5e83f15412

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 c680b8a0ed739d11a955416ccabd18c26dec1d615fe1744eee9e8635e8af8b5a
MD5 5c3483640b1f9887fb4c4a9cff69ca6b
BLAKE2b-256 e516201cdd221c92bf9ea7c2adc35ed2b02c961938371035f7cb99f968b7c356

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bea66d4b39046ee86428d7feab77022aa6b41af7588e796663d517aa003b7465
MD5 694f8b47cf54e70bddce4f68672f4379
BLAKE2b-256 f8f2b8f880852126b12b1bc62cb89027f676633928c55c1d4933d4fc91077090

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e2c3c058ad6fdec0b0b59502a4f2c9baa9adea3010b17b3f9dce2c6be6a4da49
MD5 4b4e1f6fd31dc5d49c86ff19a1dc11f5
BLAKE2b-256 dab629ca57c39f5cbd3fc5e1c13ec24633db591d36408dc71472221eaefc710a

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 809fe1851213bebb578af826e006e4462a24b51307a97783eae3ad7a1eebc97a
MD5 7ba874617abff126f0e02605e74ef4c8
BLAKE2b-256 d5e8f9eaaf159e72cbcacceb741e87634690b2a54bbe84d9817afc3c555a4b96

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a24a2be4e976b71c39d7ab1c9edd0e4358d49390dc5515cce67f6c0bb1c4a0bf
MD5 e1c13ed8c596126a9ea45c0474e2391f
BLAKE2b-256 d1047cec804654b47a8c83099230144d37349db90c8de5b7d5288fe3dd400185

See more details on using hashes here.

File details

Details for the file magicsoup-1.0.5-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for magicsoup-1.0.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f6d9bd47fff39d6effd8fffdb00e55272c335a291824ea8b8e5ad60c16d7b1d4
MD5 52f55ae4732215b590a990cae3b179b5
BLAKE2b-256 49916fdaa6682370350496f974769522cc87066c86009b36667804c3bdda5b80

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page