.. _section_example_oechem_cifdata:

Creating an OECIFData Object
--------------------------------------------------------------------------------

In this example, we will use the :oe:cls:`OEChem::OECIFData` to get, add, delete, and set header data for an input
CIF file. We will use the PDB code 5NEV read using the mmCIF format, but any CIF header can be accessed with these APIs.
First, the molecule is read and the OECIFData object is created. This object holds the header data for easy editing.
To save any changes made to the header back onto the molecule, use the
:oe:func:`OEChem::OESetMMCIFChemCompData` function.

Read the data and generate the OECIFData object.

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-READCIF

:ref:`Full listing. <listing-cifdata.py>`

The OECIFData class allows access to all the data in a CIF header, but each CIF header category in a data block
is broken into smaller :oe:cls:`OEChem::OECIFCategory` objects which can be accessed and modified.

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-CATEGORY

:ref:`Full listing. <listing-cifdata.py>`

For more information about OECIFData, OECIFCategory, and the CIF file format, see :ref:`section_moldata_CIF`.

Attribute data is accessed by first specifying the CIF category name, and a specific data value in that category can be
accessed with the attribute. For the following example, the category is '_audit_author.', and the values correlate
with the attribute names.

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-ATTRIBUTES

:ref:`Full listing. <listing-cifdata.py>`

Editing data items can be done using the Set, Add, and Delete OECIFData functions. When specifying a data value
with multiple rows of data (i.e., CIF Loop Data), attribute values on a specific row can be accessed with a
base-0 row index:

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-SETDELETEADD

:ref:`Full listing. <listing-cifdata.py>`

The :oe:cls:`OEChem::OECIFData` object can be used to update or synchronize header data with changes to the
molecule. We can simulate this by first modifying a part of the molecule:

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-MODMOL

:ref:`Full listing. <listing-cifdata.py>`

Updating requires the user to specify which parts of the header are to be updated. This is done using the
:oe:cls:`OEChem::OECIFOptions` class. A more detailed explanation about which data items are affected by perception
can be found in the :ref:`section_moldata_CIF` theory. In the following example, we update the header and check
to make sure that our residue changes from above have been applied to the pertinent header locations.

.. oe:source:: cifdata.py
   :language: python
   :frag:     SNIPPET-CIFDATA-UPDATE

:ref:`Full listing. <listing-cifdata.py>`

* :oe:func:`OEChem::OESetMMCIFChemCompData` function
* :oe:func:`OEChem::OEUpdateMMCIFData` function
* :oe:cls:`OEChem::OECIFData` class
* :oe:cls:`OEChem::OECIFCategory` class
