Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b55fa68
tests | add start of small test suite
flokno Aug 15, 2023
eb026b0
tests | add canonical_configuration
flokno Aug 15, 2023
b7d5e7b
tests | add crystal_structure_info
flokno Aug 15, 2023
1e56d08
tests | missing files for atomic_distribution
flokno Aug 15, 2023
5f3c09b
tests | add extract_forceconstants
flokno Aug 15, 2023
1563972
tests | add generate_structure
flokno Aug 15, 2023
457e726
tests | add lineshape
flokno Aug 15, 2023
ca0f590
tests | add pack_simulation
flokno Aug 15, 2023
d1dfbed
test | phonon_dispersion_relations
flokno Aug 15, 2023
785d717
tests | add thermal_conductivity
flokno Aug 15, 2023
c0a7474
tests | shortcut to do everything
flokno Aug 15, 2023
c194238
tests | add requirements.txt
flokno Aug 15, 2023
5e7028d
tests | fix
flokno Aug 15, 2023
b0070fb
tests | mention in INSTALL.md and CONTRIBUTING.md
flokno Aug 15, 2023
1c772b7
tests | add anharmonic_free_energy
flokno Aug 15, 2023
f538cee
tests | fix
flokno Aug 15, 2023
a1a1472
tests | update dispersion test
flokno Aug 15, 2023
17e3a27
tests | use np.testing.assert_allclose
flokno Aug 15, 2023
a24ec3c
tests | fix, hide thermal_conductivity for the time being
flokno Aug 15, 2023
ae6545b
tests | remove BZ test --> degeneracy
flokno Aug 15, 2023
6ee567e
tests | fix thermal_conductivity test
flokno Aug 15, 2023
5974595
tests | fix test_thermal_conductivity
flokno Aug 15, 2023
06d9824
Install | point out the bashrc lines
flokno Aug 15, 2023
1b4c9af
tests | add missing dependency for reading hdf5
flokno Aug 15, 2023
7ffb0e6
tests | use xarray[io] for handling the file io
flokno Aug 15, 2023
29e897c
Merge remote-tracking branch 'origin/main' into fk_add_tests
flokno Aug 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ documentation_carousel.md
# Annoying OSX files
.DS_Store
fortls_debug.log

