bfactor_chg

Replace the B-factor column of a PDB with residue-summed charges from a .chg file.

Behavior: - Prompts for PDB and CHG filenames. - Verifies:

  1. The total number of non-empty lines in PDB equals the number of data lines in CHG.

  2. The PDB contains NO ‘TER’ lines (will abort if found).

  3. Every non-empty PDB line is ATOM or HETATM (since we expect 1:1 with CHG lines).

  • Sums charges per residue (chainID, resSeq, iCode) and writes that sum to the B-factor of every atom in the residue.

  • Writes output as: <pdb_stem>_bfactor_charge.pdb (e.g., B401_B402_bfactor_charge.pdb)

Notes on .chg: - Similar to XYZ but no header. We read the last whitespace-separated token as charge. - The number/order of lines must exactly match the PDB atom order.

Module Contents

Functions

ask_path(prompt, default)

die(msg[, code])

is_atom_record(→ bool)

residue_key(line)

Key residues by (chain_id, resseq, icode).

set_bfactor(→ str)

Return a copy of the PDB ATOM/HETATM line with B-factor (cols 61-66, 1-based)

read_charges_from_chg(path)

count_nonempty_lines(path)

main()

bfactor_chg.ask_path(prompt, default)
bfactor_chg.die(msg, code=1)
bfactor_chg.is_atom_record(line: str) bool
bfactor_chg.residue_key(line: str)

Key residues by (chain_id, resseq, icode).

bfactor_chg.set_bfactor(line: str, b: float) str

Return a copy of the PDB ATOM/HETATM line with B-factor (cols 61-66, 1-based) set to b, preserving occupancy (cols 55-60).

bfactor_chg.read_charges_from_chg(path: str)
bfactor_chg.count_nonempty_lines(path: str)
bfactor_chg.main()