Skip to content

Mgltools

Implementation for receptor preparation using MGLTools pre-docking.

MglTools(input_file, output_basename, config_obj)

Class to handle receptor preparation using MGLTools.

Initialize MglTools with a given configuration object.

PARAMETER DESCRIPTION
input_file

Path to the input receptor file.

output_basename

Basename used for the generated receptor files. If None, defaults to same as input file without extension.

config_obj

Configuration object for prepare_receptor4.py.

config = config_obj

input_file = os.path.abspath(input_file)

output_basename = os.path.splitext(self.input_file)[0]

pdbqt_file

Path to the PDBQT that prepare_receptor4.py writes.

run()

Run the MGLTools receptor preparation process.

RETURNS DESCRIPTION
str

Path to the generated PDBQT file.

PqrAtom(record, serial, atom_name, resname, chain, resseq, icode, x, y, z, charge, radius)

The fields of a single PQR atom record, parsed out of a malformed line.

atom_name

Atom name, e.g. CA, OXT, HD11. PDB columns 13-16.

chain

Single-character chain identifier, or a space when absent. PDB column 22.

charge

Partial atomic charge in electrons, in the PDB occupancy column.

icode

Insertion code for residues sharing a number, or a space. PDB column 27.

radius

Atomic radius in angstroms, in the PDB B-factor column.

record

Record type, either ATOM or HETATM. PDB columns 1-6.

resname

Residue name, e.g. LEU, HOH, M3A. PDB columns 18-20.

resseq

Residue sequence number. PDB columns 23-26.

serial

Atom serial number, unique within the file. PDB columns 7-11.

x

Orthogonal coordinate in angstroms. PDB columns 31-38, format 8.3f.

y

Orthogonal coordinate in angstroms. PDB columns 39-46, format 8.3f.

z

Orthogonal coordinate in angstroms. PDB columns 47-54, format 8.3f.

align_chains(source_lines, output_lines)

Recover the chain of each output residue by position, not by number.

PARAMETER DESCRIPTION
source_lines

Lines of the input receptor, before the chain was removed.

output_lines

Lines of the PDBQT that MGLTools produced.

RAISES DESCRIPTION
ValueError

If an output residue cannot be found in the remaining input sequence, which would mean the order was not preserved.

RETURNS DESCRIPTION
list[str]

Chain identifier for each output residue block, in order.

blank_chain_column(lines)

Replace the chain identifier with a space on every atom line.

Vacating column 22 leaves Mgltools nothing to absorb into the residue number, so four-digit numbering survives intact.

PARAMETER DESCRIPTION
lines

The file's lines.

RETURNS DESCRIPTION
tuple[list[str], int]

Tuple of (rewritten lines, number of lines changed).

format_pqr_atom_line(atom)

Render parsed fields back into strict fixed-width PDB columns.

PARAMETER DESCRIPTION
atom

The parsed atom fields.

RETURNS DESCRIPTION
str

A single line MGLTools' fixed-width parser can read.

has_fused_resseq(lines)

Whether a chain ID abuts a four-digit residue number on any atom line.

Three-digit numbers right-pad into columns 23-26 and leave column 22 visibly separate, so they parse correctly and need no intervention.

PARAMETER DESCRIPTION
lines

The file's lines.

RETURNS DESCRIPTION
bool

True if at least one line would be corrupted by Mgltools PQR parser.

parse_pqr_atom_line(line)

Parse a PQR atom line whose columns may have run together.

Works backwards from the five trailing floats (x, y, z, charge, radius), then splits the remaining prefix on whitespace. This tolerates the fused columns PDB2PQR emits for large negative numbers as well as the extra padding added by --whitespace.

WARNING: PQR only. A PDB line's numeric tail is x, y, z, occupancy, B-factor, so this would silently relabel occupancy as charge.

PARAMETER DESCRIPTION
line

A raw ATOM/HETATM line.

RETURNS DESCRIPTION
PqrAtom | None

The parsed fields, or None if the line does not look like a PQR atom

PqrAtom | None

record (caller should then pass the line through untouched).

residue_sequence(lines)

Collapse atom lines into one entry per contiguous residue block.

PARAMETER DESCRIPTION
lines

The file's lines.

RETURNS DESCRIPTION
list[tuple[str, str, str]]

Ordered list of (chain, resSeq-plus-icode, resname), one per residue.

restore_chain_column(lines, assigned)

Write chain identifiers back onto atom lines, block by block.

Overwrites whatever Mgltools put in the chain column, which is 'U' (the first character of its 'UNK' placeholder) when no chain was present in the input.

PARAMETER DESCRIPTION
lines

The output file's lines.

assigned

Chain identifier per residue block, from :func:align_chains.

RETURNS DESCRIPTION
tuple[list[str], int]

Tuple of (rewritten lines, number of atoms restored).

strip_hetatm_lines(lines, cleanup)

Drop HETATM lines that the -U cleanup mode would remove anyway.

Stripping these up front matters because MGLTools often cannot parse HETATM records at all, so it fails before the cleanup would have applied. No line is reformatted, so this is safe for any fixed-column format.

PARAMETER DESCRIPTION
lines

The file's lines, without terminators.

cleanup

The cleanup mode passed to prepare_receptor4.py (-U flag).

RETURNS DESCRIPTION
tuple[list[str], int, int]

Tuple of (kept lines, waters removed, other HETATMs removed).