from_equation¶

gala.potential.potential.
from_equation
(expr, vars, pars, name=None, hessian=False)[source]¶ Create a potential class from an expression for the potential.
Note
This utility requires having Sympy installed.
Warning
These potentials are not pickleable and cannot be written out to YAML files (using
save()
)Parameters:  expr :
sympy.core.expr.Expr
, str Either a
Sympy
expression, or a string that can be converted to aSympy
expression. vars : iterable
An iterable of variable names in the expression.
 pars : iterable
An iterable of parameter names in the expression.
 name : str (optional)
The name of the potential class returned.
 hessian : bool (optional)
Generate a function to compute the Hessian.
Returns:  CustomPotential :
PotentialBase
A potential class that represents the input equation. To instantiate the potential, use just like a normal class with parameters.
Examples
Here we’ll create a potential class for the harmonic oscillator potential, \(\Phi(x) = \frac{1}{2}\,k\,x^2\):
>>> Potential = from_equation("1/2*k*x**2", vars="x", pars="k", ... name='HarmonicOscillator') >>> p1 = Potential(k=1.) >>> p1 <HarmonicOscillatorPotential: k=1.00 (dimensionless)>
The potential class (and object) is a fullyfledged subclass of
PotentialBase
and therefore has many useful methods. For example, to integrate an orbit:>>> orbit = p1.integrate_orbit([1.,0], dt=0.01, n_steps=1000)
 expr :