'''
This script takes a pdb file and converts it into a ANSYS mesh
Written by Tom Moore, 11/18/2009,
Michigan State Univeristy
'''
### get atoms cordinates from PDB file and write them as
###ANSYS keypoints
line_value = 0
keypoint_value = 0
file = open('C:\\xyz\\test.pdb', 'r')
igot = file.readlines()
output_file = open('C:\\xyz\\atom.txt', "a") # needs input for distinct file
output_file.write('/PREP7'+"\n") #open pre-processing menu
for line in igot:
if line.find("ATOM") > -1:
keypoint_value = keypoint_value + 1
kv = str(keypoint_value)
xyz = line.split()
#print kv,",", xyz[6], ",", xyz[7], ",", xyz[8]
line_i = "K" + ', '+ kv + ', ' + xyz[6] + ', ' + xyz[7] +', '+
xyz[8]+ "\n"
print line_i
output_file.write(line_i)
### reads connect records
elif line.find("CONECT") > -1:
con = line.split()
line_value = line_value + 1
#print line_value
#print con[2]
line_j = "L" + ', ' + str(line_value) + ', ' + con[2] + "\n"
output_file.write(line_j)
print line_j
line_i = "L" + ', ' + str(line_value) + ', ' + con[3] + "\n"
output_file.write(line_i)
print line_i
try:
line_k = "L"+ ', ' + str(line_value) + ', ' + con[4] + "\
n"
print line_k
output_file.write(line_k)
except IndexError:
continue