Skip to content

Restart Command Conflicts with Directory Option in NWChem

The write_nwchem_in function has a conflict between the restart and directory options. This simple example

from ase import Atoms
from ase.calculators.nwchem import NWChem


atoms = Atoms('N2', positions=[[0, 0, -1], [0, 0, 1]])
calc = NWChem(label='N2',
              directory='calc',
              dft=dict(maxiter=2000,
                       xc='B3LYP'),
              basis='6-31+G*',
              restart=None,
             )
atoms.calc = calc
e = atoms.get_potential_energy()
print('Energy={}'.format(e))

will throw the following error ase.calculators.calculator.CalculationFailed: Calculator "nwchem" failed with command "nwchem N2.nwi > N2.nwo" failed in /mnt/hybrid/home/dsjense/computations/estruct/nwchem/tstatepy/tstatepy/uranium/compare_g09/calc with error code 143.

The problem is that the N2.nwi file generated has the line start calc/N2. The correct line should be start N2. This can be achieved by the following code

    perm = os.path.abspath(params.pop('perm', label))
    scratch = os.path.abspath(params.pop('scratch', label))
    restart_kw = params.get('restart_kw','start')
    if restart_kw not in ('start','restart'):
       raise ValueError("Unrecognised restart keyword: {}!".format(restart_kw))
    short_label = label.rsplit('/', 1)[-1]
    out = ['title "{}"'.format(short_label),
           'permanent_dir {}'.format(perm),
           'scratch_dir {}'.format(scratch),
           '{} {}'.format(restart_kw, short_label),
           '\n'.join(_get_geom(atoms, **params)),
           '\n'.join(_get_basis(**params)),
           '\n'.join(_get_other(**params)),
           '\n'.join(_get_set(**params.get('set', dict()))),
           'task {} {}'.format(theory, task),
           '\n'.join(_get_bandpath(params.get('bandpath', None)))]

I'm not sure this is the way it should be done since the same kind of label splitting happens in ase/calculators/calculator.py but it might not be worth the work of passing down the short label to the writer.

Edited by Daniel Jensen