Table Output Example

Location: examples/rappture2/table/

This example demonstrates the <table> output type. It computes energy levels for a particle in a 1D quantum box and displays them in a table.

Inputs

  • Box size (nm) – size of the 1D quantum well

  • Effective mass – electron mass relative to m0

Script

import sys
import rappture2web.rp_library as Rappture

rx = Rappture.PyXml(sys.argv[1])

# ... physics calculations ...

# Build table rows as space-separated columns
rows = []
for n in range(1, 21):
    E = n * n * h * h / (8.0 * m_kg * L * L * J2eV)
    rows.append('%s %.3g' % (label, E))

# Set table metadata and data
rx['output.table.about.label'] = 'Energy Levels'
rx['output.table.column(labels).label'] = 'Name'
rx['output.table.column(energies).label'] = 'Energy'
rx['output.table.column(energies).units'] = 'eV'
rx['output.table.data'] = '\n'.join(rows) + '\n'

rx.close()

Key concepts

  • Define columns with column(id).label and optional column(id).units.

  • Provide data as newline-separated rows with space-separated values.

  • Column order matches the order of column(...) definitions.

tool.xml

<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
  <title>table (rappture2web)</title>
  <about>Example of a Rappture &lt;table&gt; object.

Computes energy levels for a particle in a box (1D quantum well).
  </about>
  <command>python3 @tool/table.py @driver</command>
  <contract>
    <input>
      <number id="L">
        <about>
          <label>Box size</label>
          <description>Size of the 1D quantum well containing an electron</description>
        </about>
        <units>nm</units>
        <min>0.1</min>
        <default>10</default>
      </number>
      <number id="emass">
        <about>
          <label>Effective mass</label>
          <description>Mass of the electron in a crystal, relative to the normal electron mass m0.</description>
        </about>
        <min>1e-5</min>
        <default>0.067</default>
      </number>
    </input>
    <output>
      <table id="table"><about><label>Energy Levels</label><description>Particle-in-a-box energy level table.</description></about></table>
    </output>
  </contract>
</tool>
<input>
  <number id="L">
    <about>
      <label>Box size</label>
      <description>Size of the 1D quantum well containing an electron</description>
    </about>
    <units>nm</units>
    <min>0.1</min>
    <default>10</default>
  </number>
  <number id="emass">
    <about>
      <label>Effective mass</label>
      <description>Mass of the electron in a crystal, relative to the normal electron mass m0.</description>
    </about>
    <min>1e-5</min>
    <default>0.067</default>
  </number>
</input>
</run>

Running

rappture2web examples/rappture2/table/