-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep_xyz_molcas.py
executable file
·51 lines (40 loc) · 1.45 KB
/
prep_xyz_molcas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A script that prepares a xyz structure file
for an OpenMOLCAS input file.
written 2019 by Michael Böhme
https://github.com/micb25/chemtools
"""
import sys
from openbabel import openbabel
if ( (len(sys.argv) < 2) or (len(sys.argv) > 2) ):
sys.exit("Usage: %s input.xyz" % ( sys.argv[0] ))
openbabel.OBMessageHandler().SetOutputLevel(0)
# Unfortunately, this doesn't work and OB 3.x still shows warnings
# and openbabel.OBMessageHandler().GetOutputLevel() returns 1
obconv = openbabel.OBConversion()
obconv.SetInFormat('xyz')
obmol = openbabel.OBMol()
f = obconv.ReadFile(obmol, sys.argv[1])
if ( (f == False) or (obmol.NumAtoms() < 1) ):
sys.exit("error reading xyz structure file!")
for atom in openbabel.OBMolAtomIter(obmol):
if ( len(openbabel.GetSymbol(atom.GetAtomicNum())) == 1):
print("%s%-4i %16.8f %16.8f %16.8f /Angstrom" % (
openbabel.GetSymbol(atom.GetAtomicNum()),
atom.GetIndex() + 1,
atom.GetX(),
atom.GetY(),
atom.GetZ()
)
)
else:
print("%s%-3i %16.8f %16.8f %16.8f /Angstrom" % (
openbabel.GetSymbol(atom.GetAtomicNum()),
atom.GetIndex() + 1,
atom.GetX(),
atom.GetY(),
atom.GetZ()
)
)