cif

Module for reading cif files

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

A class for reading CIF configuration files

Examples

To use a CIF reader to read a file called ‘paracetamol.cif’ and create a Molecule from it (assuming Molecule has been imported from MDMC.MD):

file = 'paracetamol.cif'
cif = CIF()
cif.open(file)
# See parse docstring for description of ``names`` parameter
# Lines are oxygen, nitrogen, carbon and hydrogen atoms
cif.parse(names=['109', '177', # Oxygens
                 '207', # Nitrogen
                 '208', '108', '90', '178', '90', '90', '90', '185',
                 '85', '85', '85', '91', '91', '91', '91', '183', '110']
         ) # Hydrogens)
paracetamol = Molecule(atoms=cif.atoms)
property atoms: list[Atom]

All subclasses must implement atoms, which returns a list of Atom objects from the data read from the file

parse(**settings: dict) None[source]

Reads a configuration file and returns a list of Atom objects.

These Atom objects can optionally have Coulombic interactions and also BondedInteraction objects if bonded interactions are defined in the CIF file.

If names or atom_types is passed, then equivalent interactions (Coulombic and BondedInteraction, if bonded interactions are defined in the CIF file) will be initialized as a single object. For instance if the CIF file includes a benzene ring, then as long as the correct names or atom_types are passed, then there will only be a single C-C Bond object, which will include all 6 of the atom pairs. If both names and atom_types are passed, atom_types will be used to group Atom objects. If neither names or atom_types is passed then each interaction will become a separate object.

Note

Not all CIF files contain bonded interactions (it is only common for biomolecules).

Note

improper dihedrals are not explicitly defined in CIF, so these must be set after initialization of DihedralAngle objects.

Note

CIF reader cannot parse CIF files with user defined text sections, so these must be stripped out before reading.

Parameters
  • file (file, str) – A file, or the absolute file name of the configuration file

  • **settings

    index (int, optional)

    The index of the configuration in the CIF file. Only a single configuration can be read from a CIF file, with the default being the first (index=0) configuration.

    names(list of str)

    A list of names for the atoms in the CIF file. These names must have the same order as the order the atoms in the file. A name must be be provided for each atom in the CIF file.

    atom_types(list of int)

    A list of int for atom types of the atoms in the CIF file. These names must have the same order as the order the atoms in the file. An atom_type must be provided for each atom in the CIF file.

    cutoff(float)

    A distance (in Ang) at which the Coulombic interactions are cutoff. If this is not passed, the cutoff will be set to 10.

    add_bonds(bool, optional)

    Whether or not any bonded interactions defined in the CIF file will be included. By default this is True.

    add_charges(bool, optional)

    Whether or not each atom in the CIF file will be assigned a Coulombic interaction with a Coulomb function. CIF files do not contain charge information, so the charge of the Coulombic interaction will be set to 0. This enables the charges to be set by the application of a ForceField object. By default this is True.

Returns

The Atom objects corresponding to the data in the CIF file

Return type

list of Atom