Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing documentation for the OpenBabel Converter #20

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ mda-openbabel-converter
| **Status** | [![GH Actions Status][badge_actions]][url_actions] [![codecov][badge_codecov]][url_codecov] |
| **Community** | [![License: GPL v2][badge_license]][url_license] [![Powered by MDAnalysis][badge_mda]][url_mda]|

[badge_actions]: https://github.com/lunamorrow/mda_openbabel_converter/actions/workflows/gh-ci.yaml/badge.svg
[badge_codecov]: https://codecov.io/gh/lunamorrow/mda_openbabel_converter/branch/main/graph/badge.svg
[badge_commits_since]: https://img.shields.io/github/commits-since/lunamorrow/mda_openbabel_converter/latest
[badge_docs]: https://readthedocs.org/projects/mda_openbabel_converter/badge/?version=latest
[badge_actions]: https://github.com/MDAnalysis/mda_openbabel_converter/actions/workflows/gh-ci.yaml/badge.svg
[badge_codecov]: https://codecov.io/gh/MDAnalysis/mda_openbabel_converter/branch/main/graph/badge.svg
[badge_commits_since]: https://img.shields.io/github/commits-since/MDAnalysis/mda_openbabel_converter/latest
[badge_docs]: https://mda-openbabel-converter.readthedocs.io/en/latest/
[badge_license]: https://img.shields.io/badge/License-GPLv2-blue.svg
[badge_mda]: https://img.shields.io/badge/powered%20by-MDAnalysis-orange.svg?logoWidth=16&logo=data:image/x-icon;base64,AAABAAEAEBAAAAEAIAAoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJD+XwCY/fEAkf3uAJf97wGT/a+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AAA2AAAAMwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB0AAADoAAAA/wAAAP8AAAD/AAAAWgC3/2AAnv3eAJ/+dgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9AAAA/wAAAP8AAAD/AAAA/wAKDzEAnP3WAKn//wCS/OgAf/8MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIQAAANwAAADtAAAA7QAAAMAAABUMAJn9gwCe/e0Aj/2LAP//AQAAAAAAAAAA
[badge_release]: https://img.shields.io/github/release-pre/lunamorrow/mda_openbabel_converter.svg
[url_actions]: https://github.com/lunamorrow/mda_openbabel_converter/actions?query=branch%3Amain+workflow%3Agh-ci
[url_codecov]: https://codecov.io/gh/lunamorrow/mda_openbabel_converter/branch/main
[badge_release]: https://img.shields.io/github/release-pre/MDAnalysis/mda_openbabel_converter.svg
[url_actions]: https://github.com/MDAnalysis/mda_openbabel_converter/actions?query=branch%3Amain+workflow%3Agh-ci
[url_codecov]: https://codecov.io/gh/MDAnalysis/mda_openbabel_converter/branch/main
[url_docs]: https://mda_openbabel_converter.readthedocs.io/en/latest/?badge=latest
[url_latest_release]: https://github.com/lunamorrow/mda_openbabel_converter/releases
[url_latest_release]: https://github.com/MDAnalysis/mda_openbabel_converter/releases
[url_license]: https://www.gnu.org/licenses/gpl-2.0
[url_mda]: https://www.mdanalysis.org

Expand All @@ -34,6 +34,10 @@ If possible, we strongly recommend that you use
Below we provide instructions both for `conda` and
for `pip`.

### Documentation

