#
# DL-FIND Transition-state and path search using the nudged elastic band method
#      in HDLC coordinates
#
# Open shell example (CH3O)
#
from chemsh       import *
from chemsh.utils import testutils

#
# Example 4 for a transition-state search taken from
# J. Baker and F. Chan, J. Computational Chem. 17, 888 (1996) [bak96a]
#
znums = [ 8, 6, 1, 1, 1 ]

# unit is a.u., since keyword 'unit' has been removed from <class Fragment>
coords1 = [ [  0.229905517825816,  0.00000000000000,  0.280813108981584 ],
            [ -0.205156034783934,  0.00000000000000,  2.82036285002196  ],
            [  2.05112434865353 ,  0.00000000000000,  0.086244864711085 ],
            [ -0.601473796715074,  1.82038088546098,  3.70246420498115  ],
            [ -0.601473796715081, -1.82038088546099,  3.70246420498117  ] ]

reactant = Fragment(znums=znums, coords=coords1)

# unit is a.u., since keyword 'unit' has been removed from <class Fragment>
coords2 = [ [ -0.950534166225885,  0.00000000000000, -0.07562157079166 ], 
            [  0.175526147581934,  0.00000000000000,  2.21552085929268 ], 
            [  2.26942896336608 ,  0.00000000000000,  1.80140353367403 ], 
            [ -0.310747353228436,  1.73822140624883,  3.32552320575095 ], 
            [ -0.310747353228442, -1.73822140624882,  3.32552320575094 ] ] 

product = Fragment(znums=znums, coords=coords2)


qm = MNDO(frag=reactant, method='am1', accuracy='veryhigh', mult=2)

# Not all atoms have to be in HDLC residues
# Here testing TS hydrogen as a Cartesian atom, all the rest in a residue
opt = Opt(theory=qm,
          frag2=product,
          neb='frozen',
          coordinates='hdlc',
          residues={ 'res1' : [0, 1, 3, 4] },
          nimages=10,
          nebk=0.01,
          tolerance=0.0003,
          maxcycle=40000,
          maxene=30000,
          maxstep=0.9,
          trust_radius='constant'
         )

opt.run()

ecalc = opt.result.energy

# Test result from Tcl-ChemShell
eref = 0.047209985462
tolerance = 1.0e-7


testutils.validate(ecalc, eref, tol=tolerance)

