Skip to content

Commit 1fd1984

Browse files
committed
Added create_guassian_input NO_JIRA
1 parent 62d796f commit 1fd1984

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Create Gaussian Input
2+
3+
----
4+
5+
## Summary
6+
7+
Allows the user to generate a Gaussian input file (.gjf) for a given CSD refcode or .mol2. If you wish to run different keywords the script will need to be changed manually.
8+
9+
10+
## Requirements
11+
12+
Tested with CSD Python API 3.0.9
13+
14+
15+
## Licensing Requirements
16+
17+
CSD-Core
18+
19+
If you wish to run Gaussian, you will need to acquire a licence for Gaussian, this is not supplied by the CCDC.
20+
21+
## Instructions on running
22+
23+
To create an input file for the
24+
```cmd
25+
>python create_gaussian_input.py HXACAN
26+
```
27+
28+
```cmd
29+
>python create_gaussian_input.py HXACAN.mol2
30+
```
31+
32+
## Author
33+
34+
_Andrew Malone_
35+
36+
> For feedback or to report any issues please contact [support@ccdc.cam.ac.uk](support@ccdc.cam.ac.uk)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#
2+
# This script can be used for any purpose without limitation subject to the
3+
# conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
4+
#
5+
# This permission notice and the following statement of attribution must be
6+
# included in all copies or substantial portions of this script.
7+
#
8+
# 2015-06-17: created by the Cambridge Crystallographic Data Centre
9+
#
10+
11+
from __future__ import division, absolute_import, print_function
12+
13+
"""
14+
This script will generate a generic Gaussian input file
15+
Input: CSD Identifier as a string
16+
Output: HTML File to working Directory
17+
Author: Andy Maloney 2015
18+
"""
19+
20+
import sys
21+
import os
22+
import ccdc.io
23+
import glob
24+
25+
26+
def fatal(*args):
27+
"""Generates an error message if necessary to smoothly exit the program."""
28+
print('ERROR:', ' '.join(map(str, args)))
29+
sys.exit(1)
30+
31+
32+
def file_writer(molecule, name):
33+
"""Writes a standard Gaussian input file for all molecules contained in the structure files."""
34+
if not mol.all_atoms_have_sites:
35+
fatal(entry_id, 'has some atoms without coordinates')
36+
mol.normalise_hydrogens()
37+
38+
for i, component in enumerate(molecule.components):
39+
40+
file_name = '%s_molecule%d.gjf' % (name, i)
41+
f = open(file_name, 'w')
42+
43+
f.write('#B3LYP/6-31G** opt\n')
44+
f.write('\n')
45+
f.write('Standard Gaussian Input File for %s, molecule %d\n' % (name, i))
46+
f.write('\n')
47+
f.write('0 1\n')
48+
49+
for atom in component.atoms:
50+
f.write('%2s %9.6f %9.6f %9.6f\n' % (atom.atomic_symbol,
51+
atom.coordinates.x,
52+
atom.coordinates.y,
53+
atom.coordinates.z))
54+
55+
f.write('\n')
56+
f.write('--Link1--')
57+
f.write('\n')
58+
f.write('\n')
59+
f.write('\n')
60+
61+
f.close()
62+
63+
64+
if __name__ == '__main__':
65+
# Get the relevant structure typed by user
66+
if len(sys.argv) != 2:
67+
fatal('you must supply a structure identifier.')
68+
entry_id = sys.argv[1]
69+
70+
# Checking the current directory for user cif file
71+
filepath = '%s' % entry_id
72+
if os.path.isfile(filepath):
73+
reader = ccdc.io.MoleculeReader(filepath)
74+
for mol in reader:
75+
identifier = mol.identifier
76+
file_writer(mol, identifier)
77+
78+
else:
79+
# Read molecule from database
80+
reader = ccdc.io.MoleculeReader('CSD')
81+
identifier = entry_id
82+
try:
83+
mol = reader.molecule(entry_id)
84+
file_writer(mol, identifier)
85+
except RuntimeError:
86+
fatal(entry_id, '- structure not found')

0 commit comments

Comments
 (0)