Skip to content

Commit

Permalink
Merge branch 'grimme-lab:main' into aISS_update
Browse files Browse the repository at this point in the history
  • Loading branch information
cplett authored Jan 26, 2024
2 parents ce88d03 + 803bc69 commit 82037c2
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 71 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/fortran-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.x

Expand Down Expand Up @@ -109,10 +109,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.x

Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option(WITH_OBJECT "To build using object library" TRUE)
option(INSTALL_MODULES "Install Fortran module files to include directory." FALSE)

# Buggy CMake versions
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0 AND CMAKE_VERSION VERSION_LESS 3.28.0)
set(WITH_OBJECT FALSE)
endif()

Expand All @@ -45,11 +45,13 @@ if(NOT TARGET "mctc-lib::mctc-lib")
endif()

if(NOT TARGET "tblite::tblite" AND WITH_TBLITE)
find_package("tblite" REQUIRED)
find_package("tblite" REQUIRED)
add_compile_definitions(-DWITH_TBLITE)
endif()

if(NOT TARGET "cpcmx::cpcmx" AND WITH_CPCMX)
find_package("cpcmx" REQUIRED)
find_package("cpcmx" REQUIRED)
add_compile_definitions(-DWITH_CPCMX)
endif()

if(NOT TARGET "test-drive::test-drive")
Expand Down Expand Up @@ -147,11 +149,10 @@ target_link_libraries(
"$<$<BOOL:${WITH_OpenMP}>:OpenMP::OpenMP_Fortran>"
"mctc-lib::mctc-lib"
"$<$<BOOL:${WITH_CPCMX}>:cpcmx::cpcmx>"
"$<$<BOOL:${WITH_TBLITE}>:tblite::tblite>"
$<$<BOOL:${WITH_TBLITE}>:tblite::tblite>
)


