File: run_gradient.py

package info (click to toggle)
votca 2025.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 132,424 kB
  • sloc: xml: 345,964; cpp: 80,067; python: 15,957; sh: 4,580; perl: 2,169; javascript: 202; makefile: 34
file content (28 lines) | stat: -rwxr-xr-x 767 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
"""Example to perform a gradient calculation."""
from pyxtp import xtp
from ase import Atoms
import numpy as np

def run_gradient() -> np.ndarray:
    """Compute gradient."""
    # define a molecule
    atoms = Atoms('CO', positions=([0,0,0],[1.4,0,0]))

    # define the calculator
    calc = xtp(nthreads=2)
    calc.select_force(energy='singlets', level=0, dynamic=False)

    # this allows to change all options
    # calc.options.dftpackage.functional = 'PBE'
    calc.options.dftpackage.basisset = 'def2-svp'
    calc.options.dftpackage.auxbasisset = 'aux-def2-svp'

    # attach the calculator
    atoms.calc = calc

    # run for the molecule in its geometry
    return atoms.get_forces()

if __name__ == "__main__":
    run_gradient()