parmed.formats.registry.load_file

parmed.formats.registry.load_file(filename, *args, **kwargs)[source]

Identifies the file format of the specified file and returns its parsed contents.

Parameters
filenamestr

The name of the file to try to parse. If the filename starts with http:// or https:// or ftp://, it is treated like a URL and the file will be loaded directly from its remote location on the web

structureobject, optional

For some classes, such as the Mol2 file class, the default return object is not a Structure, but can be made to return a Structure if the structure=True keyword argument is passed. To facilitate writing easy code, the structure keyword is always processed and only passed on to the correct file parser if that parser accepts the structure keyword. There is no default, as each parser has its own default.

natomint, optional

This is needed for some coordinate file classes, but not others. This is treated the same as structure, above. It is the # of atoms expected

hasboxbool, optional

Same as structure, but indicates whether the coordinate file has unit cell dimensions

skip_bondsbool, optional

Same as structure, but indicates whether or not bond searching will be skipped if the topology file format does not contain bond information (like PDB, GRO, and PQR files).

*argsother positional arguments

Some formats accept positional arguments. These will be passed along

**kwargsother options

Some formats can only be instantiated with other options besides just a file name.

Returns
object

The returned object is the result of the parsing function of the class associated with the file format being parsed

Raises
IOError

If filename does not exist

parmed.exceptions.FormatNotFound

If no suitable file format can be identified, a TypeError is raised

TypeError

If the identified format requires additional arguments that are not provided as keyword arguments in addition to the file name

Notes

Compressed files are supported and detected by filename extension. This applies both to local and remote files. The following names are supported:

  • .gz : gzip compressed file

  • .bz2 : bzip2 compressed file

SDF file is loaded via rdkit package.

Examples

Load a Mol2 file

>>> load_file('tripos1.mol2')
<ResidueTemplate DAN: 31 atoms; 33 bonds; head=None; tail=None>

Load a Mol2 file as a Structure

>>> load_file('tripos1.mol2', structure=True)
<Structure 31 atoms; 1 residues; 33 bonds; NOT parametrized>

Load an Amber topology file

>>> load_file('trx.prmtop', xyz='trx.inpcrd')
<AmberParm 1654 atoms; 108 residues; 1670 bonds; parametrized>

Load a CHARMM PSF file

>>> load_file('ala_ala_ala.psf')
<CharmmPsfFile 33 atoms; 3 residues; 32 bonds; NOT parametrized>

Load a PDB and CIF file

>>> load_file('4lzt.pdb')
<Structure 1164 atoms; 274 residues; 0 bonds; PBC (triclinic); NOT parametrized>
>>> load_file('4LZT.cif')
<Structure 1164 atoms; 274 residues; 0 bonds; PBC (triclinic); NOT parametrized>

Load a Gromacs topology file – only works with Gromacs installed

>>> load_file('1aki.ff99sbildn.top')
<GromacsTopologyFile 40560 atoms [9650 EPs]; 9779 residues; 30934 bonds; parametrized>

Load a SDF file – only works with rdkit installed

>>> load_file('mol.sdf', structure=True)
<Structure 34 atoms; 1 residues; 66 bonds; NOT parametrized>