Wednesday, June 22, 2016

Elizabeth Andrew's code for reading molecular coordinates from a file

#!/usr/bin/python

import sys
from pybel import *


mol = readfile("g09", "stauranthine_GC_dimer_xyz_1.out").next()

atomtotal = 0
for mol in readfile("g09", "stauranthine_GC_dimer_xyz_1.out"):
atomtotal += len(mol.atoms)


atom_number = { 1 : 'H',
6 : 'C',
7 : 'N',
8 : 'O'
}

for atom in mol:

x = atom.coords[0]
y = atom.coords[1]
z = atom.coords[2]
print atom_number[atom.atomicnum]+'\t'+str(x)+'\t'+str(y)+'\t'+str(z)

#I am having trouble getting the xyz coordinates to form right aligned even columns. Some of the coordinates have negative signs which causes the misalignment. 

3 comments:

  1. Not sure what pybel is (which library?)

    ReplyDelete
  2. Never mind (!) - located the package called openbabel - will check the code and let you know!

    ReplyDelete
  3. # seems OK - I imported into excel and it reads ok
    # check this code and let me know

    #!/usr/bin/python

    import sys
    from pybel import *

    atom_number = { 1 : 'H',
    6 : 'C',
    7 : 'N',
    8 : 'O'
    }


    atomtotal = 0

    molfile = readfile("g09", "stauranthine_GC_dimer_xyz_1.out")

    for mol in molfile:
    atomtotal += len(mol.atoms)
    for atom in mol:
    x = atom.coords[0]
    y = atom.coords[1]
    z = atom.coords[2]
    w = atom.atomicnum
    print str(w) + '\t' + str(x) + '\t' + str(y) + '\t' + str(z)

    ReplyDelete