ewald


Nameewald JSON
Version 0.1.6 PyPI version JSON
download
home_pageNone
SummaryEwald SPME force calculations
upload_time2025-09-12 22:33:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords ewald spme molecular dynamics pme force field
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Runs the Smooth Particle Ewald Mesh (SPME) algorithm for n-body simulations with periodic boundary conditions

[![Crate](https://img.shields.io/crates/v/ewald.svg)](https://crates.io/crates/ewald)
[![Docs](https://docs.rs/ewald/badge.svg)](https://docs.rs/ewald)
[![PyPI](https://img.shields.io/pypi/v/ewald.svg)](https://pypi.org/project/ewald)

[//]: # ([![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.15616833.svg)](https://doi.org/10.5281/zenodo.15616833))

[Original paper describing the SPME method](https://biomolmd.org/mw/images/e/e0/Spme.pdf)

This library is for Python and Rust.

This has applications primarily in structural biology. For example, molecular dynamics. Compared to other
n-body approximations for long-range forces, this has utility when periodic bounday conditions are used.
If not using these, for example in cosmology simulations, consider Barnes Hut, or Fast Multipole Methods (FMM)
instead.

Uses Rayon to parallelize as thread pools. Support for SIMD (256-bit and 512-bit), and CUDA (via CUDARC) are planned. For now, you may wish to write
custom GPU kernels, using this lib as a reference.

WIP code for using the SPME/recip interaction on GPU.

Used by the [Daedalus protein viewer and molecular dynamics program](https://github.com/david-oconnor/daedalus).

Here's an example of use. The Python API is equivalent.

```rust
use rayon::prelude::*;
use ewald::{force_coulomb_ewald_real, force_coulomb_ewald_real};

const LONG_RANGE_CUTOFF: f64 = 10.0;

// A bigger α means more damping, and a smaller real-space contribution. (Cheaper real), but larger
// reciprocal load.
const EWALD_ALPHA: f64 = 0.35; // Å^-1. 0.35 is good for cutoff = 10.

impl System {
    // Primary application:
    fn apply_forces(&self) {
        pairs
            .par_iter()
            .map(|(i_0, i_1)| {
                let atom_0 = &self.atoms[i_0];
                let atom_1 = &self.atoms[i_1];
                let diff = atom_1.pos - atom_0.pos;
                let r = diff.magnitude();
                let dir = diff / r;

                let mut f = Vec3::zero();

                let (f, energy) = force_coulomb_short_range(
                    dir,
                    r,
                    // We include 1/r as it's likely shared between this and Lennard Jones;
                    // improves efficiency.
                    1./r,
                    atom_0.charge,
                    atom_1.charge,
                    // e.g. (8Å, 10Å)
                    LONG_RANGE_CUTOFF,
                    ALPHA,
                );

                atom_0.force += f;
                atom_1.force -= f;
            });

        let (recip_forces_per_atom, energy_recip) = self.pme_recip.forces(&atom_posits, &[atom_charges]);
    }

    /// Run this at init, and whenever you update the sim box.
    pub fn regen_pme(&mut self) {
        self.pme_recip = PmeRecip::new((SPME_N, SPME_N, SPME_N), self.cell.extent, EWALD_ALPHA);
    }
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ewald",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ewald, spme, molecular dynamics, pme, force field",
    "author": null,
    "author_email": "David O'Connor <the_alchemist@fastmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/99/cb/cbad8ce41ad816e9b531534a99a89c7456ce354f498ba3fed091ed289ef8/ewald-0.1.6.tar.gz",
    "platform": null,
    "description": "# Runs the Smooth Particle Ewald Mesh (SPME) algorithm for n-body simulations with periodic boundary conditions\n\n[![Crate](https://img.shields.io/crates/v/ewald.svg)](https://crates.io/crates/ewald)\n[![Docs](https://docs.rs/ewald/badge.svg)](https://docs.rs/ewald)\n[![PyPI](https://img.shields.io/pypi/v/ewald.svg)](https://pypi.org/project/ewald)\n\n[//]: # ([![DOI]&#40;https://zenodo.org/badge/DOI/10.5281/zenodo.15616833.svg&#41;]&#40;https://doi.org/10.5281/zenodo.15616833&#41;)\n\n[Original paper describing the SPME method](https://biomolmd.org/mw/images/e/e0/Spme.pdf)\n\nThis library is for Python and Rust.\n\nThis has applications primarily in structural biology. For example, molecular dynamics. Compared to other\nn-body approximations for long-range forces, this has utility when periodic bounday conditions are used.\nIf not using these, for example in cosmology simulations, consider Barnes Hut, or Fast Multipole Methods (FMM)\ninstead.\n\nUses Rayon to parallelize as thread pools. Support for SIMD (256-bit and 512-bit), and CUDA (via CUDARC) are planned. For now, you may wish to write\ncustom GPU kernels, using this lib as a reference.\n\nWIP code for using the SPME/recip interaction on GPU.\n\nUsed by the [Daedalus protein viewer and molecular dynamics program](https://github.com/david-oconnor/daedalus).\n\nHere's an example of use. The Python API is equivalent.\n\n```rust\nuse rayon::prelude::*;\nuse ewald::{force_coulomb_ewald_real, force_coulomb_ewald_real};\n\nconst LONG_RANGE_CUTOFF: f64 = 10.0;\n\n// A bigger \u03b1 means more damping, and a smaller real-space contribution. (Cheaper real), but larger\n// reciprocal load.\nconst EWALD_ALPHA: f64 = 0.35; // \u00c5^-1. 0.35 is good for cutoff = 10.\n\nimpl System {\n    // Primary application:\n    fn apply_forces(&self) {\n        pairs\n            .par_iter()\n            .map(|(i_0, i_1)| {\n                let atom_0 = &self.atoms[i_0];\n                let atom_1 = &self.atoms[i_1];\n                let diff = atom_1.pos - atom_0.pos;\n                let r = diff.magnitude();\n                let dir = diff / r;\n\n                let mut f = Vec3::zero();\n\n                let (f, energy) = force_coulomb_short_range(\n                    dir,\n                    r,\n                    // We include 1/r as it's likely shared between this and Lennard Jones;\n                    // improves efficiency.\n                    1./r,\n                    atom_0.charge,\n                    atom_1.charge,\n                    // e.g. (8\u00c5, 10\u00c5)\n                    LONG_RANGE_CUTOFF,\n                    ALPHA,\n                );\n\n                atom_0.force += f;\n                atom_1.force -= f;\n            });\n\n        let (recip_forces_per_atom, energy_recip) = self.pme_recip.forces(&atom_posits, &[atom_charges]);\n    }\n\n    /// Run this at init, and whenever you update the sim box.\n    pub fn regen_pme(&mut self) {\n        self.pme_recip = PmeRecip::new((SPME_N, SPME_N, SPME_N), self.cell.extent, EWALD_ALPHA);\n    }\n}\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Ewald SPME force calculations",
    "version": "0.1.6",
    "project_urls": {
        "documentation": "https://docs.rs/ewald",
        "homepage": "https://github.com/David-OConnor/ewald",
        "repository": "https://github.com/David-OConnor/ewald"
    },
    "split_keywords": [
        "ewald",
        " spme",
        " molecular dynamics",
        " pme",
        " force field"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e3590f0a51b3e709d9bacbf8e7b048603084bb896b189ce5dd4db7055a47809c",
                "md5": "5b270b86eaae633185b97995c35ed339",
                "sha256": "85b8731b95a1663933335575149c0276bc8bc6ab3a0ee0d7c9427a26c61cb491"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "5b270b86eaae633185b97995c35ed339",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 666480,
            "upload_time": "2025-09-12T22:33:39",
            "upload_time_iso_8601": "2025-09-12T22:33:39.715996Z",
            "url": "https://files.pythonhosted.org/packages/e3/59/0f0a51b3e709d9bacbf8e7b048603084bb896b189ce5dd4db7055a47809c/ewald-0.1.6-cp310-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4ad1bf204fe5a3efbd70837d8fa39f14237028a4f400ffae961d5da0d9b09b44",
                "md5": "549885a84c8ad9e0311d16b22533af14",
                "sha256": "abb8cc41669e7c0924cd647ab26a959d466bf8c374836e09573a58a75b871fcc"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "549885a84c8ad9e0311d16b22533af14",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 516757,
            "upload_time": "2025-09-12T22:33:41",
            "upload_time_iso_8601": "2025-09-12T22:33:41.542676Z",
            "url": "https://files.pythonhosted.org/packages/4a/d1/bf204fe5a3efbd70837d8fa39f14237028a4f400ffae961d5da0d9b09b44/ewald-0.1.6-cp310-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0123460464954912f663513a1ad4c78b3b606f5b3634505a30d0d2f1b576e12a",
                "md5": "132c1748e1f46ccd2d795ba79b23fef4",
                "sha256": "0667340060747db4ed51e44ad1d051f8584f009faaafee2b6174831c81f15571"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "132c1748e1f46ccd2d795ba79b23fef4",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 583791,
            "upload_time": "2025-09-12T22:33:42",
            "upload_time_iso_8601": "2025-09-12T22:33:42.601591Z",
            "url": "https://files.pythonhosted.org/packages/01/23/460464954912f663513a1ad4c78b3b606f5b3634505a30d0d2f1b576e12a/ewald-0.1.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b3cc6859d730fe59fc76b367c9c8546b29edb4ef1acb0d3507e3cdc0904964ba",
                "md5": "8b87862b73f5e01d9739c2b5e5abf68e",
                "sha256": "dcf48a98ac9594c2791f9ea28f1f75751445a3bf4a5184bc9f79ada7aad48517"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl",
            "has_sig": false,
            "md5_digest": "8b87862b73f5e01d9739c2b5e5abf68e",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 484305,
            "upload_time": "2025-09-12T22:33:44",
            "upload_time_iso_8601": "2025-09-12T22:33:44.190747Z",
            "url": "https://files.pythonhosted.org/packages/b3/cc/6859d730fe59fc76b367c9c8546b29edb4ef1acb0d3507e3cdc0904964ba/ewald-0.1.6-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "109eca937cc3b582fe943b4aab80524ab5a98a65dcf9d396b720f3526df4206c",
                "md5": "5877151c1c1a2a03f000245aab71500e",
                "sha256": "89f314cfe3ab5d449997ce0283c10b8b9ca72eb4e453183a922c38d43ea7521a"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
            "has_sig": false,
            "md5_digest": "5877151c1c1a2a03f000245aab71500e",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 688702,
            "upload_time": "2025-09-12T22:33:45",
            "upload_time_iso_8601": "2025-09-12T22:33:45.755141Z",
            "url": "https://files.pythonhosted.org/packages/10/9e/ca937cc3b582fe943b4aab80524ab5a98a65dcf9d396b720f3526df4206c/ewald-0.1.6-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e11d1ac33c63cdc0ed05a3bf4685d0792dcf06f134eaadf27f68e89767abd3a5",
                "md5": "3093df2785bc3d4559a433c852b26e23",
                "sha256": "14bfcb5e9a8dc4c755fd997e34d431b9c6a8720c68839119941b6749d28a0c45"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl",
            "has_sig": false,
            "md5_digest": "3093df2785bc3d4559a433c852b26e23",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 538250,
            "upload_time": "2025-09-12T22:33:47",
            "upload_time_iso_8601": "2025-09-12T22:33:47.662847Z",
            "url": "https://files.pythonhosted.org/packages/e1/1d/1ac33c63cdc0ed05a3bf4685d0792dcf06f134eaadf27f68e89767abd3a5/ewald-0.1.6-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "40587d8123ac24b5771c2e16f1165bbbf1599ca4c0005b2c7ee31d4d9be855eb",
                "md5": "5f1b715cdc15850e277d1d6af2c912f1",
                "sha256": "dea63da11b47679fec045109b8e147699775a71092e508744d9d76a41072ace0"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "5f1b715cdc15850e277d1d6af2c912f1",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 744361,
            "upload_time": "2025-09-12T22:33:49",
            "upload_time_iso_8601": "2025-09-12T22:33:49.247607Z",
            "url": "https://files.pythonhosted.org/packages/40/58/7d8123ac24b5771c2e16f1165bbbf1599ca4c0005b2c7ee31d4d9be855eb/ewald-0.1.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f6fd737a92ffda71a385bc1c3165b58e1beb14b87b9e57fec195766fb2f736dd",
                "md5": "db069b118780ecbcd18a0690c8c0454b",
                "sha256": "1c2415684025d3c8f4fecf81c7624778a08d951e2812cea9af31a2a138d5786e"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-musllinux_1_2_aarch64.whl",
            "has_sig": false,
            "md5_digest": "db069b118780ecbcd18a0690c8c0454b",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 762489,
            "upload_time": "2025-09-12T22:33:50",
            "upload_time_iso_8601": "2025-09-12T22:33:50.358497Z",
            "url": "https://files.pythonhosted.org/packages/f6/fd/737a92ffda71a385bc1c3165b58e1beb14b87b9e57fec195766fb2f736dd/ewald-0.1.6-cp310-abi3-musllinux_1_2_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ec38f7e30e715ae9f4683b806f7f893727e32ce4019dbf104bd9cba7e248a5a3",
                "md5": "c1207175a28bd67d028d928f521a1733",
                "sha256": "76b0aa14df893a33ae1a7008b8815b63249b9c90f55663374677007a979d1f77"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-musllinux_1_2_armv7l.whl",
            "has_sig": false,
            "md5_digest": "c1207175a28bd67d028d928f521a1733",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 748029,
            "upload_time": "2025-09-12T22:33:51",
            "upload_time_iso_8601": "2025-09-12T22:33:51.868702Z",
            "url": "https://files.pythonhosted.org/packages/ec/38/f7e30e715ae9f4683b806f7f893727e32ce4019dbf104bd9cba7e248a5a3/ewald-0.1.6-cp310-abi3-musllinux_1_2_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8d92a70e49f93ea001b2de21d33cc653433e0836b672e453239f8ed1897c85c7",
                "md5": "a046dada53c53bcb5a40e587162a652a",
                "sha256": "163e5c4a288e4e6ad145af356e61e55a777c434f653c43e9029a631937037258"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-musllinux_1_2_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a046dada53c53bcb5a40e587162a652a",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 914741,
            "upload_time": "2025-09-12T22:33:53",
            "upload_time_iso_8601": "2025-09-12T22:33:53.021829Z",
            "url": "https://files.pythonhosted.org/packages/8d/92/a70e49f93ea001b2de21d33cc653433e0836b672e453239f8ed1897c85c7/ewald-0.1.6-cp310-abi3-musllinux_1_2_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "420a45960ed4dc098847c7cac6e0ad8b8677a7fb72138d98d9bc10c82b582ac9",
                "md5": "eeeb83ec1d40f7d713b72c86b43c61af",
                "sha256": "022f3e98531cdc87dcf84aa633d2291569771a99ff56dd05285e3632191daf2e"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6-cp310-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "eeeb83ec1d40f7d713b72c86b43c61af",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.10",
            "size": 531775,
            "upload_time": "2025-09-12T22:33:54",
            "upload_time_iso_8601": "2025-09-12T22:33:54.180752Z",
            "url": "https://files.pythonhosted.org/packages/42/0a/45960ed4dc098847c7cac6e0ad8b8677a7fb72138d98d9bc10c82b582ac9/ewald-0.1.6-cp310-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "99cbcbad8ce41ad816e9b531534a99a89c7456ce354f498ba3fed091ed289ef8",
                "md5": "780a517b3c2368276c9945396e9b86b5",
                "sha256": "2d595cc1be3df313d707ea609ab7be41fc92a2767d92e86636f234d867e427df"
            },
            "downloads": -1,
            "filename": "ewald-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "780a517b3c2368276c9945396e9b86b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 20904,
            "upload_time": "2025-09-12T22:33:55",
            "upload_time_iso_8601": "2025-09-12T22:33:55.659800Z",
            "url": "https://files.pythonhosted.org/packages/99/cb/cbad8ce41ad816e9b531534a99a89c7456ce354f498ba3fed091ed289ef8/ewald-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-12 22:33:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "David-OConnor",
    "github_project": "ewald",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ewald"
}
        
Elapsed time: 0.50945s