You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/06/22 16:53:41 UTC

[airavata-django-portal] branch master updated: tutorial: updating order of output view provider steps

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git


The following commit(s) were added to refs/heads/master by this push:
     new fe4ef5f  tutorial: updating order of output view provider steps
fe4ef5f is described below

commit fe4ef5f4b92c63c3b92145019c63d258b9e333d2
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Jun 22 12:53:28 2021 -0400

    tutorial: updating order of output view provider steps
---
 docs/tutorial/custom_ui_tutorial.md | 55 ++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/docs/tutorial/custom_ui_tutorial.md b/docs/tutorial/custom_ui_tutorial.md
index c29ff77..22aa169 100644
--- a/docs/tutorial/custom_ui_tutorial.md
+++ b/docs/tutorial/custom_ui_tutorial.md
@@ -615,8 +615,10 @@ Choose from 1, 2 [1]:
    for how to prepare the values expected in the returned dictionary. Let's
    start filling in the implementation.
 
-4. First we'll add some imports at the top. Replace the existing imports with
-   these:
+4. As a final result, the output_views/gaussian_eigenvalues_view.py file should
+   have the following contents. I'll explain each part of this in the following
+   steps, but you can go ahead and copy and paste the following into
+   `gaussian_eigenvalues_view.py`:
 
 ```python
 import io
@@ -628,18 +630,14 @@ from django.conf import settings
 from matplotlib.figure import Figure
 
 from airavata_django_portal_sdk import user_storage
-```
 
-5. Now we implement the
-   [`generate_data` function](../dev/custom_output_view_provider.md#output-view-provider-interface).
-   This function should return a dictionary with values that are expected for
-   this `display_type`. For a display type of _image_, the required return
-   values are _image_ which should be a bytes array or file-like object with the
-   image bytes and _mime-type_ which should be the image's mime type. Here's the
-   `generate_data` function:
 
-```python
+class GaussianEigenvaluesViewProvider:
+    display_type = 'image'
+    name = "Gaussian Eigenvalues"
+
     def generate_data(self, request, experiment_output, experiment, output_file=None, **kwargs):
+
         # Parse output_file
         output_text = io.TextIOWrapper(output_file)
         gaussian = ccopen(output_text)
@@ -682,16 +680,11 @@ from airavata_django_portal_sdk import user_storage
             'image': image_bytes,
             'mime-type': 'image/png'
         }
-```
 
-This plots the eigenvalues of molecular orbital energies calculated by Gaussian.
-`cclib` is a Python computational chemistry library which is used to read the
-molecular orbital energies. Then `matplotlib` is used to create two plots of
-these values. Finally, the plots are exported as a PNG image that is returns as
-a buffer of bytes.
+```
 
-7. Altogether, the output_views/gaussian_eigenvalues_view.py file should have
-   the following contents:
+5. Let's take a look at the implementation. First we added some imports at the
+   top:
 
 ```python
 import io
@@ -703,14 +696,27 @@ from django.conf import settings
 from matplotlib.figure import Figure
 
 from airavata_django_portal_sdk import user_storage
+```
 
+6.  Next we implemented the
+    [`generate_data` function](../dev/custom_output_view_provider.md#output-view-provider-interface).
+    This function should return a dictionary with values that are expected for
+    this `display_type`. For a display type of _image_, the required return
+    values are _image_ which should be a bytes array or file-like object with
+    the image bytes and _mime-type_ which should be the image's mime type. There
+    implementation plots the eigenvalues of molecular orbital energies
+    calculated by Gaussian and has three parts:
 
-class GaussianEigenvaluesViewProvider:
-    display_type = 'image'
-    name = "Gaussian Eigenvalues"
+    1. Use the _cclib_ library to parse the Gaussian log file. _cclib_ is a
+       Python computational chemistry library which is used to read the
+       molecular orbital energies.
+    2. Generate a plot using _matplotlib_.
+    3. Save the plot as a PNG image into an in-memory array of bytes.
 
-    def generate_data(self, request, experiment_output, experiment, output_file=None, **kwargs):
+    Here's the `generate_data` function:
 
+```python
+    def generate_data(self, request, experiment_output, experiment, output_file=None, **kwargs):
         # Parse output_file
         output_text = io.TextIOWrapper(output_file)
         gaussian = ccopen(output_text)
@@ -753,10 +759,9 @@ class GaussianEigenvaluesViewProvider:
             'image': image_bytes,
             'mime-type': 'image/png'
         }
-
 ```
 
-8. Now we need to register our _output view provider_ with the package metadata
+7. Now we need to register our _output view provider_ with the package metadata
    so that the Django Portal will be able to discover it. The cookiecutter
    template already created this when it generated the
    gaussian_eigenvalues_view.py code. We can take a look and make sure it added