Skip to content

Commit

Permalink
Inline equations fix (#947)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael F. Herbst <[email protected]>
  • Loading branch information
epolack and mfherbst authored Jan 24, 2024
1 parent 4250c8a commit c92b59a
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Random = "1"
Roots = "2"
SparseArrays = "1"
SpecialFunctions = "2"
Spglib = "0.9"
Spglib = "0.9 - 0.9.2"
StaticArrays = "1"
Statistics = "1"
TimerOutputs = "0.5.12"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
wannier90_jll = "c5400fa0-8d08-52c2-913f-1e3f656c1ce9"

[compat]
Documenter = "~1.1"
Documenter = "~1.2"
5 changes: 4 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ end
remote_args = CONTINUOUS_INTEGRATION ? (; ) : (; remotes=nothing)
mathengine = Documenter.MathJax3(Dict(
:tex => Dict(
:macros => Dict(
:inlineMath => [["\$","\$"], ["\\(","\\)"]],
:tags => "ams",
:packages => ["base", "ams", "autoload", "configmacros"],
:macros => Dict(
:abs => [raw"\left\|#1\right\|", 1],
:ket => [raw"\left|#1\right\rangle", 1],
:bra => [raw"\left\langle#1\right|", 1],
Expand Down
4 changes: 2 additions & 2 deletions docs/src/developer/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ to simplify typing them.
## Units
In DFTK, atomic units are used throughout, most importantly
lengths are in Bohr and energies in Hartree.
See [wikipedia](https://en.wikipedia.org/wiki/Hartree_atomic_units)
See [Wikipedia](https://en.wikipedia.org/wiki/Hartree_atomic_units)
for a list of conversion factors. Appropriate unit conversion can
can be performed using the `Unitful` and `UnitfulAtomic` packages:

Expand Down Expand Up @@ -88,7 +88,7 @@ We use the convention that the unit cell in real space is
``[0, 1)^3`` in reduced coordinates and the unit cell in reciprocal
space (the reducible Brillouin zone) is ``[-1/2, 1/2)^3``.

## Reduced and cartesian coordinates
## Reduced and Cartesian coordinates
Unless denoted otherwise the code uses **reduced coordinates**
for reciprocal-space vectors such as ``k``, ``G``, ``q``, ``p``
or real-space vectors like ``r`` and ``R``
Expand Down
2 changes: 1 addition & 1 deletion examples/geometry_optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ atoms = [H, H];

# First, we create a function that computes the solution associated to the
# position ``x ∈ ℝ^6`` of the atoms in reduced coordinates
# (cf. [Reduced and cartesian coordinates](@ref) for more
# (cf. [Reduced and Cartesian coordinates](@ref) for more
# details on the coordinates system).
# They are stored as a vector: `x[1:3]` represents the position of the
# first atom and `x[4:6]` the position of the second.
Expand Down
2 changes: 1 addition & 1 deletion examples/gross_pitaevskii.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ lattice = a .* [[1 0 0.]; [0 0 0]; [0 0 0]];
#
# For the potential term `V` we pick a harmonic
# potential. We use the function `ExternalFromReal` which uses
# cartesian coordinates ( see [Lattices and lattice vectors](@ref conventions-lattice)).
# Cartesian coordinates ( see [Lattices and lattice vectors](@ref conventions-lattice)).
pot(x) = (x - a/2)^2;

# We setup each energy term in sequence: kinetic, potential and nonlinear term.
Expand Down
4 changes: 2 additions & 2 deletions src/Model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Model{T <: Real, VT <: Real}
recip_lattice::Mat3{T}
# Dimension of the system; 3 unless `lattice` has zero columns
n_dim::Int
# Useful for conversions between cartesian and reduced coordinates
# Useful for conversions between Cartesian and reduced coordinates
inv_lattice::Mat3{T}
inv_recip_lattice::Mat3{T}
# Volumes
Expand Down Expand Up @@ -345,7 +345,7 @@ Beware that some quantities (e.g., the force constant matrix) map vectors to cov
are therefore not matrices nor comatrices; they fall outside of these methods.
Consider two covectors f and g related by a transformation matrix B. In reduced
coordinates g_red = B_red f_red and in cartesian coordinates we want g_cart = B_cart f_cart.
coordinates g_red = B_red f_red and in Cartesian coordinates we want g_cart = B_cart f_cart.
From g_cart = L⁻ᵀ g_red = L⁻ᵀ B_red f_red = L⁻ᵀ B_red Lᵀ f_cart, we see B_cart = L⁻ᵀ B_red Lᵀ.
Similarly for two vectors r and s with s_red = A_red r_red and s_cart = A_cart r_cart:
Expand Down
6 changes: 3 additions & 3 deletions src/PlaneWaveBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ G_vectors(::PlaneWaveBasis, kpt::Kpoint) = kpt.G_vectors
G_vectors_cart(basis::PlaneWaveBasis)
G_vectors_cart(basis::PlaneWaveBasis, kpt::Kpoint)
The list of ``G`` vectors of a given `basis` or `kpt`, in cartesian coordinates.
The list of ``G`` vectors of a given `basis` or `kpt`, in Cartesian coordinates.
"""
function G_vectors_cart(basis::PlaneWaveBasis)
map(recip_vector_red_to_cart(basis.model), G_vectors(basis))
Expand All @@ -451,7 +451,7 @@ end
@doc raw"""
Gplusk_vectors_cart(basis::PlaneWaveBasis, kpt::Kpoint)
The list of ``G + k`` vectors, in cartesian coordinates.
The list of ``G + k`` vectors, in Cartesian coordinates.
"""
function Gplusk_vectors_cart(basis::PlaneWaveBasis, kpt::Kpoint)
map(recip_vector_red_to_cart(basis.model), Gplusk_vectors(basis, kpt))
Expand All @@ -467,7 +467,7 @@ r_vectors(basis::PlaneWaveBasis) = basis.r_vectors
@doc raw"""
r_vectors_cart(basis::PlaneWaveBasis)
The list of ``r`` vectors, in cartesian coordinates.
The list of ``r`` vectors, in Cartesian coordinates.
"""
r_vectors_cart(basis::PlaneWaveBasis) = map(vector_red_to_cart(basis.model), r_vectors(basis))

Expand Down
2 changes: 1 addition & 1 deletion src/bzmesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end
@doc raw"""
Build a [`MonkhorstPack`](@ref) grid to ensure kpoints are at most this spacing
apart (in inverse Bohrs). A reasonable spacing is `0.13` inverse Bohrs
(around ``2π * 0.04 \AA^{-1}``).
(around ``2π * 0.04 \, \text{Å}^{-1}``).
"""
function kgrid_from_maximal_spacing(lattice, spacing; kshift=[0, 0, 0])
lattice = austrip.(lattice)
Expand Down
6 changes: 3 additions & 3 deletions src/common/spherical_bessels.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
sphericalbesselj_fast(l::Integer, x::Number)
Returns the spherical Bessel function of the first kind j_l(x). Consistent with
[wikipedia](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions) and
with `SpecialFunctions.sphericalbesselj`. Specialized for integer `0 <= l <= 5`.
Returns the spherical Bessel function of the first kind ``j_l(x)``. Consistent with
[Wikipedia](https://en.wikipedia.org/wiki/Bessel_function#Spherical_Bessel_functions) and
with `SpecialFunctions.sphericalbesselj`. Specialized for integer ``0 ≤ l ≤ 5``.
"""
@fastmath function sphericalbesselj_fast(l::Integer, x::T)::T where {T}
if l == 0
Expand Down
4 changes: 2 additions & 2 deletions src/common/spherical_harmonics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# which should be used, once it's ready.

"""
Returns the (l,m) real spherical harmonic Y_lm(r). Consistent with
[wikipedia](https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics).
Returns the ``(l,m)`` real spherical harmonic ``Y_l^m(r)``. Consistent with
[Wikipedia](https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics).
"""
function ylm_real(l::Integer, m::Integer, rvec::AbstractVector{T}) where {T}
@assert 0 l
Expand Down
39 changes: 18 additions & 21 deletions src/input_output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ Intended to give a condensed set of useful metadata to post-processing scripts o
for storing computational results (e.g. bands, bloch waves etc.).
Some details on the conventions for the returned data:
- lattice, recip_lattice: Always a zero-padded 3x3 matrix, independent on the actual dimension
- atomic_positions, atomic_positions_cart:
Atom positions in fractional or cartesian coordinates, respectively.
- atomic_symbols: Atomic symbols if known.
- terms: Some rough information on the terms used for the computation.
- n_electrons: Number of electrons, may be missing if εF is fixed instead
- εF: Fixed Fermi level to use, may be missing if n_electronis is specified instead.
- `lattice`, `recip_lattice`: Always a zero-padded 3x3 matrix, independent on the actual dimension
- `atomic_positions`, `atomic_positions_cart`:
Atom positions in fractional or Cartesian coordinates, respectively.
- `atomic_symbols`: Atomic symbols if known.
- `terms`: Some rough information on the terms used for the computation.
- `n_electrons`: Number of electrons, may be missing if `εF` is fixed instead
- `εF`: Fixed Fermi level to use, may be missing if `n_electrons` is is specified instead.
"""
todict(model::Model) = todict!(Dict{String,Any}(), model)
function todict!(dict, model::Model)
Expand Down Expand Up @@ -138,10 +138,10 @@ the same result on all MPI processors. See also the [`todict`](@ref) function
for the `Model`, which is called from this one to merge the data of both outputs.
Some details on the conventions for the returned data:
- dvol: Volume element for real-space integration
- variational: Is the k-point specific basis (for ψ) variationally consistent
- `dvol`: Volume element for real-space integration
- `variational`: Is the k-point specific basis (for ψ) variationally consistent
with the basis for ρ.
- kweights: Weights for the k-points, summing to 1.0
- `kweights`: Weights for the k-points, summing to 1.0
"""
todict(basis::PlaneWaveBasis) = todict!(Dict{String,Any}(), basis)
function todict!(dict, basis::PlaneWaveBasis)
Expand Down Expand Up @@ -182,7 +182,7 @@ but the data may be dummy.
Some details on the conventions for the returned data:
- `εF`: Computed Fermi level (if present in band_data)
- `labels`: A mapping of high-symmetry k-Point labels to the index in
the `"kcoords"` vector of the corresponding k-Point.
the `kcoords` vector of the corresponding k-point.
- `eigenvalues`, `eigenvalues_error`, `occupation`, `residual_norms`:
`(n_bands, n_kpoints, n_spin)` arrays of the respective data.
- `n_iter`: `(n_kpoints, n_spin)` array of the number of iterations the
Expand Down Expand Up @@ -288,16 +288,13 @@ function and their outputs merged. Only the master process
returns meaningful data.
Some details on the conventions for the returned data:
- ρ: (fft_size[1], fft_size[2], fft_size[3], n_spin) array of density
on real-space grid.
- energies: Dictionary / subdirectory containing the energy terms
- converged: Has the SCF reached convergence
- norm_Δρ: Most recent change in ρ during an SCF step
- occupation_threshold: Threshold below which orbitals are considered
unoccupied
- n_bands_converge: Number of bands that have been
fully converged numerically.
- n_iter: Number of iterations.
- `ρ`: (fft_size[1], fft_size[2], fft_size[3], n_spin) array of density on real-space grid.
- `energies`: Dictionary / subdirectory containing the energy terms
- `converged`: Has the SCF reached convergence
- `norm_Δρ`: Most recent change in ρ during an SCF step
- `occupation_threshold`: Threshold below which orbitals are considered unoccupied
- `n_bands_converge`: Number of bands that have been fully converged numerically.
- `n_iter`: Number of iterations.
"""
function scfres_to_dict(scfres::NamedTuple; kwargs...)
scfres_to_dict!(Dict{String,Any}(), scfres; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/postprocess/band_structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function kpath_get_branch(kinter::KPathInterpolant{D}, ibranch::Integer) where {
end

function kdistances_and_ticks(kcoords, klabels::Dict, kbranches)
# kcoords in cartesian coordinates, klabels uses cartesian coordinates
# kcoords in Cartesian coordinates, klabels uses Cartesian coordinates
function getlabel(kcoord; tol=1e-4)
findfirst(c -> norm(c - kcoord) < tol, klabels)
end
Expand Down
4 changes: 2 additions & 2 deletions src/postprocess/forces.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This uses the `compute_forces(term, ψ, occ; kwargs...)` function defined by all terms
"""
Compute the forces of an obtained SCF solution. Returns the forces wrt. the fractional
lattice vectors. To get cartesian forces use [`compute_forces_cart`](@ref).
lattice vectors. To get Cartesian forces use [`compute_forces_cart`](@ref).
Returns a list of lists of forces (as SVector{3}) in the same order as the `atoms`
and `positions` in the underlying [`Model`](@ref).
"""
Expand All @@ -14,7 +14,7 @@ and `positions` in the underlying [`Model`](@ref).
end

"""
Compute the cartesian forces of an obtained SCF solution in Hartree / Bohr.
Compute the Cartesian forces of an obtained SCF solution in Hartree / Bohr.
Returns a list of lists of forces
`[[force for atom in positions] for (element, positions) in atoms]`
which has the same structure as the `atoms` object passed to the underlying [`Model`](@ref).
Expand Down
1 change: 1 addition & 0 deletions src/postprocess/stresses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ is given by
σ_{xx} σ_{xy} σ_{xz} \\
σ_{yx} σ_{yy} σ_{yz} \\
σ_{zx} σ_{zy} σ_{zz}
\end{array}
\right) = \frac{1}{|Ω|} \left. \frac{dE[ (I+ϵ) * L]}{dM}\right|_{ϵ=0}
```
where ``ϵ`` is the strain.
Expand Down
2 changes: 1 addition & 1 deletion src/scf/scf_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end
(conv::ScfConvergenceDensity)(info) = last(info.history_Δρ) < conv.tolerance

"""
Flag convergence on the change in cartesian force between two iterations.
Flag convergence on the change in Cartesian force between two iterations.
"""
mutable struct ScfConvergenceForce
tolerance
Expand Down
8 changes: 4 additions & 4 deletions src/symmetry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ include("external/spglib.jl")
# computations. The relationship is
# S = W'
# τ = -W^-1 w
# (valid both in reduced and cartesian coordinates). In our notation the rotation matrix
# (valid both in reduced and Cartesian coordinates). In our notation the rotation matrix
# W and translation w are such that, for each atom of type A at position a, W a + w is also
# an atom of type A.

# The full (reducible) Brillouin zone is implicitly represented by a set of (irreducible)
# kpoints (see explanation in docs). Each irreducible k-point k comes with a list of
# symmetry operations (S, τ) (containing at least the trivial operation (I, 0)), where S is
# a unitary matrix (/!\ in cartesian but not in reduced coordinates) and τ a translation
# a unitary matrix (/!\ in Cartesian but not in reduced coordinates) and τ a translation
# vector. The k-point is then used to represent implicitly the information at all the
# kpoints Sk. The relationship between the Hamiltonians is
# H_{Sk} = U H_k U*, with
Expand Down Expand Up @@ -331,7 +331,7 @@ Symmetrize a density by applying all the basis (by default) symmetries and formi
end

"""
Symmetrize the stress tensor, given as a Matrix in cartesian coordinates
Symmetrize the stress tensor, given as a Matrix in Cartesian coordinates
"""
function symmetrize_stresses(model::Model, stresses; symmetries)
# see (A.28) of https://arxiv.org/pdf/0906.2569.pdf
Expand Down Expand Up @@ -361,7 +361,7 @@ function symmetrize_forces(model::Model, forces; symmetries)
# (but careful that our symmetries are r -> Wr+w, not R(r+f))
other_at = W \ (position - w)
i_other_at = findfirst(a -> is_approx_integer(a - other_at), positions_group)
# (A.27) is in cartesian coordinates, and since Wcart is orthogonal,
# (A.27) is in Cartesian coordinates, and since Wcart is orthogonal,
# Fsymcart = Wcart * Fcart <=> Fsymred = inv(Wred') Fred
symmetrized_forces[idx] += inv(W') * forces[group[i_other_at]]
end
Expand Down
4 changes: 2 additions & 2 deletions src/terms/local.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end


"""
External potential from an analytic function `V` (in cartesian coordinates).
External potential from an analytic function `V` (in Cartesian coordinates).
No low-pass filtering is performed.
"""
struct ExternalFromReal
Expand All @@ -56,7 +56,7 @@ end

"""
External potential from the (unnormalized) Fourier coefficients `V(G)`
G is passed in cartesian coordinates
G is passed in Cartesian coordinates
"""
struct ExternalFromFourier
potential::Function
Expand Down
2 changes: 1 addition & 1 deletion src/terms/magnetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Magnetic term ``A⋅(-i∇)``. It is assumed (but not checked) that ``∇⋅A =
"""
struct Magnetic
Afunction::Function # A(x,y,z) returns [Ax,Ay,Az]
# both [x,y,z] and [Ax,Ay,Az] are in *cartesian* coordinates
# both [x,y,z] and [Ax,Ay,Az] are in *Cartesian* coordinates
end
(M::Magnetic)(basis) = TermMagnetic(basis, M.Afunction)

Expand Down
5 changes: 4 additions & 1 deletion src/terms/nonlocal.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@doc raw"""
Nonlocal term coming from norm-conserving pseudopotentials in Kleinmann-Bylander form.
``\text{Energy} = ∑_a ∑_{ij} ∑_{n} f_n \braket{ψ_n}{{\rm proj}_{ai}} D_{ij} \braket{{\rm proj}_{aj}}{ψ_n}.``
```math
\text{Energy} =
∑_a ∑_{ij} ∑_{n} f_n \braket{ψ_n}{{\rm proj}_{ai}} D_{ij} \braket{{\rm proj}_{aj}}{ψ_n}.
```
"""
struct AtomicNonlocal end
function (::AtomicNonlocal)(basis::PlaneWaveBasis{T}) where {T}
Expand Down
2 changes: 1 addition & 1 deletion src/terms/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Magnetic field operator A⋅(-i∇).
struct MagneticFieldOperator{T <: Real, AT} <: RealFourierOperator
basis::PlaneWaveBasis{T}
kpoint::Kpoint{T}
Apot::AT # Apot[α][i,j,k] is the A field in (cartesian) direction α
Apot::AT # Apot[α][i,j,k] is the A field in (Cartesian) direction α
end
function apply!(Hψ, op::MagneticFieldOperator, ψ)
# TODO this could probably be better optimized
Expand Down
2 changes: 1 addition & 1 deletion src/terms/xc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ end


"""
Compute divergence of an operand function, which returns the cartesian x,y,z
Compute divergence of an operand function, which returns the Cartesian x,y,z
components in real space when called with the arguments 1 to 3.
The divergence is also returned as a real-space array.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/transfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Create the Fourier expansion of ``ψ_{k+q}`` from ``ψ_{[k+q]}``, where ``[k+q]`
If ``ΔG ≔ [k+q] - (k+q)``, then we have that
```math
∑_G \hat{u}_{[k+q]}(G) e^{i(k+q+G)·r} &= ∑_{G'} \hat{u}_{k+q}(G'-ΔG) e^{i(k+q+ΔG+G')·r},
∑_G \hat{u}_{[k+q]}(G) e^{i(k+q+G)·r} = ∑_{G'} \hat{u}_{k+q}(G'-ΔG) e^{i(k+q+ΔG+G')·r},
```
hence
```math
Expand Down
2 changes: 1 addition & 1 deletion test/Model.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testitem "Test reduced / cartesian conversion" setup=[TestCases] begin
@testitem "Test reduced / Cartesian conversion" setup=[TestCases] begin
using DFTK
using LinearAlgebra
silicon = TestCases.silicon
Expand Down
2 changes: 1 addition & 1 deletion test/scf_compare.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
for solver in (scf_anderson_solver(), scf_damping_solver(1.0), scf_CROP_solver())
@testset "Testing $solver" begin
ρ_alg = self_consistent_field(basis; ρ=ρ0, solver, tol).ρ
@test maximum(abs, ρ_alg - ρ_def) < 10tol
@test maximum(abs, ρ_alg - ρ_def) < 50tol
end
end

Expand Down

0 comments on commit c92b59a

Please sign in to comment.