Example: Constrained optimizations

Download constraints.run

#!/bin/sh

# This example demonstrates the setup of all different types of constraints.
# Note that all constraints types can be combined with each other, as long as
# the resulting set of constraints actually makes sense. (It must of course be
# possible to satisfy all of them at the same time. AMS is not able to check
# that and you might get really surprising results if that is not the case ...)


# 1. Angle constraints
# ====================

AMS_JOBNAME=angle $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
          O   0.001356   0.000999   0.000000
          H   0.994442  -0.037855   0.000000
          H  -0.298554   0.948531   0.000000
       End
   End

   Constraints
     # Fix the H--O--H angle to 125 degrees.
     Angle  3 1 2 125.0
   End

   Engine DFTB
       ResourcesDir Dresden
       DispersionCorrection Auto
   EndEngine

EOF


# 2. Distance constraints
# =======================

AMS_JOBNAME=dist $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
          O   0.001356   0.000999   0.000000
          H   0.994442  -0.037855   0.000000
          H  -0.298554   0.948531   0.000000
       End
   End

   Constraints
      # Fix the O--H bond distances to 1.03 Angstrom.
      Distance  1 2 1.03
      Distance  1 3 1.03
   End

   Engine DFTB
       ResourcesDir Dresden
       DispersionCorrection Auto
   EndEngine

EOF


# 3. Dihedral angle constraint
# ============================

AMS_JOBNAME=dihed $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
          C   -0.004115   -0.000021    0.000023
          C    1.535711    0.000022    0.000008
          H   -0.399693    1.027812   -0.000082
          H   -0.399745   -0.513934    0.890139
          H   -0.399612   -0.513952   -0.890156
          H    1.931188    0.514066    0.890140
          H    1.931432    0.513819   -0.890121
          H    1.931281   -1.027824    0.000244
       End
   End

   Constraints
      # Fix the dihedral angle H(6)--C(2)--C(1)--H(3) to 20 degrees.
      Dihedral  6 2 1 3 20.00
   End

   Engine DFTB
       ResourcesDir Dresden
       DispersionCorrection Auto
   EndEngine

EOF


# 4. Fixed atom constraint
# ========================

AMS_JOBNAME=atom $ADFBIN/ams << EOF

   Task GeometryOptimization

   GeometryOptimization
      Convergence Energy=1.0e-6 Gradients=1.0e-4 Step=1.0e-3
      CoordinateType Cartesian
   End

   System
      Atoms
         C   -0.2460249052   -1.70363153     0.0005128649944
         O    1.152833576    -1.81594932    -0.0004409224206
         C    1.489235475     0.61782051    10.0004771689226
         O    0.5700116914    0.627761615   10.0005491194077
      End
   End

   Constraints
      # Fix atom 1 and 2 at their initial positions.
      Atom 1
      Atom 2
   End

   Engine DFTB
      ResourcesDir DFTB.org/mio-1-1
   EndEngine

EOF


# 5. Fixed coordinate constraint
# ==============================

AMS_JOBNAME=coord $ADFBIN/ams << EOF

   Task GeometryOptimization

   GeometryOptimization
      Convergence Energy=1.0e-6 Gradients=1.0e-4 Step=1.0e-3
      CoordinateType Cartesian
   End

   System
      Atoms
         C   -0.2460249052   -1.70363153     0.0005128649944
         O    1.152833576    -1.81594932    -0.0004409224206
         C    1.489235475     0.61782051    10.0004771689226
         O    0.5700116914    0.627761615   10.0005491194077
      End
   End

   Constraints
      # Fix the x-coordinate of all atoms.
      Coordinate 1 x
      Coordinate 2 x
      Coordinate 3 x
      Coordinate 4 x
   End

   Engine DFTB
      ResourcesDir DFTB.org/mio-1-1
   EndEngine

EOF


# 6. Fixed atom constraint (in periodic system)
# =============================================

AMS_JOBNAME=pbcatom $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
           C  -1.23  -0.710140830   0.0
           C  -1.23  -0.710140830   3.8
           C   0.0    0.0           0.4
           C   0.0   -1.42028166    3.355
       End

       Lattice
           1.23  -2.130422493309719  0.0
           1.23   2.130422493309719  0.0
       End
   End
   
   Constraints
      # Fix atom 1 and 3 at their initial positions.
      Atom 1
      Atom 3
   End

   Engine DFTB
      ResourcesDir DFTB.org/mio-1-1
      KSpace Quality=GammaOnly
   EndEngine

