Bug in writing `FHI-aims` cube file options to `control.in` using `ase.io.aims.write_control`
Checklist
- [ x ] The issue remains in the development version of ASE.
- [ x ] An minimal example is provided to reproduce the issue.
Summary
Goal: write a control.in input file for an FHI-aims calculation with output of a cube file.
Normally, one might do the following to write a control.in file, using the current master branch as opposed to the release version:
import ase
import ase.io.aims
atoms = ase.Atoms("H2", positions=[[0, 0, 0], [0, 0, 1]])
ase.io.aims.write_control(
"control.in", atoms=atoms, parameters={"xc": "pbe", "output": ["cube total_density"], "species_dir": "..."}
)
but in order to specify cube edges, one must pass:
...
ase.io.aims.write_control(
"control.in",
atoms=atoms,
parameters={
"xc": "pbe",
"output": ["cube total_density"],
"cubes": ""
+ "cube origin 4.945 5.426 7.676 \n"
+ "cube edge 101 0.15 0.0 0.0 \n"
+ "cube edge 101 0.0 0.15 0.0 \n"
+ "cube edge 101 0.0 0.0 0.15 \n"
}
)
to write the various cube origin and edge settings that cannot be pass in a dict due to non-unique cube
keys.
In file ase/ase/io/aims.py
, function write_control()
, the cubes
parameters are popped (line 519: cubes = parameters.pop("cubes", None)
. Then, there is a bug in lines 588-589, that attempts to write the file to the string:
if cubes:
cubes.write(fd)
which raises the following error: AttributeError: 'str' object has no attribute 'write'
as the objects are the wrong way round.
Simple fix
To fix the bug, line 589 just needs to be changed to:
if cubes:
fd.write(cubes)