Skip to content
Snippets Groups Projects
io.rst 20.50 KiB

:mod:`~ost.io` - Input and Output of Sequences, Structures and Maps

The io module deals with the input and output of :class:`entities <ost.mol.EntityHandle>`, :class:`alignments <ost.seq.AlignmentHandle>`, :class:`sequences <ost.seq.SequenceHandle>`, :class:`images <ost.img.ImageHandle>`. Importers for common file formats containing molecules such as PDB, SDF and CHARMM trajectory files are available. Sequence and alignment file formats such as FASTA and CLUSTALW are supported as well as various image data (e.g. png, dm3) and density map files (e.g. CCP4, MRC).

Molecular Structures

Loading Molecular Structures

The :mod:`~ost.io` modules offer several ways to load molecular structures depending on your requirements. The most general way is offered by :func:`~ost.io.LoadEntity`, which will automatically detect the file format based on the file extension.

Some of the formats have a dedicated function that allows you to tweak many parameters that affect the import. PDB files can be loaded with :func:`LoadPDB` and mmCIF files with :func:`LoadMMCIF` (this also gives you access to the :class:`MMCifInfo` class). It offers tighter control over the exact loading behaviour.

Experimental data format capable of storing minimally required information of a :class:`ost.mol.EntityHandle` in a heavily compressed manner (OMF - OpenStructure Minimal Format). Shares lots of ideas with the mmtf or binaryCIF formats but comes with no dependencies attached.

Loading Molecular Structures From Remote Repositories

:func:`LoadPDB` already provides access to selected structural databases in the internet when enabling the remote flag. Predefined :class:`ost.io.remote.RemoteRepository` objects are available as

from ost.io import remote
repo_name = 'smtl'
repo = remote.REMOTE_REPOSITORIES.get(repo_name)

# url for entry with id 1ake.1
print(repo.URLForID('1ake.1'))

where repo_name can be one of ['pdb', 'cif', 'pdb_redo', 'smtl']. Instead of explicit access, you can directly fetch data using:

Saving Molecular Structures

Saving a complete entity or a view is a matter of calling :func:`~ost.io.SaveEntity`.

ent = io.LoadEntity('protein.pdb')
# save full entity
io.SaveEntity(ent, 'full.pdb')
# only save C-alpha atoms
io.SaveEntity(ent.Select('aname=CA and peptide=true'), 'calpha.pdb')

:func:`~ost.io.SavePDB` provides a simple way to save several entities into one file:

ent = io.LoadEntity('protein.pdb')
# Save complete entity
io.SavePDB(ent, 'full.pdb')
# Save chain A and chain B separately
io.SavePDB([ent.Select('cname=A'), ent.Select('cname=B')], 'split.pdb')

Sequences and Alignments

Loading sequence or alignment files

Saving Sequence Data

Density Maps

Loading Density Maps

Saving Density Maps

Stereochemical Parameters

In order to check the structure for some stereo-chemical and steric clashes before computing the lDDT scores it is required to pass parameter file based on Engh and Huber parameters, and on the atomic radii as defined in the Cambridge Structural Database. OpenStructure ships with default file called stereo_chemical_props.txt located in $OST_ROOT/share/openstructure directory. A function :func:`~ost.io.ReadStereoChemicalPropsFile` is used to read this file.