EOF


# 7. Block constraints (with listing the atoms in a block)
# ========================================================

AMS_JOBNAME=block_list $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
           C   0.5584839616765542   0.5023705181144142  -0.4625483159356394
           C   1.07173137896726     0.2125484528111251  -1.892767990599312
           C   1.699248504588085   -1.006061067555322   -2.191856791501442
           C   2.242484629452111   -1.236470028363516   -3.455616615521399
           C   2.18874580207099    -0.2444337131062739  -4.435483595049287
           C   1.604409798904145    0.9866950282217637  -4.135465239465763
           C   1.061086793296828    1.217355116664161   -2.871773146851866
           H   1.763625603740592   -1.780903563899969   -1.431707209662057
           H   2.716038261390732   -2.190869049673275   -3.672115451399807
           H   2.611833078693977   -0.4241619800888815  -5.420308290235123
           H   1.578029796368043    1.774138556616255   -4.884624561698751
           H   0.6247213391616491   2.187200330357715   -2.64521108544713
           C   1.303528070245188   -0.1416812092038768   0.7303699949711653
           C   0.8164830922475474  -1.314631142230651    1.326337082260565
           C   1.531799364672407   -1.947399963062604    2.342825210379356
           C   2.757684862125068   -1.432061688813837    2.765634667957531
           C   3.271640455523863   -0.2897364031184506   2.150731553729188
           C   2.556535912403799    0.3432056352653093   1.134221563049466
           H  -0.128925843064934   -1.7366201913903      0.9939642396630857
           H   1.133600273086767   -2.849990046242235    2.799740694330775
           H   3.31486005979636    -1.925049398411132    3.557912279830031
           H   4.236604921323707    0.1064455961800578   2.457138367063388
           H   2.976510069814392    1.222131876866508    0.6510413538003352
           C  -0.930165749820548    0.9153412637395284  -0.5420710991631585
           C  -1.791729737216814    0.6892660986048864   0.5418285200469819
           C  -3.111373625199894    1.139542032267652    0.5090625363459357
           C  -3.586568528476239    1.843983986018719   -0.5977864609101087
           C  -2.726152821786783    2.111108432452229   -1.663369105880468
           C  -1.406454626777386    1.660929752085611   -1.63085383469072
           H  -1.428888457076976    0.1571120160719108   1.417905619994904
           H  -3.76723983501283     0.9462006794587581   1.35432032282366
           H  -4.614972346570283    2.194578435055282   -0.6233521468909432
           H  -3.080200905921361    2.678981846821393   -2.520207901691867
           H  -0.7413545301831963   1.891248563160919   -2.459672151335554
           C   1.235557647765805    1.735720249011045    0.1803884343948648
           C   1.377191890012647    1.826646222422494    1.573181692925026
           C   1.905898822116255    2.975086608901246    2.16214311213053
           C   2.280792642899383    4.061906342938987    1.371311861877147
           C   2.105006642447361    3.998471351380415   -0.0115253875199488
           C   1.576317094651283    2.850163227898022   -0.6007264381779673
           H   1.072424817958776    0.9937816064904853   2.202306496283991
           H   2.017471491684088    3.023369029562452    3.242524256706377
           H   2.693031233132915    4.956641734238467    1.830324484771476
           H   2.372569859099136    4.8485771293401     -0.6342066225733602
           H   1.427765851939196    2.820397327218896   -1.677480576376967
       End
   End

   GeometryOptimization
       Convergence
           Energy 1.0e-6
           Gradients 1.0e-4
           Step 1.0e-4
       End
   End

   Constraints
      # Create blocks from the 4 phenyl groups by specifying the atom indices
      # explicitly. (The indices follow the order in the System%Atoms block,
      # where we happen to have the atoms belonging to the different phenyl
      # groups consecutive.)
      BlockAtoms  2  3  4  5  6  7  8  9 10 11 12
      BlockAtoms 13 14 15 16 17 18 19 20 21 22 23
      BlockAtoms 24 25 26 27 28 29 30 31 32 33 34
      BlockAtoms 35 36 37 38 39 40 41 42 43 44 45
   End

   Engine DFTB
       Model DFTB3
       ResourcesDir DFTB.org/3ob-3-1
       DispersionCorrection D3-BJ
   EndEngine

EOF


# 8. Block constraints (with named blocks)
# ========================================

