Example: GO with constraints

Download test_constraints.py

#!/usr/bin/env amspython

from scm.bert import check_output
from scm.plams import AMSJob, AMSResults

# 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 ...)


def check_results(results: AMSResults):
    assert results.ok(), results.get_errormsg()
    assert check_output(results, NLines=(2, "Total Energy (hartree)"))
    assert check_output(
        results,
        From="Total Gradients (hartree/bohr)",
        To="Total Gradients (eV/angstrom)",
        filter_options=("$ERROR 1.0e-3",),
    )
    assert check_output(
        results,
        From="Mulliken Charges",
        ToRE=r"^\s*$",
        filter_options=("$ERROR 1.0e-3",),
    )


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


def test_angle_constraints():
    results = AMSJob.from_input(
        """

           Task GeometryOptimization

           GeometryOptimization
              Convergence Step=1.0e-3
           End

           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
               Model SCC-DFTB
               ResourcesDir Dresden
               DispersionCorrection Auto
           EndEngine

        """,
        name="angle",
    ).run()

    check_results(results)


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


def test_distance_constraints():
    results = AMSJob.from_input(
        """

           Task GeometryOptimization

           GeometryOptimization
              Convergence Step=1.0e-3
           End

           System
               Atoms
                  O   0.001356   0.000999   0.000000
                  H   0.994442  -0.037855   0.000000
                  H  -0.298554   0.948531   0.000000
               End
               BondOrders
                  1 2 1.0
                  1 3 1.0
               End
           End
           Constraints
              # Fix the OH bond distances to 1.03 Angstrom, for which bonds need to be defined in the System block
              All bonds O H to 1.03
              # Alternatively you can list the distances one by one as follows
              # Distance  1 2 1.03
              # Distance  1 3 1.03
           End

           Engine DFTB
               Model SCC-DFTB
               ResourcesDir Dresden
               DispersionCorrection Auto
           EndEngine

        """,
        name="dist",
    ).run()

    check_results(results)


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


def test_dihedral_angle_constraint():
    results = AMSJob.from_input(
        """

           Task GeometryOptimization

           GeometryOptimization
              Convergence Step=1.0e-3
           End

           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
               Model SCC-DFTB
               ResourcesDir Dresden
               DispersionCorrection Auto
           EndEngine

        """,
        name="dihed",
    ).run()

    check_results(results)


# 4a. Fixed atom constraint (Atoms keyword)
# =========================================


def test_fixed_atom_constraint_atoms_keyword():
    results = AMSJob.from_input(
        """

           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
              Model SCC-DFTB
              ResourcesDir DFTB.org/mio-1-1
           EndEngine

        """,
        name="atom",
    ).run()

    check_results(results)


# 4b. Fixed atom constraint (AtomList keyword)
# ============================================


def test_fixed_atom_constraint_atomlist_keyword():
    results = AMSJob.from_input(
        """

           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.
              AtomList 1:2
           End

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

        """,
        name="atomlist",
    ).run()

    check_results(results)


# 4c. Fixed atom constraint (FixedRegion keyword)
# ===============================================


def test_fixed_atom_constraint_fixed_region_keyword():
    results = AMSJob.from_input(
        """

           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    region=fixed
                 O    1.152833576    -1.81594932    -0.0004409224206    region=fixed
                 C    1.489235475     0.61782051    10.0004771689226
                 O    0.5700116914    0.627761615   10.0005491194077
              End
           End

           Constraints
              # Fix all atoms in region "fixed"
              FixedRegion fixed
           End

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

        """,
        name="region",
    ).run()

    check_results(results)


# 4d. Fixed atom constraint (overlapping combination)
# ===================================================


def test_fixed_atom_constraint_overlapping_combination():
    results = AMSJob.from_input(
        """

           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    region=fixed
                 O    1.152833576    -1.81594932    -0.0004409224206    region=fixed
                 C    1.489235475     0.61782051    10.0004771689226
                 O    0.5700116914    0.627761615   10.0005491194077
              End
           End

           Constraints
              Atom 1
              AtomList 1 2
              FixedRegion fixed
           End

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

        """,
        name="combination",
    ).run()

    check_results(results)


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


def test_fixed_coordinate_constraint():
    results = AMSJob.from_input(
        """

           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
              Model SCC-DFTB
              ResourcesDir DFTB.org/mio-1-1
           EndEngine

        """,
        name="coord",
    ).run()

    check_results(results)


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


