-
Notifications
You must be signed in to change notification settings - Fork 149
/
main.F90
1535 lines (1320 loc) · 49.4 KB
/
main.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! This file is part of xtb.
!
! Copyright (C) 2017-2020 Stefan Grimme
!
! xtb is free software: you can redistribute it and/or modify it under
! the terms of the GNU Lesser General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! xtb is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public License
! along with xtb. If not, see <https://www.gnu.org/licenses/>.
module xtb_prog_main
use xtb_mctc_accuracy, only : wp
use xtb_mctc_io, only : stderr
use xtb_mctc_timings
use xtb_mctc_systools
use xtb_mctc_convert
use xtb_mctc_param
use xtb_type_molecule
use xtb_type_calculator
use xtb_type_restart
use xtb_type_param
use xtb_type_data
use xtb_type_environment, only : TEnvironment, init
use xtb_prog_argparser
use xtb_solv_state
use xtb_setparam
use xtb_sphereparam
use xtb_scanparam
use xtb_splitparam
use xtb_symparam
use xtb_fixparam
use xtb_constrain_param, only : read_userdata
use xtb_shake, only: init_shake
use xtb_gfnff_shake, only: gff_init_shake => init_shake
use xtb_embedding, only : init_pcem
use xtb_io_reader, only : readMolecule
use xtb_io_writer, only : writeMolecule
use xtb_mctc_filetypes, only : fileType, getFileType, generateFileMetaInfo, &
& generateFileName
use xtb_readin
use xtb_printout
use xtb_setmod
use xtb_propertyoutput
use xtb_io_writer_turbomole, only : writeResultsTurbomole
use xtb_io_writer_orca, only : writeResultsOrca
use xtb_io_writer_gaussian, only : writeResultsGaussianExternal
use xtb_restart
use xtb_readparam
use xtb_scc_core, only : iniqshell
use xtb_extern_orca, only : checkOrca
use xtb_extern_mopac, only : checkMopac
use xtb_single, only : singlepoint
use xtb_aespot, only : get_radcn
use xtb_iniq, only : iniqcn
use xtb_eeq
use xtb_disp_ncoord, only : ncoord_gfn, dncoord_erf, dncoord_d3, ncoord_erf, &
& ncoord_d3
use xtb_basis
use xtb_axis, only : axis3
use xtb_qmdff, only : ff_ini
use xtb_hessian, only : numhess
use xtb_dynamic, only : md
use xtb_modef, only : modefollow
use xtb_mdoptim, only : mdopt
use xtb_screening, only : screen
use xtb_xtb_calculator
use xtb_gfnff_calculator
use xtb_paramset
use xtb_xtb_gfn0
use xtb_xtb_gfn1
use xtb_xtb_gfn2
use xtb_main_setup
use xtb_main_defaults, only : initDefaults
use xtb_geoopt
use xtb_metadynamic
use xtb_biaspath
use xtb_coffee
use xtb_disp_dftd3param
use xtb_disp_dftd4
use xtb_gfnff_param, only : gff_print
use xtb_gfnff_convert, only : struc_convert
use xtb_scan
use xtb_kopt
implicit none
private
public :: xtbMain
contains
subroutine xtbMain(env, argParser)
!> Source of errors in the main program unit
character(len=*), parameter :: source = "prog_main"
type(TEnvironment), intent(inout) :: env
type(TArgParser), intent(inout) :: argParser
!! ========================================================================
! use some wrapper types to bundle information together
type(TMolecule) :: mol
type(scc_results) :: res
class(TCalculator), allocatable :: calc
type(freq_results) :: fres
type(TRestart) :: chk
type(chrg_parameter) :: chrgeq
! store important names and stuff like that in FORTRAN strings
character(len=:),allocatable :: fname ! geometry input file
character(len=:),allocatable :: xcontrol ! instruction file
character(len=:),allocatable :: xrc ! global instruction file
character(len=:),allocatable :: fnv ! parameter file
character(len=:),allocatable :: tmpname ! temporary string
character(len=:),allocatable :: cdum ! temporary string
character(len=:),allocatable :: extension, basename, directory
integer :: ftype
!! ========================================================================
! default names for important files in xtb
character(len=*),parameter :: p_fname_rc = '.xtbrc'
character(len=*),parameter :: p_fname_param_gfn0 = 'param_gfn0-xtb.txt'
character(len=*),parameter :: p_fname_param_gfn1 = 'param_gfn1-xtb.txt'
character(len=*),parameter :: p_fname_param_gfn2 = 'param_gfn2-xtb.txt'
character(len=*),parameter :: p_fname_param_gfnff = '.param_gfnff.xtb'
character(len=*),parameter :: p_fname_param_ipea = 'param_ipea-xtb.txt'
integer :: gsolvstate
integer :: i,j,k,l,idum
integer :: ich,ictrl,iprop ! file handle
real(wp) :: sigma(3,3)
real(wp),allocatable :: cn (:)
real(wp),allocatable :: sat (:)
real(wp),allocatable :: g (:,:)
real(wp) :: vec3(3)
type(TxTBParameter) :: globpar
real(wp),allocatable :: dcn (:,:,:)
real(wp),allocatable :: dq (:,:,:)
real(wp),allocatable :: dumdumdum (:,:,:)
real(wp),allocatable :: q (:)
real(wp),allocatable :: ql (:)
real(wp),allocatable :: qr (:)
!! ------------------------------------------------------------------------
integer,external :: ncore
!! ------------------------------------------------------------------------
logical :: struc_conversion_done = .false.
!! ========================================================================
! debugging variables for numerical gradient
logical, parameter :: gen_param = .false.
logical, parameter :: debug = .false.
type(TRestart) :: wf0
real(wp),allocatable :: coord(:,:),numg(:,:),gdum(:,:)
real(wp) :: sdum(3,3)
real(wp),parameter :: step = 0.00001_wp, step2 = 0.5_wp/step
real(wp) :: er,el
logical :: coffee ! if debugging gets really though, get a coffee
!! ------------------------------------------------------------------------
! undocumented and unexplainable variables go here
integer :: nFiles, iFile
integer :: rohf,err
real(wp) :: dum5,egap,etot,ipeashift
real(wp) :: zero,t0,t1,w0,w1,acc,etot2,g298
real(wp) :: qmdff_s6,one,two
real(wp) :: ea,ip
real(wp) :: vomega,vfukui
real(wp),allocatable :: f_plus(:), f_minus(:)
type(TRestart) :: wf_p, wf_m
parameter (zero=0.0_wp)
parameter (one =1.0_wp)
parameter (two =2.0_wp)
logical :: ex,okbas
logical :: epr,diff,murks
logical :: exist
logical :: lgrad,restart
logical :: copycontrol
logical :: newreader
logical :: strict
logical :: exitRun
logical :: cold_fusion
! OMP stuff
integer :: TID, OMP_GET_NUM_THREADS, OMP_GET_THREAD_NUM
integer :: nproc
xenv%home = env%xtbhome
xenv%path = env%xtbpath
! ------------------------------------------------------------------------
!> read the command line arguments
call parseArguments(env, argParser, xcontrol, fnv, acc, lgrad, &
& restart, gsolvstate, strict, copycontrol, coffee)
nFiles = argParser%countFiles()
select case(nFiles)
case(0)
if (.not.coffee) then
call env%error("No input file given, so there is nothing to do", source)
else
fname = 'coffee'
end if
case(1:)
do iFile = 1, nFiles-1
call argParser%nextFile(fname)
call env%warning("Input file '"//fname//"' will be ignored", source)
end do
call argParser%nextFile(fname)
end select
if (.not.allocated(xcontrol)) then
if (copycontrol) then
xcontrol = 'xtb.inp'
else
xcontrol = fname
end if
end if
call env%checkpoint("Command line argument parsing failed")
! ------------------------------------------------------------------------
!> read the detailed input file
call rdcontrol(xcontrol, env, copy_file=copycontrol)
call env%checkpoint("Reading '"//xcontrol//"' failed")
! ------------------------------------------------------------------------
!> read dot-Files before reading the rc and after reading the xcontrol
!> Total molecular charge
call open_file(ich,'.CHRG','r')
if (ich.ne.-1) then
call getline(ich,cdum,iostat=err)
if (err /= 0) then
call env%error('.CHRG is empty!', source)
else
call set_chrg(env,cdum)
call close_file(ich)
end if
end if
call env%checkpoint("Reading charge from file failed")
!> Number of unpaired electrons
call open_file(ich,'.UHF','r')
if (ich.ne.-1) then
call getline(ich,cdum,iostat=err)
if (err /= 0) then
call env%error('.UHF is empty!', source)
else
call set_spin(env,cdum)
call close_file(ich)
end if
endif
!> efield read: gfnff only
call open_file(ich,'.EFIELD','r')
if (ich.ne.-1) then
call getline(ich,cdum,iostat=err)
if (err /= 0) then
call env%error('.EFIELD is empty!', source)
else
call set_efield(env,cdum)
call close_file(ich)
end if
endif
call env%checkpoint("Reading multiplicity from file failed")
! ------------------------------------------------------------------------
!> read the xtbrc if you can find it (use rdpath directly instead of xfind)
call rdpath(env%xtbpath, p_fname_rc, xrc, exist)
if (exist) then
call rdcontrol(xrc, env, copy_file=.false.)
call env%checkpoint("Reading '"//xrc//"' failed")
endif
! ------------------------------------------------------------------------
!> FIXME: some settings that are still not automatic
!> Make sure GFN0-xTB uses the correct exttyp
if(gfn_method == 0) call set_exttyp('eht')
!> C6 scaling of QMDFF dispersion to simulate solvent
qmdff_s6 = 1.0_wp
rohf = 1 ! HS default
egap = 0.0_wp
ipeashift = 0.0_wp
! ========================================================================
!> no user interaction up to now, time to show off!
!> print the xtb banner with version number and compilation date
!> making a fancy version of this is hard, x is difficult in ASCII art
call xtb_header(env%unit)
!> make sure you cannot blame us for destroying your computer
call disclamer(env%unit)
!> how to cite this program
call citation(env%unit)
!> print current time
call prdate('S')
! ------------------------------------------------------------------------
!> get molecular structure
if (coffee) then ! it's coffee time
fname = 'caffeine'
call get_coffee(mol)
call generateFileMetaInfo(fname, directory, basename, extension)
else
call generateFileMetaInfo(fname, directory, basename, extension)
ftype = getFileType(basename, extension)
call open_file(ich, fname, 'r')
call readMolecule(env, mol, ich, ftype)
call close_file(ich)
if (mol%struc%two_dimensional) then
call env%warning("Two dimensional input structure detected", source)
end if
! Special CT input file case
if (mol%chrg /= 0.0_wp) then
if (ichrg == 0) then
ichrg = nint(mol%chrg)
else
call env%warning("Charge in sdf/mol input was overwritten", source)
end if
end if
call env%checkpoint("reading geometry input '"//fname//"' failed")
endif
! ------------------------------------------------------------------------
!> initialize the global storage
call init_fix(mol%n)
call init_split(mol%n)
call init_constr(mol%n,mol%at)
call init_scan
call init_walls
call init_pcem
if (runtyp.eq.p_run_bhess) then
call init_bhess(mol%n)
else
call init_metadyn(mol%n,metaset%maxsave)
end if
call load_rmsdbias(rmsdset,mol%n,mol%at,mol%xyz)
! ------------------------------------------------------------------------
!> get some memory
allocate(cn(mol%n),sat(mol%n),g(3,mol%n), source = 0.0_wp)
atmass = atomic_mass(mol%at) * autoamu ! from splitparam.f90
periodic = mol%npbc > 0
if (mol%npbc == 0) then
if (do_cma_trafo) then
allocate(coord(3,mol%n),source=0.0_wp)
call axis3(1,mol%n,mol%at,mol%xyz,coord,vec3)
mol%xyz = coord
deallocate(coord)
endif
endif
do i=1,mol%n
mol%z(i) = mol%at(i) - ncore( mol%at(i) )
! lanthanides without f are treated as La
if(mol%at(i).gt.57.and.mol%at(i).lt.72) mol%z(i)=3
enddo
!> initialize time step for MD if requested autocomplete
if (tstep_md < 0.0_wp) then
tstep_md = (minval(atmass)/(atomic_mass(1)*autoamu))**(1.0_wp/3.0_wp)
endif
mol%chrg = real(ichrg, wp)
mol%uhf = nalphabeta
chk%wfn%nel = idint(sum(mol%z)) - ichrg
chk%wfn%nopen = nalphabeta
if(chk%wfn%nopen == 0 .and. mod(chk%wfn%nel,2) /= 0) chk%wfn%nopen=1
call initrand
call setup_summary(env%unit,mol%n,fname,xcontrol,chk%wfn,xrc,exist)
if(fit) acc=0.2 ! higher SCF accuracy during fit
! ------------------------------------------------------------------------
!> 2D => 3D STRUCTURE CONVERTER
! ------------------------------------------------------------------------
if (mol%struc%two_dimensional) then
call struc_convert (env,restart,mol,chk,egap,etemp,maxscciter, &
& optset%maxoptcycle,etot,g,sigma)
struc_conversion_done = .true.
mol%struc%two_dimensional = .false.
end if
! ------------------------------------------------------------------------
!> CONSTRAINTS & SCANS
!> now we are at a point that we can check for requested constraints
call read_userdata(xcontrol,env,mol)
!> initialize metadynamics
call load_metadynamic(metaset,mol%n,mol%at,mol%xyz)
!> restraining potential
if (allocated(potset%xyz)) then
if (lconstr_all_bonds) call constrain_all_bonds(mol%n,mol%at,potset%xyz)
if (lconstr_all_angles) call constrain_all_angles(mol%n,mol%at,potset%xyz)
if (lconstr_all_torsions) call constrain_all_torsions(mol%n,mol%at,potset%xyz)
call setup_constrain_pot(mol%n,mol%at,potset%xyz)
else
if (lconstr_all_bonds) call constrain_all_bonds(mol%n,mol%at,mol%xyz)
if (lconstr_all_angles) call constrain_all_angles(mol%n,mol%at,mol%xyz)
if (lconstr_all_torsions) call constrain_all_torsions(mol%n,mol%at,mol%xyz)
call setup_constrain_pot(mol%n,mol%at,mol%xyz)
endif
! fragmentation for CMA constrain
if(iatf1.eq.0.and.iatf2.eq.0) then
call ncoord_erf(mol%n,mol%at,mol%xyz,cn)
call splitm(mol%n,mol%at,mol%xyz,cn)
endif
call splitprint(mol%n,mol%at,mol%xyz)
if (verbose) then
call fix_info(env%unit,mol%n,mol%at,mol%xyz)
call pot_info(env%unit,mol%n,mol%at,mol%xyz)
endif
! ------------------------------------------------------------------------
!> write copy of detailed input
if (copycontrol) then
call open_set(ictrl,xcontrol)
call write_set(ictrl)
call close_set(ictrl)
endif
! ------------------------------------------------------------------------
!> if you have requested a define we stop here...
if (define) then
if (verbose) call main_geometry(env%unit,mol)
call eval_define(veryverbose)
endif
call env%show('Please study the warnings concerning your input carefully')
call raise('F', 'Please study the warnings concerning your input carefully')
! ========================================================================
!> From here we switch to the method setup
!> enable error on warnings
if (strict) call mctc_strict
env%strict = strict
!> one last check on the input geometry
call check_cold_fusion(env, mol, cold_fusion)
if (cold_fusion) then
call env%error("XTB REFUSES TO CONTINUE WITH THIS CALCULATION!")
call env%terminate("Some atoms in the start geometry are *very* close")
endif
!> check if someone is still using GFN3...
if (gfn_method.eq.3) then
call env%terminate('This is an internal error, please use gfn_method=2!')
end if
! ------------------------------------------------------------------------
!> Print the method header and select the parameter file
if (.not.allocated(fnv)) then
select case(runtyp)
case default
call env%terminate('This is an internal error, please define your runtypes!')
case(p_run_scc,p_run_grad,p_run_opt,p_run_hess,p_run_ohess,p_run_bhess, &
p_run_md,p_run_omd,p_run_path,p_run_screen, &
p_run_modef,p_run_mdopt,p_run_metaopt)
if (mode_extrun.eq.p_ext_gfnff) then
fnv=xfind(p_fname_param_gfnff)
else
if(gfn_method.eq.0) then
fnv=xfind(p_fname_param_gfn0)
endif
if(gfn_method.eq.1) then
fnv=xfind(p_fname_param_gfn1)
endif
if(gfn_method.eq.2) then
fnv=xfind(p_fname_param_gfn2)
endif
end if
case(p_run_vip,p_run_vea,p_run_vipea,p_run_vfukui,p_run_vomega)
if(gfn_method.eq.0) then
fnv=xfind(p_fname_param_gfn0)
endif
if(gfn_method.eq.1) then
fnv=xfind(p_fname_param_ipea)
endif
if(gfn_method.eq.2) then
fnv=xfind(p_fname_param_gfn2)
endif
end select
endif
! ------------------------------------------------------------------------
!> Obtain the parameter data
call newCalculator(env, mol, calc, fnv, restart, acc)
call env%checkpoint("Could not setup parameterisation")
call initDefaults(env, calc, mol, gsolvstate)
call env%checkpoint("Could not setup defaults")
! ------------------------------------------------------------------------
!> initial guess, setup wavefunction
select type(calc)
type is(TxTBCalculator)
call chk%wfn%allocate(mol%n,calc%basis%nshell,calc%basis%nao)
!> EN charges and CN
if (gfn_method.lt.2) then
call ncoord_d3(mol%n,mol%at,mol%xyz,cn)
else
call ncoord_gfn(mol%n,mol%at,mol%xyz,cn)
endif
if (mol%npbc > 0) then
chk%wfn%q = real(ichrg,wp)/real(mol%n,wp)
else
if (guess_charges.eq.p_guess_gasteiger) then
call iniqcn(mol%n,chk%wfn%nel,mol%at,mol%z,mol%xyz,ichrg,1.0_wp,chk%wfn%q,cn,gfn_method,.true.)
else if (guess_charges.eq.p_guess_goedecker) then
call ncoord_erf(mol%n,mol%at,mol%xyz,cn)
call goedecker_chrgeq(mol%n,mol%at,mol%xyz,real(ichrg,wp),cn,dcn,chk%wfn%q,dq,er,g,&
.false.,.false.,.false.)
else
call ncoord_gfn(mol%n,mol%at,mol%xyz,cn)
chk%wfn%q = real(ichrg,wp)/real(mol%n,wp)
end if
end if
!> initialize shell charges from gasteiger charges
call iniqshell(calc%xtbData,mol%n,mol%at,mol%z,calc%basis%nshell,chk%wfn%q,chk%wfn%qsh,gfn_method)
end select
! ------------------------------------------------------------------------
!> printout a header for the exttyp
call calc%writeInfo(env%unit, mol)
select case(mode_extrun)
case(p_ext_qmdff)
call ff_ini(mol%n,mol%at,mol%xyz,cn,qmdff_s6)
case(p_ext_orca)
call checkOrca(env)
case(p_ext_mopac)
call checkMopac(env)
end select
call delete_file('.sccnotconverged')
call env%checkpoint("Setup for calculation failed")
select type(calc)
type is(TxTBCalculator)
if (restart.and.calc%xtbData%level /= 0) then ! only in first run
call readRestart(env,chk%wfn,'xtbrestart',mol%n,mol%at,gfn_method,exist,.true.)
endif
calc%etemp = etemp
calc%maxiter = maxscciter
ipeashift = calc%xtbData%ipeashift
end select
! ========================================================================
!> the SP energy which is always done
call start_timing(2)
call singlepoint &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,2,exist,lgrad,acc,etot,g,sigma,res)
call stop_timing(2)
select type(calc)
type is(TGFFCalculator)
gff_print=.false.
end select
call env%checkpoint("Single point calculation terminated")
!> write 2d => 3d converted structure
if (struc_conversion_done) then
call generateFileName(tmpname, 'gfnff_convert', extension, mol%ftype)
write(env%unit,'(10x,a,1x,a,/)') &
"converted geometry written to:",tmpname
call open_file(ich,tmpname,'w')
call writeMolecule(mol, ich, energy=res%e_total, gnorm=res%gnorm)
call close_file(ich)
end if
! ========================================================================
!> determine kopt for bhess including final biased geometry optimization
if (runtyp.eq.p_run_bhess) then
call set_metadynamic(metaset,mol%n,mol%at,mol%xyz)
call get_kopt (metaset,env,restart,mol,chk,calc,egap,etemp,maxscciter, &
& optset%maxoptcycle,optset%optlev,etot,g,sigma,acc)
end if
! ------------------------------------------------------------------------
!> numerical gradient for debugging purposes
if (debug) then
! generate a warning to keep release versions from calculating numerical gradients
call env%warning('XTB IS CALCULATING NUMERICAL GRADIENTS, RESET DEBUG FOR RELEASE!')
print'(/,"analytical gradient")'
print *, g
allocate( coord(3,mol%n), source = mol%xyz )
allocate( numg(3,mol%n),gdum(3,mol%n), source = 0.0_wp )
wf0 = chk
do i = 1, mol%n
do j = 1, 3
mol%xyz(j,i) = mol%xyz(j,i) + step
chk = wf0
call singlepoint &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,0,.true.,.true.,acc,er,gdum,sdum,res)
mol%xyz(j,i) = mol%xyz(j,i) - 2*step
chk = wf0
call singlepoint &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,0,.true.,.true.,acc,el,gdum,sdum,res)
mol%xyz(j,i) = mol%xyz(j,i) + step
numg(j,i) = step2 * (er - el)
enddo
enddo
print'(/,"numerical gradient")'
print *, numg
print'(/,"difference gradient")'
print*,g-numg
endif
! ------------------------------------------------------------------------
! ANCopt
if ((runtyp.eq.p_run_opt).or.(runtyp.eq.p_run_ohess).or. &
& (runtyp.eq.p_run_omd).or.(runtyp.eq.p_run_screen).or. &
& (runtyp.eq.p_run_metaopt)) then
if (opt_engine.eq.p_engine_rf) &
call ancopt_header(env%unit,veryverbose)
call start_timing(3)
call geometry_optimization &
& (env, mol,chk,calc, &
& egap,etemp,maxscciter,optset%maxoptcycle,etot,g,sigma,optset%optlev,.true.,.false.,murks)
res%e_total = etot
res%gnorm = norm2(g)
if (nscan.gt.0) then
call relaxed_scan(env,mol,chk,calc)
endif
if (murks) then
call generateFileName(tmpname, 'xtblast', extension, mol%ftype)
write(env%unit,'(/,a,1x,a,/)') &
"last geometry written to:",tmpname
call open_file(ich,tmpname,'w')
call writeMolecule(mol, ich, energy=res%e_total, gnorm=res%gnorm)
call close_file(ich)
call env%terminate("Geometry optimization failed")
end if
call stop_timing(3)
endif
! ------------------------------------------------------------------------
!> automatic VIP and VEA single point (maybe after optimization)
if (runtyp.eq.p_run_vip.or.runtyp.eq.p_run_vipea &
& .or.runtyp.eq.p_run_vomega) then
call start_timing(2)
call vip_header(env%unit)
chk%wfn%nel = chk%wfn%nel-1
if (mod(chk%wfn%nel,2).ne.0) chk%wfn%nopen = 1
call singlepoint &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,2,.true.,.false.,acc,etot2,g,sigma,res)
ip=etot2-etot-ipeashift
write(env%unit,'(72("-"))')
write(env%unit,'("empirical IP shift (eV):",f10.4)') &
& autoev*ipeashift
write(env%unit,'("delta SCC IP (eV):",f10.4)') autoev*ip
write(env%unit,'(72("-"))')
chk%wfn%nel = chk%wfn%nel+1
call stop_timing(2)
endif
if (runtyp.eq.p_run_vea.or.runtyp.eq.p_run_vipea &
& .or.runtyp.eq.p_run_vomega) then
call start_timing(2)
call vea_header(env%unit)
chk%wfn%nel = chk%wfn%nel+1
if (mod(chk%wfn%nel,2).ne.0) chk%wfn%nopen = 1
call singlepoint &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,2,.true.,.false.,acc,etot2,g,sigma,res)
ea=etot-etot2-ipeashift
write(env%unit,'(72("-"))')
write(env%unit,'("empirical EA shift (eV):",f10.4)') &
& autoev*ipeashift
write(env%unit,'("delta SCC EA (eV):",f10.4)') autoev*ea
write(env%unit,'(72("-"))')
chk%wfn%nel = chk%wfn%nel-1
call stop_timing(2)
endif
! ------------------------------------------------------------------------
!> vomega (electrophilicity) index
if (runtyp.eq.p_run_vomega) then
write(env%unit,'(a)')
write(env%unit,'(72("-"))')
write(env%unit,'(a,1x,a)') &
"Calculation of global electrophilicity index",&
"(IP+EA)²/(8·(IP-EA))"
vomega=(ip+ea)**2/(8*(ip-ea))
write(env%unit,'("Global electrophilicity index (eV):",f10.4)') &
autoev*vomega
write(env%unit,'(72("-"))')
endif
! ------------------------------------------------------------------------
!> Fukui Index from Mulliken population analysis
if (runtyp.eq.p_run_vfukui) then
allocate(f_plus(mol%n),f_minus(mol%n))
write(env%unit,'(a)')
write(env%unit,'("Fukui index Calculation")')
wf_p%wfn=chk%wfn
wf_m%wfn=chk%wfn
wf_p%wfn%nel = wf_p%wfn%nel+1
if (mod(wf_p%wfn%nel,2).ne.0) wf_p%wfn%nopen = 1
call singlepoint &
& (env,mol,wf_p,calc, &
& egap,etemp,maxscciter,1,.true.,.false.,acc,etot2,g,sigma,res)
f_plus=wf_p%wfn%q-chk%wfn%q
wf_m%wfn%nel = wf_m%wfn%nel-1
if (mod(wf_m%wfn%nel,2).ne.0) wf_m%wfn%nopen = 1
call singlepoint &
& (env,mol,wf_m,calc, &
& egap,etemp,maxscciter,1,.true.,.false.,acc,etot2,g,sigma,res)
f_minus=chk%wfn%q-wf_m%wfn%q
write(env%unit,'(a)')
write(env%unit, '(1x," # f(+) f(-) f(0)")')
do i=1,mol%n
write(env%unit,'(i6,a4,2f9.3,2f9.3,2f9.3)') i, mol%sym(i), f_plus(i), f_minus(i), 0.5d0*(wf_p%wfn%q(i)-wf_m%wfn%q(i))
enddo
deallocate(f_plus,f_minus)
endif
! ------------------------------------------------------------------------
!> numerical hessian calculation
if ((runtyp.eq.p_run_hess).or.(runtyp.eq.p_run_ohess).or.(runtyp.eq.p_run_bhess)) then
if (runtyp.eq.p_run_bhess) then
call generic_header(env%unit,"Biased Numerical Hessian",49,10)
else
call numhess_header(env%unit)
end if
if (mol%npbc > 0) then
call env%error("Phonon calculations under PBC are not implemented", source)
endif
call start_timing(5)
call numhess &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,etot,g,sigma,fres)
call stop_timing(5)
call env%checkpoint("Hessian calculation terminated")
endif
! reset the gap, since it is currently not updated in ancopt and numhess
if (allocated(chk%wfn%emo)) then
res%hl_gap = chk%wfn%emo(chk%wfn%ihomo+1)-chk%wfn%emo(chk%wfn%ihomo)
end if
call env%checkpoint("Calculation terminated")
! ========================================================================
!> PRINTOUT SECTION
if (allocated(property_file)) then
call open_file(iprop,property_file,'w')
if (iprop.eq.-1) then
iprop = env%unit
deallocate(property_file)
else
write(env%unit,'(/,a)') "Property printout bound to '"//property_file//"'"
if (allocated(cdum)) deallocate(cdum)
call get_command(length=l)
allocate( character(len=l) :: cdum )
call get_command(cdum)
write(iprop,'("command: ''",a,"''")') cdum
call rdvar('HOSTNAME',cdum,err)
if (err.eq.0) &
write(iprop,'("hostname: ''",a,"''")') cdum
write(iprop,'("date: ",a)') prtimestring('S')
endif
else
iprop = env%unit
endif
call generic_header(iprop,'Property Printout',49,10)
if (lgrad) then
call writeResultsTurbomole(mol, energy=etot, gradient=g, sigma=sigma)
if (allocated(basename)) then
cdum = basename // '.engrad'
else
cdum = 'xtb-orca.engrad'
end if
call open_file(ich, cdum, 'w')
call writeResultsOrca(ich, mol, etot, g)
call close_file(ich)
end if
if (mol%ftype .eq. fileType%gaussian) then
if (allocated(basename)) then
cdum = basename // '.EOu'
else
cdum = 'xtb-gaussian.EOu'
end if
call open_file(ich, cdum, 'w')
call writeResultsGaussianExternal(ich, etot, res%dipole, g)
call close_file(ich)
end if
if(periodic)then
write(*,*)'Periodic properties'
else
select type(calc)
type is(TxTBCalculator)
call main_property(iprop,env,mol,chk%wfn,calc%basis,calc%xtbData,res, &
& calc%solvation,acc)
call main_cube(verbose,mol,chk%wfn,calc%basis,res)
end select
endif
if (pr_json) then
select type(calc)
type is(TxTBCalculator)
call open_file(ich,'xtbout.json','w')
call main_json(ich, &
mol,chk%wfn,calc%basis,res,fres)
call close_file(ich)
end select
endif
if ((runtyp.eq.p_run_opt).or.(runtyp.eq.p_run_ohess).or. &
(runtyp.eq.p_run_omd).or.(runtyp.eq.p_run_screen).or. &
(runtyp.eq.p_run_metaopt).or.(runtyp.eq.p_run_bhess)) then
call main_geometry(iprop,mol)
endif
if ((runtyp.eq.p_run_hess).or.(runtyp.eq.p_run_ohess).or.(runtyp.eq.p_run_bhess)) then
call generic_header(iprop,'Frequency Printout',49,10)
call main_freq(iprop,mol,chk%wfn,fres)
endif
if (allocated(property_file)) then
if (iprop.ne.-1 .and. iprop.ne.env%unit) then
call write_energy(iprop,res,fres, &
& (runtyp.eq.p_run_hess).or.(runtyp.eq.p_run_ohess).or.(runtyp.eq.p_run_bhess))
call close_file(iprop)
endif
endif
if ((runtyp.eq.p_run_opt).or.(runtyp.eq.p_run_ohess).or. &
(runtyp.eq.p_run_omd).or.(runtyp.eq.p_run_screen).or. &
(runtyp.eq.p_run_metaopt).or.(runtyp.eq.p_run_bhess)) then
call generateFileName(tmpname, 'xtbopt', extension, mol%ftype)
write(env%unit,'(/,a,1x,a,/)') &
"optimized geometry written to:",tmpname
call open_file(ich,tmpname,'w')
call writeMolecule(mol, ich, energy=res%e_total, gnorm=res%gnorm)
call close_file(ich)
endif
select type(calc)
type is(TxTBCalculator)
call write_energy(env%unit,res,fres, &
& (runtyp.eq.p_run_hess).or.(runtyp.eq.p_run_ohess).or.(runtyp.eq.p_run_bhess))
type is(TGFFCalculator)
call write_energy_gff(env%unit,res,fres, &
& (runtyp.eq.p_run_hess).or.(runtyp.eq.p_run_ohess).or.(runtyp.eq.p_run_bhess))
end select
! ------------------------------------------------------------------------
! xtb molecular dynamics
if ((runtyp.eq.p_run_md).or.(runtyp.eq.p_run_omd)) then
if (metaset%maxsave .gt. 0) then
if (mol%npbc > 0) then
call env%error("Metadynamic under PBC is not implemented", source)
endif
call metadyn_header(env%unit)
else
call md_header(env%unit)
endif
fixset%n = 0 ! no fixing for MD runs
call start_timing(6)
idum = 0
select type(calc)
class default
if (shake_md) call init_shake(mol%n,mol%at,mol%xyz,chk%wfn%wbo)
type is(TGFFCalculator)
if (shake_md) call gff_init_shake(mol%n,mol%at,mol%xyz,calc%topo)
end select
call md &
& (env,mol,chk,calc, &
& egap,etemp,maxscciter,etot,g,sigma,0,temp_md,idum)
call stop_timing(6)
endif
! ------------------------------------------------------------------------
! metadynamics
if (runtyp.eq.p_run_metaopt) then
if (mol%npbc > 0) then
call env%warning("Metadynamic under PBC is not implemented", source)
endif
call metadyn_header(env%unit)
! check if ANCOPT already convered
if (murks) then
call env%error('Optimization did not converge, aborting', source)
endif
write(env%unit,'(1x,"output written to xtbmeta.log")')
call open_file(ich,'xtbmeta.log','w')
call writeMolecule(mol, ich, fileType%xyz, energy=etot, gnorm=norm2(g))
k = metaset%nstruc+1
call start_timing(6)
do l = k, metaset%maxsave
metaset%nstruc = l
metaset%xyz(:,:,metaset%nstruc) = mol%xyz
! randomize structure to avoid zero RMSD
do i = 1, mol%n
do j = 1, 3
call random_number(er)
mol%xyz(j,i) = mol%xyz(j,i) + 1.0e-6_wp*er
enddo
enddo
call geometry_optimization &
& (env, mol,chk,calc, &
& egap,etemp,maxscciter,optset%maxoptcycle,etot,g,sigma,optset%optlev,verbose,.true.,murks)
if (.not.verbose) then
write(env%unit,'("current energy:",1x,f20.8)') etot
endif
if (murks) then
call close_file(ich)
write(env%unit,'(/,3x,"***",1x,a,1x,"***",/)') &
"FAILED TO CONVERGE GEOMETRY OPTIMIZATION"
call touch_file('NOT_CONVERGED')
endif
call writeMolecule(mol, ich, fileType%xyz, energy=etot, gnorm=norm2(g))
enddo
call close_file(ich)
call stop_timing(6)
endif
! ------------------------------------------------------------------------
! path finder
if (runtyp.eq.p_run_path) then
call rmsdpath_header(env%unit)
if (mol%npbc > 0) then
call env%warning("Metadynamics under PBC are not implemented", source)
endif
call start_timing(4)
call bias_path(env,mol,chk,calc,egap,etemp,maxscciter,etot,g,sigma)
call stop_timing(4)
endif
! ------------------------------------------------------------------------
! screen over input structures
if (runtyp.eq.p_run_screen) then
call start_timing(8)
call screen(env,mol,chk,calc,egap,etemp,maxscciter,etot,g,sigma)
call stop_timing(8)
endif
! ------------------------------------------------------------------------
! mode following for conformer search
if (runtyp.eq.p_run_modef) then
if (mol%npbc > 0) then
call env%warning("Modefollowing under PBC is not implemented", source)
endif
call start_timing(9)
call modefollow(env,mol,chk,calc,egap,etemp,maxscciter,etot,g,sigma)
call stop_timing(9)
endif
! ------------------------------------------------------------------------
! optimize along MD from xtb.trj for conformer searches
if (runtyp.eq.p_run_mdopt) then
call start_timing(10)