Skip to content

Commit

Permalink
Reformat orca write_input
Browse files Browse the repository at this point in the history
  • Loading branch information
lmacaya committed Sep 4, 2020
1 parent 28c167c commit 0f628f8
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions iodata/inputs/orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
# --
"""Orca Input Module."""


from typing import TextIO
from string import Template

import attr
from .common import populate_fields

from ..docstrings import document_write_input
from ..iodata import IOData
from ..periodic import num2sym
from ..utils import angstrom

__all__ = []

Expand All @@ -38,27 +39,18 @@
*"""


@document_write_input("ORCA", ['atnums', 'atcoords'],
['title', 'run_type', 'lot', 'obasis_name', 'spinmult', 'charge'])
def write_input(f: TextIO, data: IOData, template: str = None):
"""Do not edit this docstring. It will be overwritten."""
# load IOData dict using attr.asdict because the IOData class uses __slots__
fields = attr.asdict(data, recurse=False)

# store atomic coordinates in angstrom
fields["atcoords"] = data.atcoords / angstrom

# replace None for default values
fields["title"] = data.title if data.title is not None else 'Input Generated by IOData'
fields["run_type"] = data.run_type if data.run_type is not None else 'energy'
# convert spin polarization to multiplicity
fields["spinmult"] = int(data.spinpol) + 1 if data.spinpol is not None else 1
fields["charge"] = int(data.charge) if data.nelec is not None else 0
# initialize a dictionary with fields to replace in the template
fields = populate_fields(data)
# set format-specific defaults
fields["lot"] = data.lot if data.lot is not None else 'HF'
fields["obasis_name"] = data.obasis_name if data.obasis_name is not None else 'STO-3G'

# convert run type to orca keywords
# convert run type to Orca keywords
run_types = {"energy": "Energy", "freq": "Freq", "opt": "Opt"}
fields["run_type"] = run_types[fields["run_type"].lower()]

# generate geometry (in angstrom)
geometry = []
for num, coord in zip(fields["atnums"], fields["atcoords"]):
Expand All @@ -68,10 +60,8 @@ def write_input(f: TextIO, data: IOData, template: str = None):
sym = f"{sym:>11}" # adding an appropiate indentation
geometry.append(f"{sym} {coord[0]:10.6f} {coord[1]:10.6f} {coord[2]:10.6f}")
fields["geometry"] = "\n".join(geometry)

# get template
if template is None:
template = default_template

# populate files & write input
print(Template(template).substitute(fields), file=f)

0 comments on commit 0f628f8

Please sign in to comment.