Skip to content

Commit

Permalink
Add docstrings to Sphinx documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
martimunicoy committed Jul 17, 2020
1 parent 1bf8599 commit 912e8da
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
24 changes: 24 additions & 0 deletions docs/_templates/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

{% block methods %}
{% if methods %}
{% for item in methods %}
.. automethod:: {{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
96 changes: 96 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

import sphinx


# -- Project information -----------------------------------------------------

project = 'Open Force Field for PELE'
copyright = '2020, Barcelona Supercomputing Center'
author = 'Martí Municoy'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'm2r',
'sphinx.ext.napoleon', 'sphinx.ext.viewcode', ]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


def monkeypatch(cls):
""" decorator to monkey-patch methods """
def decorator(f):
method = f.__name__
old_method = getattr(cls, method)
setattr(cls, method, lambda self, *args, **kwargs: f(old_method, self, *args, **kwargs))
return decorator


# workaround until https://github.com/miyakogi/m2r/pull/55 is merged
@monkeypatch(sphinx.registry.SphinxComponentRegistry)
def add_source_parser(_old_add_source_parser, self, *args, **kwargs):
# signature is (parser: Type[Parser], **kwargs), but m2r expects
# the removed (str, parser: Type[Parser], **kwargs).
if isinstance(args[0], str):
args = args[1:]
return _old_add_source_parser(self, *args, **kwargs)


# Custom options
autosummary_generate = True
#autoclass_content = "class"
#autodoc_default_flags = ['members', 'inherited-members']
autodoc_member_order = 'bysource'
#numpydoc_class_members_toctree = False
source_suffix = ['.rst', '.md']
master_doc = 'index'

import offpele
version = offpele.__version__

pygments_style = 'sphinx'

html_theme = 'sphinx_rtd_theme'

napoleon_google_docstring = False
napoleon_use_param = False
napoleon_use_ivar = True
#html_theme = 'bootstrap'
#html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
25 changes: 25 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Open Force Field for PELE
=========================

The Open Force Field for PELE is a Python package that builds
PELE-compatible force field templates using the Open Force Field
toolkit.


User guide
----------

.. toctree::
:maxdepth: 2
:caption: Contents:


API documentation
-----------------

.. toctree::
:maxdepth: 1

topology
template
solvent
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
20 changes: 20 additions & 0 deletions docs/solvent.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _solvent ::

Solvent models
==============

This module provides different methods to parameterize solvent models
for PELE.

.. currentmodule:: offpele.solvent

Primary objects
---------------

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst

OBC1
OBC2
35 changes: 35 additions & 0 deletions docs/template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _template ::

Template handlers
=================

This module provides a toolkit to generate parameter templates for PELE.

.. currentmodule:: offpele.template

Primary objects
---------------

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst

Impact


Secondary objects
-----------------

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst

impact.WritableWrapper
impact.WritableAtom
impact.WritableBond
impact.WritableAngle
impact.WritableProper
impact.WritableImproper

44 changes: 44 additions & 0 deletions docs/topology.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. _topology ::

Topology representations
========================

This module provides different topological representations to
translate from external toolkits the different molecular parameters
for PELE.

.. currentmodule:: offpele.topology

Primary objects
---------------

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst

Molecule


Secondary objects
-----------------

.. autosummary::
:nosignatures:
:toctree: api/autogenerated
:template: class.rst

Atom
Bond
Angle
Dihedral
Proper
Improper
molecule.DummyAtom
topology.OFFDihedral
topology.OFFProper
topology.OFFImproper
ZMatrix
rotamer.Rotamer
rotamer.RotamerLibrary
rotamer.MolecularGraph

1 comment on commit 912e8da

@martimunicoy
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a first implementation of an automated API builder with Sphinx. See issue #5

Please sign in to comment.