diff --git a/Project.toml b/Project.toml index e9f0767..4fe9ea0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PotentialCalculation" uuid = "76415700-ec45-11e8-0f65-f1df3c899b21" authors = ["Teemu Järvinen "] -version = "0.5.1-DEV" +version = "0.6.0-DEV" [deps] AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" @@ -11,7 +11,6 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" -PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" @@ -25,7 +24,6 @@ Distances = "0.10" FileIO = "1" JLD2 = "0.4" ProgressMeter = "1.2" -PyCall = "1.90" Reexport = "1.0" Rotations = "1.0" Unitful = "1" diff --git a/docs/src/index.md b/docs/src/index.md index a8c5793..ce7bac4 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -13,7 +13,7 @@ experiments. - Calculate potentials with [ORCA](https://orcaforum.kofo.mpg.de) or [Psi4](http://www.psicode.org/) - Automatic sampling of calculation points -- Supports parallelisation of calculation across compute nodes +- Supports parallelization of calculation across compute nodes ### [PotentialFitting](https://github.com/MatrixLabTools/PotentialFitting.jl) diff --git a/docs/src/install.md b/docs/src/install.md index ef51320..d662d45 100644 --- a/docs/src/install.md +++ b/docs/src/install.md @@ -9,7 +9,7 @@ pkg> add PotentialCalculation Currently there are two backends, [ORCA](https://orcaforum.kofo.mpg.de) and [Psi4](http://www.psicode.org/). To do any calculation, you need to have -at least one of these installed. +at least one of these installed. With Psi4 you need to also load [Psi4Calculator](https://github.com/MatrixLabTools/Psi4Calculator.jl) ## Testing installation diff --git a/docs/src/use.md b/docs/src/use.md index 41ee9dc..07179ed 100644 --- a/docs/src/use.md +++ b/docs/src/use.md @@ -89,7 +89,7 @@ data3 = continue_calculation( ## Calculators PotentilaCalculation can use either [Orca](@ref) -or [Psi4](@ref) as a backend for calculations. +or [Psi4](https://github.com/MatrixLabTools/Psi4Calculator.jl) as a backend for calculations. To create ORCA calculator you can use @@ -108,7 +108,8 @@ PATH is searched for orca-binary. `tmp_dir` is by default created in `$TMP`. For Psi4 use ```julia -using PotentialCalculation.psi4 +using PotentialCalculation +using Psi4Calculator Psi4( memory="1GiB", @@ -116,10 +117,10 @@ Psi4( ) ``` -You need to import Psi4 explicitly with `using PotentialCalculation.psi4`. All -Psi4 global environmental variables are present. To access them you need to use -`PotentialCalculation.psi4.gPsi4`-handel after using -`PotentialCalculation.psi4.initpsi()`-function to initialize Psi4 environment. +You need to install Psi4Calculator separately, as it has now been moved to its own package. +All Psi4 global environmental variables are present. To access them you need to use +`Psi4Calculator.gPsi4`-handel after using +`Psi4Calculator.initpsi()`-function to initialize Psi4 environment. ### Adding Calculation Method and Basis Set @@ -205,3 +206,5 @@ using ClusterManagers addprocs_slurm(number_of_processes) # ntasks option in Slurm job file @everywhere using PotentialCalculation ``` + +Consider also using [SlurmClusterManager](https://github.com/kleinhenz/SlurmClusterManager.jl) to make things easy. diff --git a/src/PotentialCalculation.jl b/src/PotentialCalculation.jl index 4ff9e47..4efb8cf 100644 --- a/src/PotentialCalculation.jl +++ b/src/PotentialCalculation.jl @@ -33,6 +33,5 @@ include("SubModules/sample.jl") include("SubModules/restarttools.jl") @reexport using .Restarttools -include("SubModules/psi4.jl") end # module diff --git a/src/SubModules/clusters.jl b/src/SubModules/clusters.jl index 4731541..830f51a 100644 --- a/src/SubModules/clusters.jl +++ b/src/SubModules/clusters.jl @@ -233,23 +233,24 @@ end """ - print_xyz(io::IO, c::AbstractClusterWithSymbols, note=""; printheader=true) + print_xyz(io::IO, c, note=""; printheader=true) Prints cluster in xyz file format # Arguments - `io::IO` : stream where writing is done -- `c::AbstractClusterWithSymbols` : cluster that is writen +- `c` : `AtomsBase` compatable structure - `note=""` : message writen on note line - `printheader=true` : wheather or not header is writen (number of atoms and note) """ -function print_xyz(io::IO, c::AbstractClusterWithSymbols, note=""; printheader=true) +function print_xyz(io::IO, c, note=""; printheader=true) if printheader println(io, " ",length(c)) println(io, note) end for i in 1:length(c) - println(io, c.atoms[i].id, " ", c.xyz[1,i], " ", c.xyz[2,i], " ", c.xyz[3,i]) + r = ustrip.(u"Å", position(c,i)) + println(io, atomic_symbol(c, i), " ", r[1], " ", r[2], " ", r[3]) end end diff --git a/src/SubModules/psi4.jl b/src/SubModules/psi4.jl deleted file mode 100644 index 5342dfc..0000000 --- a/src/SubModules/psi4.jl +++ /dev/null @@ -1,90 +0,0 @@ -module psi4 - -using PyCall -using ..Calculators -using ..Clusters - -export Psi4 - -""" - gpsi4init=false - -Global variable to see if Psi4 was initiated for current process -""" -global gpsi4init=false - -""" - gPsi4 = undef - -Hold Psi4 object given by PyCall. Used to do calculation in current process -""" -global gPsi4 = undef - -""" - initpsi4(;memory="500 MiB", quiet=true, nthreads=1) - -Used to intialize Psi4 environment -""" -function initpsi4(;memory="500 MiB", quiet=true, nthreads=1) - global gPsi4 = pyimport("psi4") - global gpsi4init = true - quiet && gPsi4.core.be_quiet() - gPsi4.set_memory(memory) - nthreads > 1 && gPsi4.set_num_threads(nthreads) -end - -""" - mutable struct Psi4 <: AbstractCalculationProgram - -Holds information that calculations are to be done with Psi4 - -# Fields -- `memory="500MiB"` : memory used by Psi4 -- `nthreads=1` : number of threads used by Psi4 -""" -mutable struct Psi4 <: AbstractCalculationProgram - memory::String - nthreads::UInt - function Psi4(;memory="500MiB", nthreads=1) - initpsi4(memory=memory, nthreads=nthreads) - @debug gPsi4 - new(memory, nthreads) - end -end - - -function Calculators.calculate_energy(cal::Calculator{Psi4}, point::Cluster; - basename="base", ghost=undef, id="", pchannel=undef) - ! gpsi4init && initpsi4(memory=cal.calculator.memory, nthreads=cal.calculator.nthreads) - s=sprint( (io, x) -> print_xyz(io,x, printheader=false), point) - c = gPsi4.geometry(s) - out = gPsi4.energy(cal.method*"/"*cal.basis, molecule=c) - pchannel != undef && put!(pchannel,true) - return out -end - - -function Calculators.calculate_energy(cal::Calculator{Psi4}, points; - basename="base", ghost=undef, id="", pchannel=undef) - return map( x -> calculate_energy(cal, x, basename=basename, ghost=ghost, id=id, pchannel=pchannel), points ) -end - - -function Calculators.bsse_corrected_energy(cal::Calculator{Psi4}, c1::Cluster, c2::Cluster; - basename="base", id="", pchannel=undef) - ! gpsi4init && initpsi4(memory=cal.calculator.memory) - s1=sprint( (io, x) -> print_xyz(io,x, printheader=false), c1) - s2=sprint( (io, x) -> print_xyz(io,x, printheader=false), c2) - c = gPsi4.geometry(s1*"\n--\n"*s2) - out = gPsi4.energy(cal.method*"/"*cal.basis, molecule=c, bsse_type="cp") - pchannel != undef && put!(pchannel,true) - return out -end - -function Calculators.bsse_corrected_energy(cal::Calculator{Psi4}, c1, c2; - basename="base", id="", pchannel=undef) - return map( (x,y) -> bsse_corrected_energy(cal, x, y, basename=basename, id=id, pchannel=pchannel ), c1, c2 ) -end - - -end # module psi4 diff --git a/test/Project.toml b/test/Project.toml index 2fd6907..e07791b 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,5 +1,4 @@ [deps] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a" diff --git a/test/test_restarttools.jl b/test/test_restarttools.jl index 6112d00..81960da 100644 --- a/test/test_restarttools.jl +++ b/test/test_restarttools.jl @@ -1,11 +1,9 @@ using Test -using PyCall using Distributed addprocs(2) @everywhere using PotentialCalculation -@everywhere using PotentialCalculation.psi4 fname = tempname() * ".jld2" rname = tempname() * ".jld2" @@ -31,7 +29,7 @@ pbar=true testrestarts = false -if Sys.which("orca") != nothing && Sys.which("orca_scf") != nothing +if Sys.which("orca") !== nothing && Sys.which("orca_scf") !== nothing @info "Orca binary found. Testing ORCA." @testset "Orca" begin ca = Calculator("blyp d3bj TIGHTSCF", "def2-svp", Orca()) @@ -55,37 +53,6 @@ end -testpsi4 = true - -try - pyimport("psi4") -catch - global testpsi4 = false - @warn "Psi4 was not detected. Skipping testing. Psi4 backend is not working!" -end -if testpsi4 - @info "Psi4 found. Testing Psi4." - @testset "Psi4" begin - ca = Calculator("blyp-d3bj", "def2-svp",Psi4(memory="1000MiB", nthreads=2)) - - input1=create_inputs(xyzname, Ar, ca) - inputs=create_inputs(xyzname, N2, ca; npoints=5) - inputss=create_inputs(xyzname, xyzname, ca) - - data1=calculate_potential(inputs, save_file=fname, pbar=pbar) - data2=calculate_potential(fname,ca,save_file=sname, restart_file=rname, pbar=pbar) - data3=continue_calculation(rname,ca, save_file=sname, restart_file=rname, pbar=pbar) - - calculate_energy(ca, N2) - calculate_energy(ca, [N2,N2]) - @test all(isapprox.(data1["Energy"], data2["Energy"], atol=2E-6)) - @test all(isapprox.(data1["Energy"], data3["Energy"], atol=2E-6)) - @test all(isapprox.(data2["Energy"], data3["Energy"], atol=2E-6)) - end - testrestarts = true -end - - if testrestarts @testset "restarttools" begin savedata = load_data_file(sname)