parmed.formats.mol2 module

This module contains parsers for mol2-format files (with support for the mol3 extension described at http://q4md-forcefieldtools.org/Tutorial/leap-mol3.php

class parmed.formats.mol2.Mol2File[source]

Bases: object

Class to read and write TRIPOS Mol2 files

Methods

id_format(filename)

Identify the file as a Mol2 (or Mol3) file format or not

parse(filename[, structure])

Parses a mol2 file (or mol3) file

write(struct, dest[, mol3, split, …])

Writes a mol2 file from a structure or residue template

BOND_ORDER_MAP = {'am': 1.25, 'ar': 1.5}
REVERSE_BOND_ORDER_MAP = {1.25: 'am', 1.5: 'ar'}
static id_format(filename)[source]

Identify the file as a Mol2 (or Mol3) file format or not

Parameters
filenamestr

Name of the file to test whether or not it is a mol2 file

Returns
is_fmtbool

True if it is a mol2 (or mol3) file, False otherwise

static parse(filename, structure=False)[source]

Parses a mol2 file (or mol3) file

Parameters
filenamestr or file-like

Name of the file to parse or file-like object to parse from

structurebool, optional

If True, the return value is a Structure instance. If False, it is either a ResidueTemplate or ResidueTemplateContainter instance, depending on whether there is one or more than one residue defined in it. Default is False

Returns
moleculeStructure, ResidueTemplate, or

ResidueTemplateContainer

The molecule defined by this mol2 file

Raises
Mol2Error

If the file format is not recognized or non-numeric values are present where integers or floating point numbers are expected. Also raises Mol2Error if you try to parse a mol2 file that has multiple @<MOLECULE> entries with structure=True.

static write(struct, dest, mol3=False, split=False, compress_whitespace=False)[source]

Writes a mol2 file from a structure or residue template

Parameters
structStructure or ResidueTemplate or

ResidueTemplateContainer

The input structure to write the mol2 file from

deststr or file-like obj

Name of the file to write or open file handle to write to

mol3bool, optional

If True and struct is a ResidueTemplate or container, write HEAD/TAIL sections. Default is False

splitbool, optional

If True and struct is a ResidueTemplateContainer or a Structure with multiple residues, each residue is printed in a separate @<MOLECULE> section that appear sequentially in the output file

compress_whitespacebool, optional

If True, seprate fields on one line with a single space instead of aligning them with whitespace. This is useful for parsers that truncate lines at 80 characters (e.g., some versions of OpenEye). However, it will not look as “neat” upon visual inspection in a text editor. Default is False.