From a691bbb0963212e7b19798b19da153d730c30716 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Tue, 4 Feb 2020 20:56:52 +0100 Subject: [PATCH] Test reformatting and fixes --- Project.toml | 6 +++--- test/forces.jl | 21 +++------------------ test/runtests.jl | 6 +++++- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Project.toml b/Project.toml index f15bdb1b4d..48de958589 100644 --- a/Project.toml +++ b/Project.toml @@ -17,14 +17,13 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Memoization = "6fafb56a-5788-4b4e-91ca-c0cea6611c73" NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab" -NLSolversBase = "d41bc354-129a-5804-8e4c-c37616107c6c" NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56" Optim = "429524aa-4258-5aef-a3af-852621145aeb" Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee" +Requires = "ae029012-a4dd-5104-9daa-d747884805df" Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" @@ -36,7 +35,8 @@ julia = "1.2" [extras] DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "DoubleFloats", "IntervalArithmetic"] +test = ["Test", "DoubleFloats", "IntervalArithmetic", "Random"] diff --git a/test/forces.jl b/test/forces.jl index d054950d49..6d38c9ac95 100644 --- a/test/forces.jl +++ b/test/forces.jl @@ -11,33 +11,18 @@ using Test lattice = silicon.lattice Si = Element(silicon.atnum, psp=load_psp(silicon.psp)) atoms = [Si => pos] - - model = Model(lattice; - atoms=atoms, - external=term_external(atoms), - nonlocal=term_nonlocal(atoms), - hartree=term_hartree(), - xc=term_xc(:lda_xc_teter93)) - + model = model_dft(silicon.lattice, :lda_xc_teter93, atoms) kcoords, ksymops = bzmesh_ir_wedge(kgrid, lattice, atoms) basis = PlaneWaveBasis(model, Ecut, kcoords, ksymops) - # Run SCF. Note Silicon is a semiconductor, so we use an insulator - # occupation scheme. This will cause warnings in some models, because - # e.g. in the :reduced_hf model silicon is a metal n_bands_scf = Int(model.n_electrons / 2) ham = Hamiltonian(basis, guess_density(basis)) scfres = self_consistent_field(ham, n_bands_scf, tol=1e-12) - ham = scfres.ham - energies = scfres.energies - sum(values(energies)), forces(scfres) + sum(values(scfres.energies)), forces(scfres) end - using Random - Random.seed!(0) - - pos1 = [(ones(3)+.1*randn(3))/8, -ones(3)/8] + pos1 = [(ones(3)+0.1*randn(3))/8, -ones(3)/8] disp = randn(3) ε = 1e-7 pos2 = [pos1[1]+ε*disp, pos1[2]] diff --git a/test/runtests.jl b/test/runtests.jl index 06a823af76..af94cd9e5e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,6 @@ using Test using DFTK +using Random # # This test suite test arguments. For example: @@ -26,6 +27,8 @@ else println(" Running tests (TAGS = $(join(TAGS, ", "))).") end +# Initialise seed +Random.seed!(0) # Wrap in an outer testset to get a full report if one test fails @testset "DFTK.jl" begin @@ -65,11 +68,12 @@ end end if "all" in TAGS - include("energy_ewald.jl") + include("ewald.jl") include("energy_nuclear.jl") include("occupation.jl") include("energies_guess_density.jl") include("compute_density.jl") + include("forces.jl") end if "all" in TAGS