I made {sample}.csv consisted of chain name, residue name and residue id extracted from original pdb files.
> {sample}.csv
> >{sample}, A, NDP, 351
But it includes HETATM so I would like to make new files of pdb format which only contain HETATM information.
I used code below and got the error saying string is not defined
.
import os
import sys
input = [f for f in os.listdir('./') if f.endswith('.pdb')]
pdb = input
input2 = [c for c in os.listdir('./') if c.endswith('csv')]
csv = input2
HETATM = []
# iterate over lines in pdb
for file in pdb:
f_open = open('./'+file,'r')
for file in csv:
c_open = open('./'+file, 'r')
for line in f_open:
if line.startswith('HETATM'):
res_name = line[17:20].replace(' ','')
chain_name = line[21:22].replace(' ','')
residue_id = line[22:26].replace(' ','')
string = chain_name + ',' + res_name + ',' + residue_id + '\n'
for line2 in c_open:
if string in c_open:
HETATM.append(string)
I am totally a beginner just started to learn python so don't have an idea how to approach. I would really appreciate your help!
Can you post the exact error from your console please? We don't know where your error is arising.