The docs can be found [here] (https://mda-openbabel-converter.readthedocs.io/en/latest/)

#### With conda

Ensure that you have [conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) installed.
Expand Down
13 changes: 13 additions & 0 deletions docs/source/autosummary/mda_openbabel_converter.OpenBabel.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mda\_openbabel\_converter.OpenBabel
===================================

.. automodule:: mda_openbabel_converter.OpenBabel


.. rubric:: Classes

.. autosummary::

OpenBabelConverter
OpenBabelReader

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mda\_openbabel\_converter.OpenBabelParser
=========================================

.. automodule:: mda_openbabel_converter.OpenBabelParser


.. rubric:: Classes

.. autosummary::

OpenBabelParser

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mda\_openbabel\_converter.data.files
====================================

.. automodule:: mda_openbabel_converter.data.files


13 changes: 13 additions & 0 deletions docs/source/autosummary/mda_openbabel_converter.data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mda\_openbabel\_converter.data
==============================

.. automodule:: mda_openbabel_converter.data


.. rubric:: Modules

.. autosummary::
:toctree:
:recursive:

files
15 changes: 15 additions & 0 deletions docs/source/autosummary/mda_openbabel_converter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mda\_openbabel\_converter
=========================

.. automodule:: mda_openbabel_converter


.. rubric:: Modules

.. autosummary::
:toctree:
:recursive:

OpenBabel
OpenBabelParser
data
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"mdanalysis": ("https://docs.mdanalysis.org/stable/", None),
"openbabel": ("https://openbabel.org/", None),
}
58 changes: 54 additions & 4 deletions mda_openbabel_converter/OpenBabel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
"""
Documentation...
"""OpenBabel molecule I/O --- :mod:`mda_openbabel_converter.OpenBabel`
======================================================================

Read coordinates data from an
`OpenBabel <http://openbabel.org/api/3.0/classOpenBabel_1_1OBMol.shtml>`_
:class:`openbabel.openbabel.OBMol` with :class:`OpenBabelReader` into an
MDAnalysis Universe. Convert it back to a :class:`openbabel.openbabel.OBMol`
with :class:`OpenBabelConverter`.

Example
-------

To read an OpenBabel OBMol and then convert the AtomGroup back to an OpenBabel
OBMol::

>>> from openbabel import openbabel as ob
>>> import MDAnalysis as mda
>>> obconversion = ob.OBConversion()
>>> obconversion.SetInFormat("pdb")
>>> mol = ob.OBMol()
>>> obconversion.ReadFile(mol, "1crn.pdb")
>>> u = mda.Universe(mol)
>>> u
<Universe with 327 atoms>
>>> u.trajectory
<OpenBabelReader with 1 frame of 327 atoms>
>>> u.atoms.convert_to("OPENBABEL")
<openbabel.openbabel.OBMol object at 0x7fcebb958148>


.. warning::
The OpenBabel converter is currently *experimental* and may not work as
expected for all molecules.


Classes
-------

.. autoclass:: OpenBabelReader
:members:

.. autoclass:: OpenBabelConverter
:members:
"""

import MDAnalysis as mda
Expand All @@ -22,9 +63,14 @@

class OpenBabelReader(MemoryReader):
"""
Coordinate reader for OpenBabel.

Inherits from MemoryReader and converts OpenBabel OBMol Coordinates to a
MDAnalysis Trajectory which is used to build a Universe. This reader
does not work in the reverse direction.
does NOT work in the reverse direction.

See :class:`mda_openbabel_converter.OpenBabel.OpenBabelConverter` for
MDAnalysis Universe to OpenBabel OBMol conversion.
"""
format = 'OPENBABEL'

Expand Down Expand Up @@ -77,7 +123,11 @@ def __init__(self, filename: OBMol, **kwargs):

class OpenBabelConverter(ConverterBase):
"""
Convert a MDAnalysis AtomGroup to an OpenBabel OBMol
Inherits from ConverterBase and converts a MDAnalysis Universe to an
OpenBabel OBMol. This converter does NOT work in the opposite direction.

See :class:`mda_openbabel_converter.OpenBabelReader` for OpenBabel OBMol
to MDAnalysis Universe conversion.
"""
def __repr__(self, **kwargs):
"""
Expand Down
97 changes: 95 additions & 2 deletions mda_openbabel_converter/OpenBabelParser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
"""
Documentation...
OpenBabel topology parser --- :mod:`mda_openbabel_converter.OpenBabel`
======================================================================

Converts an
`OpenBabel <http://openbabel.org/api/3.0/classOpenBabel_1_1OBMol.shtml>`_
:class:`openbabel.openbabel.OBMol` into a :class:`MDAnalysis.core.Topology`.


See Also
--------
:mod:`mda_openbabel_converter.OpenBabel`


Classes
-------

.. autoclass:: OpenBabelParser
:members:
:inherited-members:

"""

import MDAnalysis as mda
Expand Down Expand Up @@ -46,9 +65,84 @@

