Mod:Hunt Research Group:gen symbolic zmat

From wiki
Jump to navigation Jump to search

create the input file

  • create a file called *.xyz
  • where * is your base filename
  • use the code extract_structure.py
  • this will give you a file filename.xyz
  • the format of the file obtained from extract_structure.py will be
number of atoms
headings
atomic no, then xyz coords
  • YOU will need to
add the number of a single fixed atom (after the number of atoms)
if no atoms are fixed put a zero here
change the atomic number to an atomic character
eg change 6 to C
  • for example below is a standard output for a water log file
[tricia@]/Users/tricia/files/work/jobs/field $ cat water.xyz
3 
atomic no, xyz coords 
   8   0.077373   0.000000   0.000000 
   1   0.603764   0.000000   0.790154 
   1   0.603764   0.000000  -0.790154 
  • I've changed this to fix atom 2
  • note I've named the new file watera.xyz
[tricia@]/Users/tricia/files/work/jobs/field $ vi watera.xyz
3
2
atomic no, xyz coords 
   8   0.077373   0.000000   0.000000 
   1   0.603764   0.000000   0.790154
   1   0.603764   0.000000  -0.790154

run the code

  • now run the code to generate the symbolic z-matrix
  • use the new filename.xyz file as an argument (without .xyz)
symb_zmat.py filename
the output file will be *.symb
you should see something like the following
  • where the code cat's the final file to the screen
[tricia@]/Users/tricia/files/work/jobs/field $ symb_zmat.py watera
directory is /Users/tricia/Files/work/jobs/field
input file is watera.xyz
output file is watera.symb
number of atoms 3
fixed atom is  2
cat of file:
3 
8  0  x1    y1     z1    
1  0  x2    y2     z2    
1  0  x3    y3     z3    

  x1  = 0.077373 
  y1  = 0.000000 
  z1  = 0.000000 
  x3  = 0.603764 
  y3  = 0.000000 
  z3  =-0.790154 

  x2  = 0.603764 
  y2  = 0.000000 
  z2  = 0.790154 


  • output file
first is the number of atoms
then the coord matrix
then the variables
then the fixed atom coordinates as constants

symb_zmat.py

#!/opt/local/bin/python3
#
# symb_zmat.py
#
# python script to take cartesian coords and convert to a symbolic z-matrix format.
# FIRST use extract_structure.pp to extract a structure
# to run the script type python pos_zmat.py input_file_name (without extension)
# input file has extension .xyz and same format as extract_structure.py output
#   number of atoms
#   fixed atom
#   column headings
#   atomic symbol and coordinates

#
import sys
import os
dir=os.getcwd()
#
if len(sys.argv) == 1:
  print('to run the script please type: python symb_zmat.py input_file_name \(without extension\)')
  sys.exit()
else:
  base=str(sys.argv[1])
  file=base+'.xyz'
  out=base+'.symb'
  s='directory is '
  print('{0:}{1:}'.format(s,dir))
  s='input file is '
  print('{0:}{1:}'.format(s,file))
  s='output file is '
  print('{0:}{1:}'.format(s,out))
#close if
#
# set some defaults
col_atom=[]
col_x=[]
col_y=[]
col_z=[]

# open file and read lines one by one
f=open(file,"r")

line =f.readline()
atomno=int(line.rstrip())
s='number of atoms '
print('{0:}{1:}'.format(s,atomno))
line =f.readline()
fixedatom=int(line.rstrip())
if fixedatom==0 :
  s='no fixed atoms  '
  print('{0:}'.format(s))
else:
  s='fixed atom is  '
  print('{0:}{1:}'.format(s,fixedatom))
#endif
line =f.readline()
n=0
while n < atomno :
  line =f.readline()
#  print('{0:}'.format(line))
  a1,b1,c1,d1=line.rstrip().split()
  col_atom.append(a1)
  col_x.append(float(b1))
  col_y.append(float(c1))
  col_z.append(float(d1))
  n=n+1
#close while

#now write to the .symb_xyz file
c=open(out,"w")
c.write('{0:} \n'.format(atomno))

#
#write out z-matrix
#
#note that we don't have x0,y0,z0 variables so print m
n=0
while n < atomno:
  m=n+1
  c.write('{0:}  0  x{1:<4} y{2:<4}  z{3:<4} \n'.format(col_atom[n],m,m,m))
  n=n+1
#close while

#
#write out constants and variables, variables first
#
if fixedatom == 0:
  print('fixed atom',fixedatom)
  n=0
  while n < atomno:
    m=n+1
    c.write('  x{0:<3}={1:>9.6f} \n  y{2:<3}={3:9.6f} \n  z{4:<3}={5:9.6f} \n'.format(m,col_x[n],m,col_y[n],m,col_z[n]))
    n=n + 1
  #close while
else:
#variables
  n=0
  c.write('\n'.format())
  while n < fixedatom-1:
#    print('n= ',n)
    m=n+1
    c.write('  x{0:<3}={1:>9.6f} \n  y{2:<3}={3:9.6f} \n  z{4:<3}={5:9.6f} \n'.format(m,col_x[n],m,col_y[n],m,col_z[n]))
    n=n+1
  #endwhile
  if n == fixedatom-1: n=n+1
#  print('fixed n= ',n-1)
  while ( n > fixedatom-1 and n < atomno ):
#    print('n= ',n)
    m=n+1
    c.write('  x{0:<3}={1:>9.6f} \n  y{2:<3}={3:9.6f} \n  z{4:<3}={5:9.6f} \n'.format(m,col_x[n],m,col_y[n],m,col_z[n]))
    n=n+1
  #endwhile
#constant
  c.write('\n'.format())
  n=fixedatom-1
  m=n+1
  c.write('  x{0:<3}={1:>9.6f} \n  y{2:<3}={3:9.6f} \n  z{4:<3}={5:9.6f} \n'.format(m,col_x[n],m,col_y[n],m,col_z[n]))
#endif
#
#terminate with blank line
#
c.write('\n\n'.format())
# close all open files
#
f.close()
c.close()
#
#print file to screen
#
print('cat of file:')
os.system("cat " +out )
#