def test_fixed_atom_constraint_in_periodic_system():
    results = AMSJob.from_input(
        """

           Task GeometryOptimization

           GeometryOptimization
              Convergence Step=1.0e-3
           End

           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
              Model SCC-DFTB
              ResourcesDir DFTB.org/mio-1-1
              KSpace Quality=GammaOnly
           EndEngine

        """,
        name="pbcatom",
    ).run()

    check_results(results)


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


def test_block_constraints_with_explicit_atom_lists():
    results = AMSJob.from_input(
        """

           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
               CoordinateType Delocalized
           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

        """,
        name="block_list",
    ).run()

    check_results(results)


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


def test_block_constraints_with_named_blocks():
    results = AMSJob.from_input(
        """

           Task GeometryOptimization

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

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

           Constraints
              # Use the region 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

        """,
        name="block_names",
    ).run()

    check_results(results)


# 9. Frozen strain components
# ===========================


def test_frozen_strain_components():
    results = AMSJob.from_input(
        """

        Task GeometryOptimization

        GeometryOptimization
            OptimizeLattice Yes
            Convergence Step=1.0e-3
        End

        Constraints
           # Keeps first two lattice vectors orthogonal to the third.  Also fixes the
           # length of the third vector, keeping the graphene layer compressed.
           FreezeStrain xz yz zz
        End

        System
            Atoms
                C 1.332002504889882e-05 -0.0005830055256093706 -8.209389319526933e-06
                C -1.22799350000696 -0.7102112812520209 2.281155685325205e-06
                C -0.0006872840163290542 -0.0003386565731411325 -1.981477647175959
                C 1.2274512359848 0.7092866246929653 -1.981478017299119
                C 2.455989750017203 -0.000767672446473915 -5.638209535859324e-06
                C 1.227983749989149 -0.7105220051279582 3.556077144406634e-06
                C 2.455553905980411 -0.0003697961984884611 -1.981476578954899
                C 3.68349483597652 0.7093774139714127 -1.981475303736415
                C 4.912014119974971 -0.0004697689000645081 8.202057640607653e-06
                C 3.68401303002027 -0.7103327188132248 -6.644074866545941e-06
                C 4.911561265976663 -0.0002732185613776612 -1.98147535090646
                C -3.685503114025999 0.7094747213946447 -1.98147447813657
                C -2.457004890026731 -0.0008782302621621878 8.760751751649826e-06
                C -3.684994169978904 -0.7103491590560944 -6.913500704937906e-06
                C -2.45740142402999 -0.0002120088132086839 -1.981473170030486
                C -1.229200584026242 0.709517932531879 -1.98147439816519
                C 1.227980230018157 2.127401471357515 -5.950364005944094e-06
                C 9.469984377119545e-06 1.417970232416515 5.120417805695729e-06
                C 1.227229005981529 2.127790824745807 -1.981476944534885
                C 2.45544009594217 2.837313001498961 -1.981464045820237
                C 3.683977240012926 2.127396400995821 -4.237131224100653e-06
                C 2.456019429974761 1.41770041892015 8.271514976735398e-06
                C 3.683520895940616 2.127826615636785 -1.981463536474189
                C 4.911484545967099 2.837408990674362 -1.981472216079415
                C 6.140019459971655 2.127636216669431 9.289406940173374e-06
                C 4.912011129977858 1.417969521782559 7.256699431696856e-06
                C 6.139527915931508 2.12792209328836 -1.981460550680031
                C -2.457504644023984 2.837506078460876 -1.981475136785154
                C -1.229001220032881 2.127025640069692 1.077705178964691e-05
                C -2.457025360024441 1.417788944250494 8.010947395781608e-06
                C -1.229428944072945 2.128012192586653 -1.981459091806229
                C -0.001217694074323372 2.837543459113209 -1.981458639351295
                C 2.455982410005773 4.255441598373883 -1.892083560740779e-06
                C 1.228003499971814 3.545886142064043 9.237737681677788e-06
                C 2.455221785970465 4.255792992279458 -1.981473318340598
                C -1.228386974045185 -3.547700260767117 -1.981468190394571
                C 4.911976899993052 4.255411828501257 2.27723146438149e-06
                C 3.684014579960917 3.545723396055813 1.280915829951697e-05
                C 4.911520375955087 4.255828023455356 -1.981468278811
                C 1.227655395958869 -3.547614761418386 -1.98146951906497
                C -2.457018900008975 4.255512695928259 2.943041159330732e-06
                C 6.140026009993287 3.545891232143294 2.20060806891485e-06
                C 7.367526315913146 4.255927240986645 -1.981454533470139
                C -6.141340994042006 -3.547511474074143 -1.981469232026619
                C -0.001002500050462096 4.255387679251578 1.654017565004685e-05
                C -1.228981830007242 3.545851372434187 2.37503105142233e-06
                C -0.00142595404759982 4.256013860539822 -1.981467396982039
                C -3.685044664049419 -3.547477052980626 -1.981466802486946
                C -1.227808819999351 -2.12938224692705 -2.127801149456805e-07
                C -2.455832350038186 -2.838708610558109 1.251523005803983e-05
                C -1.228620264037983 -2.129205540950233 -1.981470550283798
                C -0.0004192140835714842 -1.419477849521901 -1.981455609514733
                C 1.228193719957573 -2.129406616582517 1.390527520593389e-05
                C 0.0001477699611014405 -2.839255138681037 1.274825905530347e-05
                C 1.227684425953123 -2.129163359695275 -1.981467635427455
                C 2.455626385910209 -1.419413169537493 -1.981453570671329
                C -6.140842350045955 -2.129322170430451 1.506226938282425e-05
                C 2.456153479955113 -2.839200210115958 1.47101339575357e-05
                C 3.683689305925244 -2.129064842197087 -1.981458500475127
                C -4.913374384079035 -1.419316522220884 -1.981457095053834
                C -3.684843340052955 -2.129350560151249 1.735547419229382e-05
                C -4.912808430047692 -2.839071261955975 1.563048016823986e-05
                C -3.685268534086676 -2.128978772839927 -1.98145459141338
                C -2.45712732409351 -1.419353221465499 -1.981452351546793
                C -2.996192032925579e-05 -0.000699242152149526 3.962939886687566
                C -1.228003971875175 -0.7103778453492622 3.962925088122617
                C -0.000700355908038296 -0.0003332148789394825 1.981452859744668
                C 1.227439704045832 0.7092909964964251 1.981467977918086
                C 2.455972288079895 -0.000591484995550912 3.962939812711258
                C 1.228003298120663 -0.7104549535647978 3.962926452096982
                C 2.455542044092204 -0.0003647244468015716 1.981452779807835
                C 3.683482354040657 0.7093820057289575 1.981469673526022
                C 4.912000348117807 -0.0004686671456845799 3.96292738718769
                C 3.683997778083127 -0.7103249572456309 3.962938753391991
                C 4.911548884078128 -0.0002680168299863262 1.981457393146928
                C -3.685515265933381 0.7094801331342701 1.981461165904004
                C -2.457014661901717 -0.0008761383582568633 3.962933787286889
                C -3.685007531928472 -0.7103425373777408 3.962942555784025
                C -2.457412705931413 -0.0002065770405354501 1.981460520958165
                C -1.229211335932976 0.7095228343414065 1.98146103281522
                C 1.227967348110556 2.127386193561453 3.962929764672974
                C -4.281883530521391e-06 1.417919455416095 3.96292782690195
                C 1.227218624090811 2.127796526544795 1.981453236878594
                C 2.455427384033809 2.83731889320433 1.981471917810995
                C 3.683966438104317 2.127406352683383 3.962931809362267
                C 2.456006178071116 1.417740879775001 3.962942690498066
                C 3.683508864080636 2.127831077384122 1.981456571921596
                C 4.911472874041424 2.837414422441095 1.981469423240322
                C 6.140006188100173 2.127640908364754 3.96293316778528
                C 4.912000948062944 1.417975193600739 3.962945368689221
                C 6.139515384034993 2.127928054994523 1.981471530520008
                C -2.457516635928298 2.837511270211092 1.981459501137365
                C -1.229012451945974 2.127104470095207 3.962948291371187
                C -2.457033631907664 1.417792836176979 3.962935736248542
                C -1.229441855971066 2.128017364296635 1.981473516125039
                C -0.001231065982844282 2.83754798082405 1.981477377543141
                C 2.455970918062962 4.255446730162459 3.962945363741043
                C 1.227990978068837 3.545888883850297 3.962943437699987
                C 2.455207564067417 4.255798083939164 1.981460905296909
                C -1.228397585936881 -3.54769452897796 1.981462310609218
                C 4.911964488060532 4.255420650159205 3.962946159605713
                C 3.684002968100828 3.545727757822979 3.962932953064215
                C 4.911507194030889 4.25583213519047 1.981472875202606
                C 1.22764468406568 -3.547609799614339 1.981461473160161
                C -2.457027591902453 4.255510887977889 3.962934029953071
                C 6.140011718057854 3.545898453762834 3.962947035832434
                C 7.367513404018803 4.25593209270268 1.981476837527609
                C -6.141352815949912 -3.547506482310592 1.981466583645511
                C -0.001013701916043441 4.255385511194097 3.962938483249906
                C -1.228995721948309 3.545866003895579 3.962949056786192
                C -0.001438315946372004 4.256019262267359 1.98146542401001
                C -3.68505504595736 -3.547472521146422 1.981469025022036
                C -1.227817711946263 -2.129397354545356 3.962948386486201
                C -2.45584760189824 -2.838693919188594 3.962932647309199
                C -1.22863031596877 -2.129200899095368 1.981472763926178
                C -0.0004312259786934947 -1.419471387806733 1.981476015973903
                C 1.228183428085925 -2.129384525179524 3.962937836939656
                C 0.0001342880538246494 -2.839225227582055 3.962948356816577
                C 1.227671624025677 -2.129158527960262 1.981474583888431
                C 2.455614294015247 -1.419407657803005 1.981478001551132
                C -6.140855951953014 -2.129314868796188 3.962950599781267
                C 2.456139408049645 -2.839212628030558 3.962949726809414
                C 3.683677514018658 -2.12905939044384 1.98147688315868
                C -4.913386125957436 -1.419311390469788 1.981469050050141
                C -3.68485488196171 -2.129348928295441 3.96295344930467
                C -4.91282016191732 -2.839063750265042 3.962938899273355
                C -3.685281025994509 -2.12897353111013 1.981481200585353
                C -2.457141595966529 -1.419347949824808 1.981472029890663
            End
            Lattice
                9.825000579999999 0.0 0.0
                4.91182904 8.51302256 0.0
                0.0 0.0 8.0
            End
        End

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

        """,
        name="freezestrain",
    ).run()

    check_results(results)


