# Linear Block Copolymer Init Generator

This repository contains a MATLAB script that generates HOOMD-blue input templates for a **linear block copolymer–type chain** designed for hierarchical folding studies.  
The output files describe a chain that can fold into polygon-like motifs and subsequently assemble into membrane-like structures on a substrate.

## What this script does

The script:

- builds a 1D chain with alternating **flexible** and **helix-forming** blocks,
- adds extra flexible buffers at both ends of the chain,
- assigns particle types for primary / secondary helix and multiple flexible subtypes,
- attaches **patchy rigid bodies** to helix sites (for helix-forming and lateral patches),
- constructs bonded connectivity with different bond types for helix and flexible segments,
- recenters the chain and defines a cubic simulation box,
- writes HOOMD-ready text files to a parameter-encoded output directory.

These output files are then read by HOOMD run scripts that perform the actual MD simulation and hierarchical folding protocol.

## Generated files

For each parameter set, the script creates a folder:

```text
Nh<N_helix>_Nf<N_flex>_B<N_repeat>/
```

and writes the following files inside:

- `init.txt`  
  Particle list for one chain (plus attached rigid-body constituents).  
  Columns: particle type id, body id, x, y, z, `sigma_monomer`, `sigma_patch_helix`, `sigma_patch_lateral`, `Lbox`.

- `init_bond.txt`  
  Bond list. Each line: bond type id, index i, index j (0‑based for HOOMD).

- `init_rigid.txt`  
  Rigid-body template for the primary helix type.  
  Each line: particle type id, x, y, z (relative to the helix core).

- `init_rigid_secondary.txt`  
  Rigid-body template for the secondary helix type.  
  Same format as `init_rigid.txt`.

- `director_helix.txt`  
  Patch director vectors for helix-forming patches.  
  Each line: patch type id, dx, dy, dz.

These files are designed to be consistent with the HOOMD scripts used later to simulate **hierarchical folding of linear block copolymer chains into polygons and membrane-like assemblies**.

## Model and types

### Particle types

The script assigns integer particle types to distinguish blocks:

- `type_helix` / `type_helix_secondary`  
  Helix-forming backbone monomers with different local environments.

- `type_flex`, `type_flex_secondary`, `type_flex_tertiary`  
  Flexible backbone monomers (e.g., interior, near-helix, and terminal segments).

Additional type ids are reserved and assigned for **patch particles** that form part of rigid bodies attached to helix sites:

- `type_patch_helix`  
  Helix-forming patches (two per helix site, opposite directions).

- `type_patch_lateral`  
  Lateral alignment patches (two variants, used for primary vs secondary rigid templates).

### Bond types

Bond type ids encode different mechanical roles:

- `type_bond_helix`  
  Bonds within helix-forming sections.

- `type_bond_flexer`  
  Flexible bonds in the first repeat block and in the terminal tail.

- `type_bond_flexer_mid`  
  Flexible bonds in later repeat blocks (if you want to treat them differently in HOOMD).

## Parameters

At the top of the script you can control:

- `N_helix` – length of each helix block,
- `N_flex` – length of each flexible block,
- `buffer_flex` – extra flexible monomers added at each end,
- `N_repeat` – number of [flex, helix] block pairs along the chain,
- `sigma_monomer` – backbone monomer diameter,
- `sigma_patch_helix`, `sigma_patch_lateral` – patch sizes,
- `mod_repeat` – spacing for labeling every *n*-th helix monomer as a secondary type.

Adjusting these parameters lets you explore different linear block copolymer architectures while keeping the downstream HOOMD run scripts unchanged.

## How to run

1. Open MATLAB in the repository directory.
2. Run the main script (for example):

```matlab
run('generate_init_files.m')
```

3. After running, you should see a folder such as:

```text
Nh5_Nf4_B2/
```

containing the HOOMD input templates.

These files can then be used as inputs to:

- the **run script** that performs MD (FENE ramp, folding, deposition, compression, assembly),
- geometry-analysis scripts that measure polygon areas, angles, edge lengths, and membrane-like domain properties.

## Repository structure (suggested)

```text
project/
├── generate_init_files.m      % this MATLAB script
├── run_hierarchical_folding.py
├── analysis/
│   ├── polygon_area_angles.py
│   ├── Nh_end_to_end_analysis.py
│   └── cluster_rg_234.py
└── README.md
```

You can adapt this layout depending on how you organize run and analysis scripts.

## Notes

- The script uses the current working directory as the base path for outputs (`base_path = pwd`), so no user-specific paths are hard-coded.
- Particle and body indices are written in 0‑based form to match HOOMD’s expectations.
- The plotting/checking code has been removed from the generation script for clarity; if you want visual inspection, it is recommended to place plotting routines in a separate `check_plot.m`.

This README focuses on the **init generator** as the first step in a larger workflow for **hierarchical folding of linear block copolymer–type chains into polygonal and membrane-like assemblies**.