-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'write_input' of https://github.com/FarnazH/iodata into …
…FarnazH-write_input
- Loading branch information
Showing
15 changed files
with
587 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# IODATA is an input and output module for quantum chemistry. | ||
# Copyright (C) 2011-2019 The IODATA Development Team | ||
# | ||
# This file is part of IODATA. | ||
# | ||
# IODATA is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 3 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# IODATA is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
# -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# IODATA is an input and output module for quantum chemistry. | ||
# Copyright (C) 2011-2019 The IODATA Development Team | ||
# | ||
# This file is part of IODATA. | ||
# | ||
# IODATA is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 3 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# IODATA is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
# -- | ||
"""Utilities for writing input files.""" | ||
|
||
import attr | ||
|
||
import numpy as np | ||
|
||
from ..iodata import IOData | ||
from ..utils import angstrom | ||
|
||
__all__ = ['populate_fields'] | ||
|
||
|
||
def populate_fields(data: IOData) -> dict: | ||
"""Generate a dictionary with fields to replace in the template.""" | ||
# 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 | ||
# set general defaults | ||
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(abs(np.round(data.spinpol))) + 1 if data.spinpol is not None else 1 | ||
fields["charge"] = int(data.charge) if data.charge is not None else 0 | ||
return fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# IODATA is an input and output module for quantum chemistry. | ||
# Copyright (C) 2011-2019 The IODATA Development Team | ||
# | ||
# This file is part of IODATA. | ||
# | ||
# IODATA is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 3 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# IODATA is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
# -- | ||
"""Gaussian Input Module.""" | ||
|
||
|
||
from typing import TextIO | ||
from string import Template | ||
|
||
from .common import populate_fields | ||
|
||
from ..docstrings import document_write_input | ||
from ..iodata import IOData | ||
from ..periodic import num2sym | ||
|
||
|
||
__all__ = [] | ||
|
||
|
||
default_template = """\ | ||
#n ${lot}/${obasis_name} ${run_type} | ||
${title} | ||
${charge} ${spinmult} | ||
${geometry} | ||
""" | ||
|
||
|
||
@document_write_input("GAUSSIAN", ['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.""" | ||
# 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 Gaussian keywords | ||
run_types = {"energy": "sp", "energy_force": "force", "opt": "opt", "scan": "scan", | ||
"freq": "freq"} | ||
fields["run_type"] = run_types[fields["run_type"].lower()] | ||
# generate geometry (in angstrom) | ||
geometry = [] | ||
for num, coord in zip(fields["atnums"], fields["atcoords"]): | ||
geometry.append(f"{num2sym[num]:3} {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) |
Oops, something went wrong.