__pycache__
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ In order to contribute code to `TDEP`, please follow the usual steps for [prepar

This will format the code with an indent (`-i`) of 4 characters, without enforcing line breaks (`-l 500` allows up to 500 characters per line - please use less.)

- Please _document_ and _test_ your changes by providing an example in the `examples` folder.
- Please _document_ and _test_ your changes by providing an example in the [`./examples`](./examples) or [`./tests`](./tests) folder.
21 changes: 19 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,28 @@ Then run the build script via
bash build_things.sh --nthreads_make 4
```

If everything works find, the last lines of the output should be something like:

```bash
...

Printing bashrc_tdep, append these lines to your .bashrc for stuff to work nicely
MANPATH=$MANPATH:/path/to/tdep/man
PATH=$PATH:/path/to/tdep/bin
export MANPATH
export PATH
alias gnuplot='gnuplot -persist'

Everything should be set up and good to go!
```

i.e., add the respective lines to your `.bashrc` and you are all set up!

**If problems occur, please look at the [Troubleshooting section below](#Troubleshooting). If you cannot fix the error, please reach out, e.g., via the [issue tracker](https://github.com/tdep-developers/tdep/issues).**

## Check your installation

We advise to run the examples in `tdep/examples` to test your installation after compilation.
We advise to run the tests in [`./tests`](./tests) to check your installation.

## HDF5

Expand Down Expand Up @@ -157,4 +174,4 @@ If you see the error
... error: unrecognized command line option '-fallow-argument-mismatch'; did you mean '-Wno-argument-mismatch'?
```

it likely means that you are using an older Fortran version, and should replace `-fallow-argument-mismatch` with `-Wno-argument-mismatch` in your `important_settings` as suggested.
it likely means that you are using an older Fortran version, and should replace `-fallow-argument-mismatch` with `-Wno-argument-mismatch` in your `important_settings` as suggested.
17 changes: 17 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
testfiles:
bash make_all_testfiles.sh

test:
pytest

all: clean testfiles
pytest

clean:
rm -f */outfile*
rm -rf */__pycache__/
rm -rf *.pytest_cache/
rm -f */contcar*
rm -f */*.dat
rm -f */*.log

42 changes: 42 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Test suite
===

## Run binaries and create test files

```bash
make testfiles
```

will run the TDEP binaries **from your current PATH** and create their output.

## Run tests

To check the files that were created against reference data, please run

```bash
make test
```

This will run python scripts in each folder to check the produced output. **Please note that this requires some python dependencies which you find in `requirements.txt` and install via `pip install -r requirements.txt`**.

Run

```bash
make all
```

to run everything.

## Clean up

Use

```bash
make clean
```

to clean test files.

## Reference files

Were created with TDEP commit `8c01e0343e4098f1d160efc141f8af6ae7f54941` on a macbook with M1 chip.
2 changes: 2 additions & 0 deletions tests/anharmonic_free_energy/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testfiles:
anharmonic_free_energy
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.forceconstant
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.forces
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.meta
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.positions
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.ssposcar
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.stat
1 change: 1 addition & 0 deletions tests/anharmonic_free_energy/infile.ucposcar
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Lowest order approximation to the free energy: (eV/atom)
# Calculated as <U - U_second - U_polar> + F_phonon
F = -3744.8107316589626
# Absolute bound on error: 0.0000000000000000
# Components of the Free energy
U0 = -3744.8468307109688
F_phonon = 3.6099052005669353E-002
29 changes: 29 additions & 0 deletions tests/anharmonic_free_energy/test_anharmonic_free_energy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
from pathlib import Path

parent = Path(__file__).parent
folder = parent / "reference"


def _read_file(file):
with open(file) as f:
next(f)
next(f)
F = float(next(f).split()[2])
next(f)
next(f)
U0 = float(next(f).split()[2])
Fp = float(next(f).split()[2])

return np.array([F, U0, Fp])


def test_output(file="outfile.anharmonic_free_energy"):
data_ref = _read_file(folder / file)
data_new = _read_file(parent / file)

np.testing.assert_allclose(data_ref, data_new, err_msg=(parent / file).absolute())


if __name__ == "__main__":
test_output()
3 changes: 3 additions & 0 deletions tests/atomic_distribution/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testfiles:
rm -f outfile.*
atomic_distribution
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.forces
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.meta
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.positions
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.ssposcar
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.stat
1 change: 1 addition & 0 deletions tests/atomic_distribution/infile.ucposcar
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0.0000000000E+00 0.1324324513E-01 0.7575131815E-02 0.5668113312E-02
0.1000000000E+01 0.1325716124E-01 0.6431467011E-02 0.6825694228E-02
0.2000000000E+01 0.1521220719E-01 0.8681552719E-02 0.6530654468E-02
0.3000000000E+01 0.1354675923E-01 0.7593830527E-02 0.5952928702E-02
0.4000000000E+01 0.1350535340E-01 0.7621549108E-02 0.5883804293E-02
0.5000000000E+01 0.1451778889E-01 0.7683050491E-02 0.6834738404E-02
0.6000000000E+01 0.1366543408E-01 0.7647978904E-02 0.6017455175E-02
0.7000000000E+01 0.1374110908E-01 0.7262810932E-02 0.6478298147E-02
0.8000000000E+01 0.1420842632E-01 0.7729059346E-02 0.6479366977E-02
0.9000000000E+01 0.1478612211E-01 0.7998269465E-02 0.6787852645E-02
0.1000000000E+02 0.1342004651E-01 0.7007244616E-02 0.6412801889E-02
0.1100000000E+02 0.1204463696E-01 0.6593592776E-02 0.5451044183E-02
0.1200000000E+02 0.1456863041E-01 0.8343406443E-02 0.6225223967E-02
0.1300000000E+02 0.1381476779E-01 0.7974751335E-02 0.5840016458E-02
0.1400000000E+02 0.1250360305E-01 0.6971732195E-02 0.5531870852E-02
0.1500000000E+02 0.1343391609E-01 0.7125686577E-02 0.6308229517E-02
0.1600000000E+02 0.1203339223E-01 0.6173066149E-02 0.5860326077E-02
0.1700000000E+02 0.1346966481E-01 0.7444351019E-02 0.6025313793E-02
0.1800000000E+02 0.1280969769E-01 0.6846304693E-02 0.5963392995E-02
0.1900000000E+02 0.1403983413E-01 0.8144062000E-02 0.5895772131E-02
0.2000000000E+02 0.1221906310E-01 0.6789029898E-02 0.5430033200E-02
0.2100000000E+02 0.1301751363E-01 0.6752937241E-02 0.6264576394E-02
0.2200000000E+02 0.1412698324E-01 0.6992694849E-02 0.7134288387E-02
0.2300000000E+02 0.1359467381E-01 0.7785864242E-02 0.5808809569E-02
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions tests/atomic_distribution/test_atomic_distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import numpy as np
import xarray as xr
from pathlib import Path

parent = Path(__file__).parent
folder = parent / "reference"

files_hdf5 = [
"outfile.mean_square_displacement.hdf5",
"outfile.pair_distribution.hdf5",
"outfile.powder_diffraction.hdf5",
]


def test_mean_square_displacement(file="outfile.mean_square_displacement"):
file_ref = folder / file
file_new = parent / file

data_ref = np.loadtxt(file_ref)
data_new = np.loadtxt(file_new)

np.testing.assert_allclose(data_ref, data_new, err_msg=file_new.absolute())


def test_hdf5(files=files_hdf5, decimals=7):
for file in files:
file_ref = folder / file
file_new = parent / file

ds_ref = xr.load_dataset(file_ref)
ds_new = xr.load_dataset(file_new)

for var in ds_ref.data_vars:
x = ds_ref[var].round(decimals=decimals)
y = ds_new[var].round(decimals=decimals)
np.testing.assert_allclose(x, y, err_msg=var)


if __name__ == "__main__":
test_mean_square_displacement()
test_hdf5()
6 changes: 6 additions & 0 deletions tests/canonical_configuration/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
testfiles:
canonical_configuration --modes | tail -n 12 | tee canonical_configuration.dat
rm contcar*

test: testfiles
pytest
1 change: 1 addition & 0 deletions tests/canonical_configuration/infile.forceconstant
1 change: 1 addition & 0 deletions tests/canonical_configuration/infile.ssposcar
1 change: 1 addition & 0 deletions tests/canonical_configuration/infile.ucposcar
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1 + 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
2 - 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
3 + 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
4 - 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
5 + 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
6 - 0.00000 0.00000 NaN 0.00000 0.00000 0.00000000
7 + 50.00000 50.00000 1.00000 50.00000 7.14286 0.00397797
8 - 50.00000 50.00000 1.00000 50.00000 12.50000 0.00696145
9 + 50.00000 50.00000 1.00000 50.00000 16.66667 0.00928193
10 - 50.00000 50.00000 1.00000 50.00000 20.00000 0.01113832
11 + 50.00000 20.79236 1.13229 35.39618 21.39965 0.01175817
12 - 50.00000 20.79236 1.24180 35.39618 22.56603 0.01227471
33 changes: 33 additions & 0 deletions tests/canonical_configuration/test_canonical_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import numpy as np
from pathlib import Path

parent = Path(__file__).parent
folder = parent / "reference"


def _check_numeric(character):
try:
float(character)
return True
except ValueError:
return False


def _read_log(file):
rows = []
with open(file) as f:
for line in f:
rows.append([s for s in line.split() if _check_numeric(s)])

return np.nan_to_num(np.array(rows, dtype=float))


def test_log(file="canonical_configuration.dat"):
data_ref = _read_log(folder / file)
data_new = _read_log(parent / file)

np.testing.assert_allclose(data_ref, data_new, err_msg=(parent / file).absolute())


if __name__ == "__main__":
test_log()
5 changes: 5 additions & 0 deletions tests/crystal_structure_info/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
testfiles:
crystal_structure_info

test: testfiles
pytest
1 change: 1 addition & 0 deletions tests/crystal_structure_info/infile.ucposcar
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FCC ! Bravais lattice type
100 ! Number of points on each path
4 ! Number paths between special points
GM X ! Starting and ending special point
X U !
K GM !
GM L !
16 changes: 16 additions & 0 deletions tests/crystal_structure_info/test_crystal_structure_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path
import filecmp

parent = Path(__file__).parent
folder = parent / "reference"


def test_output(file="outfile.qpoints_dispersion"):
file_ref = folder / file
file_new = parent / file

assert filecmp.cmp(file_ref, file_new), file_new.absolute()


if __name__ == "__main__":
test_output()
2 changes: 2 additions & 0 deletions tests/extract_forceconstants/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testfiles:
extract_forceconstants -rc2 0 -rc3 0 --polar
1 change: 1 addition & 0 deletions tests/extract_forceconstants/infile.lotosplitting
1 change: 1 addition & 0 deletions tests/extract_forceconstants/infile.sim.hdf5
1 change: 1 addition & 0 deletions tests/extract_forceconstants/infile.ssposcar
1 change: 1 addition & 0 deletions tests/extract_forceconstants/infile.ucposcar
Loading