You can take advantage of such programs like MDAnalysis, which provide you with a powerful Python glue for MD analysis commands. In this link you can learn how to write a PDB file. Just before that use can use command
atoms=u.selectAtoms("all")
atoms.set_name("lalalal some string")
(there is also the same attribute for residues(chains) and etc)