Skip to content

Commit

Permalink
Add Random position sampler (#49)
Browse files Browse the repository at this point in the history
* random sampler

* update random sampler

* use tmp_dir with orca

* clean docs a bit

* update random sampler

* add tests
  • Loading branch information
tjjarvinen authored Nov 16, 2023
1 parent a95174d commit 8289562
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 90 deletions.
60 changes: 30 additions & 30 deletions docs/src/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ with various distances and orientations from each other.
```julia
# Creating calculation method
mp2 = Calculator(
"RI-MP2 RIJK TIGHTSCF",
"aug-cc-pVTZ aug-cc-pVTZ/C def2/JK",
Orca()
)
"RI-MP2 RIJK TIGHTSCF",
"aug-cc-pVTZ aug-cc-pVTZ/C def2/JK",
Orca()
)

# Creating argon atom
Ar = Cluster( Atom(:Ar, zeros(3)u"Å") )
Expand All @@ -40,14 +40,14 @@ trajfile="Some trajectory.xyz"

# Create input for calculations
inputs = create_inputs(
trajfile, # First molecule will be picked from here
Ar, # Second molecule will be picked from here
mp2; # Calculator to do electronic structure calculations
nsaples=32, # How many lines are calculated
max_e=10000u"cm^-1", # Maximum energy in cm⁻¹ -
# limit to areas where energy is less than this
npoints=50 # Number of points per line
)
trajfile, # First molecule will be picked from here
Ar, # Second molecule will be picked from here
mp2; # Calculator to do electronic structure calculations
nsaples=32, # How many lines are calculated
max_e=10000u"cm^-1", # Maximum energy in cm⁻¹ -
# limit to areas where energy is less than this
npoints=50 # Number of points per line
)

# Do calculation
data = calculate_potential(inputs, save_file="save file")
Expand All @@ -62,28 +62,28 @@ New calculations with different method can be done on previous points.
```julia
#New method
ccf12 = Calculator(
"CCSD(T)-F12/RI TIGHTSCF",
"cc-pVDZ-F12 cc-pVDZ-F12-CABS cc-pVTZ/C",
Orca(maxmem=4000)
)
"CCSD(T)-F12/RI TIGHTSCF",
"cc-pVDZ-F12 cc-pVDZ-F12-CABS cc-pVTZ/C",
Orca(maxmem=4000)
)

