Debian Codegraph @

tests/test_python.py

raw
1 import numpy as np
2 import pytest
3 from pytest import approx
4
5 from pymbd import (
6 atomic_polarizabilities,
7 from_volumes,
8 mbd_energy_species,
9 molecular_polarizability,
10 screening,
11 screening_matrix,
12 )
13
14
15 @pytest.mark.no_scalapack
16 def test_ethylcarbamate(ethylcarbamate):
17 enes = [
18 mbd_energy_species(
19 coords, species, vol_ratios, 0.83, lattice=lattice, k_grid=k_grid
20 )
21 for coords, lattice, k_grid, species, vol_ratios in ethylcarbamate
22 ]
23 ene_int = enes[0] - 2 * enes[1]
24 assert ene_int == approx(-0.037040868610822564, rel=1e-10)
25
26
27 @pytest.mark.no_scalapack
28 def test_screening_matrix(benzene_dimer):
29 coords, species, vol_ratios = benzene_dimer[0]
30 n = len(species)
31 alpha_0, C6, R_vdw = from_volumes(species, vol_ratios)
32 a_nlc = screening_matrix(coords, alpha_0, R_vdw, 0.83)
33 assert a_nlc.shape == (3 * n, 3 * n)
34 # inverse of a symmetric matrix, so symmetric
35 assert a_nlc == approx(a_nlc.T)
36
37
38 @pytest.mark.no_scalapack
39 def test_polarizabilities(benzene_dimer):
40 coords, species, vol_ratios = benzene_dimer[0]
41 na = len(species)
42 alpha_0, C6, R_vdw = from_volumes(species, vol_ratios)
43 alpha_scs = screening(coords, alpha_0, C6, R_vdw, 0.83)[0]
44 # atomic polarizabilities are per-atom isotropic scalars, equal to the
45 # static screened polarizabilities returned by screening()
46 alpha_a = atomic_polarizabilities(coords, species, vol_ratios, 0.83)
47 assert alpha_a.shape == (na,)
48 assert alpha_a == approx(alpha_scs)
49 # the molecular polarizability is a symmetric 3x3 tensor whose isotropic
50 # part is the sum of the atomic polarizabilities
51 alpha_mol = molecular_polarizability(coords, species, vol_ratios, 0.83)
52 assert alpha_mol.shape == (3, 3)
53 assert alpha_mol == approx(alpha_mol.T)
54 assert np.trace(alpha_mol) / 3 == approx(alpha_a.sum())