# Polygon Geometry Analysis for Deposited B<n> Structures

This script analyzes HOOMD GSD trajectories stored in folders named `B<num_side>` such as `B3`, `B4`, and `B5`, and summarizes the projected polygon geometry of the deposited molecular structures.

It reads `sample.gsd` and `init.txt` from each folder, identifies polygon vertex indices from the molecular layout encoded in `init.txt`, computes polygon area, interior angles, and edge lengths, averages those quantities over late-time frames, and writes the results to `summary_avg_area_angles.txt`.

## Input layout

Each analyzed folder must match the pattern `B<num_side>` and contain the following files:

- `sample.gsd`: HOOMD trajectory file.
- `init.txt`: initial particle layout used to determine the polygon vertex indices.

Example directory structure:

```text
.
├── B3/
│   ├── sample.gsd
│   └── init.txt
├── B4/
│   ├── sample.gsd
│   └── init.txt
└── B5/
    ├── sample.gsd
    └── init.txt
```

## Vertex definition

For a folder `B<num_side>`, the polygon uses exactly `num_side` vertices.

The vertex list is constructed as follows:

- The first vertex is always particle index `0`.
- The remaining `num_side - 1` vertices are taken as the midpoint indices of contiguous type-2 blocks parsed from `init.txt`.

This convention is specific to the molecular architecture being analyzed, so the script checks that the number of detected type-2 blocks matches `num_side - 1` before proceeding.

## Geometry convention

Geometry is evaluated in the `y-z` plane, so the script treats the selected vertices as a 2D polygon rather than a full 3D object.

This approximation is appropriate for the present systems because the molecules are deposited and exhibit negligible out-of-plane fluctuations, making their geometry effectively two-dimensional for the purpose of this analysis.

The area is obtained from a resolved polygon path using a shoelace-based calculation, while angles and edge lengths are computed from the ordered polygon vertices.

## Frame averaging

The script ignores the first `SKIP_FRAMES` frames, then averages over the last `NUM_LAST_FRAMES` valid frames, or all remaining frames if fewer are available.

For each molecule, it stores frame-averaged values for:

- projected polygon area,
- interior angles at all vertices,
- edge lengths for all polygon edges.

It then reports the mean and standard error of the mean (SEM) across molecules, with pooled angle and edge statistics over all vertices and edges, respectively.

## Output

The script writes a tab-delimited summary file named `summary_avg_area_angles.txt`.

Each row contains:

- `num_side`
- `folder`
- `mean_area`
- `sem_area`
- `mean_angle`
- `sem_angle`
- `mean_edge`
- `sem_edge`
- `regular_area_from_mean_edge`
- `vertex_indices`

`regular_area_from_mean_edge` is a geometric reference value: the area of an ideal regular `n`-gon having the measured mean edge length.

## Requirements

The script depends on:

- Python 3
- `numpy`
- `gsd`
- `pyclipr`

Install the required Python packages in the environment used for analysis before running the script.

## Notes

- The script assumes that particles are ordered molecule-by-molecule in the trajectory and that all molecules contain the same number of particles.
- By default, `NUM_MOLECULES = 1`, but the code supports larger values if the trajectory is organized accordingly.
- The analysis is intended for deposited structures where a 2D projected polygon is a meaningful representation of the molecular shape.
