Skip to content

Commit

Permalink
Update for newest XTB (duartegroup#30)
Browse files Browse the repository at this point in the history
* Update for XTB v 6.4
  • Loading branch information
t-young31 authored Feb 11, 2021
1 parent be21386 commit e6d579f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
12 changes: 7 additions & 5 deletions autode/wrappers/XTB.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,17 @@ def get_final_atoms(self, calc):
for i, line in enumerate(calc.output.file_lines):

# XTB 6.2.x have a slightly different way of printing the atoms
if 'xtb version' in line and len(line.split()) >= 4:
if line.split()[3] == '6.2.3' or '6.3' in line.split()[3]:
atoms = self._get_final_atoms_6_2_above(calc)
break
if ('xtb version' in line or 'Version' in line
and len(line.split()) >= 4):

elif line.split()[3] == '6.2.2' or '6.1' in line.split()[3]:
if line.split()[3] == '6.2.2' or '6.1' in line.split()[2]:
atoms = self._get_final_atoms_old(calc)
break

else:
atoms = self._get_final_atoms_6_2_above(calc)
break

# Version is not recognised if we're 50 lines into the output file
# - try and use the old version
if i > 50:
Expand Down
Binary file modified tests/data/xtb.zip
Binary file not shown.
37 changes: 35 additions & 2 deletions tests/test_xtb_calc.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import numpy as np
import os
import pytest
from autode.atoms import Atom
from autode.wrappers.XTB import XTB
from autode.calculation import Calculation
from autode.species.molecule import Molecule
from autode.point_charges import PointCharge
from autode.exceptions import AtomsNotFound
from autode.config import Config
from . import testutils
import numpy as np
import os

here = os.path.dirname(os.path.abspath(__file__))

method = XTB()
Expand Down Expand Up @@ -56,6 +58,15 @@ def test_xtb_calculation():
const_opt.clean_up(force=True)
assert not os.path.exists('xcontrol_const_opt_xtb')

# Write an empty output file
open('tmp.out', 'w').close()
const_opt.output.filename = 'tmp.out'
const_opt.output.set_lines()

# cannot get atoms from an empty file
with pytest.raises(AtomsNotFound):
_ = const_opt.get_final_atoms()


@testutils.work_in_zipped_dir(os.path.join(here, 'data', 'xtb.zip'))
def test_point_charge():
Expand Down Expand Up @@ -143,3 +154,25 @@ def test_xtb_6_3_2():

assert len(calc.get_final_atoms()) == 5


@testutils.work_in_zipped_dir(os.path.join(here, 'data', 'xtb.zip'))
def test_xtb_6_1_old():

mol = Molecule(name='methane', smiles='C')
calc = Calculation(name='test',
molecule=mol,
method=method,
keywords=method.keywords.opt)

for filename in ('xtb_6_1_opt.out', 'xtb_no_version_opt.out'):

calc.output.filename = filename
calc.output.set_lines()

assert len(calc.get_final_atoms()) == 5
mol.atoms = calc.get_final_atoms()

assert set([atom.label for atom in mol.atoms]) == {'C', 'H'}
assert 0.9 < mol.distance(0, 1) < 1.2

calc.output.set_lines()

0 comments on commit e6d579f

Please sign in to comment.