data2 = calculate_potential(
"previous results file",
ccf12, # Calculate with this method now
save_file="new save file",
restart_file="restart file"
)
"previous results file",
ccf12, # Calculate with this method now
save_file="new save file",
restart_file="restart file"
)
```

To restart calculations from restart file.

```julia
data3 = continue_calculation(
"restart file",
Orca(maxmem=4000),
save_file="final save file",
restart_file="new restart file"
)
"restart file",
Orca(maxmem=4000),
save_file="final save file",
restart_file="new restart file"
)
```

## Calculators
Expand Down Expand Up @@ -170,10 +170,10 @@ when using ORCA, you should use something like

```julia
ccf12 = Calculator(
"CCSD(T)-F12/RI TIGHTSCF",
"cc-pVDZ-F12 cc-pVDZ-F12-CABS cc-pVTZ/C",
Orca(maxmem=4000)
)
"CCSD(T)-F12/RI TIGHTSCF",
"cc-pVDZ-F12 cc-pVDZ-F12-CABS cc-pVTZ/C",
Orca(maxmem=4000)
)
```

For larger molecules ORCA has DLPNO-CCSD(T)-F12, but in the limited testing that
Expand Down
90 changes: 72 additions & 18 deletions src/SubModules/calculators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Calculates energy for given clusters.
- `id=""` : additional information for calculator - needed for multiprocessing in same folder
- `pchannel=undef` : (Remote)Channel where progess information is added
"""
function calculate_energy(cal::Calculator{Orca}, points; basename="base", ghost=undef, id="", pchannel=undef)
function calculate_energy(cal::Calculator{Orca}, points; basename="base", ghost=undef, id="", pchannel=undef, use_tmpdir=true)
clean_calculation_files(basename=basename)
inname = "$(basename).inp"
outname= "$(basename).out"
Expand All @@ -212,7 +212,19 @@ function calculate_energy(cal::Calculator{Orca}, points; basename="base", ghost=
pchannel != undef && put!(pchannel,true)
return out
end
return map(x -> do_calculation(x), points)
dir = pwd()
out = nothing
if use_tmpdir
try
cd(cal.calculator.tmp_dir)
out = map(x -> do_calculation(x), points)
finally
cd(dir)
end
else
out = map(x -> do_calculation(x), points)
end
return out
end


Expand All @@ -231,20 +243,39 @@ Calculates energy for given cluster.
- `id=""` : additional information for calculator - needed for multiprocessing in same folder
- `pchannel=undef` : (Remote)Channel where progess information is added
"""
function calculate_energy(cal::Calculator{Orca}, point::Cluster; basename="base", ghost=undef, id="", pchannel=undef)
function calculate_energy(cal::Calculator{Orca}, point::Cluster; basename="base", ghost=undef, id="", pchannel=undef, use_tmpdir=true)
clean_calculation_files(basename=basename)
inname = "$(basename).inp"
outname= "$(basename).out"
cmd = pipeline(`$(cal.calculator.executable) $(inname)`, outname)

ts = time()
open(inname,"w") do io
write_input(io, cal, point, ghost=ghost)
out = nothing

if use_tmpdir
dir = pwd()
try
cd(cal.calculator.tmp_dir)
ts = time()
open(inname,"w") do io
write_input(io, cal, point, ghost=ghost)
end
run(cmd)
out = read_energy(outname)
te = time()
@debug "Calculation done in $(round(te-ts, digits=1)) seconds"
finally
cd(dir)
end
else
ts = time()
open(inname,"w") do io
write_input(io, cal, point, ghost=ghost)
end
run(cmd)
out = read_energy(outname)
te = time()
@debug "Calculation done in $(round(te-ts, digits=1)) seconds"
end
run(cmd)
out = read_energy(outname)
te = time()
@debug "Calculation done in $(round(te-ts, digits=1)) seconds"

pchannel != undef && put!(pchannel,true)
return out
end
Expand Down Expand Up @@ -272,8 +303,21 @@ function bsse_corrected_energy(cal::Calculator{Orca}, c1, c2; basename="base", i
e = calculate_energy(cal, points, basename=basename, id=id, pchannel=pchannel)
l1 = length(c1[1])
l2 = length(c2[1]) + l1
bsse1 = calculate_energy(cal, points, basename=basename, ghost=1:l1, id=id, pchannel=pchannel)
bsse2 = calculate_energy(cal, points, basename=basename, ghost=(l1+1):l2, id=id, pchannel=pchannel)
dir = pwd()
bsse1 = nothing
bsse2 = nothing
e = nothing
try
cd(cal.calculator.tmp_dir)
e = calculate_energy(cal, points, basename=basename, id=id, pchannel=pchannel)
l1 = length(c1[1])
l2 = length(c2[1]) + l1
bsse1 = calculate_energy(cal, points, basename=basename, ghost=1:l1, id=id, pchannel=pchannel, use_tmpdir=false)
bsse2 = calculate_energy(cal, points, basename=basename, ghost=(l1+1):l2, id=id, pchannel=pchannel, use_tmpdir=false)
finally
cd(dir)
end

return e .- bsse1 .- bsse2
end

Expand All @@ -296,11 +340,21 @@ function bsse_corrected_energy(cal::Calculator{Orca}, c1::Cluster, c2::Cluster;
basename="base", id="", pchannel=undef)
# expects ORCA calculator
points = c1 + c2
e = calculate_energy(cal, points, basename=basename, id=id, pchannel=pchannel)
l1 = length(c1)
l2 = length(c2) + l1
bsse1 = calculate_energy(cal, points, basename=basename, ghost=1:l1, id=id, pchannel=pchannel)
bsse2 = calculate_energy(cal, points, basename=basename, ghost=(l1+1):l2, id=id, pchannel=pchannel)
e = nothing
bsse1 = nothing
bsse2 = nothing
dir = pwd()
try
cd(cal.calculator.tmp_dir)
e = calculate_energy(cal, points, basename=basename, id=id, pchannel=pchannel)
l1 = length(c1)
l2 = length(c2) + l1
bsse1 = calculate_energy(cal, points, basename=basename, ghost=1:l1, id=id, pchannel=pchannel)
bsse2 = calculate_energy(cal, points, basename=basename, ghost=(l1+1):l2, id=id, pchannel=pchannel)
finally
cd(dir)
end

return e .- bsse1 .- bsse2
end

Expand Down
Loading

0 comments on commit 8289562

Please sign in to comment.