pestifer.charmmff.ligand_paramgen.mol2_writer module

Write a protonated RDKit Mol to a Tripos mol2 file via Open Babel.

We stamp PDB-style atom names onto every atom (heavy atoms keep the names attached by protonate_ligand(); hydrogens get sequential H<n> names), emit a PDB block, then shell out to obabel for format conversion. Open Babel only sees the already-protonated, already-named structure, so it never mangles atom names or alters the H count.

exception pestifer.charmmff.ligand_paramgen.mol2_writer.Mol2WriteError[source]

Bases: RuntimeError

Raised when mol2 generation fails.

pestifer.charmmff.ligand_paramgen.mol2_writer.write_mol2(mol: Chem.Mol, resname: str, outpath: str | os.PathLike) Path[source]

Write mol to outpath as a mol2 file via Open Babel.

Atom names on the result are:

  • heavy atoms: the value of the RDKit property _pdb_name if set, otherwise the atom’s element symbol.

  • hydrogens: sequential H1, H2, … in RDKit atom-index order.

Parameters:
  • mol – RDKit Mol with 3D coordinates and explicit Hs (as returned by pestifer.charmmff.ligand_paramgen.protonate_ligand()).

  • resname – Three-letter residue name to stamp on every atom (used by CGenFF and by Open Babel’s PDB reader).

  • outpath – Destination mol2 path.

Returns:

The path that was written.

Return type:

pathlib.Path