I have a text file (b.txt) like the following:
SOURCE 8 EXPRESSION_SYSTEM_PLASMID: PLEHP20
KEYWDS 2 METHODS, IRON-SULPHUR CLUSTER, METALLOPROTEIN
EXPDTA X-RAY DIFFRACTION
AUTHOR E.PARISINI,F.CAPOZZI,P.LUBINI,V.LAMZIN,C.LUCHINAT,
REVDAT 4 24-FEB-09 1CKU 1 VERSN
JRNL PMID 10531472
REMARK 1 REFERENCE 1
ATOM 1 N SER A 1 -8.686 33.363 10.216 1.00 33.39 N
ANISOU 1 N SER A 1 2884 4416 5388 1179 -1154 1000 N
HETATM 1565 O HOH B 350 7.855 16.938 27.107 1.00 34.27 O
ANISOU 1565 O HOH B 350 3399 5455 4168 135 -563 -23 O
I have a python code (see below) that reads only the lines that start with “ATOM” or “HETATOM”.
pdb_text = open("b.txt","r")
# read contents of the file to string
data = ""
data = pdb_text.read()
for line in data.split('\n'):
if line.startswith("ATOM") or line.startswith("HETATM"):
print(line)
The code works well and generates an output as the following.
ATOM 1 N SER A 1 -8.686 33.363 10.216 1.00 33.39 N
HETATM 1565 O HOH B 350 7.855 16.938 27.107 1.00 34.27 O
However, I want to export the output to a new file. How should I change the last line of the code to do this?