Skip to content

Instantly share code, notes, and snippets.

@twobob
Created June 29, 2022 13:05
Show Gist options
  • Save twobob/001104a2e89420f8b6ac799dea4aef4d to your computer and use it in GitHub Desktop.
Save twobob/001104a2e89420f8b6ac799dea4aef4d to your computer and use it in GitHub Desktop.
#gpt3 create a mogli xyz file using python for a molecule that is composed of a metal center and a radical, which consists of a cyclopentadienyl group and a methyl group. The metal center can be iron, nickel, or cobalt.
#!/usr/bin/env python
import re
import sys
import itertools
import numpy as np
from mogli import *
def main():
# check for correct usage
if len(sys.argv) != 4:
print ('Usage: mogli.py -m <metal> -r <radical1> -r <radical2>')
return
# process command line arguments
metal = sys.argv[1]
if metal not in ['Fe', 'Ni', 'Co']:
print ('Error: invalid metal argument')
return
radicals = sys.argv[2:]
if len(radicals) != 2:
print ('Error: invalid number of radicals')
return
# build the molecule
mol = Molecule()
mol.add_atom(Atom(metal, 0.0, 0.0, 0.0))
for radical in radicals:
if radical == 'Cp*':
mol.add_atom(Atom('C', 1.39, 0.0, 0.0))
mol.add_atom(Atom('H', 1.39, 0.927, 0.0))
mol.add_atom(Atom('H', 1.39, -0.927, 0.0))
mol.add_atom(Atom('C', 0.0, 1.39, 0.0))
mol.add_atom(Atom('H', 0.927, 1.39, 0.0))
mol.add_atom(Atom('H', -0.927, 1.39, 0.0))
mol.add_atom(Atom('C', -1.39, 0.0, 0.0))
mol.add_atom(Atom('H', -1.39, -0.927, 0.0))
mol.add_atom(Atom('H', -1.39, 0.927, 0.0))
mol.add_atom(Atom('C', 0.0, -1.39, 0.0))
mol.add_atom(Atom('H', 0.927, -1.39, 0.0))
mol.add_atom(Atom('H', -0.927, -1.39, 0.0))
elif radical == 'CH3':
mol.add_atom(Atom('C', 0.0, 0.0, 1.2))
mol.add_atom(Atom('H', 0.0, 0.0, 2.2))
mol.add_atom(Atom('H', 0.0, 0.927, 1.2))
mol.add_atom(Atom('H', 0.811, -0.464, 1.2))
mol.add_atom(Atom('H', -0.811, -0.464, 1.2))
else:
print ('Error: invalid radical argument')
return
# write the xyz file
with open('mogli.xyz', 'w') as fout:
fout.write('%d\n\n' % len(mol.atoms))
for atom in mol.atoms:
fout.write('%-2s %f %f %f\n' % (atom.symbol, atom.x, atom.y, atom.z))
if __name__ == '__main__':
main()
#mog.py -m Fe -r 'Cp*' -r 'CH3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment