for an assignment I have to read a small .pdb file in Python, change some values, and save it as a new .pdb file.
My original file is like this:
ATOM 19 HD2 TYR 1 26.910 61.717 39.871 1.00 0.00 H ATOM 20 C TYR 1 29.796 62.354 41.246 1.00 0.00 C ATOM 23 H SER 2 30.611 61.950 39.410 1.00 0.00 H ATOM 24 CA SER 2 30.082 64.035 39.354 1.00 0.00 C END I have tried with Pandas but with no success, as I cannot save it in the desired extension without it also saving an index, which I don't want (I used .to_csv('newfile.pdb')).
I have found a module called BioPython, and this is my attempt with it:
from Bio.PDB import PDBParser, PDBIOdef translate_atoms(structure, resname, translation_vector): for model in structure: for chain in model: for residue in chain: if residue.resname == resname: for atom in residue: atom.coord += translation_vectorpdb_file = "pdb1.pdb"# Read the PDB filepdb_parser = PDBParser(QUIET=True)structure = pdb_parser.get_structure("original_pdb1", pdb_file)# Translation vector for x direction (0.55 nm, so 5.5Å)translation_vector = [5.5, 0, 0]# Translate all atoms of SER residue in x directiontranslate_atoms(structure, "SER", translation_vector)# Write the modified structure to a new PDB fileoutput_pdb = "modified_pdb1.pdb"pdb_io = PDBIO()pdb_io.set_structure(structure)pdb_io.save(output_pdb)This does what I want as far as changing the values but when I save it adds an unwanted line, like so:
ATOM 19 HD2 TYR 1 26.910 61.717 39.871 1.00 0.00 H ATOM 20 C TYR 1 29.796 62.354 41.246 1.00 0.00 C ATOM 23 H SER 2 36.111 61.950 39.410 1.00 0.00 H ATOM 24 CA SER 2 35.582 64.035 39.354 1.00 0.00 C TER 33 SER 2ENDHow can I save it without that last line?
Thank you for your help!