# 10. Equalized strain components
# ===============================


def test_equalized_strain_components():
    results = AMSJob.from_input(
        """

        Task GeometryOptimization

        GeometryOptimization
            OptimizeLattice Yes
            Convergence Step=1.0e-3
        End

        Constraints
           # Keep the cell cubic, but allow the size of the cube to vary.
           FreezeStrain xy xz yz
           EqualStrain  xx yy zz
        End

        System
            Atoms
                C -0.132285 3.230196 3.399625
                H 0.67231 2.571995 3.747816
                H -0.546925 3.782407 4.25108
                H -0.921872 2.627955 2.935193
                H 0.267346 3.938428 2.664409
                C 2.647972 3.79511 0.161215
                H 2.745753 2.707187 0.254494
                H 2.108302 4.189352 1.030219
                H 2.093026 4.03506 -0.753279
                H 3.644808 4.248843 0.113424
                C -3.290954 -3.607704 -3.419879
                H -4.099867 -4.000479 -4.046956
                H -2.386445 -3.482146 -4.026458
                H -3.088346 -4.309774 -2.602634
                H -3.589157 -2.638419 -3.003466
                C -3.900392 1.971446 -2.092972
                H -2.821972 1.97396 -1.895882
                H -4.303924 2.977719 -1.930439
                H -4.394183 1.265761 -1.414725
                H -4.081488 1.668344 -3.130841
                C -3.143958 -3.520015 3.393796
                H -3.128547 -4.088022 2.456262
                H -3.994325 -3.845525 4.004334
                H -3.24151 -2.450891 3.171766
                H -2.211449 -3.695621 3.94282
                C -0.31406 -0.626145 3.522914
                H -0.044022 0.228271 4.154493
                H -1.353702 -0.912447 3.720437
                H 0.346904 -1.471041 3.749005
                H -0.205421 -0.349364 2.467723
                C 3.411151 -3.454122 0.161835
                H 2.877462 -2.569463 0.528433
                H 4.211866 -3.141886 -0.518755
                H 2.711585 -4.107617 -0.372385
                H 3.843691 -3.997522 1.010048
                H -3.283653 -0.451758 -4.172013
                H -1.922139 0.6502520000000001 -3.802207
                H -2.586463 -0.412172 -2.523601
                C -2.360175 -0.332772 -3.593334
                H -1.648446 -1.117408 -3.875514
                C 3.046249 -3.33059 3.76859
                H 2.414628 -3.18136 2.88506
                H 2.465863 -3.831302 4.55235
                H 3.39517 -2.358701 4.136729
                H 3.909333 -3.950995 3.500222
                C -3.086408 3.73574 0.4638
                H -2.559805 3.990117 -0.463465
                H -2.394025 3.813016 1.310247
                H -3.469203 2.710618 0.397221
                H -3.922599 4.429208 0.611196
                C 3.736451 0.338903 -0.234383
                H 4.139844 -0.659226 -0.441391
                H 4.286082 0.789262 0.6004350000000001
                H 2.675343 0.256879 0.028602
                H 3.844535 0.968696 -1.125179
                C -0.953217 3.761489 -3.029722
                H -0.738671 2.687271 -2.986546
                H -2.017033 3.913231 -3.24677
                H -0.349572 4.223228 -3.819817
                H -0.707592 4.222226 -2.065757
                C 3.438238 3.368005 3.536049
                H 3.718968 3.030104 2.531632
                H 4.305113 3.831685 4.021198
                H 3.102844 2.509703 4.129906
                H 2.62603 4.10053 3.461459
                C -0.093351 2.447961 0.147782
                H 0.412783 2.191741 -0.790311
                H -1.100739 2.015519 0.149423
                H -0.163522 3.53817 0.239205
                H 0.478074 2.046413 0.99281
                C -0.06737899999999999 -1.067744 -0.644773
                H 0.831493 -1.69444 -0.611303
                H -0.920384 -1.630791 -0.248288
                H -0.271712 -0.77696 -1.681851
                H 0.091087 -0.168785 -0.037648
                C -3.13266 0.095347 1.684164
                H -2.468956 -0.758832 1.506078
                H -3.797646 -0.127993 2.526632
                H -3.731911 0.285949 0.786162
                H -2.532126 0.982263 1.917783
                C -3.650862 -2.700373 -0.074687
                H -4.155919 -2.467829 0.87013
                H -2.740814 -3.276506 0.129574
                H -3.385824 -1.767849 -0.58654
                H -4.32089 -3.289309 -0.711913
                C 3.803884 3.754796 -3.348637
                H 3.946713 2.667857 -3.350306
                H 2.769436 3.987861 -3.626912
                H 4.48894 4.214494 -4.07059
                H 4.010448 4.148971 -2.34674
                C 2.868209 0.11231 2.894284
                H 2.317604 0.914041 2.388417
                H 2.406222 -0.09055000000000001 3.867554
                H 3.909847 0.420825 3.041412
                H 2.839161 -0.7950739999999999 2.279753
                C -0.320765 -3.560008 1.887422
                H -0.965068 -2.68183 2.011986
                H 0.02585 -3.901247 2.869895
                H 0.543227 -3.294315 1.26713
                H -0.88707 -4.36264 1.400678
                C 2.415398 -1.437717 -2.776235
                H 1.964383 -1.676188 -3.746573
                H 2.445411 -2.340763 -2.155392
                H 1.816728 -0.668767 -2.274091
                H 3.43507 -1.065149 -2.928883
                C -3.625996 2.934989 3.78523
                H -4.070333 2.734452 2.803299
                H -3.043299 2.064066 4.107404
                H -4.421782 3.131813 4.513121
                H -2.968572 3.809626 3.717096
                C 1.422335 1.538945 -3.931672
                H 0.608488 0.8054 -3.894205
                H 2.3282 1.060135 -4.321529
                H 1.616409 1.921293 -2.92272
                H 1.136242 2.368954 -4.588236
                C 0.028875 -3.521123 -2.677443
                H 0.240436 -2.624091 -3.271089
                H -0.857142 -3.347281 -2.055678
                H 0.888225 -3.744967 -2.034598
                H -0.156019 -4.368152 -3.348409
            End
            Lattice
                10.0 0.0 0.0
                0.0 10.0 0.0
                0.0 0.0 10.0
            End
        End

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

        """,
        name="equalstrain",
    ).run()

    check_results(results)