Skip to content

Updated gaussian.py so it can read Gaussian input files containing fragments without error message (fragment information is not read in though)

To whom this concerns

Brief description of update

  • This request is to update the gaussian.py file so it can read Gaussian input files that contain fragments.
  • This update does not read anything about the fragments into ASE. It only allows ASE to read in Gaussian input files that contain fragments.

Background for this update

I want to be able for ASE to read in Gaussian input (.gjf) files that contain fragments. Fragments allow Gaussian users to segment a chemical system into parts, such as molecules. This is useful for me as I perform coupling calculations on these fragments (see https://gaussian.com/molspec for more information).

The format of the charge and multiplicity of .gjf files (containing fragments) can include the charge and multiplicity of each fragment, along with the overall charge and multiplicity. For example, consider a gjf file containing two two fragments. Here, I show the part of the gif file describing charge and multiplicity (see below).

...
Title

0 1 1 1 -1 1 # Total charge and multiplicity, followed by fragment-specific ones. 
C(Fragment=1) -3.05015529 -0.24077322 0.00000698 
C(Fragment=1) -1.64875545 -0.24070572 0.00067327 
...

Here, I have specified that:

  • I want the overall charge to be 0 and the overall multiplicity to be 1,
  • For fragment 1, I want the charge to be +1, and the multiplicity to be 1,
  • For fragment 2, I want the charge to be -1, and the multiplicity to be 1.

What does ASE currently do

When I try to input gjf files like this, it fails because it can not recognise the charge and multiplicity line when it contains more than two numbers.

  File "/home/rocky/.local/lib/python3.9/site-packages/ase/io/gaussian.py", line 610, in _get_charge_mult
    raise ParseError("ERROR: Could not read the charge and multiplicity "
ase.io.ParseError: ERROR: Could not read the charge and multiplicity from the Gaussian input file. These must be 2 integers separated with whitespace or a comma.

What does this update do

This update is very similar to the original code, but it now allows ASE to accept the charge+multiplicity line of the gjf even if the line contains an even number of numbers.

  • If it does, it recognises it as the charge and multiplicity line.
  • ASE will only reads in the first two digits from this line, being the total charge and total multiplicity of the system, respectively.

This updated code does not allow ASE to read in fragment information, it only reads in the charge and multiplicity of the overall chemical system.

Main code change of this merge

old code:

_re_chgmult = re.compile(r'^\s*[+-]?\d+(?:,\s*|\s+)[+-]?\d+\s*$')

new code

_re_chgmult = re.compile(r'^(\s*[+-]?\d+(?:,\s*|\s+)[+-]?\d+\s*){1,}$')

Checklist

Thanks for all the work on ASE!

Edited by Geoffrey Weal

Merge request reports