def test_turbomole_h2o(): from ase.calculators.turbomole import Turbomole from ase.build import molecule mol = molecule('H2O') params = { 'title': 'water', 'task': 'geometry optimization', 'use redundant internals': True, 'basis set name': 'def2-SV(P)', 'total charge': 0, 'multiplicity': 1, 'use dft': True, 'density functional': 'b3-lyp', 'use resolution of identity': True, 'ri memory': 1000, 'force convergence': 0.001, 'geometry optimization iterations': 50, 'scf iterations': 100 } calc = Turbomole(**params) mol.calc = calc calc.calculate(mol) assert calc.converged # use the get_property() method print(calc.get_property('energy', mol, False)) print(calc.get_property('forces', mol, False)) print(calc.get_property('dipole', mol, False)) # use the get_results() method results = calc.get_results() print(results['molecular orbitals']) # use the __getitem__() method print(calc['results']['molecular orbitals']) print(calc['results']['geometry optimization history']) # perform a normal mode calculation with the optimized structure params.update({ 'task': 'normal mode analysis', 'density convergence': 1.0e-7 }) calc = Turbomole(**params) mol.calc = calc calc.calculate(mol) print(calc['results']['vibrational spectrum']) print(calc.todict(skip_default=False))
def polarization_cycle(partition_1, partition_2, charges_2=None): """Performs an iteration of a polarization calculation.""" properties = {} calc = Turbomole(atoms=partition_1, **params) if charges_2 is not None: calc.embed(charges=charges_2, positions=partition_2.positions) properties['e1'] = partition_1.get_potential_energy() properties['c1'] = partition_1.get_charges() calc = Turbomole(atoms=partition_2, **params) calc.embed(charges=properties['c1'], positions=partition_1.positions) properties['e2'] = partition_2.get_potential_energy() properties['c2'] = partition_2.get_charges() return properties
def test_turbomole_au13(): from ase.cluster.cubic import FaceCenteredCubic from ase.calculators.turbomole import Turbomole surfaces = [(1, 0, 0), (1, 1, 0), (1, 1, 1)] layers = [1, 2, 1] atoms = FaceCenteredCubic('Au', surfaces, layers, latticeconstant=4.08) params = { 'title': 'Au13-', 'task': 'energy', 'basis set name': 'def2-SV(P)', 'total charge': -1, 'multiplicity': 1, 'use dft': True, 'density functional': 'pbe', 'use resolution of identity': True, 'ri memory': 1000, 'use fermi smearing': True, 'fermi initial temperature': 500, 'fermi final temperature': 100, 'fermi annealing factor': 0.9, 'fermi h**o-lumo gap criterion': 0.09, 'fermi stopping criterion': 0.002, 'scf energy convergence': 1.e-4, 'scf iterations': 250 } calc = Turbomole(**params) atoms.calc = calc calc.calculate(atoms) # use the get_property() method print(calc.get_property('energy')) print(calc.get_property('dipole')) # test restart params = {'task': 'gradient', 'scf energy convergence': 1.e-6} calc = Turbomole(restart=True, **params) assert calc.converged calc.calculate() print(calc.get_property('energy')) print(calc.get_property('forces')) print(calc.get_property('dipole'))
def test_turbomole_h3o2m(): # http://jcp.aip.org/resource/1/jcpsa6/v97/i10/p7507_s1 doo = 2.74 doht = 0.957 doh = 0.977 angle = radians(104.5) initial = Atoms('HOHOH', positions=[(-sin(angle) * doht, 0., cos(angle) * doht), (0., 0., 0.), (0., 0., doh), (0., 0., doo), (sin(angle) * doht, 0., doo - cos(angle) * doht) ]) if 0: view(initial) final = Atoms('HOHOH', positions=[(-sin(angle) * doht, 0., cos(angle) * doht), (0., 0., 0.), (0., 0., doo - doh), (0., 0., doo), (sin(angle) * doht, 0., doo - cos(angle) * doht)]) if 0: view(final) # Make band: images = [initial.copy()] for i in range(3): images.append(initial.copy()) images.append(final.copy()) neb = NEB(images, climb=True) # Write all commands for the define command in a string define_str = ('\n\na coord\n\n*\nno\nb all 3-21g ' 'hondo\n*\neht\n\n-1\nno\ns\n*\n\ndft\non\nfunc ' 'pwlda\n\n\nscf\niter\n300\n\n*') # Set constraints and calculator: constraint = FixAtoms(indices=[1, 3]) # fix OO BUG No.1: fixes atom 0 and 1 # constraint = FixAtoms(mask=[0,1,0,1,0]) # fix OO #Works without patch for image in images: image.calc = Turbomole(define_str=define_str) image.set_constraint(constraint) # Relax initial and final states: if 1: dyn1 = QuasiNewton(images[0]) dyn1.run(fmax=0.10) dyn2 = QuasiNewton(images[-1]) dyn2.run(fmax=0.10) # Interpolate positions between initial and final states: neb.interpolate() if 1: for image in images: print(image.get_distance(1, 2), image.get_potential_energy()) dyn = BFGS(neb, trajectory='turbomole_h3o2m.traj') dyn.run(fmax=0.10) for image in images: print(image.get_distance(1, 2), image.get_potential_energy())
def test_turbomole_H2(atoms): # Write all commands for the define command in a string define_str = '\n\na coord\n*\nno\nb all sto-3g hondo\n*\neht\n\n\n\n*' atoms.calc = Turbomole(define_str=define_str) # Run turbomole atoms.get_potential_energy()
def test_turbomole_H2(): from ase import Atoms from ase.calculators.turbomole import Turbomole atoms = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)]) # Write all commands for the define command in a string define_str = '\n\na coord\n*\nno\nb all sto-3g hondo\n*\neht\n\n\n\n*' atoms.set_calculator(Turbomole(define_str=define_str)) # Run turbomole atoms.get_potential_energy()
def test_turbomole_optimizer(): water = molecule('H2O') params = { 'title': 'water', 'basis set name': 'sto-3g hondo', 'total charge': 0, 'multiplicity': 1, 'use dft': True, 'density functional': 'b-p', 'use resolution of identity': True, } calc = Turbomole(**params) optimizer = calc.get_optimizer(water) optimizer.run(fmax=0.01, steps=5)
def test_turbomole_H2_uhf_singlet(atoms): atoms.calc = Turbomole(**{"multiplicity": 1, "uhf": True, "use dft": True}) # Run turbomole atoms.get_potential_energy() # check that it performed a DFT calculation (i.e. basic inputs were most # likely understood, cf. issue #735) dft_in_output = False with open("ASE.TM.dscf.out") as fd: for line in fd: if "density functional" in line: dft_in_output = True assert dft_in_output # also check that UHF was understood (alpha and beta files present) assert os.path.exists("alpha") assert os.path.exists("beta") assert not os.path.exists("mos")
from ase.calculators.tip3p import TIP3P, epsilon0, sigma0, rOH, angleHOH from ase.calculators.qmmm import SimpleQMMM, EIQMMM, LJInteractions from ase.calculators.turbomole import Turbomole from ase.constraints import FixInternals from ase.optimize import BFGS r = rOH a = angleHOH * pi / 180 D = np.linspace(2.5, 3.5, 30) interaction = LJInteractions({('O', 'O'): (epsilon0, sigma0)}) qm_par = {'esp fit': 'kollman', 'multiplicity': 1} for calc in [ TIP3P(), SimpleQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), TIP3P()), SimpleQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), TIP3P(), vacuum=3.0), EIQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), interaction), EIQMMM([3, 4, 5], Turbomole(**qm_par), TIP3P(), interaction, vacuum=3.0), EIQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), interaction,
# Date : July 25,2015 import os from subprocess import Popen, PIPE, STDOUT from ase import Atoms from ase.calculators.turbomole import Turbomole from ase.io import read, write # Delete old coord, control, ... files, if exist for f in ['coord', 'basis', 'energy', 'mos', 'statistics', 'control' 'job.*']: if os.path.exists(f): os.remove(f) atoms = read('replica00.xyz') atoms.set_calculator(Turbomole()) # Writes a coord file as well # Write all commands for the define command in a string (GEO_OPT with DFT) # Basis - def2-TZVP # SCF conv 10e-8 # SCF iter 999 # Functional - b3-lyp define_str = '\nexcite-geo-opt\na coord\n*\nno\nb all def2-TZVP\n*\neht\ny\n1\ny\nscf\nconv\n8\niter\n999\n\nex\nrpas\nq\na 1000\nq\nrpacor 1000\nq\ny\ndft\non\nfunc b3-lyp\n\n*' # Run define p = Popen('define', stdout=PIPE, stdin=PIPE, stderr=STDOUT) stdout = p.communicate(input=define_str) # Run turbomole for TDDFT os.system('jobex -dscf -level=scf -energy 6 -c 1000 > jobex.out')
from ase.calculators.turbomole import Turbomole from ase.build import molecule water = molecule('H2O') params = { 'title': 'water', 'basis set name': 'sto-3g hondo', 'total charge': 0, 'multiplicity': 1, 'use dft': True, 'density functional': 'b-p', 'use resolution of identity': True, } calc = Turbomole(**params) optimizer = calc.get_optimizer(water) optimizer.run(fmax=0.01, steps=5)
import os from ase.io import read from ase.neb import NEB from ase.calculators.turbomole import Turbomole from ase.optimize import BFGS initial = read('initial.coord') final = read('final.coord') os.system('rm -f coord; cp initial.coord coord') # Make a band consisting of 5 configs: configs = [initial] configs += [initial.copy() for i in range(3)] configs += [final] band = NEB(configs, climb=True) # Interpolate linearly the positions of the not-endpoint-configs: band.interpolate() #Set calculators for config in configs: config.set_calculator(Turbomole()) # Optimize the Path: relax = BFGS(band, trajectory='neb.traj') relax.run(fmax=0.05)
images = [initial.copy()] for i in range(3): images.append(initial.copy()) images.append(final.copy()) neb = NEB(images, climb=True) # Write all commands for the define command in a string define_str = ('\n\na coord\n\n*\nno\nb all 3-21g ' 'hondo\n*\neht\n\n-1\nno\ns\n*\n\ndft\non\nfunc ' 'pwlda\n\n\nscf\niter\n300\n\n*') # Set constraints and calculator: constraint = FixAtoms(indices=[1, 3]) # fix OO BUG No.1: fixes atom 0 and 1 # constraint = FixAtoms(mask=[0,1,0,1,0]) # fix OO #Works without patch for image in images: image.set_calculator(Turbomole(define_str=define_str)) image.set_constraint(constraint) # Relax initial and final states: if 1: dyn1 = QuasiNewton(images[0]) dyn1.run(fmax=0.10) dyn2 = QuasiNewton(images[-1]) dyn2.run(fmax=0.10) # Interpolate positions between initial and final states: neb.interpolate() if 1: for image in images: print(image.get_distance(1, 2), image.get_potential_energy())
'multiplicity': 1, 'use dft': True, 'density functional': 'pbe', 'use resolution of identity': True, 'ri memory': 1000, 'use fermi smearing': True, 'fermi initial temperature': 500, 'fermi final temperature': 100, 'fermi annealing factor': 0.9, 'fermi h**o-lumo gap criterion': 0.09, 'fermi stopping criterion': 0.002, 'scf energy convergence': 1.e-4, 'scf iterations': 250 } calc = Turbomole(**params) atoms.set_calculator(calc) calc.calculate(atoms) # use the get_property() method print(calc.get_property('energy')) print(calc.get_property('dipole')) # test restart params = {'task': 'gradient', 'scf energy convergence': 1.e-6} calc = Turbomole(restart=True, **params) assert calc.converged calc.calculate()
def test_turbomole_qmmm(): """Test the Turbomole calculator in simple QMMM and explicit interaction QMMM simulations.""" r = rOH a = angleHOH * pi / 180 D = np.linspace(2.5, 3.5, 30) interaction = LJInteractions({('O', 'O'): (epsilon0, sigma0)}) qm_par = {'esp fit': 'kollman', 'multiplicity': 1} for calc in [ TIP3P(), SimpleQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), TIP3P()), SimpleQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), TIP3P(), vacuum=3.0), EIQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), interaction), EIQMMM([3, 4, 5], Turbomole(**qm_par), TIP3P(), interaction, vacuum=3.0), EIQMMM([0, 1, 2], Turbomole(**qm_par), TIP3P(), interaction, vacuum=3.0) ]: dimer = Atoms('H2OH2O', [(r * cos(a), 0, r * sin(a)), (r, 0, 0), (0, 0, 0), (r * cos(a / 2), r * sin(a / 2), 0), (r * cos(a / 2), -r * sin(a / 2), 0), (0, 0, 0)]) dimer.calc = calc E = [] F = [] for d in D: dimer.positions[3:, 0] += d - dimer.positions[5, 0] E.append(dimer.get_potential_energy()) F.append(dimer.get_forces()) F = np.array(F) F1 = np.polyval(np.polyder(np.polyfit(D, E, 7)), D) F2 = F[:, :3, 0].sum(1) error = abs(F1 - F2).max() assert error < 0.9 dimer.set_constraint( FixInternals(bonds=[(r, (0, 2)), (r, (1, 2)), (r, (3, 5)), (r, (4, 5))], angles_deg=[(angleHOH, (0, 2, 1)), (angleHOH, (3, 5, 4))])) opt = BFGS(dimer, trajectory=calc.name + '.traj', logfile=calc.name + 'd.log') opt.run(0.01) e0 = dimer.get_potential_energy() d0 = dimer.get_distance(2, 5) R = dimer.positions v1 = R[1] - R[5] v2 = R[5] - (R[3] + R[4]) / 2 a0 = np.arccos( np.dot(v1, v2) / (np.dot(v1, v1) * np.dot(v2, v2))**0.5) / np.pi * 180 fmt = '{0:>20}: {1:.3f} {2:.3f} {3:.3f} {4:.1f}' print(fmt.format(calc.name, -min(E), -e0, d0, a0))
if 0: view(final) # Make band: images = [initial.copy()] for i in range(3): images.append(initial.copy()) images.append(final.copy()) neb = NEB(images, climb=True) # Set constraints and calculator: constraint = FixAtoms(indices=[1, 3]) # fix OO #BUG No.1: fixes atom 0 and 1 #constraint = FixAtoms(mask=[0,1,0,1,0]) # fix OO #Works without patch for image in images: image.set_calculator(Turbomole()) #BUG No.2: (Over-)writes coord file image.set_constraint(constraint) # Write all commands for the define command in a string define_str = '\n\na coord\n\n*\nno\nb all 3-21g hondo\n*\neht\n\n-1\nno\ns\n*\n\ndft\non\nfunc pwlda\n\n\nscf\niter\n300\n\n*' # Run define p = Popen('define', stdout=PIPE, stdin=PIPE, stderr=STDOUT) stdout = p.communicate(input=define_str) # Relax initial and final states: if 1: dyn1 = QuasiNewton(images[0]) dyn1.run(fmax=0.10) dyn2 = QuasiNewton(images[-1]) dyn2.run(fmax=0.10)
def run(params): """Run Turbomole calculation in specified folder. Removes all files before starting calculation. If successful safly write foldername in file. (Therefore lock has to be provided) Parameters ---------- params : :obj:`list` folder : obj`str` name of folder to perform calculation in. options : :obj`dict` Options. restartfilename : :obj:`str` path to restartfile. lock : :obj:`multiprocessing.Manager.lock` lock for multiprocessing. """ folder = params[0] options = params[1] restartfileloc = params[2] lock = params[3] coord = options['dissotionoutname'] tmparams = options['sp_control']['params'] cwd = os.getcwd() os.chdir(folder) calc = Turbomole(**tmparams) # Clean directory if options['restart']: files = glob.glob('*') cleanupFiles = files cleanupFiles.remove(coord) for cleanupFile in cleanupFiles: os.remove(cleanupFile) lock.acquire() molecule = ase.io.read(coord, format='xyz') lock.release() # Run molecule.set_calculator(calc) # Redirect output tmoutname = 'turbomole.stdout' if options['verbose']: print(''' Starting turbomole in \'{}\' Redirecting output to \'{}\' '''.format(folder, tmoutname)) f = io.StringIO() with open(tmoutname, 'w') as f: with redirect_stdout(f): molecule.get_potential_energy() os.chdir(cwd) if restartfileloc is not None: restartfile = os.path.join(restartfileloc, options['sp_restart_file']) lock.acquire() with open(restartfile, 'a') as restart_file: restart_file.write(folder + ' ') lock.release() # else: # restartfile = options['sp_restart_file'] # Safefly write to restartfile return folder