set_target_properties(
set_target_properties(
"lib-${PROJECT_NAME}-static"
PROPERTIES
Fortran_MODULE_DIRECTORY "${PROJECT_BINARY_DIR}/include"
Expand Down Expand Up @@ -224,6 +225,7 @@ target_link_libraries(
PRIVATE
"lib-${PROJECT_NAME}-static"
)

set_target_properties(
${PROJECT_NAME}-exe
PROPERTIES
Expand Down
5 changes: 4 additions & 1 deletion man/xtb.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ GENERAL
clutter the screen less (not supported in every unit)

*--ceasefiles*::
reduce the amount of output and files written
reduce the amount of output and files written (e.g. xtbtopo.mol)

*--strict*::
turns all warnings into hard errors
Expand Down Expand Up @@ -345,6 +345,9 @@ OUTPUT
*hessian*::
contains the (not mass weighted) cartesian Hessian, *--namespace* compatible.

*xtbtopo.mol*::
topology information written in molfile format.

*xtbopt.xyz*, *xtbopt.coord*::
optimized geometry in the same format as the input geometry.

Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ xtb_exe = executable(
dependencies: xtb_dep_static,
link_language: 'fortran',
install: install,
fortran_args: [
'-DWITH_TBLITE=@0@'.format(tblite_dep.found() ? 1 : 0),
'-DWITH_CPCMX=@0@'.format(cpx_dep.found() ? 1 : 0),
],
)

xtb_header = files('include/xtb.h')
Expand Down
17 changes: 12 additions & 5 deletions src/constrain_param.f90
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,19 @@ subroutine set_constr(env,key,val,nat,at,idMap,xyz)
potset%pos%n = size(list)
case('atoms')
call atl%new(val)
if (atl%get_error()) then
call env%warning('something is wrong in the fixing list',source)
return
if (val.eq."all") then
allocate(list(nat))
do i=1,nat
list(i)=i
enddo
else
if (atl%get_error()) then
call env%warning('something is wrong in the fixing list',source)
return
endif
if (potset%pos%n > 0) call atl%add(potset%pos%atoms(:potset%pos%n))
call atl%to_list(list)
endif
if (potset%pos%n > 0) call atl%add(potset%pos%atoms(:potset%pos%n))
call atl%to_list(list)
potset%pos%atoms = list
potset%pos%n = size(list)

Expand Down
99 changes: 62 additions & 37 deletions src/geoopt_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,81 @@
module xtb_geoopt
contains

!> wrapper for relaxation engines
!> more info: https://xtb-docs.readthedocs.io/en/latest/optimization.html
subroutine geometry_optimization &
& (env,mol,wfn,calc,egap,et,maxiter,maxcycle_in,etot,g,sigma, &
& tight,pr,initial_sp,fail)

use xtb_mctc_accuracy, only : wp
use xtb_mctc_io, only : stdout

use xtb_type_molecule
use xtb_type_restart
use xtb_type_calculator
use xtb_type_data

use xtb_optimizer
use xtb_relaxation_engine
use xtb_single

use xtb_setparam

! Declaration section
implicit none

character(len=*), parameter :: source = 'xtb_geoopt'

!> Dummy-argument list
!> instace of polymorphic calculatior
class(TCalculator), intent(inout) :: calc
!! instance of calculatior

!> calculation environment
type(TEnvironment), intent(inout) :: env
!! calculation environment

!> molecular data information
type(TMolecule), intent(inout) :: mol
!! molecular information

!> wavefunction
type(TRestart),intent(inout) :: wfn
!! wavefunction

!> optimization level
integer, intent(in) :: tight
!! optimization level

!> max number of SCC cycles
integer, intent(in) :: maxiter
!! max number of SCC cycles

!> max number of optimization cycles
integer, intent(in) :: maxcycle_in
!! max number of optimization cycles

!> total energy
real(wp),intent(inout) :: etot
!! total energy

!> electronic temperature
real(wp),intent(in) :: et
!! electronic temprature

!> HOMO-LUMO gap
real(wp),intent(inout) :: egap
!! HOMO-LUMO gap

!> gradients
real(wp),intent(inout) :: g(3,mol%n)
!! gradients

!> strain derivatives
real(wp),intent(inout) :: sigma(3,3)
!! strain derivatives

!> internal printlevel
logical, intent(in) :: pr
!! printlevel

!> optimization convergence
logical, intent(out) :: fail
!! true-> optimization not converged

!> perform initial single point
logical, intent(in) :: initial_sp
!! true-> perform initial single point

!> Local variables
type(scc_results) :: res
logical :: final_sp, exitRun
integer :: printlevel
integer :: ilog

!----------------!
! Initialization !
!----------------!

final_sp = pr

if (pr) then
Expand All @@ -88,10 +103,9 @@ subroutine geometry_optimization &
printlevel = 0
endif

!> create optimization log file
! create/open optimization log !
if (.not.allocated(set%opt_logfile)) then
call open_file(ilog,'xtbopt.log','w')
!! default
else
if (set%opt_logfile == '-') then
ilog = stdout
Expand All @@ -102,36 +116,46 @@ subroutine geometry_optimization &
endif
endif

! create ONIOM optimization logs for low & high methods !
if (set%oniom_settings%logs) then
call open_file(set%oniom_settings%ilog1,"low.inner_region.log",'w')
call open_file(set%oniom_settings%ilog2,"high.inner_region.log",'w')
endif

call mol%update
!! update interatomic and minimum image(periodic) distances
call mol%update ! update interatomic and minimum image (periodic) distances

!-------------!
! Calculation !
!-------------!

if (initial_sp) call singlepoint &
&(env,mol,wfn,calc, &
& egap,et,maxiter,printlevel-1,.false.,.false.,1.0_wp,etot,g,sigma,res)

!> actual calculation
select case(set%opt_engine)
case(p_engine_rf)
case(p_engine_rf) ! ANCopt !
call ancopt &
&(env,ilog,mol,wfn,calc, &
& egap,et,maxiter,maxcycle_in,etot,g,sigma,tight,pr,fail)
final_sp = .true.
!! required since ANCopt might perform an untracked displacement
final_sp = .true. ! required since ANCopt might perform an untracked displacement

case(p_engine_lbfgs)
call l_ancopt &
call l_ancopt & ! L-ANCopt !
&(env,ilog,mol,wfn,calc, &
& tight,maxcycle_in,etot,egap,g,sigma,printlevel,fail)

case(p_engine_inertial)
call fire &
call fire & ! FIRE !
&(env,ilog,mol,wfn,calc, &
& tight,maxcycle_in,etot,egap,g,sigma,printlevel,fail)

end select


!-----------------!
! Post-processing !
!-----------------!

! check convergence !
if (pr) then
if (fail) then
call touch_file('NOT_CONVERGED')
Expand All @@ -141,14 +165,14 @@ subroutine geometry_optimization &
endif
end if

call env%check(exitRun)
!! check if any errors occur
call env%check(exitRun) ! error check

if (exitRun) then
call env%rescue("Trying to recover from failed geometry optimization", source)
fail = .true.
end if

! print fine details of optimized geometry !
if (pr.and.set%pr_finalstruct) then
write(env%unit,'(''================'')')
write(env%unit,*) 'final structure:'
Expand All @@ -157,17 +181,18 @@ subroutine geometry_optimization &
endif
if (pr.and.set%pr_geosum) call geosum(mol%n,mol%at,mol%xyz)

!> usually final SP is performed for all three engines
! final SP (usually for all engines) !
if (final_sp) then
if (pr) call generic_header(env%unit,'Final Singlepoint',49,10)
call singlepoint &
&(env,mol,wfn,calc, &
& egap,et,maxiter,printlevel,.false.,.false.,1.0_wp,etot,g,sigma,res)
endif

if (ilog .ne.stdout) call close_file(ilog)
!! close log file if it is not printed out on stdout
! close log file !
if (ilog.ne.stdout) call close_file(ilog)

! close ONIOM optlogs !
if (set%oniom_settings%logs) then
call close_file(set%oniom_settings%ilog1)
call close_file(set%oniom_settings%ilog2)
Expand Down
4 changes: 3 additions & 1 deletion src/optimizer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ subroutine ancopt(env,ilog,mol,chk,calc, &
character(len=*),parameter :: chrfmt = &
'(10x,":",3x,a,a18, 10x,":")'


! Print ANCopt header !
call ancopt_header(env%unit,set%veryverbose)

if(mol%n.eq.1) return
!! do not optimize for 1 molecule
if (profile) call timer%new(8,.false.)
Expand Down
Loading

0 comments on commit 82037c2

Please sign in to comment.