Skip to main content

multipoles

PyPI version Python versions Build status Code coverage License

multipoles computes multipole expansions of the solutions of the Poisson equation, such as electrostatic or gravitational potentials. Instead of integrating over the whole charge or mass distribution for every point where you need the potential, you compute a few multipole moments once and evaluate the expansion cheaply anywhere outside (or, for the interior expansion, inside) the distribution.

Documentation · Changelog

Features

  • Point charges, or charge densities on evenly or unevenly spaced grids
  • Exterior and interior expansions, about the center of charge or any point you choose
  • The potential, the field E = -∇Φ and the Hessian, computed analytically, at single points or for whole arrays
  • Potential and field on the grid, e.g. boundary values for Poisson solvers
  • Error bounds, and l_max='auto' to reach a given accuracy
  • Spherical moments in several conventions, and cartesian moments of any order
  • Moving, adding and scaling expansions; saving and loading them
  • Electrostatics in Gaussian or SI units, and gravity
  • Warnings when you evaluate the expansion where it does not converge

Installation

pip install --upgrade multipoles

multipoles only needs NumPy. For plotting, install it with pip install multipoles[plot].

Quickstart

Two point charges +1 and -1 on the z-axis:

from multipoles import MultipoleExpansion

Phi = MultipoleExpansion.from_charges(q=[1, -1], xyz=[(0, 0, 1), (0, 0, -1)], l_max=8)

Phi(0, 0, 10)            # 0.0202020199..., exact: 1/9 - 1/11 = 0.0202020202...
Phi(0, 0, 10, l_max=1)   # 0.02, only monopole and dipole
Phi.field(0, 0, 10)      # [0, 0, 0.004081], the field E = -∇Φ
Phi.error_bound(0, 0, 10)  # 2.2e-10, an upper bound of the truncation error
Phi.dipole_moment        # [0, 0, 2]

A charge density on a grid, with l_max chosen for a relative accuracy of 1e-6 on the boundary of the grid:

import numpy as np

x = y = z = np.linspace(-10, 10, 101)
X, Y, Z = np.meshgrid(x, y, z, indexing='ij', sparse=True)
rho = np.exp(-(X**2 + Y**2 + (Z - 1)**2)) - np.exp(-(X**2 + Y**2 + (Z + 1)**2))

Phi = MultipoleExpansion.from_density(rho, (x, y, z), l_max='auto')
boundary = Phi.boundary_values()   # the potential on the boundary of the grid

For the interior expansion, units and gravity, moments, and more, see the usage guide.

Units

multipoles computes Φ = Σ q / r, i.e. the potential in Gaussian units. Pass prefactor='SI' for the electrostatic potential in SI units, or pass masses as charges and prefactor='gravity' for the gravitational potential.

Contributing

Bug reports, ideas and pull requests are welcome, see CONTRIBUTING.md.

Metadata

Release files for multipoles 0.6.0

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

Source distribution (sdist)

Source distribution for multipoles 0.6.0
File Size Uploaded Provenance Actions
multipoles-0.6.0.tar.gz 44.1 kB With provenance Details for multipoles-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for multipoles 0.6.0
File Interpreter ABI Platform Actions
multipoles-0.6.0-py3-none-any.whl Python 3 none any Details for multipoles-0.6.0-py3-none-any.whl

Total release size: 72.8 kB

Release files / multipoles-0.6.0.tar.gz

Download URL multipoles-0.6.0.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c2d5c35158953f9f2d639608444f616e724854110fb5ad19452806d52d4e0d32
BLAKE2b-256 checksum
How to use checksums
28bef481507b2eac1e049e33751eceb51b6cad869224fea74410da9583c6a6c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / multipoles-0.6.0-py3-none-any.whl

Download URL multipoles-0.6.0-py3-none-any.whl
Size 28.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffb415978bdfd67999ecff88611bf798849affb7dc50084f97f28b4c6935b1e9
BLAKE2b-256 checksum
How to use checksums
c046225c57647943de4786acf000f8e888c3c355844e15d24391c91f35ae8c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for multipoles 0.6.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for multipoles-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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.

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