iphasimulator.build_pha

Created on Thu Jul 2 15:15:00 2026

@author: daniel

PHA polymer construction tools.

This module provides the main builder class for a PHA-specific structure database. It currently supports three stages of the AmberTools-based PHA construction workflow:

  1. Parameterise a PHA trimer from a SMILES string.

  2. Generate head, mainchain and tail prepin files from manual prepgen definition files.

  3. Build a polymer of a chosen length using tleap.

The class relies on:

PHAFileManager

Handles directory creation and path construction.

PHAResidueCodeManager

Handles residue code assignment and lookup.

External programs required:

  • OpenBabel / pybel

  • AmberTools: antechamber, parmchk2, prepgen, tleap

Classes

PHAPolymerBuilder

Main interface for building PHA structures.

Module Contents

class iphasimulator.build_pha.PHAPolymerBuilder(root_dir='structure_database')

Main interface for building PHA structures.

Parameters:

root_dir (str or pathlib.Path, optional) – Root directory of the PHA structure database.

Notes

This class coordinates chemistry-building tasks, but delegates all path handling to PHAFileManager and all residue-code handling to PHAResidueCodeManager.

paths
residue_codes
parameterise_trimer(PHA_type, trimer_name, trimer_smiles, monomer_smiles, forcefield='gaff2', charge_model='abcg2')

Parameterise a PHA trimer using AmberTools.

Parameters:
  • PHA_type (str) – PHA type name, e.g. “3HB”.

  • trimer_name (str) – Name of the trimer, e.g. “P3HB_3”.

  • trimer_smiles (str) – SMILES string for the trimer.

  • monomer_smiles (str) – SMILES string for the monomer unit. This is stored in the residue code database for the head, mainchain and tail components.

  • forcefield (str, optional) – Amber atom type set to use with antechamber.

  • charge_model (str, optional) – Charge model to use with antechamber.

Returns:

Paths to the generated trimer files and residue information.

Return type:

dict

generate_polymer_prepins(PHA_type)

Generate head, mainchain and tail prepin files for a PHA type.

Parameters:

PHA_type (str) – PHA type name, e.g. “3HB”.

Returns:

Paths to the generated prepin files and associated residue codes.

Return type:

dict

Notes

Manual prepgen definition files must already exist in:

structure_database/PHA_types/<PHA_type>/input/

For PHA_type=”3HB”, the expected files are:

head_P3HB_3.txt mainchain_P3HB_3.txt tail_P3HB_3.txt

build_PHA_polymer(PHA_type, length, forcefield='gaff2')

Build a PHA polymer using existing monomer prepin files.

Parameters:
  • PHA_type (str) – PHA type name, e.g. “3HB”.

  • length (int) – Number of repeat units in the polymer.

  • forcefield (str, optional) – Amber forcefield leaprc suffix.

Returns:

Paths to generated Amber files and sequence information.

Return type:

dict

Notes

For length 10, this constructs:

head + 8 mainchain units + tail

Required files:

hP<PHA_type>.prepin mP<PHA_type>.prepin tP<PHA_type>.prepin P<PHA_type>_3.frcmod

smiles_to_pdb(smiles, output_pdb)

Convert a SMILES string into a 3D PDB structure.

Parameters:
  • smiles (str) – Input SMILES string.

  • output_pdb (str or pathlib.Path) – Path where the generated PDB file should be written.

Returns:

Path to the generated PDB file.

Return type:

pathlib.Path

replace_pdb_residue_name(pdb_file, old_resname, new_resname)

Replace residue names in a PDB file.

Parameters:
  • pdb_file (str or pathlib.Path) – PDB file to modify.

  • old_resname (str) – Existing residue name to replace.

  • new_resname (str) – New residue name to write.

Notes

OpenBabel commonly writes generated structures using the residue name UNL. AmberTools workflows usually need this to be replaced with the assigned trimer residue code.

run_command(command, workdir=None)

Run a shell command and report its output.

Parameters:
  • command (str) – Command to execute.

  • workdir (str or pathlib.Path, optional) – Working directory in which to run the command.

Returns:

Completed subprocess result.

Return type:

subprocess.CompletedProcess

Raises:

RuntimeError – Raised if the command exits with a non-zero return code.

build_PHA_copolymer(PHA_types, length, pattern=None, sequence_mode='pattern', forcefield='gaff2', random_seed=None)

Build a PHA copolymer from existing PHA monomer-unit prepins.

Examples

Patterned AB copolymer:

build_PHA_copolymer(
    PHA_types=["3HB", "4HB"],
    length=10,
    pattern="AB",
    sequence_mode="pattern",
)

Random copolymer:

build_PHA_copolymer(
    PHA_types=["3HB", "4HB"],
    length=10,
    sequence_mode="random",
)

Output names

Patterned::

co_P3HB_P4HB_AB

Random::

co_P3HB_P4HB_rand

get_monomer_smiles(PHA_type)

Get the monomer SMILES for a PHA type from residue_codes.csv.

generate_polymer_smiles_from_sequence(monomer_smiles_sequence)

Generate a polymer SMILES string from monomer SMILES. Rule


For every monomer except the final one, remove the trailing character before joining.

Example


[“OCCCC(=O)O”, “OCCCC(=O)O”, “OCCCC(=O)O”]

becomes:

OCCCC(=O)OCCCC(=O)OCCCC(=O)O

save_polymer_smiles(polymer_name, smiles)

Save or update a polymer SMILES entry in polymer_smiles.csv.