Writing Input FilesΒΆ

IOData can be used to write input files for quantum-chemistry software. By default minimal settings are used, which can be changed if needed. For example, the following will prepare a Gaussian input for a HF/STO-3G calculation from a PDB file:

1from iodata import load_one, write_input
2
3write_input(load_one("water.pdb"), "water.com", fmt="gaussian")

The level of theory and other settings can be modified by setting corresponding attributes in the IOData object:

1from iodata import load_one, write_input
2
3mol = load_one("water.pdb")
4mol.lot = "B3LYP"
5mol.obasis_name = "6-31g*"
6mol.run_type = "opt"
7write_input(mol, "water.com", fmt="gaussian")

The run types can be any of the following: energy, energy_force, opt, scan or freq. These are translated into program-specific keywords when the file is written.

It is possible to define a custom input file template to allow for specialized commands. This is done by passing a template string using the optional template keyword, placing each IOData attribute (or additional keyword, as shown below) in curly brackets:

 1from iodata import load_one, write_input
 2
 3mol = load_one("water.pdb")
 4mol.lot = "B3LYP"
 5mol.obasis_name = "Def2QZVP"
 6mol.run_type = "opt"
 7custom_template = """\
 8%NProcShared=4
 9%mem=16GB
10%chk=B3LYP_def2qzvp_H2O
11#n {lot}/{obasis_name} scf=(maxcycle=900,verytightlineq,xqc)
12integral=(grid=ultrafinegrid) pop=(cm5, hlygat, mbs, npa, esp)
13
14{title}
15
16{charge} {spinmult}
17{geometry}
18
19"""
20write_input(mol, "water.com", fmt="gaussian", template=custom_template)

The input file template may also include keywords that are not part of the IOData object:

 1from iodata import load_one, write_input
 2
 3mol = load_one("water.pdb")
 4mol.lot = "B3LYP"
 5mol.obasis_name = "Def2QZVP"
 6mol.run_type = "opt"
 7custom_template = """\
 8%chk={chk_name}
 9#n {lot}/{obasis_name} {run_type}
10
11{title}
12
13{charge} {spinmult}
14{geometry}
15
16"""
17# Custom keywords as arguments (best for few extra arguments)
18write_input(
19    mol, "water.com", fmt="gaussian", template=custom_template, chk_name="B3LYP_def2qzvp_water"
20)
21
22# Custom keywords from a dict (in cases with many extra arguments)
23custom_keywords = {"chk_name": "B3LYP_def2qzvp_waters"}
24write_input(mol, "water.com", fmt="gaussian", template=custom_template, **custom_keywords)

In some cases, it may be preferable to load the template from file, instead of defining it in the script:

1from iodata import load_one, write_input
2
3mol = load_one("water.pdb")
4mol.lot = "B3LYP"
5mol.obasis_name = "6-31g*"
6mol.run_type = "opt"
7with open("my_template.com") as fh:
8    write_input(mol, "water.com", fmt="gaussian", template=fh.read())

More details can be found in the API documentation of iodata.api.write_input().