Skip to content

Commit e278a84

Browse files
authored
Merge pull request #50 from MDAnalysis/pyedr
Create the pyedr and panedr packages
2 parents 9bad58e + 91ef910 commit e278a84

32 files changed

+518
-224
lines changed

.coveragerc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[run]
22
omit =
3-
panedr/*
4-
tests/data/*
3+
pyedr/pyedr/tests/data/*
54

65
[report]
76
exclude_lines =

.github/workflows/deploy.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "package-*"
7+
push:
8+
branches:
9+
- "package-*"
10+
tags:
11+
- "package-*"
12+
release:
13+
types:
14+
- published
15+
16+
17+
concurrency:
18+
group: "${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}"
19+
cancel-in-progress: true
20+
21+
22+
defaults:
23+
run:
24+
shell: bash -l {0}
25+
26+
27+
jobs:
28+
build_wheels:
29+
environment: deploy
30+
if: "github.repository == 'MDAnalysis/panedr'"
31+
name: Build pure Python wheel
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- uses: actions/checkout@v3
36+
with:
37+
fetch-depth: 0
38+
39+
- name: setup_miniconda
40+
uses: conda-incubator/setup-miniconda@v2
41+
with:
42+
python-version: 3.8
43+
auto-update-conda: true
44+
add-pip-as-python-dependency: true
45+
architecture: x64
46+
47+
- name: install_deps
48+
run: |
49+
cd pyedr && python -m pip install build
50+
cd panedr && python -m pip install build
51+
52+
- name: build
53+
run: |
54+
cd pyedr && python -m build --sdist --wheel --outdir ../dist/
55+
cd panedr && python -m build --sdist --wheel --outdir ../dist
56+
57+
- name: publish_testpypi
58+
# Upload to testpypi on every tag
59+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
60+
uses: pypa/gh-action-pypi-publish@master
61+
with:
62+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
63+
repository_url: https://test.pypi.org/legacy/
64+
65+
- name: publish_pypi
66+
if: github.event_name == 'release' && github.event.action == 'published'
67+
uses: pypa/gh-action-pypi-publish@master
68+
with:
69+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/gh-ci.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: install package deps
4747
run: |
48-
mamba install pandas pytest pytest-xdist pytest-cov codecov pbr
48+
mamba install pytest pytest-xdist pytest-cov codecov pbr numpy
4949
5050
- name: check install
5151
run: |
@@ -54,28 +54,32 @@ jobs:
5454
conda info
5555
conda list
5656
57-
- name: install panedrlite package
57+
- name: install pyedr package
5858
run: |
5959
# installing via pip leads to codecov not being able to report coverage
60-
cd panedrlite && python setup.py develop
60+
cd pyedr && python setup.py develop
61+
62+
- name: run pyedr tests
63+
run: |
64+
pytest -n 2 -v --cov=pyedr/pyedr --cov-report=xml --color=yes pyedr/pyedr/tests
6165
6266
- name: install panedr package
6367
run: |
68+
mamba install pandas
6469
cd panedr && python setup.py develop
6570
71+
- name: run panedr tests
72+
run: |
73+
pytest -n2 -v --cov=panedr/panedr --cov-report=xml --color=yes --cov-append panedr/panedr/tests
74+
6675
- name: test imports
6776
# Exit the git repo in order for pbr to stop auto-picking up version info
6877
# from the local git data
6978
working-directory: ../
7079
run: |
71-
python -Ic "from panedrlite import edr_to_dict"
80+
python -Ic "from pyedr import edr_to_dict"
7281
python -Ic "from panedr import edr_to_df"
7382
74-
75-
- name: run unit tests
76-
run: |
77-
pytest -n 2 -v --cov=panedrlite/panedrlite --cov-report=xml --color=yes ./tests
78-
7983
- name: codecov
8084
uses: codecov/codecov-action@v3
8185
with:

MANIFEST.in

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.rst

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,131 @@
1-
Panedr
2-
======
1+
Pyedr and Panedr
2+
================
33

44
|Build Status| |cov|
55

6-
Panedr reads a `Gromacs EDR`_ binary energy XDR file and returns its content
7-
as a pandas_ dataframe. The library exposes three functions:
6+
This repository hosts the source files for both the Pyedr and Panedr packages.
87

9-
- the ``edr_to_df`` function, which gets the path to an EDR file and returns a
10-
pandas DataFrame,
8+
``pyedr`` and ``panedr`` are compatible with Python 3.6 and greater.
9+
10+
Pyedr
11+
-----
12+
13+
Pyedr provides a means of reading a `Gromacs EDR`_ binary XDR file and
14+
return its contents as a dictionary of `numpy`_ arrays. Pyedr exposes
15+
the following functions:
1116

12-
- the ``edr_to_dict`` function, which returns a dictionary of NumPy arrays instead
13-
of a pandas DataFrame
17+
- ``edr_to_dict``: returns a dictionary of NumPy arrays keyed by the energy
18+
type from a given path to an EDR file.
19+
- ``read_edr``: parses an EDR file and returns the energy terms
20+
in a nested list
1421

15-
- and the ``read_edr`` function, which is called by the other two functions to
16-
do the actual reading of EDR files. It returns a tuple of lists.
1722

18-
``panedr`` is compatible with Python 3.6 and greater.
23+
Panedr
24+
------
25+
26+
Panedr uses the Pyedr library to read a `Gromacs EDR`_ binary energy XDR file
27+
and returns its contents as a pandas_ dataframe. Panedr exposes the
28+
following function:
29+
30+
- ``edr_to_df``: which gets the path to an EDR file and returns a
31+
pandas DataFrame,
32+
1933

2034
Example
2135
-------
2236

37+
Using ``pyedr``:
38+
39+
40+
.. code:: python
41+
42+
import pyedr
43+
44+
# Read the EDR file
45+
path = 'ener.edr'
46+
dic = pyedr.edr_to_dict(path)
47+
48+
# The `verbose` optional parameter can be set to True to display the
49+
# progress on stderr
50+
dic = pyedr.edr_to_dict(path, verbose=True)
51+
52+
# Get the average pressure after the first 10 ns
53+
pressure_avg = dic['Pressure'][dic['Time'] > 10000].mean()
54+
55+
56+
Using ``panedr``:
57+
58+
2359
.. code:: python
2460
2561
import panedr
2662
2763
# Read the EDR file
2864
path = 'ener.edr'
2965
df = panedr.edr_to_df(path)
30-
dic = panedr.edr_to_dict(path)
3166
3267
# The `verbose` optional parameter can be set to True to display the
3368
# progress on stderr
3469
df = panedr.edr_to_df(path, verbose=True)
35-
dic = panedr.edr_to_dict(path, verbose=True)
3670
3771
# Get the average pressure after the first 10 ns
3872
pressure_avg = df['Pressure'][df['Time'] > 10000].mean()
39-
pressure_avg = dic['Pressure'][dic['Time'] > 10000].mean()
4073
4174
4275
Install
4376
-------
44-
Install panedr ``pip``:
77+
78+
You can install ``pyedr`` and ``panedr`` using ``pip``:
4579

4680
.. code:: bash
4781
82+
pip install pyedr
83+
84+
# installing panedr automatically installs pyedr
4885
pip install panedr
4986
5087
51-
If you are using `conda`_ and `conda-forge`_, you can install with
88+
If you are using `conda`_ and `conda-forge`_, you can install with:
5289

5390
.. code:: bash
5491
92+
conda install -c conda-forge pyedr
93+
94+
# install panedr automatically installs pyedr
5595
conda install -c conda-forge panedr
5696
97+
5798
Tests
5899
-----
59100

60-
The ``panedr`` repository contains a series of tests. If you downloaded or
61-
cloned the code from the repository, you can run the tests. To do so,
62-
install `pytest`_, and, in the directory of the
101+
The ``pyedr`` and ``panedr`` repositories contains a series of tests.
102+
If you downloaded or cloned the code from the repository, you can run
103+
the tests. To do so, install `pytest`_, and, in the directory of the
63104
panedr source code, run:
64105

106+
For ``pyedr``:
107+
108+
65109
.. code:: bash
66110
67-
pytest -v tests
111+
pytest -v pyedr/pyedr/tests
68112
69113
70-
panedrlite
71-
----------
72-
Under the hood, panedr is just a metapackage that installs panedrlite and
73-
the requirements for all functions, notably including pandas. To avoid requiring
74-
pandas in downstream applications, panedrlite is available for installation as
75-
well. It provides all functionality, except that pandas is not automatically
76-
installed as a dependency, and therefore :func:`edr_to_df` will not work
77-
out-of-the-box unless it is installed manually. `panedrlite` also uses the panedr
78-
namespace, so `import panedr` works.
114+
For ``panedr``:
79115

80116

81117
.. code:: bash
82118
83-
pip install panedrlite
119+
pytest -v panedr/panedr/tests
84120
85121
86122
License
87123
-------
88124

89-
Panedr translate in python part of the source code of Gromacs.
125+
Pyedr and Panedr translate part of the source code of Gromacs into Python.
90126
Therefore, Panedr is distributed under the same GNU Lesser General
91-
Public License version 2.1 as Gromacs.
92-
93-
Panedr — a library to manipulate Gromacs EDR file in python
94-
95-
Copyright (C) 2016 Jonathan Barnoud
96-
97-
This library is free software; you can redistribute it and/or modify
98-
it under the terms of the GNU Lesser General Public License as
99-
published by the Free Software Foundation; either version 2.1 of the
100-
License, or (at your option) any later version.
101-
102-
This library is distributed in the hope that it will be useful, but
103-
WITHOUT ANY WARRANTY; without even the implied warranty of
104-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
105-
Lesser General Public License for more details.
127+
Public License version 2.1 as Gromacs. See the `license`_ for more details.
106128

107-
You should have received a copy of the GNU Lesser General Public
108-
License along with this library; if not, write to the Free Software
109-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
110-
02110-1301 USA
111129

112130
.. |Build Status| image:: https://github.com/MDAnalysis/panedr/actions/workflows/gh-ci.yaml/badge.svg
113131
:alt: Github Actions Build Status
@@ -118,7 +136,9 @@ Public License version 2.1 as Gromacs.
118136
:target: https://codecov.io/gh/MDAnalysis/panedr
119137

120138
.. _`Gromacs EDR`: https://manual.gromacs.org/documentation/current/reference-manual/file-formats.html#edr
139+
.. _numpy: https://numpy.org/
121140
.. _pandas: https://pandas.pydata.org/
122141
.. _conda: https://docs.conda.io
123142
.. _`conda-forge`: https://conda-forge.org/
124143
.. _pytest: https://docs.pytest.org/
144+
.. _license: https://github.com/MDAnalysis/panedr/blob/master/LICENSE.txt

panedr/MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include ../README.rst ../LICENSE.txt
2+
include setup.py setup.cfg

panedr/panedr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
__version__ = pbr.version.VersionInfo('panedr').release_string()
55
del pbr
66

7-
from panedrlite import edr_to_dict, edr_to_df, read_edr
7+
from .panedr import edr_to_df

panedr/panedr/panedr.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#-*- coding:utf-8 -*-
2+
# Panedr -- a library to manipulate Gromacs EDR file in python
3+
# Copyright (C) 2016 Jonathan Barnoud
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
18+
# Boston, MA 02110-1301 USA
19+
20+
# Most of this file is a python rewrite of part of
21+
# `src/gromacs/fileio/enxio.c` from Gromacs 5.1.
22+
# See gromacs.org.
23+
24+
"""
25+
Panedr -- Read Gromacs energy file (EDR) to ``pandas.Dataframe`` in python
26+
==========================================================================
27+
28+
The ``panedr`` library allows users to read and manipulate the content of
29+
Gromacs energy file (.edr files) in python using pandas Dataframes.
30+
31+
This uses the ``pyedr`` library which tries to be in par with Gromacs 5.1.1
32+
when it comes to reading EDR files.
33+
34+
So far, only one function is exposed by the library : the :fun:`edr_to_df`
35+
function that returns a pandas ``DataFrame`` from an EDR file.
36+
37+
.. autofunction:: edr_to_df
38+
"""
39+
40+
from pyedr import edr_to_dict, read_edr
41+
import pandas as pd
42+
43+
44+
__all__ = ['edr_to_df', ]
45+
46+
47+
def edr_to_df(path: str, verbose: bool = False) -> pd.DataFrame:
48+
"""Calls :func:`read_edr` from ``pyedr`` and packs its return values into
49+
a ``pandas.DataFrame``.
50+
51+
Parameters
52+
----------
53+
path : str
54+
path to EDR file to be read
55+
verbose : bool
56+
Optionally show verbose output while reading the file
57+
Returns
58+
-------
59+
df: pandas.DataFrame
60+
:class:`pandas.DataFrame()` object that holds all energy terms found in
61+
the EDR file.
62+
"""
63+
all_energies, all_names, times = read_edr(path, verbose=verbose)
64+
df = pd.DataFrame(all_energies, columns=all_names, index=times)
65+
return df

0 commit comments

Comments
 (0)