Skip to content

Commit

Permalink
Add test to the PpafmParameters class
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Aug 30, 2024
1 parent d86fbe6 commit 6985c4c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/data/test_params.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
probeType 8 # atom type of ProbeParticle (to choose L-J potential ),e.g. 8 for CO, 24 for Xe
probeType Xe # atom type of ProbeParticle (to choose L-J potential ),e.g. 8 for CO, 24 for Xe
tip 'p' # multipole of the PP {'dz2' is the most popular now}, charge cloud is not tilting
sigma 2.7 # FWHM of the gaussian charge cloud {0.7 or 0.71 are standarts}
charge 0.5 # effective charge of probe particle [e] {for multipoles the real moment is q*sigma - dipole - or q*sigma**2 - quadrupole}
ffModel Morse # Two possibilities now: L-J > 'LJ' or Morse'potential > 'Morse'
r0Probe 1.00 1.00 5.00 # [Å] equilibirum position of probe particle (x,y,R) components, R is bond length, x,y introduce tip asymmetry
klat 1.5 # Lateral harmonic spring constant [N/m] {for CO typically 0.24}
krad 30.00 # Radial harmonic spring constant [N/m]
PBC False # Periodic boundary conditions ? [ True/False ]
nPBC 2 3 4
gridN 10 20 30 # number of grid points in x,y,z directions
gridA 5.0 6.0 7.0 # a-vector of unit cell; recomanded format (x,y,0)
gridB 8.0 9.0 10.0 # b-vector of unit cell; recomanded format (x,y,0)
gridC 11.0 12.0 13.0 # c-vector of unit cell; recomanded format (0,0,z)
scanStep 0.10 0.20 0.30
scanMin 1.0 2.0 5.0 # start of scanning (x,y,z)
scanMax 21.0 22.0 9.0 # end of scanning (x,y,z)
Amplitude 8.0 # [Å] oscilation amplitude (peak-to-peak) for conversion Fz->df
aMorse -2.6
vdWDampKind 3 # vdW damping 0:Constant, 1:R2func, 2:R4func, 3:invR4, 4:invR8
49 changes: 49 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,52 @@ def test_sphere_tangent_space(n=2):
]
),
)


def test_ppafm_parameters():
# First, testing the default values
p_default = common.PpafmParameters()
assert p_default.PBC == True
assert p_default.nPBC == [1, 1, 1]
assert p_default.probeType == "O"
assert np.isclose(p_default.charge, 0.0)
assert p_default.ffModel == "LJ"
assert np.isclose(p_default.r0Probe, [0.0, 0.0, 4.0]).all()
assert p_default.gridN == [-1, -1, -1]
assert np.isclose(p_default.klat, 0.5)
assert np.isclose(p_default.gridA, [20.0, 0.0, 0.0]).all()
assert np.isclose(p_default.gridB, [0.0, 20.0, 0.0]).all()
assert np.isclose(p_default.gridC, [0.0, 0.0, 20.0]).all()
assert np.isclose(p_default.scanStep, 0.1).all()
assert np.isclose(p_default.scanMin, [0.0, 0.0, 5.0]).all()
assert np.isclose(p_default.scanMax, [20.0, 20.0, 8.0]).all()
assert np.isclose(p_default.Amplitude, 1.0)
assert np.isclose(p_default.aMorse, -1.6)
assert p_default.vdWDampKind == 2

# Load the parameters from a file
p_ini = common.PpafmParameters.from_file("data/test_params.ini")
assert p_ini.PBC == False
assert p_ini.nPBC == [2, 3, 4]
assert p_ini.probeType == "Xe"
assert np.isclose(p_ini.charge, 0.5)
assert p_ini.ffModel == "Morse"
assert np.isclose(p_default.r0Probe, [0.0, 0.0, 4.0]).all()
assert np.isclose(p_ini.gridN, [10, 20, 30]).all()
assert np.isclose(p_ini.klat, 1.5)
assert np.isclose(p_ini.gridA, [5.0, 6.0, 7.0]).all()
assert np.isclose(p_ini.gridB, [8.0, 9.0, 10.0]).all()
assert np.isclose(p_ini.gridC, [11.0, 12.0, 13.0]).all()
assert np.isclose(p_ini.scanStep, [0.1, 0.2, 0.3]).all()
assert np.isclose(p_ini.scanMin, [1.0, 2.0, 5.0]).all()
assert np.isclose(p_ini.scanMax, [21.0, 22.0, 9.0]).all()
assert np.isclose(p_ini.Amplitude, 8.0)
assert np.isclose(p_ini.aMorse, -2.6)
assert p_ini.vdWDampKind == 3

# Dump the parameters to a toml file
p_ini.to_file("data/test_params.toml")

# Load the parameters from the toml file and compare to the original
p_toml = common.PpafmParameters.from_file("data/test_params.toml")
assert p_ini == p_toml

0 comments on commit 6985c4c

Please sign in to comment.