diff --git a/biopandas/pdb/pandas_pdb.py b/biopandas/pdb/pandas_pdb.py index 9e713c7..c25773d 100644 --- a/biopandas/pdb/pandas_pdb.py +++ b/biopandas/pdb/pandas_pdb.py @@ -610,6 +610,9 @@ def to_pdb(self, path, records=None, gz=False, append_newline=True): dfs = {r: self.df[r].copy() for r in records if not self.df[r].empty} + # Drop unexpected columns + dfs = {k: v[[pdb_df_columns]] for k, v in dfs.items() if k in {"ATOM", "HETATM"}} + for r in dfs: for col in pdb_records[r]: dfs[r][col["id"]] = dfs[r][col["id"]].apply(col["strf"])