MDMC.readers.configurations package

Submodules

MDMC.readers.configurations.ase module

MDMC wrapper for the ASE reader.

class MDMC.readers.configurations.ase.ASEReader(file_name: str)[source]

Bases: ConfigurationReader

Reader that wraps around the ASE reader.

extension = 'N/A'
parse(**settings: dict) None[source]

Parses any format supported by ASE’s file reader; the file is read in as an ase.atoms.Atoms object and then converted to MDMC Atoms.

MDMC.readers.configurations.cif module

Reads a .cif file into an MDMC molecule, optionally ignoring symmetry data. Adapted from https://wiki.fysik.dtu.dk/ase/_modules/ase/io/cif.html#read_cif.

class MDMC.readers.configurations.cif.CIFReader(file_name: str)[source]

Bases: ConfigurationReader

Reads a .cif file into a list of MDMC Atoms.

extension = 'cif'
parse(**settings: dict) None[source]

Parse a .cif file into a list of MDMC Atoms, optionally ignoring symmetry data.

Parameters:

settings

ignore_symmetry: bool, default True

Whether to read or ignore symmetry data.

MDMC.readers.configurations.conf_reader module

Module for observable reader abstract class

class MDMC.readers.configurations.conf_reader.ConfigurationReader(file_name: str)[source]

Bases: Reader

Abstract class (as it does not implement Reader.parse) that defines properties common to all readers for configurations

A ConfigurationReader is created using ConfigurationReaderFactory

property atoms: list[Atom]

The Atom objects parsed from the file.

MDMC.readers.configurations.conf_reader_factory module

Factory class for generating readers for configurations

class MDMC.readers.configurations.conf_reader_factory.ConfigurationReaderFactory[source]

Bases: ReaderFactory

Provides a factory for creating readers. Any module within the readers submodule can be created with a string of the class name, as long as it is a subclass of ConfigurationReader.

static base_class() type[ConfigurationReader][source]

This should be implemented to return the base class of objects returned by the ReaderFactory

classmethod create_reader_from_ext(extension: str, file_name: str) ConfigurationReader[source]
Parameters:
  • extension (str) – The file extension from which to initialize a subclass of ConfigurationReader

  • file_name (str) – The name of the file that you want to read.

Returns:

An initialized configuration reader which has the extension specified by extension

Return type:

ConfigurationReader

Raises:

NotImplementedError – If extension does not match the extension property of any subclass of ConfigurationReader

MDMC.readers.configurations.packmol_pdb module

A reader for reading in the PDB configuration of whole packmol systems

class MDMC.readers.configurations.packmol_pdb.PackmolPDBReader(file_name: str)[source]

Bases: ConfigurationReader

A class to read in packmol PDB output files

extension = 'NONE'
parse(**settings: dict) None[source]

Parses a .pdb file into a list of Structure`s (atoms and molecules) which can then be accessed as the `structures property of the reader.

Parameters:

**settings (dict, optional) – None are necessary for this reader.

property structures: List[Structure]

Returns a list of Molecule objects from the data read from the file

MDMC.readers.configurations.pdb module

Module for reading pdb files

class MDMC.readers.configurations.pdb.ProteinDataBankReader(file_name: str)[source]

Bases: ConfigurationReader

A class for reading pdb configuration files

Examples

To use a pdb reader to read a file called ‘paracetamol.pdb’ and create a set of ``Molecule``s from it:

file = 'water.pdb'
pdb_reader = pdb(file)
with pdb_reader:
    pdb_reader.parse()
    water = pdb_reader.molecules[0]
property atoms: list[Atom]

The Atom objects parsed from the file.

property bonds: list[Bond]

Returns the bonds within the molecule, as specified by “CONECT” statements in the pdb file

create_bond(atom1: Atom, atom2: Atom) None[source]

Checks the bond lengths of the atoms in the molecule and creates a bond if it is below a certain threshold

This is needed because PDB files are able to include H-bonds (which MDMC does not support) alongside other types of bonds, which are undistinguishable from each other in a pdb file. Therefore, cutting off the bond length at a reasonable distance prevents an extremely long bond being introduced into a molecule structure

extension = 'pdb'
parse(**settings: dict) None[source]

Parses the file data so that it is in a format expected by the class calling the data reader

For readers which are not specific to one data type, the calling class must be determined so that the file data can be parsed into the appropriate data type.

Parameters:

**settings (dict) – dictionary of settings for reader

Module contents

A subpackage for reading files containing atomic configurations

MDMC.readers.configurations.read(file: str, docstring: bool = False, **settings: dict) list[Atom] | None[source]

Reads a configuration file and returns a list of atoms corresponding to the atoms in the file

Note

The docstring of the required reader (as determined from the file) can be accessed by passing help=True. This may be necessary to determine the reader specific **settings that can be passed. In this case, the file will not be read and None will be returned, rather than a list of Atom objects.

Parameters:
  • file (str) – The file name of the configuration file

  • docstring (bool, optional) – This will show the docstring (help) related to the type of configuration file that has been passed. If this is True, the file will not be read and None will be returned. The default is False.

  • **settings – Parameters passed to ConfigurationReader.parse

Returns:

Atom objects corresponding to the configuration in the file. None will be returned if docstring=True.

Return type:

list of Atom, or None

Examples

To read a CIF file and define the atom_types of the atoms:

atoms = read('example.cif', atom_types=[1, 1, 2, 2, 2, 1, 3])

To get the docstring (help) for reading a CIF file:

read('example.cif', help=True)