8000 update release branch by hechtprojects · Pull Request #111 · amepproject/amep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

update release branch #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 9, 2025
8 changes: 4 additions & 4 deletions amep/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ def radius_of_gyration(

Notes:
------
For a cluster composed of $n$ particles of masses $m_i, i=1,2, \ldots, n$,
located at fixed distances $s_i$ from the centre of mass, the radius of gyration is
the square-root of the mass average of $s_i^2$ over all mass elements, i.e.,
$R_g=\left(\sum_{i=1}^n m_i s_i^2 / \sum_{i=1}^n m_i\right)^{1 / 2}$
For a cluster composed of :math:`n` particles of masses :math:`m_i, i=1,2, \ldots, n`,
located at fixed distances :math:`s_i` from the centre of mass, the radius of gyration is
the square-root of the mass average of :math:`s_i^2` over all mass elements, i.e.,
:math:`R_g=\left(\sum_{i=1}^n m_i s_i^2 / \sum_{i=1}^n m_i\right)^{1 / 2}`.

Parameters:
-----------
Expand Down
2 changes: 1 addition & 1 deletion amep/continuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def sf2d(
.. math::
S(\vec{q}) = <\rho(\vec{q})\rho(\vec{-q})>= <|\rho(\vec{q})|^2>,

where $\rho(\vec{q})$ is the Fourier transform of the particle number
where :math:`\rho(\vec{q})` is the Fourier transform of the particle number
density (see Ref. [1]_ [2]_ [3]_ for further information).

.. [1] Hansen, J.-P., & McDonald, I. R. (2006). Theory of Simple Liquids
Expand Down
4 changes: 2 additions & 2 deletions amep/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ def __init__(
S_{2D}(q) = \frac{1}{N}\left\langle\sum_{m,l=1}^N J_0(qr_{ml}\right\rangle

with :math:`r_{ml}=|\vec{r}_m-\vec{r}_l|` and the Bessel function
of the first kind $J_0(x)$.
of the first kind :math:`J_0(x)`.
See also Ref. [1]_ for further information on the
static structure factor.

Expand Down Expand Up @@ -1715,7 +1715,7 @@ def __init__(
.. math::
C_{\vec{k}_0}(r) = <\exp(i\vec{k}_0\cdot (\vec{r}_j-\vec{r}_l))>

with $r=|\vec{r}_j-\vec{r}_l|$ (see Ref. [1]_ for further information).
with :math:`r=|\vec{r}_j-\vec{r}_l|` (see Ref. [1]_ for further information).
As shown in Ref. [2]_, this can be rewritten as

.. math::
Expand Down
4 changes: 2 additions & 2 deletions amep/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,8 @@ def psi_k(
\Psi_k(\vec{r}_j) = \frac{1}{k} \sum_{n=1}^k\exp(ik\theta_{jn}),

where the sum goes over the k nearest neighbors of the particle at
position $\vec{r}_j$. The value of $\theta_{jn}$ is equal to the angle
between the connection line from $\vec{r}_j$ to $\vec{r}_n$ and the
position :math:`\vec{r}_j`. The value of :math:`\theta_{jn}` is equal to the angle
between the connection line from :math:`\vec{r}_j` to :math:`\vec{r}_n` and the
x axis. See also Refs. [1]_ [2]_ [3]_ for further information.

References:
Expand Down
57 changes: 55 additions & 2 deletions amep/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# =============================================================================
# Copyright (C) 2023-2024 Lukas Hecht and the AMEP development team.
# Copyright (C) 2023-2025 Lukas Hecht and the AMEP development team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,7 +45,7 @@
from scipy.spatial import Voronoi, voronoi_plot_2d
from matplotlib.ticker import MultipleLocator
from matplotlib.ticker import NullFormatter
from matplotlib.patches import Rectangle, FancyBboxPatch, ConnectionPatch, Circle
from matplotlib.patches import Rectangle, FancyBboxPatch, ConnectionPatch, Circle, FancyArrow
from matplotlib.collections import LineCollection, PatchCollection
from matplotlib.colors import to_rgba, ListedColormap
from matplotlib.animation import FuncAnimation
Expand Down Expand Up @@ -1885,3 +1885,56 @@ def voronoi(axs: mpl.axes.Axes, vor: Voronoi, **kwargs):
else:
raise Exception("amep.plot.voronoi: Cannot plot 3d data.")
plt.show()

def draw_arrow(fig, x: float, y: float, dx: float, dy: float, **kwargs):
r"""Draws an arrow on a Matplotlib figure.

This function uses the `FancyArrow` class to draw an arrow on a Matplotlib
figure at a specified position, with a given displacement. The arrow is
added directly to the figure object.

Parameters
----------
fig : matplotlib.figure.Figure
The Matplotlib figure object on which the arrow will be drawn.
x : float
The starting x-coordinate of the arrow, in figure coordinates (0 to 1).
y : float
The starting y-coordinate of the arrow, in figure coordinates (0 to 1).
dx : float
The horizontal displacement (change in x) of the arrow, in figure coordinates.
dy : float
The vertical displacement (change in y) of the arrow, in figure coordinates.
**kwargs
Additional keyword arguments passed to `matplotlib.patches.FancyArrow`,
such as `color`, `width`, `head_width`, and `head_length`.

Returns
-------
None.

Notes
-----
The arrow's position and size are specified in figure coordinates. Figure
coordinates range from 0 to 1, where (0, 0) represents the bottom-left
corner and (1, 1) represents the top-right corner of the figure.

Examples
--------
>>> fig, axs = amep.plot.new(figsize=(3, 3))
>>> x=0.2
>>> y=0.2
>>> dx=0.5
>>> dy=0.5
>>> amep.plot.draw_arrow(
... fig, x, y, dx, dy, color="blue", alpha=0.8, width=0.05,
... head_width=0.1, head_length=0.03
... )
>>>

"""
arrow = FancyArrow(
x, y, dx, dy, transform=fig.transFigure,
length_includes_head=True, **kwargs
)
fig.add_artist(arrow)
10 changes: 7 additions & 3 deletions amep/spatialcor.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def spatialcor(
The spatial correlation function is defined by the following equation
in which f can be a complex-valued scalar or vector:

..math::
.. math::
C(r) = <f(r)*f(0)> / <f(0)^2>.

Parameters
Expand Down Expand Up @@ -1379,7 +1379,11 @@ def sfiso(
where :math:`N` is the number of particles [1]_.

Mode 'fft' only works in 2D!!!


The minimum wave vector is fixed to :math:`2\pi/L`, where :math:`L` is the
box length.


References
----------

Expand Down Expand Up @@ -1635,7 +1639,7 @@ def sf2d(
S(\vec{q}) = \frac{1}{N} \left\langle\sum_{j=1}^{N}\sum_{k=1}^{N}\exp\left\lbrace-i\vec{q}\cdot(\vec{r}_j-\vec{r}_k)\right\rbrace\right\rangle\\
= \frac{1}{N} \left\langle\sum_{j=1}^{N}\left\lvert\exp\left\lbrace-i\vec{q}\cdot\vec{r}_j\right\rbrace\right\rvert^2\right\rangle,

where $\rho(\vec{q})$ is the Fourier transform of the particle number
where :math:`\rho(\vec{q})` is the Fourier transform of the particle number
density (see Ref. [1]_ for further information).

S(0,0) is set to 0
Expand Down
2 changes: 1 addition & 1 deletion amep/timecor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def isf(start, frame, k):

F_{\text{s}}(k,t)=\frac{1}{N}\left\langle\sum_{j=1}^{N}\frac{\sin\left(k\cdot\left|\vec{r}_j\left(t_0+t\right)-\vec{r}_j\left(t_0\right)\right|\right)}{k\cdot\left|\vec{r}_j\left(t_0+t\right)-\vec{r}_j\left(t_0\right)\right|}\right\rangle_{t_0}.

that can be obtained via taking the mean over all directions of $\vec{k}$.
that can be obtained via taking the mean over all directions of :math:`\vec{k}`.
A detailed derivation can be found in Ref. [1]_.

References
Expand Down
4 changes: 3 additions & 1 deletion amep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,8 @@ def domain_length(

L(t) = 2\pi\frac{\int_{q_{\rm min}}^{q_{\rm max}}{\rm d}q\,S(q,t)}{\int_{q_{\rm min}}^{q_{\rm max}}{\rm d}q\,qS(q,t)}

and has been used in Refs. [1]_ [2]_ [3]_ [4]_ for example.
where :math:`q=n \frac{2\pi}{L}` with :math:`n\in \mathbb{N}` and box legth :math:`L`.
It has been used in Refs. [1]_ [2]_ [3]_ [4]_ for example.

References
----------
Expand Down Expand Up @@ -1356,6 +1357,7 @@ def domain_length(
l: float
Domain length as inverse expectation value of q.


Examples
--------
>>> import amep
Expand Down
16 changes: 15 additions & 1 deletion test/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# =============================================================================
# Copyright (C) 2023-2024 Lukas Hecht and the AMEP development team.
# Copyright (C) 2023-2025 Lukas Hecht and the AMEP development team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -69,6 +69,20 @@ def test_set_locators(self):
plot.set_locators(axe)
fig.savefig(PLOT_DIR/"test_locators.pdf")
close(fig2)

def test_draw_arrow(self):
"""Test the amep.plot.draw_arrow method"""
fig, axs = plot.new(figsize=(3,3))
x = 0.2
y = 0.2
dx = 0.5
dy = 0.5
plot.draw_arrow(
fig, x, y, dx, dy, color="blue", alpha=0.8, width=0.05,
head_width=0.1, head_length=0.03
)
fig.savefig(PLOT_DIR/"test_draw_arrow.pdf")
close(fig)

def test_format_axis(self):
"""Testing the format axis function"""
Expand Down
0