AMS_JOBNAME=block_names $ADFBIN/ams << EOF

   Task GeometryOptimization

   System
       Atoms
           C           0.5584839616765542   0.5023705181144142  -0.4625483159356394
           C.phenyl1   1.07173137896726     0.2125484528111251  -1.892767990599312
           C.phenyl1   1.699248504588085   -1.006061067555322   -2.191856791501442
           C.phenyl1   2.242484629452111   -1.236470028363516   -3.455616615521399
           C.phenyl1   2.18874580207099    -0.2444337131062739  -4.435483595049287
           C.phenyl1   1.604409798904145    0.9866950282217637  -4.135465239465763
           C.phenyl1   1.061086793296828    1.217355116664161   -2.871773146851866
           H.phenyl1   1.763625603740592   -1.780903563899969   -1.431707209662057
           H.phenyl1   2.716038261390732   -2.190869049673275   -3.672115451399807
           H.phenyl1   2.611833078693977   -0.4241619800888815  -5.420308290235123
           H.phenyl1   1.578029796368043    1.774138556616255   -4.884624561698751
           H.phenyl1   0.6247213391616491   2.187200330357715   -2.64521108544713
           C.phenyl2   1.303528070245188   -0.1416812092038768   0.7303699949711653
           C.phenyl2   0.8164830922475474  -1.314631142230651    1.326337082260565
           C.phenyl2   1.531799364672407   -1.947399963062604    2.342825210379356
           C.phenyl2   2.757684862125068   -1.432061688813837    2.765634667957531
           C.phenyl2   3.271640455523863   -0.2897364031184506   2.150731553729188
           C.phenyl2   2.556535912403799    0.3432056352653093   1.134221563049466
           H.phenyl2  -0.128925843064934   -1.7366201913903      0.9939642396630857
           H.phenyl2   1.133600273086767   -2.849990046242235    2.799740694330775
           H.phenyl2   3.31486005979636    -1.925049398411132    3.557912279830031
           H.phenyl2   4.236604921323707    0.1064455961800578   2.457138367063388
           H.phenyl2   2.976510069814392    1.222131876866508    0.6510413538003352
           C.phenyl3  -0.930165749820548    0.9153412637395284  -0.5420710991631585
           C.phenyl3  -1.791729737216814    0.6892660986048864   0.5418285200469819
           C.phenyl3  -3.111373625199894    1.139542032267652    0.5090625363459357
           C.phenyl3  -3.586568528476239    1.843983986018719   -0.5977864609101087
           C.phenyl3  -2.726152821786783    2.111108432452229   -1.663369105880468
           C.phenyl3  -1.406454626777386    1.660929752085611   -1.63085383469072
           H.phenyl3  -1.428888457076976    0.1571120160719108   1.417905619994904
           H.phenyl3  -3.76723983501283     0.9462006794587581   1.35432032282366
           H.phenyl3  -4.614972346570283    2.194578435055282   -0.6233521468909432
           H.phenyl3  -3.080200905921361    2.678981846821393   -2.520207901691867
           H.phenyl3  -0.7413545301831963   1.891248563160919   -2.459672151335554
           C.phenyl4   1.235557647765805    1.735720249011045    0.1803884343948648
           C.phenyl4   1.377191890012647    1.826646222422494    1.573181692925026
           C.phenyl4   1.905898822116255    2.975086608901246    2.16214311213053
           C.phenyl4   2.280792642899383    4.061906342938987    1.371311861877147
           C.phenyl4   2.105006642447361    3.998471351380415   -0.0115253875199488
           C.phenyl4   1.576317094651283    2.850163227898022   -0.6007264381779673
           H.phenyl4   1.072424817958776    0.9937816064904853   2.202306496283991
           H.phenyl4   2.017471491684088    3.023369029562452    3.242524256706377
           H.phenyl4   2.693031233132915    4.956641734238467    1.830324484771476
           H.phenyl4   2.372569859099136    4.8485771293401     -0.6342066225733602
           H.phenyl4   1.427765851939196    2.820397327218896   -1.677480576376967
           #  ^---- Element symbols augmented with a tag that we will use in the Constraints block
       End
   End

   GeometryOptimization
       Convergence
           Energy 1.0e-6
           Gradients 1.0e-4
           Step 1.0e-4
       End
   End

   Constraints
      # Use the tag from System%Atoms to set up the block constraints.
      Block phenyl1
      Block phenyl2
      Block phenyl3
      Block phenyl4
   End

   Engine DFTB
       Model DFTB3
       ResourcesDir DFTB.org/3ob-3-1
       DispersionCorrection D3-BJ
   EndEngine

EOF