class OpenBabelParser(TopologyReaderBase):
"""
For OpenBabel structure

Inherits from TopologyReaderBase and converts an OpenBabel OBMol to a
MDAnalysis Topology or adds it to a pre-existing Topology. This parser
does not work in the reverse direction.

For use examples, please see :class:`mda_openbabel_converter.OpenBabel`

Creates the following Attributes:
- Atomids
- Atomtypes
- Aromaticities
- Elements
- Masses
- Bonds
- Resids
- Resnums
- Segids

Depending on OpenBabel's input, the following Attributes might be present:
- Charges
- Resnames
- ICodes

Guesses the following:
- Atomnames

Missing Attributes unable to be retrieved from OpenBabel:
- Chiralities
- RSChirality
- Occupancies
- Tempfactors
- ChainIDs
- AltLocs

Attributes table:

+---------------------------------------------+-------------------------+
| OpenBabel attribute | MDAnalysis equivalent |
lunamorrow marked this conversation as resolved.
Show resolved Hide resolved
+=============================================+=========================+
| | altLocs |
+---------------------------------------------+-------------------------+
| atom.IsAromatic() | aromaticities |
+---------------------------------------------+-------------------------+
| | chainIDs |
+---------------------------------------------+-------------------------+
| atom.GetPartialCharge() | charges |
+---------------------------------------------+-------------------------+
| GetSymbol(atom.GetAtomicNum()) | elements |
+---------------------------------------------+-------------------------+
| atom.GetResidue().GetInsertionCode() | icodes |
+---------------------------------------------+-------------------------+
| atom.GetIdx() | indices |
+---------------------------------------------+-------------------------+
| atom.GetExactMass() | masses |
+---------------------------------------------+-------------------------+
| "%s%d" % (GetSymbol(atom.GetAtomicNum()), | names |
| atom.GetIdx()) | |
+---------------------------------------------+-------------------------+
| | chiralities |
+---------------------------------------------+-------------------------+
| | occupancies |
+---------------------------------------------+-------------------------+
| atom.GetResidue().GetName() | resnames |
+---------------------------------------------+-------------------------+
| atom.GetResidue().GetNum() | resnums |
+---------------------------------------------+-------------------------+
| | tempfactors |
+---------------------------------------------+-------------------------+
| atom.GetType() | types |
+---------------------------------------------+-------------------------+

Raises
------
ValueError
If only some of the atoms have ResidueInfo, from resid.GetNum(),
available

"""
format = 'OPENBABEL'

Expand Down Expand Up @@ -84,7 +178,6 @@ def parse(self, **kwargs):
ids = []
atomtypes = []
segids = []
chainids = []
icodes = []

if mol.Empty():
Expand Down
5 changes: 0 additions & 5 deletions mda_openbabel_converter/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
Global pytest fixtures
"""

# Use this file if you need to share any fixtures
# across multiple modules
# More information at
# https://docs.pytest.org/en/stable/how-to/fixtures.html#scope-sharing-fixtures-across-classes-modules-packages-or-session

import pytest
from mda_openbabel_converter.data.files import MDANALYSIS_LOGO

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Unit and regression test for the mda_openbabel_converter package.
Base tests for the mda_openbabel_converter package.
"""

# Import package, test suite, and other packages as needed
import mda_openbabel_converter
import pytest
import sys
Expand Down
6 changes: 5 additions & 1 deletion mda_openbabel_converter/tests/test_openbabel_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Testing OpenBabel and Pybel
"""
Test suite for the OpenBabel Parser that converts an OBMol's attributes to an
MDAnalysis topology, alongside the OpenBabel Reader, that can be used to
construct an MDAnalysis Universe.
"""

import MDAnalysis as mda
import openbabel
Expand Down
6 changes: 5 additions & 1 deletion mda_openbabel_converter/tests/test_openbabel_reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Testing OpenBabel and Pybel
"""
Test suite for the OpenBabel Reader that converts an OBMol's atom coordinates
to an MDAnalysis topology, alongside the OpenBabel Parser, that can be used to
construct an MDAnalysis Universe.
"""

import MDAnalysis as mda
import openbabel
Expand Down
Loading